/* ---------- tokens ---------- */
:root {
  --bg: #faf9f7;
  --bg-elev: #ffffff;
  --sidebar: #f3f2ef;
  --surface: #f0efec;
  --surface-2: #e9e7e3;
  --border: #e4e2dd;
  --border-strong: #d3d0ca;
  --text: #1d1c1a;
  --text-2: #4a4845;
  --muted: #7b7873;
  --faint: #a6a39d;
  --accent: #d4683a;
  --accent-soft: rgba(212, 104, 58, 0.12);
  --primary: #1d1c1a;
  --on-primary: #ffffff;
  --ok: #2f8f5b;
  --warn: #b7791f;
  --danger: #c2413a;
  --danger-soft: rgba(194, 65, 58, 0.1);
  --code-bg: #f5f4f1;
  --shadow-sm: 0 1px 2px rgba(20, 18, 15, 0.06);
  --shadow-md: 0 4px 14px rgba(20, 18, 15, 0.08), 0 1px 3px rgba(20, 18, 15, 0.06);
  --shadow-lg: 0 18px 50px rgba(20, 18, 15, 0.16), 0 3px 10px rgba(20, 18, 15, 0.08);
  --scrim: rgba(20, 18, 15, 0.32);
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-xl: 26px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI Variable Text", "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", Inter, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sidebar-w: 276px;
  --content-w: 768px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #1a1a19;
  --bg-elev: #242422;
  --sidebar: #151514;
  --surface: #262624;
  --surface-2: #2f2f2c;
  --border: #31302d;
  --border-strong: #45433f;
  --text: #ecebe7;
  --text-2: #c9c7c2;
  --muted: #9a978f;
  --faint: #6f6c66;
  --accent: #e8814f;
  --accent-soft: rgba(232, 129, 79, 0.16);
  --primary: #ecebe7;
  --on-primary: #1a1a19;
  --ok: #5cc08a;
  --warn: #e0a44a;
  --danger: #ef6a62;
  --danger-soft: rgba(239, 106, 98, 0.14);
  --code-bg: #1f1f1d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55), 0 4px 12px rgba(0, 0, 0, 0.35);
  --scrim: rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; height: 100%; touch-action: manipulation; }
/* Scrolling stays, scrollbars are hidden everywhere */
* { scrollbar-width: none; }
*::-webkit-scrollbar { display: none; width: 0; height: 0; }
body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent-soft); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 15px; height: 15px; }
svg.i.lg { width: 22px; height: 22px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#root { height: var(--app-h, 100dvh); }
.boot { display: grid; place-items: center; }
.boot-mark { width: 44px; height: 44px; border-radius: 12px; background: url(/icons/icon-192.png) center / cover; animation: pulse 1.4s var(--ease) infinite; }
@keyframes pulse { 50% { opacity: 0.45; transform: scale(0.94); } }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; overflow: hidden; }
.app.sidebar-collapsed { grid-template-columns: 0 1fr; }
.sidebar {
  background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  min-width: 0; overflow: hidden; padding-top: var(--safe-top); padding-left: var(--safe-left);
}
.app.sidebar-collapsed .sidebar { border-right: 0; }
.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; height: 100%; grid-column: -2; grid-row: 1; }

