/* ==========================================================================
   analysed.ch Chat - brand: deep blue #2A6599, yellow #FFD800 (logo), lime #B0C90C
   ========================================================================== */
:root {
  --brand: #2A6599;          /* fills: buttons, highlights */
  --brand-strong: #1D4F7C;
  --brand-fg: #7DB2DE;       /* brand colour for text/icons on dark surfaces */
  --brand-soft: rgba(42, 101, 153, .20);
  --brand-ring: rgba(66, 130, 190, .55);
  --yellow: #FFD800;
  --lime: #B0C90C;
  --lime-soft: rgba(176, 201, 12, .16);
  --danger: #e5484d;
  --danger-soft: rgba(229, 72, 77, .12);
  --ok: #3dbf7a;

  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 280px;
  --thread-w: 820px;
  --font-size: 15.5px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
  --ease: cubic-bezier(.2, .7, .2, 1);
}

[data-theme="dark"] {
  --bg: #0b121b;
  --bg-grad: radial-gradient(1200px 600px at 70% -10%, rgba(42,101,153,.10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(176,201,12,.05), transparent 60%);
  --surface: #101925;
  --surface-2: #152131;
  --surface-3: #1b2a3d;
  --border: #22334a;
  --border-soft: #1a2839;
  --text: #e7eef6;
  --text-2: #b5c3d3;
  --muted: #7f93a9;
  --user-bubble: #1a2b40;
  --code-bg: #0a1018;
  --code-head: #111b27;
  --shadow: 0 10px 40px rgba(0,0,0,.45), 0 2px 8px rgba(0,0,0,.25);
  --shadow-sm: 0 2px 10px rgba(0,0,0,.25);
  --scroll: #26384f;
  color-scheme: dark;
}

[data-theme="light"] {
  --brand: #245C8D;
  --brand-strong: #1A4770;
  --brand-fg: #1F5A8C;
  --brand-soft: rgba(36, 92, 141, .12);
  --lime: #8FA50A;
  --bg: #f5f7fa;
  --bg-grad: radial-gradient(1200px 600px at 70% -10%, rgba(42,101,153,.10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(176,201,12,.08), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f1f4f8;
  --surface-3: #e7edf4;
  --border: #dbe3ec;
  --border-soft: #e8eef5;
  --text: #14202d;
  --text-2: #3a4a5c;
  --muted: #66788c;
  --user-bubble: #e5eff8;
  --code-bg: #0d1520;
  --code-head: #172231;
  --shadow: 0 12px 40px rgba(20,40,70,.14), 0 2px 8px rgba(20,40,70,.06);
  --shadow-sm: 0 2px 10px rgba(20,40,70,.07);
  --scroll: #c9d4e0;
  color-scheme: light;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 400 var(--font-size)/1.6 var(--font);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--brand-ring); outline-offset: 2px; }
kbd {
  font: 500 11px/1 var(--mono);
  padding: 3px 5px; border-radius: 5px;
  border: 1px solid var(--border); border-bottom-width: 2px;
  color: var(--muted); background: var(--surface-2);
}
[hidden] { display: none !important; }
::selection { background: var(--brand-ring); }
* { scrollbar-width: thin; scrollbar-color: var(--scroll) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--scroll); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
[data-icon] { display: inline-flex; align-items: center; justify-content: center; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); transition: background .15s, color .15s;
  flex: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.ghost-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 10px; color: var(--text-2);
  transition: background .15s, color .15s;
}
.ghost-btn:hover { background: var(--surface-3); color: var(--text); }
.ghost-btn.bordered { border: 1px solid var(--border); }
.ghost-btn.danger, .danger { color: var(--danger) !important; }
.ghost-btn.danger:hover { background: var(--danger-soft); }

/* ---------- layout ---------- */
.app { display: flex; height: 100%; height: 100dvh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px 12px 12px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-right: 1px solid var(--border-soft);
  backdrop-filter: blur(12px);
  transition: margin-left .25s var(--ease), transform .25s var(--ease);
  z-index: 30;
}
.app.sidebar-hidden .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }
.app:not(.sidebar-hidden) #open-sidebar { display: none; }

