:root {
  --bg: #ffffff;
  --bg-sidebar: #f6f6f4;
  --bg-elev: #ffffff;
  --bg-soft: #f2f2ef;
  --bg-hover: #ebebe7;
  --bg-active: #e3e3de;
  --bg-user: #eef1f6;
  --bg-code: #f6f7f9;
  --border: #e3e3de;
  --border-strong: #cfcfc8;
  --text: #1c1d1f;
  --text-muted: #6b6d72;
  --text-faint: #9a9ca1;
  --accent: #2f6fdb;
  --accent-contrast: #ffffff;
  --accent-soft: #e6eefc;
  --danger: #c2392b;
  --danger-soft: #fdecea;
  --ok: #2e8b57;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 6px 24px rgba(0,0,0,.06);
  --radius: 14px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1b1e;
    --bg-sidebar: #141517;
    --bg-elev: #232428;
    --bg-soft: #26272b;
    --bg-hover: #2c2d32;
    --bg-active: #34363b;
    --bg-user: #2a2d34;
    --bg-code: #16171a;
    --border: #303136;
    --border-strong: #44464c;
    --text: #e8e8ea;
    --text-muted: #a2a4aa;
    --text-faint: #75777d;
    --accent: #6c9ef5;
    --accent-contrast: #0f1115;
    --accent-soft: #23304a;
    --danger: #ef7b6e;
    --danger-soft: #3a2224;
    --ok: #6fcf97;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1b1e;
  --bg-sidebar: #141517;
  --bg-elev: #232428;
  --bg-soft: #26272b;
  --bg-hover: #2c2d32;
  --bg-active: #34363b;
  --bg-user: #2a2d34;
  --bg-code: #16171a;
  --border: #303136;
  --border-strong: #44464c;
  --text: #e8e8ea;
  --text-muted: #a2a4aa;
  --text-faint: #75777d;
  --accent: #6c9ef5;
  --accent-contrast: #0f1115;
  --accent-soft: #23304a;
  --danger: #ef7b6e;
  --danger-soft: #3a2224;
  --ok: #6fcf97;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; }
svg:not([id^="mermaid-"]) { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app { display: grid; grid-template-columns: 272px 1fr; height: 100dvh; }

/* sidebar */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
  padding: 12px 10px;
  gap: 10px;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14.5px; letter-spacing: -.01em; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-contrast); font-size: 14px; font-weight: 700;
}
.new-chat {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--bg-elev);
  cursor: pointer; font-weight: 500; font-size: 14px;
}
.new-chat:hover { background: var(--bg-hover); }
.chat-list { overflow-y: auto; flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1px; margin: 0 -4px; padding: 0 4px; }
.chat-list-empty { color: var(--text-faint); font-size: 13px; padding: 8px 10px; }
.chat-item {
  display: flex; align-items: center; gap: 4px;
  border-radius: 8px; padding: 0 4px 0 10px; min-height: 36px;
  cursor: pointer; font-size: 14px; color: var(--text);
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); }
.chat-item-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 7px 0; }
.chat-item-actions { display: flex; opacity: 0; transition: opacity .12s; }
.chat-item:hover .chat-item-actions, .chat-item.active .chat-item-actions, .chat-item:focus-within .chat-item-actions { opacity: 1; }
.chat-item-actions .icon-btn { width: 28px; height: 28px; }
.chat-item-actions svg { width: 15px; height: 15px; }
.chat-item input {
  flex: 1; min-width: 0; font: inherit; color: var(--text);
  background: var(--bg-elev); border: 1px solid var(--accent); border-radius: 6px; padding: 4px 6px; outline: none;
}
.chat-item .streaming-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; animation: pulse 1.2s infinite; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); }
.only-mobile, .sidebar-toggle { display: none; }
.sidebar-foot { display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--border); padding: 10px 2px 0 6px; }
.user-avatar {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--bg-active); color: var(--text); font-size: 13px; font-weight: 600;
}
.user-name { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-backdrop { display: none; }

/* main */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border); min-height: 54px;
}
.topbar-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px; white-space: nowrap;
  background: var(--accent-soft); color: var(--accent); font-weight: 500;
}
.mode-badge svg { width: 14px; height: 14px; }
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}