/* sidebar */
.sb-head { display: flex; align-items: center; gap: 8px; padding: 14px 12px 10px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font: 600 15px/1 var(--font-display); letter-spacing: -0.01em; flex: 1; min-width: 0; }
.brand-mark { width: 26px; height: 26px; border-radius: 8px; background: url(/icons/icon-192.png) center / cover; box-shadow: var(--shadow-sm); flex: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: var(--text-2);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.new-chat {
  display: flex; align-items: center; gap: 10px; margin: 2px 10px 10px; padding: 9px 12px; border-radius: 12px;
  font-weight: 550; color: var(--text); transition: background 0.15s;
}
.new-chat:hover { background: var(--surface); }
.new-chat .kbd { margin-left: auto; color: var(--faint); font-size: 12px; font-weight: 500; }
.sb-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; -webkit-overflow-scrolling: touch; }
.sb-group { margin-top: 14px; }
.sb-group-label { font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 10px 6px; }
.conv-item {
  position: relative; display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border-radius: 10px;
  text-align: left; color: var(--text-2); font-size: 14px; transition: background 0.12s;
}
.conv-item:hover { background: var(--surface); color: var(--text); }
.conv-item.active { background: var(--surface-2); color: var(--text); font-weight: 520; }
.conv-item .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .badge-agent { color: var(--muted); display: inline-flex; }
.conv-item .running-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.2s infinite; flex: none; }
.conv-item .del { opacity: 0; width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; color: var(--muted); flex: none; }
.conv-item:hover .del, .conv-item.active .del { opacity: 1; }
.conv-item .del:hover { background: var(--border); color: var(--danger); }
.sb-empty { color: var(--muted); font-size: 13.5px; padding: 18px 12px; line-height: 1.5; }
.sb-foot { border-top: 1px solid var(--border); padding: 10px 10px calc(10px + var(--safe-bottom)); display: flex; align-items: center; gap: 6px; }
.server-pill { flex: 1; display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 10px; font-size: 13px; color: var(--text-2); text-align: left; min-width: 0; }
.server-pill:hover { background: var(--surface); }
.server-pill .meta { min-width: 0; }
.server-pill .meta b { display: block; font-weight: 560; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.server-pill .meta span { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; box-shadow: 0 0 0 3px transparent; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 18%, transparent); }
.dot.wait { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.off { background: var(--danger); }

/* header */
.topbar {
  position: absolute; inset: 0 0 auto 0; z-index: 20; display: flex; align-items: center; gap: 6px;
  padding: calc(8px + var(--safe-top)) calc(12px + var(--safe-right)) 8px 12px; min-height: calc(56px + var(--safe-top));
  background: color-mix(in srgb, var(--bg) 82%, transparent); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px);
}
.topbar.scrolled { box-shadow: 0 1px 0 var(--border); }
.topbar .spacer { flex: 1; }
.model-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px 7px 12px; border-radius: 12px; font: 600 16px/1.2 var(--font-display);
  letter-spacing: -0.012em; color: var(--text); max-width: 60vw; transition: background 0.15s;
}
.model-btn:hover, .model-btn[aria-expanded="true"] { background: var(--surface); }
.model-btn .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-btn .chev { color: var(--muted); }
.seg {
  display: inline-flex; padding: 3px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); gap: 2px;
}
.seg button {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 9px; font-size: 13.5px; font-weight: 560; color: var(--muted);
  transition: background 0.18s var(--ease), color 0.18s, box-shadow 0.18s;
}
.seg button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