.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px 4px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand img { border-radius: 9px; box-shadow: 0 4px 14px rgba(42,101,153,.35); }
.brand-text { font-weight: 700; font-size: 19px; letter-spacing: -.02em; }
.brand-dot { color: var(--yellow); }
[data-theme="light"] .brand-dot { color: #C9A400; }

.new-chat-btn {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  color: #fff; font-weight: 600;
  box-shadow: 0 6px 18px rgba(42,101,153,.28);
  transition: transform .15s var(--ease), box-shadow .15s;
}
.new-chat-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(42,101,153,.36); }
.new-chat-btn kbd { margin-left: auto; background: rgba(255,255,255,.15); border-color: rgba(255,255,255,.2); color: rgba(255,255,255,.85); }

.search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px; height: 38px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
  color: var(--muted);
}
.search:focus-within { border-color: var(--brand); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); }
.search input::-webkit-search-cancel-button { display: none; }
.search.compact { height: 34px; flex: 1; }

.chat-list { flex: 1; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.chat-group { margin-top: 12px; }
.chat-group h4 { margin: 0 0 4px; padding: 0 10px; font-size: 11.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.chat-item {
  position: relative; display: flex; align-items: center;
  border-radius: 9px; color: var(--text-2);
}
.chat-item > button.title {
  flex: 1; min-width: 0; text-align: left;
  padding: 8px 10px; border-radius: 9px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 14px;
}
.chat-item:hover { background: var(--surface-3); color: var(--text); }
.chat-item.active { background: var(--brand-soft); color: var(--text); }
.chat-item.active::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 3px; background: var(--yellow); }
.chat-item .item-actions { display: none; gap: 2px; padding-right: 4px; }
.chat-item:hover .item-actions, .chat-item.active .item-actions { display: flex; }
.chat-item .item-actions button { width: 26px; height: 26px; border-radius: 7px; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; }
.chat-item .item-actions button:hover { color: var(--text); background: var(--surface-2); }
.chat-item .item-actions .icon { width: 15px; height: 15px; }
.chat-item input.rename { flex: 1; margin: 3px; padding: 5px 8px; border-radius: 7px; border: 1px solid var(--brand); background: var(--surface); outline: 0; font-size: 14px; }
.chat-empty { color: var(--muted); font-size: 13.5px; padding: 18px 10px; text-align: center; }

.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.privacy-card {
  display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px;
  background: var(--lime-soft); border: 1px solid color-mix(in srgb, var(--lime) 30%, transparent);
}
.privacy-card > span { color: var(--lime); margin-top: 2px; }
.privacy-card strong { display: block; font-size: 13px; }
.privacy-card small { display: block; font-size: 12px; line-height: 1.45; color: var(--text-2); }
.foot-row { display: flex; justify-content: space-between; align-items: center; }

.backdrop { display: none; }

/* ---------- main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; min-height: 58px;
  border-bottom: 1px solid transparent;
  transition: border-color .2s, background .2s;
  z-index: 10;
}
.topbar.scrolled { border-bottom-color: var(--border-soft); background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(10px); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); padding: 0 10px; }
.status i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.ok i { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.status.err i { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

/* model picker */
.model-picker { position: relative; min-width: 0; }
.model-btn {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px 7px 14px; border-radius: 11px;
  font-weight: 600; font-size: 15px; max-width: 100%;
  transition: background .15s;
}
.model-btn:hover, .model-btn[aria-expanded="true"] { background: var(--surface-3); }
.model-btn-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-btn-tags { display: flex; gap: 4px; }
.model-btn > [data-icon] { color: var(--muted); }

.model-menu {
  position: absolute; top: calc(100% + 6px); left: 0;
  width: min(440px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; max-height: min(560px, 72vh);
  animation: pop .16s var(--ease);
  z-index: 50;
}
.model-menu-head { display: flex; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border-soft); }
.model-list { overflow-y: auto; padding: 6px; }
.model-item {
  width: 100%; display: flex; align-items: flex-start; gap: 10px;
  text-align: left; padding: 9px 10px; border-radius: 10px;
}
.model-item:hover, .model-item.focused { background: var(--surface-2); }
.model-item.selected { background: var(--brand-soft); }
.model-item .mi-check { width: 18px; color: var(--brand-fg); margin-top: 2px; }
.model-item .mi-main { flex: 1; min-width: 0; }
.model-item .mi-name { font-weight: 600; font-size: 14.5px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.model-item .mi-meta { font-size: 12.5px; color: var(--muted); }
.model-menu-foot { padding: 8px 14px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border-soft); }
.model-empty { padding: 20px; text-align: center; color: var(--muted); font-size: 14px; }

.tag {
  display: inline-flex; align-items: center; gap: 3px;
  font: 600 10.5px/1 var(--font); letter-spacing: .02em;
  padding: 3px 6px; border-radius: 6px;
  background: var(--surface-3); color: var(--text-2);
}
.tag .icon { width: 11px; height: 11px; stroke-width: 2.4; }
.tag.vision { background: var(--brand-soft); color: var(--brand-fg); }
.tag.thinking { background: rgba(168,120,255,.16); color: #a98bff; }
.tag.loaded { background: var(--lime-soft); color: var(--lime); }
.tag.default { background: var(--surface-3); color: var(--muted); }

/* popover menus */
.menu-wrap { position: relative; }
.popover {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 210px;
  padding: 6px; border-radius: 12px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  animation: pop .14s var(--ease);
}
.popover button { width: 100%; display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.popover button:hover { background: var(--surface-2); }
.popover hr { border: 0; border-top: 1px solid var(--border-soft); margin: 5px 0; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }

/* ---------- thread ---------- */
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; }
.thread { max-width: var(--thread-w); margin: 0 auto; padding: 12px 20px 40px; }

.msg { display: flex; gap: 14px; padding: 14px 0; animation: fadein .25s var(--ease); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
.msg.user { justify-content: flex-end; }
.msg .avatar {
  width: 32px; height: 32px; border-radius: 10px; flex: none; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
}
.msg.assistant .avatar img { width: 32px; height: 32px; border-radius: 10px; }
.msg .body { min-width: 0; flex: 1; }
.msg.user .body { flex: 0 1 auto; max-width: 82%; display: flex; flex-direction: column; align-items: flex-end; }

.bubble {
  background: var(--user-bubble); padding: 10px 16px; border-radius: 18px 18px 6px 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-files { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.msg-images { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; }
.msg-images img { max-width: 220px; max-height: 180px; border-radius: 12px; border: 1px solid var(--border); cursor: zoom-in; object-fit: cover; }

.meta-row { display: flex; align-items: center; gap: 2px; margin-top: 6px; color: var(--muted); font-size: 12.5px; opacity: 0; transition: opacity .15s; flex-wrap: wrap; }
.msg:hover .meta-row, .msg.last .meta-row, .meta-row:focus-within { opacity: 1; }
.meta-row button { width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; }
.meta-row button:hover { background: var(--surface-3); color: var(--text); }
.meta-row .icon { width: 16px; height: 16px; }
.meta-row .stats { margin-left: 8px; font-variant-numeric: tabular-nums; }
.meta-row .stats b { font-weight: 600; color: var(--text-2); }

.edit-box { width: min(640px, 100%); display: flex; flex-direction: column; gap: 8px; }
.edit-box textarea { width: 100%; min-height: 90px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--brand); background: var(--surface); outline: 0; resize: vertical; }
.edit-box .row { display: flex; gap: 8px; justify-content: flex-end; }
.btn { padding: 7px 14px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-strong); }
.btn.secondary { background: var(--surface-3); }

/* thinking */
.thinking {
  margin: 2px 0 12px; border-left: 2px solid var(--border);
  padding-left: 14px; color: var(--muted);
}
.thinking summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  font-size: 13.5px; font-weight: 500; color: var(--muted); user-select: none;
  padding: 3px 10px 3px 8px; margin-left: -8px; border-radius: 8px;
}
.thinking summary:hover { background: var(--surface-2); color: var(--text-2); }
.thinking summary::-webkit-details-marker { display: none; }
.thinking summary .chev { transition: transform .2s; }
.thinking[open] summary .chev { transform: rotate(90deg); }
.thinking .think-body { font-size: .92em; padding: 4px 0 2px; }
.thinking .think-body > :first-child { margin-top: 4px; }
.thinking.live summary .label { background: linear-gradient(90deg, var(--muted) 20%, var(--text) 50%, var(--muted) 80%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* waiting indicator */
.waiting { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 6px 0; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--brand-fg); animation: bounce 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: .15s; background: color-mix(in srgb, var(--brand-fg) 55%, var(--yellow)); }
.dots i:nth-child(3) { animation-delay: .3s; background: var(--yellow); }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .5; } 40% { transform: scale(1); opacity: 1; } }

.error-box {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 14px; border-radius: 12px; margin-top: 6px;
  background: var(--danger-soft); color: var(--danger); font-size: 14px;
  border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent);
}
.stopped-note { font-size: 12.5px; color: var(--muted); font-style: italic; margin-top: 4px; }