.thread { flex: 1; overflow-y: auto; min-height: 0; }
.data-hours-notice {
  padding: 8px 16px; font-size: 13px; text-align: center;
  background: var(--danger-soft); color: var(--danger); border-bottom: 1px solid var(--border);
}
.thread-inner { max-width: 820px; margin: 0 auto; padding: 24px 20px 32px; display: flex; flex-direction: column; gap: 26px; }

/* empty state */
.empty { margin: 9vh auto 0; text-align: center; max-width: 620px; width: 100%; }
.empty h1 { font-size: 28px; font-weight: 600; letter-spacing: -.02em; margin: 0 0 8px; }
.empty p { color: var(--text-muted); margin: 0 0 28px; }
.examples { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; text-align: left; }
.example {
  border: 1px solid var(--border); background: var(--bg-elev); border-radius: 12px;
  padding: 12px 14px; cursor: pointer; font-size: 14px; line-height: 1.4; color: var(--text);
  text-align: left;
}
.example:hover { background: var(--bg-soft); border-color: var(--border-strong); }
.example small { display: block; color: var(--text-faint); font-size: 12.5px; margin-top: 3px; }

/* messages */
.msg { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.msg-user { align-items: flex-end; }
.msg-user .bubble {
  background: var(--bg-user); border-radius: 18px; padding: 10px 16px; max-width: 85%;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-assistant .content { overflow-wrap: anywhere; }
.msg .wide-scope { align-self: flex-start; }
.msg-attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.msg-user .msg-attachments { justify-content: flex-end; }

.content > :first-child { margin-top: 0; }
.content > :last-child { margin-bottom: 0; }
.content p, .content ul, .content ol, .content blockquote, .content table, .content pre { margin: 0 0 14px; }
.content h1, .content h2, .content h3, .content h4 { line-height: 1.3; margin: 22px 0 10px; letter-spacing: -.01em; }
.content h1 { font-size: 22px; } .content h2 { font-size: 19px; } .content h3 { font-size: 16.5px; } .content h4 { font-size: 15px; }
.content ul, .content ol { padding-left: 24px; }
.content li { margin: 3px 0; }
.content a { color: var(--accent); text-decoration: none; }
.content a:hover { text-decoration: underline; }
.content blockquote { border-left: 3px solid var(--border-strong); padding: 2px 0 2px 14px; color: var(--text-muted); }
.content hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.content code {
  font-family: var(--mono); font-size: .86em;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px;
}
.content code.path { color: var(--accent); background: transparent; border-color: transparent; padding: 0; }
.table-wrap { overflow-x: auto; margin: 0 0 14px; border: 1px solid var(--border); border-radius: 10px; }
.content table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 0; }
.content th, .content td { padding: 7px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.content th { background: var(--bg-soft); font-weight: 600; }
.content tr:last-child td { border-bottom: 0; }

.code-block { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 0 0 14px; background: var(--bg-code); }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px 4px 12px; font-size: 12px; color: var(--text-muted);
  border-bottom: 1px solid var(--border); background: var(--bg-soft);
}
.code-head button {
  border: 0; background: transparent; cursor: pointer; font-size: 12px; color: var(--text-muted);
  padding: 3px 8px; border-radius: 6px; display: inline-flex; gap: 5px; align-items: center;
}
.code-head button:hover { background: var(--bg-hover); color: var(--text); }
.code-head svg { width: 14px; height: 14px; }
.code-block pre { margin: 0; overflow-x: auto; }
.code-block pre code, .code-block pre code.hljs {
  display: block; padding: 12px 14px; background: transparent; border: 0; border-radius: 0;
  font-size: 13px; line-height: 1.55;
}
.mermaid-block { border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin: 0 0 14px; overflow-x: auto; background: var(--bg-elev); text-align: center; }
.mermaid-block svg { max-width: 100%; height: auto; }
.mermaid-error { color: var(--danger); font-size: 13px; text-align: left; }

/* agent progress */
.activity { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: 13.5px; min-height: 22px; }
.activity .spinner { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
.activity .label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.activity code { font-family: var(--mono); font-size: 12.5px; }
.tools { font-size: 13.5px; color: var(--text-muted); }
.tools summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 4px; border-radius: 6px; user-select: none; }
.tools summary::-webkit-details-marker { display: none; }
.tools summary:hover { background: var(--bg-soft); color: var(--text); }
.tools summary svg { width: 14px; height: 14px; transition: transform .15s; }
.tools[open] summary svg { transform: rotate(90deg); }
.tools ul { list-style: none; margin: 6px 0 2px; padding: 0 0 0 10px; border-left: 2px solid var(--border); }
.tools li { padding: 2px 0 2px 10px; overflow-wrap: anywhere; }
.tools li .tool-name { color: var(--text-faint); margin-right: 6px; }
.tools li code { font-family: var(--mono); font-size: 12.5px; color: var(--text); }

.cursor::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; margin-left: 1px; }