/* popovers & menus */
.popover {
  position: fixed; z-index: 60; min-width: 280px; max-width: min(380px, calc(100vw - 24px)); background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 6px; transform-origin: top left; animation: pop 0.16s var(--ease);
}
@keyframes pop { from { opacity: 0; transform: scale(0.97) translateY(-4px); } }
.popover .p-label { font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px 4px; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 9px 10px; border-radius: 10px; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface); outline: none; }
.menu-item .mi-text { flex: 1; min-width: 0; }
.menu-item .mi-title { display: flex; align-items: center; gap: 8px; font-weight: 560; }
.menu-item .mi-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.menu-item .check { color: var(--text); visibility: hidden; }
.menu-item[aria-checked="true"] .check { visibility: visible; }
.tag { font-size: 11px; font-weight: 600; letter-spacing: 0.01em; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.live { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.popover .divider { height: 1px; background: var(--border); margin: 6px 4px; }

/* conversation */
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-top: calc(64px + var(--safe-top)); }
.thread { max-width: var(--content-w); margin: 0 auto; padding: 8px calc(20px + var(--safe-right)) 24px calc(20px + var(--safe-left)); }
.msg { margin: 0 0 26px; animation: fadein 0.25s var(--ease); }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble {
  max-width: min(85%, 620px); background: var(--surface); border-radius: 20px 20px 6px 20px; padding: 10px 16px; white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 15.5px; line-height: 1.55;
}
.attach-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 85%; }
.file-chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px 6px 8px; border: 1px solid var(--border); background: var(--bg-elev);
  border-radius: 12px; font-size: 13px; max-width: 260px;
}
.file-chip .fi { width: 28px; height: 28px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.file-chip .fn { min-width: 0; }
.file-chip .fn b { display: block; font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fn span { display: block; color: var(--muted); font-size: 11.5px; }
.file-chip .x { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; color: var(--muted); margin-left: 2px; }
.file-chip .x:hover { background: var(--surface); color: var(--text); }

.msg.assistant { display: flex; flex-direction: column; gap: 10px; }
.msg.assistant.live { animation: none; }
.assistant-head { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12.5px; font-weight: 550; }
.assistant-head .av { width: 22px; height: 22px; border-radius: 7px; background: url(/icons/icon-192.png) center / cover; }
.status-line { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.shimmer {
  background: linear-gradient(90deg, var(--muted) 0%, var(--muted) 35%, var(--text) 50%, var(--muted) 65%, var(--muted) 100%);
  background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 1.8s linear infinite;
}
@keyframes shimmer { from { background-position: 125% 0; } to { background-position: -125% 0; } }
.typing { display: inline-flex; gap: 4px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); animation: bounce 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.15s; }
.typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-4px); opacity: 1; } }

/* thinking */
.think { border-radius: var(--radius); }
.think-head { display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; margin-left: -4px; border-radius: 8px; color: var(--muted); font-size: 14px; font-weight: 520; }
.think-head:hover { color: var(--text); background: var(--surface); }
.think-head .chev { transition: transform 0.2s var(--ease); }
.think.open .think-head .chev { transform: rotate(90deg); }
.think-body {
  display: none; margin: 6px 0 2px 7px; padding: 2px 0 2px 16px; border-left: 2px solid var(--border); color: var(--muted); font-size: 14px; line-height: 1.6;
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 420px; overflow-y: auto;
}
.think.open .think-body { display: block; }
.think-preview { margin: 4px 0 0 7px; padding-left: 16px; border-left: 2px solid var(--border); color: var(--faint); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.think.open .think-preview { display: none; }

/* tool calls */
.tool { border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); overflow: hidden; box-shadow: var(--shadow-sm); }
.tool-head { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; text-align: left; min-height: 44px; }
.tool-head:hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }
.tool-ic { width: 28px; height: 28px; border-radius: 8px; background: var(--surface); color: var(--text-2); display: grid; place-items: center; flex: none; }
.tool-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.tool-title b { font-weight: 580; font-size: 14px; white-space: nowrap; }
.tool-title code { font: 12.5px/1.4 var(--mono); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tool-state { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; flex: none; }
.tool-state .ok { color: var(--ok); }
.tool-state .err { color: var(--danger); }
.spin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: rot 0.8s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.tool .chev { color: var(--faint); transition: transform 0.2s var(--ease); }
.tool.open .tool-head .chev { transform: rotate(90deg); }
.tool-body { display: none; border-top: 1px solid var(--border); background: var(--code-bg); }
.tool.open .tool-body { display: block; }
.tool-sec { padding: 10px 12px; }
.tool-sec + .tool-sec { border-top: 1px dashed var(--border); }
.tool-sec .lbl { font-size: 11px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); margin-bottom: 6px; }
.tool-sec pre { margin: 0; font: 12.5px/1.55 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 340px; overflow: auto; color: var(--text-2); }
.tool.error { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.diff-del { background: var(--danger-soft); color: var(--danger); display: block; }
.diff-add { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); display: block; }