/* ---------- markdown ---------- */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md table, .md pre { margin: 0 0 .9em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.3em 0 .5em; letter-spacing: -.01em; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.5em; }
.md li { margin: .25em 0; }
.md li::marker { color: var(--muted); }
.md a { color: var(--brand-fg); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--brand-fg) 40%, transparent); text-underline-offset: 2px; }
.md a:hover { text-decoration-color: var(--brand-fg); }
.md strong { font-weight: 650; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md blockquote { border-left: 3px solid var(--lime); padding: 2px 0 2px 14px; color: var(--text-2); }
.md img { max-width: 100%; border-radius: 10px; }
.md :not(pre) > code {
  font: .88em var(--mono); padding: .15em .4em; border-radius: 6px;
  background: var(--surface-3); color: color-mix(in srgb, var(--text) 80%, var(--brand-fg));
}
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; font-size: .94em; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.md th { background: var(--surface-2); font-weight: 600; }
.md tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 45%, transparent); }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }
.md .math-error { color: var(--danger); font-family: var(--mono); font-size: .9em; }

/* code blocks - always dark for contrast, clearly separated from prose */
.codeblock {
  margin: 0 0 1em; border-radius: 12px; overflow: hidden;
  background: var(--code-bg); border: 1px solid #1f2d3f;
  box-shadow: var(--shadow-sm);
}
.code-head {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 6px 6px 14px; background: var(--code-head);
  border-bottom: 1px solid #1f2d3f; color: #8fa3b8; font-size: 12.5px;
}
.code-lang { font: 600 12px var(--mono); color: #c2d3e4; text-transform: lowercase; display: inline-flex; align-items: center; gap: 7px; }
.code-lang::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--lang-color, var(--brand)); }
.code-meta { color: #6f8399; font-size: 12px; }
.code-actions { margin-left: auto; display: flex; gap: 2px; }
.code-actions button {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 9px; border-radius: 7px; color: #9fb2c6; font-size: 12.5px;
}
.code-actions button:hover { background: #1c2a3b; color: #fff; }
.code-actions button.on { color: var(--lime); }
.code-actions .icon { width: 14px; height: 14px; }
.codeblock pre { margin: 0; overflow-x: auto; }
.codeblock pre code.hljs {
  display: block; padding: 14px 16px; background: transparent;
  font: 13.5px/1.6 var(--mono); tab-size: 4; color: #e1e8f0;
}
.codeblock.wrap pre code.hljs { white-space: pre-wrap; overflow-wrap: anywhere; }

/* blinking caret while streaming */
.md.streaming > :last-child:not(.codeblock):not(ul):not(ol):not(table)::after,
.md.streaming > :is(ul, ol):last-child > li:last-child::after {
  content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 3px;
  vertical-align: text-bottom; border-radius: 2px; background: var(--brand-fg);
  animation: caret 1s steps(2) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- welcome ---------- */
.welcome {
  max-width: var(--thread-w); margin: 0 auto; padding: 8vh 20px 40px;
  text-align: center; animation: fadein .35s var(--ease);
}
.welcome-logo { border-radius: 18px; box-shadow: 0 12px 40px rgba(42,101,153,.35); }
.welcome h1 { font-size: clamp(24px, 4vw, 32px); letter-spacing: -.03em; margin: 22px 0 6px; font-weight: 700; }
.welcome h1 .grad { background: linear-gradient(90deg, var(--brand-fg), var(--lime)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.welcome-sub { color: var(--muted); margin: 0 0 30px; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; text-align: left; max-width: 680px; margin: 0 auto; }
.suggestion {
  text-align: left;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border-soft);
  transition: border-color .15s, transform .15s var(--ease), box-shadow .15s;
  display: flex; gap: 12px; align-items: flex-start;
}
.suggestion:hover { border-color: var(--brand-fg); transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.suggestion .s-icon { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--brand-soft); color: var(--brand-fg); flex: none; }
.suggestion:nth-child(2n) .s-icon { background: var(--lime-soft); color: var(--lime); }
.suggestion strong { display: block; font-size: 14.5px; font-weight: 600; }
.suggestion small { display: block; color: var(--muted); font-size: 13px; line-height: 1.45; }

/* ---------- composer ---------- */
.composer-wrap { padding: 0 20px 14px; }
.composer {
  position: relative; max-width: var(--thread-w); margin: 0 auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; box-shadow: var(--shadow);
  padding: 10px 10px 8px 16px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--brand) 70%, var(--border)); box-shadow: var(--shadow), 0 0 0 4px var(--brand-soft); }
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: 0; background: none;
  padding: 6px 4px; max-height: 40vh; min-height: 28px; line-height: 1.55;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.composer-left, .composer-right { display: flex; align-items: center; gap: 6px; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 34px; padding: 0 12px; border-radius: 17px;
  border: 1px solid var(--border); color: var(--text-2); font-size: 13.5px;
  transition: background .15s, color .15s, border-color .15s;
}
.chip-btn:hover { background: var(--surface-2); color: var(--text); }
.chip-btn .icon { width: 16px; height: 16px; }
.chip-btn.toggle.on { background: rgba(168,120,255,.14); border-color: rgba(168,120,255,.5); color: #a98bff; }
.send-btn {
  width: 38px; height: 38px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong)); color: #fff;
  transition: transform .12s, opacity .15s, background .15s;
}
.send-btn:hover:not(:disabled) { transform: scale(1.06); }
.send-btn:disabled { opacity: .35; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.ctx-meter { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ctx-meter svg { width: 18px; height: 18px; transform: rotate(-90deg); }
.ctx-meter circle { fill: none; stroke-width: 3.5; }
.ctx-meter .track { stroke: var(--surface-3); }
.ctx-meter .fill { stroke: var(--brand-fg); stroke-linecap: round; transition: stroke-dashoffset .4s; }
.ctx-meter.warn .fill { stroke: #e8a13a; }
.ctx-meter.full .fill { stroke: var(--danger); }

.attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.attachments:not(:empty) { padding: 4px 0 8px; }
.att {
  position: relative; display: flex; align-items: center; gap: 8px;
  padding: 6px 30px 6px 8px; border-radius: 11px; max-width: 240px;
  background: var(--surface-2); border: 1px solid var(--border-soft); font-size: 13px;
}
.file-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border-soft); font-size: 13px; max-width: 260px; }
.att .f-icon, .file-chip .f-icon { width: 30px; height: 30px; border-radius: 8px; background: var(--brand-soft); color: var(--brand-fg); display: flex; align-items: center; justify-content: center; flex: none; }
.att .f-name, .file-chip .f-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.att .f-size, .file-chip .f-size { color: var(--muted); font-size: 11.5px; display: block; }
.att .f-text, .file-chip .f-text { min-width: 0; }
.att img { width: 44px; height: 44px; object-fit: cover; border-radius: 7px; }
.att.img { padding: 4px 30px 4px 4px; }
.att .remove { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.att .remove:hover { background: var(--surface-3); color: var(--text); }
.att .remove .icon { width: 13px; height: 13px; }

.drop-overlay {
  position: absolute; inset: 0; border-radius: 22px;
  display: none; align-items: center; justify-content: center; gap: 10px;
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
  border: 2px dashed var(--brand-fg); color: var(--brand-fg); font-weight: 600;
}
.main.dragging .drop-overlay { display: flex; }

.disclaimer { max-width: var(--thread-w); margin: 8px auto 0; text-align: center; font-size: 12px; color: var(--muted); display: flex; gap: 6px; justify-content: center; align-items: center; }
.disclaimer .icon { width: 13px; height: 13px; color: var(--lime); }

.jump-btn {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%);
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm); color: var(--text-2);
  z-index: 5;
}
.jump-btn:hover { color: var(--text); }

/* ---------- dialog ---------- */
.dialog {
  width: min(640px, calc(100vw - 24px)); max-height: min(86vh, 900px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(5,10,16,.55); backdrop-filter: blur(3px); }
.dialog[open] { animation: pop .18s var(--ease); display: flex; }
.dialog-inner { display: flex; flex-direction: column; width: 100%; max-height: inherit; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 12px 24px; border-bottom: 1px solid var(--border-soft); }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-body { padding: 6px 24px 24px; overflow-y: auto; }
.dialog section { padding: 16px 0; border-bottom: 1px solid var(--border-soft); }
.dialog section:last-of-type { border-bottom: 0; }
.dialog h3 { margin: 0 0 6px; font-size: 14.5px; }
.hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; }
.dialog textarea, .dialog select {
  width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); outline: 0;
}
.dialog textarea { resize: vertical; font-size: 14px; line-height: 1.5; }
.dialog textarea:focus, .dialog select:focus { border-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 8px; }
.field span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 5px; }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.presets button { padding: 5px 11px; border-radius: 16px; border: 1px solid var(--border); font-size: 12.5px; color: var(--text-2); }
.presets button:hover { border-color: var(--brand); color: var(--text); }
.presets button.active { background: var(--brand-soft); border-color: var(--brand); color: var(--text); }