.error-block {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); color: var(--danger);
  border-radius: 10px; padding: 9px 12px; font-size: 14px;
}
.error-block span { flex: 1; min-width: 180px; }
.error-block button {
  border: 1px solid currentColor; background: transparent; color: inherit; border-radius: 8px; padding: 4px 12px; cursor: pointer; font-size: 13px;
}
.error-block button:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.stopped-note { color: var(--text-faint); font-size: 13px; }
.msg-model { color: var(--text-faint); font-size: 12px; font-family: var(--mono); line-height: 1.2; }

/* attachments */
.thumb {
  display: block; width: 120px; height: 90px; border-radius: 10px; overflow: hidden; padding: 0;
  border: 1px solid var(--border); background: var(--bg-soft); cursor: zoom-in;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 280px;
  border: 1px solid var(--border); background: var(--bg-elev); border-radius: 10px;
  padding: 7px 10px; font-size: 13px; color: var(--text); text-decoration: none;
}
a.file-chip:hover { background: var(--bg-soft); }
.file-chip .file-icon { width: 30px; height: 30px; border-radius: 7px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.file-chip .file-icon svg { width: 16px; height: 16px; }
.file-chip .file-meta { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.file-chip .file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.file-chip .file-size { color: var(--text-faint); font-size: 12px; }

/* composer */
.composer { padding: 6px 20px 14px; max-width: 860px; width: 100%; margin: 0 auto; }
.composer-box {
  border: 1px solid var(--border-strong); border-radius: 22px; background: var(--bg-elev);
  box-shadow: var(--shadow); padding: 8px;
}
.composer-box:focus-within { border-color: var(--accent); }
.composer-row { display: flex; align-items: center; gap: 6px; }
.composer-spacer { flex: 1; }
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: none; background: transparent; color: var(--text);
  font: 15px/1.5 var(--font); padding: 6px 8px; max-height: 220px; min-height: 36px;
}
.model-picker { position: relative; min-width: 0; }
.model-btn {
  display: inline-flex; align-items: center; gap: 4px; max-width: 240px; height: 32px; padding: 0 8px 0 12px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--bg-soft); color: var(--text-muted);
  font-size: 13px; cursor: pointer;
}
.model-btn:hover, .model-btn[aria-expanded="true"] { color: var(--text); border-color: var(--border-strong); }
.model-btn-label { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-btn svg { width: 16px; height: 16px; }
.model-menu {
  position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 20;
  width: min(340px, calc(100vw - 32px)); max-height: min(420px, 60dvh);
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.provider-select, .model-search {
  width: 100%; height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: 14px var(--font); flex: none;
}
.provider-select:focus, .model-search:focus { outline: none; border-color: var(--accent); }
.model-status { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-faint); padding: 0 4px; flex: none; }
.model-status:empty { display: none; }
.model-status .spinner { width: 13px; height: 13px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.model-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; }
.model-option {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left;
  border: 0; background: transparent; border-radius: 7px; padding: 6px 8px; cursor: pointer;
  font: 13.5px var(--mono); color: var(--text); overflow-wrap: anywhere;
}
.model-option:hover, .model-option:focus-visible { background: var(--bg-hover); outline: none; }
.model-option[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
.model-option small { font: 11.5px var(--font); color: var(--text-faint); white-space: nowrap; flex: none; }
.model-empty { color: var(--text-faint); font-size: 13px; padding: 6px 8px; }
.no-key-hint {
  border: 1px dashed var(--accent); background: var(--accent-soft); color: var(--accent);
  border-radius: 999px; padding: 4px 12px; font-size: 13px; cursor: pointer; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.composer textarea::placeholder { color: var(--text-faint); }
.send-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; cursor: pointer; flex: none;
  background: var(--text); color: var(--bg); display: grid; place-items: center;
}
.send-btn:disabled { opacity: .3; cursor: default; }
.send-btn svg { stroke-width: 2.2; }
.send-btn .icon-stop { display: none; fill: currentColor; stroke: none; }
.send-btn.stop .icon-send { display: none; }
.send-btn.stop .icon-stop { display: block; }
.composer-hint { color: var(--text-faint); font-size: 12px; text-align: center; margin-top: 7px; }
.pending-files { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 4px 8px; }
.pending { position: relative; }
.pending .thumb { width: 64px; height: 64px; cursor: default; }
.pending .file-chip { padding-right: 28px; }
.pending-remove {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--bg-elev); cursor: pointer; display: grid; place-items: center; padding: 0; color: var(--text-muted);
}
.pending-remove:hover { color: var(--danger); }
.pending-remove svg { width: 11px; height: 11px; stroke-width: 2.4; }

/* overlays */
.drop-overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent); backdrop-filter: blur(2px);
  pointer-events: none;
}
.drop-overlay div { border: 2px dashed var(--accent); border-radius: 18px; padding: 28px 40px; background: var(--bg-elev); color: var(--accent); font-weight: 600; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.82); display: grid; place-items: center; padding: 24px; cursor: zoom-out; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.lightbox-close { position: absolute; top: 12px; right: 12px; color: #fff; }
.lightbox-close:hover { background: rgba(255,255,255,.15); color: #fff; }
[hidden] { display: none !important; }

/* settings dialog */
.settings {
  width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); color: var(--text);
  box-shadow: var(--shadow);
}
.settings::backdrop { background: rgba(0,0,0,.45); }
.settings-inner { padding: 16px 20px 20px; }
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.settings-hint { color: var(--text-muted); font-size: 13.5px; margin: 6px 0 14px; }
.settings-list { display: flex; flex-direction: column; gap: 10px; }
.key-row { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.key-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.key-label { font-weight: 600; font-size: 14px; }
.key-status { font-size: 12.5px; color: var(--text-faint); white-space: nowrap; }
.key-status.ok { color: var(--ok); }
.key-form { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.key-form input {
  flex: 1 1 180px; min-width: 0; height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text); font: 14px var(--mono);
}
.key-form input:focus { outline: none; border-color: var(--accent); }
.key-note { font-size: 13px; color: var(--ok); margin-top: 6px; }
.key-note:empty { display: none; }
.key-note.error { color: var(--danger); }
.btn {
  height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg-elev); color: var(--text); cursor: pointer; font-size: 14px;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: .88; }
.btn:disabled { opacity: .5; cursor: default; }

/* login page */
.login-body { overflow: auto; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px 24px 22px;
}
.login-card .brand { margin-bottom: 18px; }
.login-card h1 { font-size: 20px; margin: 0 0 16px; font-weight: 600; letter-spacing: -.01em; }
.login-card label { display: block; font-size: 13px; color: var(--text-muted); margin: 0 0 4px; }
.login-card input {
  width: 100%; height: 40px; padding: 0 12px; margin: 0 0 12px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text); font: 15px var(--font);
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card .btn { width: 100%; height: 40px; margin-top: 4px; font-weight: 500; }
.login-error {
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); background: var(--danger-soft); color: var(--danger);
  border-radius: 9px; padding: 8px 12px; font-size: 13.5px; margin: 0 0 12px;
}
.login-foot { color: var(--text-faint); font-size: 12.5px; text-align: center; margin-top: 14px; }
.login-theme { position: fixed; top: 10px; right: 10px; }
.toasts { position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: calc(100% - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 480px; animation: fade-in .15s; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 50% { opacity: .35; } }
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } }

/* narrow screens */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow);
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.35); }
  .only-mobile, .sidebar-toggle { display: inline-grid; }
  .chat-item-actions { opacity: 1; }
}
@media (max-width: 600px) {
  body { font-size: 15px; }
  .topbar { padding: 8px 10px; gap: 6px; }
  .mode-long { display: none; }
  .thread-inner { padding: 16px 16px 24px; }
  .composer { padding: 4px 10px 10px; }
  .composer-hint { display: none; }
  .model-btn { max-width: 190px; }
  .composer-box { position: relative; }
  .model-picker { position: static; }
  .model-menu { left: 0; right: 0; width: auto; }
  .examples { grid-template-columns: 1fr; }
  .empty { margin-top: 5vh; }
  .empty h1 { font-size: 23px; }
  .msg-user .bubble { max-width: 92%; }
}

/* admin page */
.admin-body { overflow: auto; }
.admin-top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.admin-top .brand { color: var(--text); text-decoration: none; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.admin-tabs { display: flex; gap: 4px; }
.admin-tab {
  border: 0; background: transparent; cursor: pointer; padding: 6px 12px; border-radius: 8px;
  font-size: 14px; color: var(--text-muted);
}
.admin-tab:hover { background: var(--bg-hover); color: var(--text); }
.admin-tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.admin-main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 40px; }
.admin-panel { display: flex; flex-direction: column; gap: 14px; }
.admin-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.admin-toolbar input:not([type="checkbox"]), .admin-toolbar select, .field input, .field select {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--bg); color: var(--text); font: 14px var(--font); min-width: 0;
}
.admin-toolbar input:not([type="checkbox"]) { flex: 0 1 260px; }
.admin-toolbar input:focus, .admin-toolbar select:focus, .field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.admin-hint { color: var(--text-muted); font-size: 13px; }
.muted { color: var(--text-faint); font-size: 13px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }
.check small { display: block; color: var(--text-muted); font-size: 12.5px; flex-basis: 100%; }
.admin-table { border-collapse: collapse; width: 100%; font-size: 14px; }
.admin-table th, .admin-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.admin-table th { background: var(--bg-soft); font-weight: 600; white-space: nowrap; }
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tr.is-disabled td { color: var(--text-faint); }
.cell-name { font-weight: 600; white-space: nowrap; }
.cell-time { white-space: nowrap; color: var(--text-muted); }
.cell-grants { min-width: 180px; }
.cell-grants .grant { display: flex; margin: 1px 0; font-size: 13.5px; }
.cell-actions { min-width: 220px; }
.cell-actions .row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.cell-details { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; min-width: 240px; }
.status-on { color: var(--ok); white-space: nowrap; }
.status-off { color: var(--danger); white-space: nowrap; }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.tag {
  display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 999px; font-size: 11.5px; font-weight: 500;
  background: var(--bg-soft); color: var(--text-muted); border: 1px solid var(--border); white-space: nowrap; line-height: 18px;
}
.tag.prod { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.tag.off { background: var(--bg-active); }
.readonly-banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 13.5px;
  background: var(--accent-soft); color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.readonly-banner svg { color: var(--accent); margin-top: 2px; }
.connection-list { display: flex; flex-direction: column; gap: 10px; }
.connection-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; background: var(--bg-elev); display: flex; flex-direction: column; gap: 8px; }
.connection-card.is-disabled { opacity: .7; }
.connection-head { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; }
.connection-name { font-weight: 600; font-size: 15px; }
.connection-meta { display: flex; flex-direction: column; gap: 2px; color: var(--text-muted); font-size: 13px; overflow-wrap: anywhere; }
.connection-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.check-result { border-radius: 9px; padding: 8px 12px; font-size: 13.5px; background: var(--bg-soft); display: flex; flex-direction: column; gap: 4px; overflow-wrap: anywhere; }
.check-result.ok { color: var(--ok); }
.check-result.fail { background: var(--danger-soft); color: var(--danger); }
.check-result .warn { color: var(--danger); font-weight: 500; }
.connection-dialog { width: min(640px, calc(100vw - 32px)); }
.field textarea {
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-strong); resize: vertical;
  background: var(--bg); color: var(--text); font: 14px var(--font);
}
.field textarea:focus { outline: none; border-color: var(--accent); }
.finding-body {
  margin: 10px 0 0; padding: 10px 12px; border-radius: 9px; background: var(--bg-soft); max-height: 45vh; overflow: auto;
  white-space: pre-wrap; overflow-wrap: anywhere; font: 13px/1.5 var(--mono); color: var(--text);
}
.finding-link { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font: inherit; text-align: left; }
.finding-link:hover { text-decoration: underline; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 12px 0; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid .check { flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
#confirm-dialog { width: min(420px, calc(100vw - 32px)); }
.once-password { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.once-password code {
  flex: 1 1 200px; font: 15px var(--mono); padding: 8px 10px; border-radius: 8px; user-select: all;
  background: var(--bg-soft); border: 1px solid var(--border); overflow-wrap: anywhere;
}
.admin-denied { text-align: center; margin: 12vh auto; max-width: 420px; }
.admin-denied h1 { font-size: 24px; margin: 0 0 8px; }
.admin-denied p { color: var(--text-muted); margin: 0 0 18px; }
.admin-link { text-decoration: none; }
.data-list { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.settings-section { margin: 18px 0 6px; font-size: 14px; font-weight: 600; }
@media (max-width: 600px) {
  .admin-top { padding: 8px 10px; gap: 8px; }
  .admin-tabs { order: 3; width: 100%; overflow-x: auto; }
  .admin-main { padding: 12px 16px 32px; }
  .form-grid { grid-template-columns: 1fr; }
  .admin-toolbar input:not([type="checkbox"]) { flex: 1 1 100%; }
}

/* shared chats */
.shared-section { display: flex; flex-direction: column; flex: none; min-height: 0; }
.shared-list { flex: none; max-height: 34vh; }
.chat-section-title {
  display: flex; align-items: center; gap: 6px; padding: 8px 10px 4px;
  font-size: 12px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--text-faint);
}
.chat-section-title svg { width: 14px; height: 14px; }
.shared-item .shared-icon { display: grid; place-items: center; color: var(--accent); margin-right: 4px; }
.shared-item .shared-icon svg { width: 15px; height: 15px; }
.msg-author { color: var(--text-faint); font-size: 12px; line-height: 1.2; }
.msg-author .tag { font-size: 11px; }
.msg-user.msg-other { align-items: flex-start; }
.msg-user.msg-other .bubble { background: var(--bg-soft); border: 1px solid var(--border); }
.msg-user.msg-other .msg-attachments { justify-content: flex-start; }
.shared-empty { color: var(--text-muted); text-align: center; margin: 12vh auto 0; font-size: 14px; }
.topbar-title .tag { vertical-align: 1px; }
.send-mode { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 999px; padding: 2px; flex: none; }
.send-mode-option {
  border: 0; background: transparent; color: var(--text-muted); font: 500 12.5px var(--font);
  padding: 4px 10px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.send-mode-option[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.composer-hint.warn { color: var(--text-muted); }
@media (max-width: 600px) {
  .send-mode-option { padding: 4px 8px; }
}
.shared-members { display: flex; flex-wrap: wrap; gap: 6px 14px; }