/* markdown */
.md { font-size: 15.5px; line-height: 1.7; overflow-wrap: anywhere; color: var(--text); }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 0.85em; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--font-display); letter-spacing: -0.015em; line-height: 1.3; margin: 1.4em 0 0.5em; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.08em; } .md h4 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 0.9em; padding-left: 1.5em; }
.md li { margin: 0.25em 0; }
.md li::marker { color: var(--muted); }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; text-decoration-thickness: 1px; }
.md blockquote { margin: 0 0 0.9em; padding: 0.1em 0 0.1em 1em; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md table { border-collapse: collapse; margin: 0 0 1em; font-size: 14px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--surface); font-weight: 600; }
.md :not(pre) > code { font: 0.88em var(--mono); background: var(--surface); border: 1px solid var(--border); padding: 0.1em 0.35em; border-radius: 6px; }
.code { margin: 0 0 1em; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); font-family: var(--mono); }
.copy-btn { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; font: 500 12px var(--font); color: var(--muted); }
.copy-btn:hover { background: var(--surface); color: var(--text); }
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; font: 13px/1.6 var(--mono); }
.code pre code.hljs { background: transparent; padding: 0; }
.cursor::after { content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -0.15em; background: var(--text); border-radius: 2px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.msg-error { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); font-size: 14px; }
.notice { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 13.5px; }
.msg-actions { display: flex; align-items: center; gap: 2px; color: var(--muted); margin-top: -2px; }
.msg-actions .icon-btn { width: 32px; height: 32px; border-radius: 8px; }
.msg-actions .stats { font-size: 12px; color: var(--faint); margin-left: 6px; font-variant-numeric: tabular-nums; }

/* empty state */
.empty { min-height: calc(var(--app-h, 100dvh) - 64px - 140px - var(--safe-top) - var(--safe-bottom)); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 24px 20px 40px; }
.empty .mark { width: 52px; height: 52px; border-radius: 15px; background: url(/icons/icon-192.png) center / cover; box-shadow: var(--shadow-md); margin-bottom: 22px; }
.empty h1 { font: 600 clamp(24px, 4.2vw, 32px)/1.2 var(--font-display); letter-spacing: -0.025em; margin: 0 0 8px; }
.empty p { color: var(--muted); margin: 0; max-width: 460px; font-size: 15px; }
.empty .ws { margin-top: 10px; font: 12.5px var(--mono); color: var(--faint); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 28px; width: 100%; max-width: 620px; }
.suggestion { text-align: left; padding: 13px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--bg-elev); transition: border-color 0.15s, background 0.15s, transform 0.15s var(--ease); }
.suggestion:hover { border-color: var(--border-strong); background: var(--surface); }
.suggestion:active { transform: scale(0.985); }
.suggestion b { display: block; font-weight: 580; font-size: 14px; }
.suggestion span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }

/* composer */
.composer-wrap { padding: 0 calc(16px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(16px + var(--safe-left)); background: linear-gradient(to bottom, transparent, var(--bg) 22px); }
.banner {
  max-width: var(--content-w); margin: 0 auto 10px; display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 14px; border-radius: 14px;
  background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow-sm); font-size: 14px;
}
.banner .txt { flex: 1; min-width: 0; }
.banner .txt b { font-weight: 600; }
.banner .txt span { color: var(--muted); }
.composer {
  max-width: var(--content-w); margin: 0 auto; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md); transition: border-color 0.15s, box-shadow 0.15s; padding: 6px;
}
.composer:focus-within { border-color: var(--border-strong); }
.composer.drag { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-md); }
.composer .files { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 6px 2px; }
.composer textarea {
  display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent; padding: 10px 12px 6px; font-size: 16px; line-height: 1.5;
  max-height: 38vh; min-height: 44px; overflow-y: hidden; scrollbar-width: none;
}
.composer textarea::-webkit-scrollbar { display: none; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer textarea::placeholder { color: var(--faint); }
.composer-bar { display: flex; align-items: center; gap: 4px; padding: 2px 2px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 11px; border-radius: 999px; font-size: 13.5px; font-weight: 550; color: var(--text-2);
  border: 1px solid var(--border); transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip:hover { background: var(--surface); color: var(--text); }
.chip.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chip .count { font-size: 11px; background: var(--surface-2); color: var(--muted); padding: 1px 6px; border-radius: 999px; }
.chip.on .count { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }
.composer-bar .round { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--text-2); border: 1px solid var(--border); }
.composer-bar .round:hover { background: var(--surface); color: var(--text); }
.composer-bar .grow { flex: 1; }
.send {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: var(--on-primary);
  transition: opacity 0.15s, transform 0.12s var(--ease);
}
.send:disabled { opacity: 0.25; }
.send:not(:disabled):active { transform: scale(0.92); }
.send .stop { width: 12px; height: 12px; border-radius: 3px; background: currentColor; }
.foot-note { text-align: center; color: var(--faint); font-size: 12px; margin-top: 8px; }

/* modal / sheet */
.scrim { position: fixed; inset: 0; z-index: 70; background: var(--scrim); display: grid; place-items: center; animation: fade 0.18s ease; padding: 20px; }
@keyframes fade { from { opacity: 0; } }
.modal {
  width: min(860px, 100%); height: min(640px, calc(100dvh - 40px)); background: var(--bg-elev); border-radius: 22px; box-shadow: var(--shadow-lg);
  display: grid; grid-template-columns: 210px 1fr; overflow: hidden; animation: rise 0.22s var(--ease); border: 1px solid var(--border);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
.modal-nav { background: var(--sidebar); border-right: 1px solid var(--border); padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; }
.modal-nav h2 { font: 600 17px var(--font-display); margin: 4px 10px 14px; letter-spacing: -0.01em; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--text-2); font-size: 14px; font-weight: 520; text-align: left; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item[aria-current="true"] { background: var(--surface-2); color: var(--text); }
.modal-body { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.modal-top { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 6px 24px; }
.modal-top h3 { font: 600 18px var(--font-display); margin: 0; letter-spacing: -0.01em; }
.modal-scroll { flex: 1; overflow-y: auto; padding: 4px 24px 24px; -webkit-overflow-scrolling: touch; }
.mobile-tabs { display: none; }
.row { display: flex; align-items: center; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.row:last-child { border-bottom: 0; }
.row .rt { flex: 1; min-width: 0; }
.row .rt b { display: block; font-weight: 560; font-size: 14.5px; }
.row .rt span { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; line-height: 1.45; }
.row.stack { flex-direction: column; align-items: stretch; gap: 10px; }
.section-label { font-size: 12px; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--faint); margin: 22px 0 2px; }
.section-label:first-child { margin-top: 8px; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); background: var(--bg); border-radius: 10px; padding: 9px 12px; font-size: 15px; outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--border-strong); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.select { appearance: none; -webkit-appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; width: auto; min-width: 170px; }
.mono { font-family: var(--mono); font-size: 13.5px; }
.switch { position: relative; width: 44px; height: 26px; border-radius: 999px; background: var(--border-strong); flex: none; transition: background 0.2s var(--ease); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.22s var(--ease); }
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"]::after { transform: translateX(18px); }
.range-wrap { display: flex; align-items: center; gap: 12px; }
.range-wrap output { min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); font-size: 14px; }
input[type="range"] { accent-color: var(--accent); width: 170px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 11px; font-weight: 560; font-size: 14px; border: 1px solid var(--border); background: var(--bg-elev); transition: background 0.15s, transform 0.12s var(--ease); }
.btn:hover { background: var(--surface); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: transparent; }
.btn.primary:hover { opacity: 0.9; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; }
.seg-wide { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface); border: 1px solid var(--border); }
.seg-wide button { padding: 6px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 550; color: var(--muted); }
.seg-wide button[aria-pressed="true"] { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.device { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.device .di { width: 36px; height: 36px; border-radius: 10px; background: var(--surface); display: grid; place-items: center; color: var(--text-2); }
.device .dt { flex: 1; min-width: 0; }
.device .dt b { font-weight: 560; display: flex; gap: 8px; align-items: center; }
.device .dt span { color: var(--muted); font-size: 12.5px; }

/* dialog (agent questions, confirmations) */
.dialog { width: min(440px, 100%); background: var(--bg-elev); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 22px; animation: rise 0.2s var(--ease); border: 1px solid var(--border); }
.dialog h3 { margin: 0 0 6px; font: 600 17px var(--font-display); }
.dialog p { margin: 0 0 14px; color: var(--text-2); font-size: 14.5px; white-space: pre-wrap; }
.dialog .opts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.dialog .opts .btn { justify-content: flex-start; height: auto; padding: 11px 14px; text-align: left; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* lock screen */
.lock { height: 100%; display: grid; place-items: center; padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom)); background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.lock-card { width: min(380px, 100%); text-align: center; }
.lock-card .mark { width: 64px; height: 64px; border-radius: 18px; background: url(/icons/icon-192.png) center / cover; margin: 0 auto 22px; box-shadow: var(--shadow-md); }
.lock-card h1 { font: 600 26px/1.2 var(--font-display); letter-spacing: -0.02em; margin: 0 0 8px; }
.lock-card p { color: var(--muted); margin: 0 0 28px; font-size: 15px; }
.pin { display: flex; gap: 12px; justify-content: center; position: relative; }
.pin .cell { width: 58px; height: 66px; border-radius: 16px; border: 1.5px solid var(--border-strong); background: var(--bg-elev); display: grid; place-items: center; font: 600 26px var(--font-display); transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s; }
.pin .cell.active { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.pin .cell.filled::after { content: ""; width: 12px; height: 12px; border-radius: 50%; background: var(--text); }
.pin input { position: absolute; inset: 0; opacity: 0; font-size: 16px; caret-color: transparent; width: 100%; }
.pin.shake { animation: shake 0.42s var(--ease); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.lock-msg { min-height: 22px; margin-top: 16px; font-size: 14px; color: var(--danger); }
.lock-msg.info { color: var(--muted); }

/* toasts */
.toasts { position: fixed; z-index: 90; left: 50%; transform: translateX(-50%); top: calc(14px + var(--safe-top)); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 24px); }
.toast { pointer-events: auto; background: var(--primary); color: var(--on-primary); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg); animation: rise 0.2s var(--ease); }
.toast.error { background: var(--danger); color: #fff; }

.scroll-down {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 100%; margin-bottom: 10px; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow-md); color: var(--text-2);
}
.composer-anchor { position: relative; }

/* ---------- mobile ---------- */
.scrim-sb { display: none; }
@media (max-width: 860px) {
  .app, .app.sidebar-collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(86vw, 320px); transform: translateX(-102%); transition: transform 0.28s var(--ease);
    box-shadow: var(--shadow-lg); border-right: 0;
  }
  .app.sidebar-open .sidebar { transform: none; }
  .app.sidebar-open .scrim-sb { display: block; position: fixed; inset: 0; z-index: 45; background: var(--scrim); animation: fade 0.2s; }
  .topbar { gap: 2px; padding-left: calc(6px + var(--safe-left)); padding-right: calc(6px + var(--safe-right)); }
  .model-btn { font-size: 15.5px; padding: 7px 4px 7px 6px; max-width: 40vw; min-width: 0; flex: 0 1 auto; }
  .topbar .spacer { min-width: 4px; }
  .seg { flex: none; }
  .seg button { padding: 6px 9px; font-size: 13px; gap: 5px; }
  .topbar .icon-btn { width: 40px; height: 40px; flex: none; }
  .seg button .lbl-long { display: none; }
  .thread { padding-left: calc(16px + var(--safe-left)); padding-right: calc(16px + var(--safe-right)); }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion:nth-child(n + 3) { display: none; }
  .foot-note { display: none; }
  .composer-wrap { padding-left: calc(10px + var(--safe-left)); padding-right: calc(10px + var(--safe-right)); padding-bottom: calc(8px + var(--safe-bottom)); }
  .keyboard-open .composer-wrap { padding-bottom: 8px; }
  .scrim { padding: 0; align-items: end; }
  .modal { width: 100%; height: calc(100% - 10px - var(--safe-top)); border-radius: 22px 22px 0 0; grid-template-columns: 1fr; animation: sheet 0.3s var(--ease); border: 0; }
  @keyframes sheet { from { transform: translateY(100%); } }
  .modal-nav { display: none; }
  .modal-top { padding: 14px 12px 4px 20px; }
  .mobile-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 6px 16px 10px; scrollbar-width: none; flex: none; }
  .mobile-tabs::-webkit-scrollbar { display: none; }
  .mobile-tabs button { flex: none; padding: 7px 13px; border-radius: 999px; border: 1px solid var(--border); font-size: 13.5px; font-weight: 550; color: var(--text-2); }
  .mobile-tabs button[aria-current="true"] { background: var(--primary); color: var(--on-primary); border-color: transparent; }
  .modal-scroll { padding: 0 20px calc(24px + var(--safe-bottom)); }
  .row { flex-wrap: wrap; }
  .select { min-width: 0; }
  input[type="range"] { width: 140px; }
  .popover { left: 12px !important; right: 12px; max-width: none; }
  .conv-item .del { opacity: 1; }
  .msg-actions .icon-btn { width: 36px; height: 36px; }
}
@media (hover: none) { .conv-item .del { opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; } }
@media (max-width: 430px) {
  .seg button svg { display: none; }
  .seg button { padding: 6px 11px; }
  .model-btn { max-width: 44vw; }
}
/* simpler mobile view, no zoom on focus (iOS zooms inputs under 16px) */
@media (max-width: 860px) {
  .input, .select, .textarea { font-size: 16px; }
  .suggestions { display: none; }
  .msg-actions .stats { display: none; }
  .empty { padding-bottom: 12vh; }
}

