:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #202421;
  background: #eef1ed;
  letter-spacing: 0;
  --surface: #fff;
  --surface-soft: #f6f7f5;
  --line: #d9ded8;
  --muted: #6b746d;
  --accent: #176c4d;
  --accent-strong: #0e533a;
  --warning: #9b5b13;
  --danger: #a43b34;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #eef1ed; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.app-shell {
  width: min(1180px, calc(100% - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(27, 38, 31, .08);
}

.topbar { height: 64px; padding: 0 20px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 6px; color: #fff; background: var(--accent); font-size: 13px; font-weight: 750; }
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 15px; }
.brand-copy span { color: var(--muted); font-size: 12px; }
.status-badge { margin-left: auto; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #aeb5af; }
.status-badge[data-state="online"] .status-dot { background: #2b966c; }
.status-badge[data-state="error"] .status-dot { background: var(--danger); }

.login-view { min-height: calc(100vh - 98px); display: grid; place-items: center; padding: 24px; }
.login-panel { width: min(440px, 100%); display: grid; gap: 18px; }
h1, h2, p { margin: 0; }
h1 { margin-top: 4px; font-size: 28px; line-height: 1.2; }
h2 { margin-top: 3px; font-size: 17px; line-height: 1.25; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 750; text-transform: uppercase; }
label { display: block; color: #525b54; font-size: 12px; font-weight: 650; }
input, textarea { width: 100%; color: #202421; background: #fff; border: 1px solid #cdd3cd; border-radius: 6px; outline: none; }
input { height: 42px; padding: 0 12px; }
textarea { padding: 10px 12px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 108, 77, .1); }
.input-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.primary-button, .send-button { border: 0; color: #fff; background: var(--accent); border-radius: 6px; font-weight: 700; }
.primary-button { padding: 0 18px; }
.primary-button:hover, .send-button:hover { background: var(--accent-strong); }
.form-error { min-height: 18px; color: var(--danger); font-size: 13px; }

.workspace { min-height: calc(100vh - 98px); display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.settings-panel { padding: 20px; display: flex; flex-direction: column; gap: 9px; background: var(--surface-soft); border-right: 1px solid var(--line); }
.settings-panel textarea { margin-bottom: 10px; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.icon-button { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 6px; color: #495149; background: #fff; font-size: 20px; }
.icon-button:hover { border-color: #aeb7af; background: #f5f7f4; }
.session-details { margin: 10px 0 0; display: grid; gap: 12px; }
.session-details div { min-width: 0; }
.session-details dt { color: var(--muted); font-size: 11px; }
.session-details dd { margin: 2px 0 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 650; }

.chat-panel { min-width: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto auto auto; height: calc(100vh - 98px); background: #fbfcfa; }
.messages { min-height: 0; overflow-y: auto; padding: 28px clamp(18px, 5vw, 64px); display: flex; flex-direction: column; gap: 12px; }
.empty-state { margin: auto; display: grid; gap: 4px; color: var(--muted); text-align: center; }
.empty-state strong { color: #454d47; font-size: 15px; }
.empty-state span { font-size: 13px; }
.message { width: fit-content; max-width: min(680px, 82%); padding: 10px 12px 7px; border: 1px solid var(--line); border-radius: 7px; background: #fff; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; font-size: 14px; }
.message[data-role="user"] { margin-left: auto; color: #fff; background: var(--accent); border-color: var(--accent); }
.message[data-role="system"] { align-self: center; padding: 5px 9px; color: var(--muted); background: #f1f3f0; border: 0; font-size: 11px; text-align: center; }
.message-time { display: block; margin-top: 4px; color: inherit; opacity: .65; font-size: 10px; text-align: right; }
.pending-bar { margin: 0 clamp(18px, 5vw, 64px) 8px; display: flex; align-items: center; gap: 8px; color: var(--warning); font-size: 12px; }
.spinner { width: 12px; height: 12px; border: 2px solid #e7cda9; border-top-color: var(--warning); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.composer { margin: 0 clamp(12px, 3vw, 36px) 14px; padding: 8px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: end; border: 1px solid #ccd2cc; border-radius: 8px; background: #fff; }
.composer textarea { min-height: 38px; max-height: 140px; padding: 9px 5px; border: 0; box-shadow: none; resize: none; }
.composer textarea:focus { box-shadow: none; }
.composer .icon-button { border: 0; }
.send-button { width: 38px; height: 38px; font-size: 20px; }
.send-button:disabled { cursor: default; opacity: .5; }
.file-chip { width: fit-content; max-width: calc(100% - 72px); margin: -7px 36px 12px auto; padding: 5px 8px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--muted); font-size: 11px; }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { border: 0; background: transparent; color: var(--muted); font-size: 17px; }

@media (max-width: 760px) {
  .app-shell { width: 100%; min-height: 100vh; margin: 0; border: 0; border-radius: 0; }
  .workspace { grid-template-columns: 1fr; }
  .settings-panel { padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .settings-panel textarea, .session-details { display: none; }
  .panel-heading { margin-bottom: 3px; }
  .chat-panel { height: calc(100vh - 236px); min-height: 440px; }
  .messages { padding: 18px 14px; }
  .message { max-width: 90%; }
  .composer { margin: 0 10px 10px; }
  .pending-bar { margin-left: 14px; }
}