.switch-row { display: flex; align-items: center; gap: 12px; padding: 8px 0; cursor: pointer; font-size: 14px; }
.switch-row small { color: var(--muted); }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 38px; height: 22px; border-radius: 11px; background: var(--surface-3); flex: none; transition: background .2s; border: 1px solid var(--border); }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch-row input:checked + .switch { background: var(--brand); border-color: var(--brand); }
.switch-row input:checked + .switch::after { transform: translateX(16px); }
.switch-row input:focus-visible + .switch { outline: 2px solid var(--brand-ring); outline-offset: 2px; }

.sampling { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; padding-top: 6px; }
.sampling.disabled { opacity: .45; pointer-events: none; }
.range span { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); }
.range output { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.range input { width: 100%; accent-color: var(--brand); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 6px 0 0; font-size: 13.5px; }
.shortcuts dt { white-space: nowrap; }
.shortcuts dd { margin: 0; color: var(--text-2); }
.about { color: var(--muted); font-size: 12.5px; margin: 14px 0 0; text-align: center; }

/* ---------- toasts & lightbox ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow); animation: toast-in .2s var(--ease);
}
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(6px); transition: .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.lightbox { position: fixed; inset: 0; z-index: 120; background: rgba(5,10,16,.85); display: flex; align-items: center; justify-content: center; cursor: zoom-out; padding: 24px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: var(--shadow); }

/* ---------- responsive ---------- */
.only-mobile { display: none; }
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .only-desktop { display: none; }
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); margin-left: 0 !important; box-shadow: var(--shadow); background: var(--surface); }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(5,10,16,.5); z-index: 25; }
  #open-sidebar { display: inline-flex !important; }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion:nth-child(n+3) { display: none; }
  .status span { display: none; }
  .thread { padding: 8px 14px 30px; }
  .composer-wrap { padding: 0 10px 10px; }
  .msg .avatar { display: none; }
  .msg.user .body { max-width: 92%; }
  .hide-sm { display: none; }
  .chip-btn { padding: 0 10px; }
  .grid2, .sampling { grid-template-columns: 1fr; }
  .new-chat-btn kbd, .search kbd { display: none; }
  .meta-row { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