/* ---------- Claude-style start and type ---------- */
:root { --serif: ui-serif, "New York", "Iowan Old Style", "Charter", "Source Serif 4", Georgia, Cambria, serif; }
.empty h1.greet {
  display: flex; align-items: center; justify-content: center; gap: 14px; margin: 0;
  font: 400 clamp(30px, 4.6vw, 42px)/1.15 var(--serif); letter-spacing: -0.012em; color: var(--text);
}
.greet-mark {
  width: 0.92em; height: 0.92em; flex: none; background: var(--accent);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.9 7.2 16.8 11.1 24 12C16.8 12.9 12.9 16.8 12 24C11.1 16.8 7.2 12.9 0 12C7.2 11.1 11.1 7.2 12 0Z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 0C12.9 7.2 16.8 11.1 24 12C16.8 12.9 12.9 16.8 12 24C11.1 16.8 7.2 12.9 0 12C7.2 11.1 11.1 7.2 12 0Z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.empty .ws { margin-top: 14px; font: 13px var(--font); color: var(--muted); }
.md { font-family: var(--serif); font-size: 17px; line-height: 1.68; }
.md h1, .md h2, .md h3, .md h4 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.005em; }
.md table, .md .code, .md code { font-family: var(--mono); }
.md table { font-family: var(--font); }

@media (min-width: 861px) {
  .main.is-empty { justify-content: center; }
  .main.is-empty .scroller { flex: 0 0 auto; overflow: visible; padding-top: 0; }
  .main.is-empty .empty { min-height: 0; padding: 0 20px 30px; }
  .main.is-empty .composer-wrap { background: none; padding-bottom: 14vh; }
  .main.is-empty .foot-note { display: none; }
}
@media (max-width: 860px) {
  .md { font-size: 16.5px; }
  .empty h1.greet { font-size: 32px; }
}