/* ---------- tokens ---------- */
:root {
  --bg: #fbfbfc;
  --bg-elev: #ffffff;
  --bg-soft: #f3f3f6;
  --sidebar: #f5f5f8;
  --border: #e6e6ec;
  --border-strong: #d6d6df;
  --text: #17171c;
  --text-2: #55566a;
  --text-3: #8b8c9d;
  --hover: rgba(20, 20, 40, .055);
  --active: rgba(124, 92, 255, .10);
  --user-bubble: #f0eefc;
  --accent: #7c5cff;
  --accent-ink: #6445f0;
  --accent-2: #22c1ee;
  --danger: #e5484d;
  --ok: #22a06b;
  --warn: #e0a21b;
  --code-bg: #0e1016;
  --code-head: #181b24;
  --shadow-sm: 0 1px 2px rgba(16, 16, 32, .06);
  --shadow: 0 10px 30px -12px rgba(16, 16, 40, .18), 0 2px 6px rgba(16, 16, 40, .05);
  --shadow-lg: 0 24px 60px -20px rgba(16, 16, 48, .35);
  --composer-bg: rgba(255, 255, 255, .86);
  --radius: 14px;
  --font: "Inter", "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  --side-w: 272px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0d11;
    --bg-elev: #15161c;
    --bg-soft: #1a1b23;
    --sidebar: #101116;
    --border: #23242d;
    --border-strong: #30313c;
    --text: #ececf2;
    --text-2: #a7a8b8;
    --text-3: #6d6e80;
    --hover: rgba(255, 255, 255, .06);
    --active: rgba(124, 92, 255, .18);
    --user-bubble: #1f1d2e;
    --accent-ink: #a993ff;
    --code-head: #161922;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 12px 32px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
    --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
    --composer-bg: rgba(21, 22, 28, .86);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c0d11;
  --bg-elev: #15161c;
  --bg-soft: #1a1b23;
  --sidebar: #101116;
  --border: #23242d;
  --border-strong: #30313c;
  --text: #ececf2;
  --text-2: #a7a8b8;
  --text-3: #6d6e80;
  --hover: rgba(255, 255, 255, .06);
  --active: rgba(124, 92, 255, .18);
  --user-bubble: #1f1d2e;
  --accent-ink: #a993ff;
  --code-head: #161922;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 12px 32px -12px rgba(0, 0, 0, .6), 0 2px 6px rgba(0, 0, 0, .3);
  --shadow-lg: 0 24px 60px -20px rgba(0, 0, 0, .8);
  --composer-bg: rgba(21, 22, 28, .86);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: var(--accent-ink); }
kbd { font: 500 11px var(--font); color: var(--text-3); }
hr { border: 0; border-top: 1px solid var(--border); margin: 20px 0; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }
::selection { background: rgba(124, 92, 255, .28); }

.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.i.sm { width: 16px; height: 16px; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 10px;
  color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--bg-elev);
  font-weight: 500; font-size: 14px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, #8b6cff, #6a4bff); border-color: transparent; color: #fff; box-shadow: 0 6px 18px -8px rgba(124, 92, 255, .8); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn.block { width: 100%; height: 44px; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { color: var(--accent-ink); font-size: 13px; font-weight: 500; }
.link-btn:hover { text-decoration: underline; }

/* ---------- brand ---------- */
.brand-mark {
  display: inline-grid; place-items: center;
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(135deg, #a78bfa, #7c5cff 55%, #22c1ee);
  box-shadow: 0 6px 16px -6px rgba(124, 92, 255, .7), inset 0 1px 0 rgba(255, 255, 255, .25);
}
.brand-mark svg { width: 60%; height: 60%; fill: #fff; }
.brand-mark.lg { width: 56px; height: 56px; border-radius: 16px; }

/* ---------- login ---------- */
.login { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; overflow: hidden; }
.login-glow {
  position: absolute; inset: -20%;
  background:
    radial-gradient(40% 35% at 30% 30%, rgba(124, 92, 255, .28), transparent 70%),
    radial-gradient(35% 30% at 75% 70%, rgba(34, 193, 238, .22), transparent 70%);
  filter: blur(20px);
  animation: drift 14s ease-in-out infinite alternate;
}
@keyframes drift { to { transform: translate(3%, -2%) scale(1.05); } }
.login-card {
  position: relative; width: min(400px, 100%);
  padding: 36px 32px 32px; border-radius: 22px;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(16px);
  text-align: center;
}
.login-card h1 { margin: 16px 0 4px; font-size: 26px; letter-spacing: -.02em; }
.login-card > .muted { margin: 0 0 24px; font-size: 14px; }
.login-card .field { text-align: left; }

/* ---------- form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field input, .field textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--bg);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(124, 92, 255, .18); }
.form-error { color: var(--danger); font-size: 13px; margin: -6px 0 14px; text-align: left; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.range-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.range-row input[type=range] { flex: 1; min-width: 160px; accent-color: var(--accent); }
.row-end { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row-between p { margin: 2px 0 0; }

.segmented { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--bg-soft); border: 1px solid var(--border); align-self: flex-start; }
.segmented button { padding: 6px 14px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.segmented button.active { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; height: 100dvh; transition: grid-template-columns .22s ease; }
.app.collapsed { grid-template-columns: 0 1fr; }
.app.collapsed .sidebar { visibility: hidden; opacity: 0; }

/* ---------- sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
  background: var(--sidebar); border-right: 1px solid var(--border);
  padding: 12px 10px; transition: opacity .2s, visibility .2s;
}
.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 10px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.new-chat {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: 12px;
  background: var(--bg-elev); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm); font-weight: 500; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.new-chat:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); box-shadow: 0 0 0 3px rgba(124, 92, 255, .1); }
.new-chat kbd { margin-left: auto; }
.side-search {
  display: flex; align-items: center; gap: 8px; margin: 10px 0 6px;
  padding: 0 10px; height: 36px; border-radius: 10px; color: var(--text-3);
  background: var(--hover);
}
.side-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 14px; }
.side-search:focus-within { box-shadow: 0 0 0 2px rgba(124, 92, 255, .35); }

.chat-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; }
.chat-group { margin-top: 14px; }
.chat-group h3 { margin: 0 0 4px; padding: 0 10px; font-size: 11.5px; font-weight: 600; color: var(--text-3); letter-spacing: .02em; }
.chat-item {
  position: relative; display: flex; align-items: center;
  border-radius: 10px; color: var(--text-2);
}
.chat-item a {
  flex: 1; min-width: 0; padding: 8px 10px; font-size: 14px;
  color: inherit; text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item:hover { background: var(--hover); color: var(--text); }
.chat-item.active { background: var(--active); color: var(--text); }
.chat-item.active a { font-weight: 500; }
.chat-item .item-actions { display: none; gap: 2px; padding-right: 4px; }
.chat-item:hover .item-actions, .chat-item.confirming .item-actions, .chat-item.active .item-actions { display: flex; }
.chat-item:hover a, .chat-item.active a { -webkit-mask-image: linear-gradient(90deg, #000 75%, transparent); mask-image: linear-gradient(90deg, #000 75%, transparent); }
.item-actions button { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; color: var(--text-3); }
.item-actions button:hover { background: var(--hover); color: var(--text); }
.item-actions .confirm-del { width: auto; padding: 0 8px; font-size: 12px; font-weight: 600; color: #fff; background: var(--danger); }
.item-actions .confirm-del:hover { background: var(--danger); color: #fff; filter: brightness(1.1); }
.chat-item input { flex: 1; min-width: 0; margin: 3px; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--accent); background: var(--bg-elev); outline: none; font-size: 14px; }
.chat-empty { padding: 24px 12px; text-align: center; color: var(--text-3); font-size: 13px; }
.spinner-dot { display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1s ease-in-out infinite; vertical-align: middle; }

.side-foot { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 8px; }
.side-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 10px; font-size: 14px; color: var(--text-2); }
.side-item:hover { background: var(--hover); color: var(--text); }
.status-dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.status-dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.status-dot.bad { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent); }
.backdrop { display: none; }

/* ---------- main ---------- */
.main { position: relative; display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 6px;
  height: 56px; padding: 0 12px; flex: none;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
}
.topbar.scrolled { border-bottom-color: var(--border); }
#menuBtn { display: none; }
.app.collapsed #menuBtn { display: inline-grid; }
.chat-title { flex: 1; min-width: 0; text-align: center; font-size: 14px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; }

/* model picker */
.model-picker { position: relative; }
.model-btn {
  display: flex; align-items: center; gap: 8px; max-width: 46vw;
  height: 38px; padding: 0 10px 0 6px; border-radius: 11px;
  font-weight: 600; font-size: 15px; color: var(--text);
  transition: background .15s;
}
.model-btn:hover, .model-btn[aria-expanded=true] { background: var(--hover); }
.model-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-btn .i { color: var(--text-3); }
.model-avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--brand, var(--accent)); color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .25);
}
.model-avatar svg { width: 58%; height: 58%; fill: currentColor; }

.popover {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg);
  animation: pop .14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.model-menu { width: min(380px, calc(100vw - 24px)); display: flex; flex-direction: column; max-height: min(520px, 70vh); }
.pop-search { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); color: var(--text-3); }
.pop-search input { flex: 1; border: 0; outline: 0; background: transparent; font-size: 14px; color: var(--text); }
.model-list { overflow-y: auto; padding: 6px; scrollbar-width: thin; }
.model-group h4 { margin: 8px 8px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-3); letter-spacing: .02em; }
.model-opt {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 8px; border-radius: 10px; font-size: 14px;
}
.model-opt:hover, .model-opt.kb { background: var(--hover); }
.model-opt.selected { background: var(--active); }
.model-opt .model-avatar { width: 28px; height: 28px; }
.model-opt .mo-text { flex: 1; min-width: 0; }
.model-opt .mo-name { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-opt .mo-id { display: block; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }
.model-opt .check-ic { color: var(--accent-ink); }
.pop-foot { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; border-top: 1px solid var(--border); font-size: 12px; }
.model-empty { padding: 28px 16px; text-align: center; font-size: 14px; color: var(--text-3); }

/* ---------- thread ---------- */
.thread { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; padding: 8px 16px 24px; scrollbar-gutter: stable; }
.thread-inner { max-width: 780px; margin: 0 auto; }

.empty { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px 0 40px; }
.empty .brand-mark.lg { margin-bottom: 20px; animation: float 6s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-6px); } }
.empty h1 {
  margin: 0; font-size: clamp(26px, 4vw, 34px); letter-spacing: -.025em; font-weight: 700;
  background: linear-gradient(90deg, var(--text) 20%, var(--accent-ink) 60%, var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.empty .sub { margin: 8px 0 28px; color: var(--text-3); }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; width: min(640px, 100%); }
.suggestion {
  display: flex; flex-direction: column; gap: 2px; text-align: left;
  padding: 14px 16px; border-radius: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.suggestion:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); transform: translateY(-1px); box-shadow: var(--shadow); }
.suggestion b { font-size: 14px; font-weight: 600; }
.suggestion span { font-size: 13px; color: var(--text-3); }
.notice {
  display: flex; align-items: center; gap: 10px; margin-bottom: 20px; padding: 10px 14px;
  border-radius: 12px; font-size: 14px; text-align: left;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
}
.notice button { margin-left: auto; white-space: nowrap; }

/* messages */
.msg { padding: 14px 0; animation: msgIn .25s ease-out; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .bubble {
  max-width: min(85%, 640px); padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  background: var(--user-bubble); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.user .att-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-bottom: 6px; max-width: 85%; }
.msg.user .att-row img { max-width: 220px; max-height: 220px; border-radius: 14px; border: 1px solid var(--border); object-fit: cover; cursor: zoom-in; }
.file-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 10px;
  background: var(--bg-soft); border: 1px solid var(--border); font-size: 13px; max-width: 260px;
}
.file-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.msg.assistant { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 14px; }
.msg.assistant .model-avatar { width: 30px; height: 30px; border-radius: 9px; margin-top: 2px; }
.msg-head { font-size: 13px; font-weight: 600; color: var(--text-2); margin: 3px 0 4px; display: flex; align-items: center; gap: 8px; }
.msg-head .muted { font-weight: 400; }

.msg-actions { display: flex; gap: 2px; margin-top: 6px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions, .msg.last .msg-actions { opacity: 1; }
.msg-actions button { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; color: var(--text-3); }
.msg-actions button:hover { background: var(--hover); color: var(--text); }
.msg-actions .i { width: 16px; height: 16px; }

.msg-error {
  margin-top: 8px; padding: 10px 14px; border-radius: 12px; font-size: 14px;
  color: var(--danger); background: color-mix(in srgb, var(--danger) 9%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 28%, transparent);
  overflow-wrap: anywhere;
}
.msg-stopped { margin-top: 6px; font-size: 13px; color: var(--text-3); font-style: italic; }

.edit-box { width: min(85%, 640px); }
.edit-box textarea { width: 100%; min-height: 90px; padding: 12px 14px; border-radius: 16px; border: 1px solid var(--accent); background: var(--bg-elev); outline: none; resize: vertical; box-shadow: 0 0 0 3px rgba(124, 92, 255, .15); }
.edit-box .row-end { margin-top: 8px; }

/* thinking */
.think { margin: 2px 0 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-soft); font-size: 14px; }
.think summary { display: flex; align-items: center; gap: 8px; padding: 8px 12px; cursor: pointer; color: var(--text-2); list-style: none; user-select: none; }
.think summary::-webkit-details-marker { display: none; }
.think summary .i { width: 15px; height: 15px; transition: transform .2s; }
.think[open] summary .i { transform: rotate(90deg); }
.think .think-body { padding: 0 14px 12px; color: var(--text-3); white-space: pre-wrap; max-height: 320px; overflow-y: auto; }
.think.live summary b { background: linear-gradient(90deg, var(--text-3), var(--text), var(--text-3)); 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; } }

/* typing indicator */
.typing { display: inline-flex; gap: 5px; padding: 10px 2px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: pulse 1.2s ease-in-out infinite; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .3; transform: scale(.85); } 40% { opacity: 1; transform: scale(1); } }

/* markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .85em; }
.md h1, .md h2, .md h3, .md h4 { margin: 1.3em 0 .55em; line-height: 1.35; 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 { margin: 0 0 .85em; padding-left: 1.5em; }
.md li { margin: .25em 0; }
.md li::marker { color: var(--text-3); }
.md blockquote { margin: 0 0 .85em; padding: 2px 16px; border-left: 3px solid var(--accent); color: var(--text-2); background: var(--bg-soft); border-radius: 0 10px 10px 0; }
.md a { text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); }
.md a:hover { border-bottom-color: var(--accent); }
.md hr { margin: 1.4em 0; }
.md img { max-width: 100%; border-radius: 12px; }
.md :not(pre) > code {
  font: .88em var(--mono); padding: .12em .4em; border-radius: 6px;
  background: var(--bg-soft); border: 1px solid var(--border);
}
.md table { display: block; overflow-x: auto; border-collapse: collapse; margin: 0 0 1em; font-size: 14px; max-width: 100%; }
.md th, .md td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.md th { background: var(--bg-soft); font-weight: 600; }
.codeblock { margin: 0 0 1em; border-radius: 12px; overflow: hidden; background: var(--code-bg); border: 1px solid #1f2330; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; background: var(--code-head); color: #9aa0b4; font: 12px var(--mono); }
.copy-code { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 7px; color: #9aa0b4; font: 500 12px var(--font); }
.copy-code:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.copy-code .i { width: 14px; height: 14px; }
.codeblock pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.codeblock code { font: 13.5px/1.6 var(--mono); color: #e6e8ef; background: none !important; padding: 0 !important; }
.md .cursor::after { content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -.15em; border-radius: 2px; background: var(--accent); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- composer ---------- */
.composer-wrap { flex: none; padding: 0 16px calc(10px + env(safe-area-inset-bottom)); }
.composer {
  max-width: 780px; margin: 0 auto;
  border-radius: 22px; border: 1px solid var(--border-strong);
  background: var(--composer-bg); backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border-strong)); box-shadow: var(--shadow), 0 0 0 4px rgba(124, 92, 255, .12); }
.composer textarea {
  display: block; width: 100%; max-height: 40vh; min-height: 52px;
  padding: 15px 18px 4px; border: 0; outline: 0; resize: none; background: transparent;
  font-size: 15.5px; line-height: 1.55;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 8px; }
.composer-hint { flex: 1; font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send-btn {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 12px;
  background: linear-gradient(135deg, #8b6cff, #6a4bff); color: #fff;
  box-shadow: 0 6px 16px -6px rgba(124, 92, 255, .9);
  transition: transform .1s, opacity .15s, filter .15s;
}
.send-btn:hover:not(:disabled) { filter: brightness(1.1); }
.send-btn:active:not(:disabled) { transform: scale(.94); }
.send-btn:disabled { opacity: .35; box-shadow: none; cursor: default; }
.send-btn .i { stroke-width: 2.2; }
.send-btn .stop-icon { display: none; }
.composer.busy .send-btn { background: var(--text); color: var(--bg); box-shadow: none; opacity: 1; }
.composer.busy .send-icon { display: none; }
.composer.busy .stop-icon { display: block; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 14px 0; }
.att { position: relative; }
.att img { display: block; width: 64px; height: 64px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
.att .file-chip { height: 64px; }
.att-x {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; background: var(--text); color: var(--bg); box-shadow: var(--shadow-sm);
}
.att-x .i { width: 12px; height: 12px; stroke-width: 2.6; }
.disclaimer { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--text-3); }

.to-bottom {
  position: absolute; left: 50%; bottom: 150px; transform: translateX(-50%); z-index: 5;
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg-elev); border: 1px solid var(--border-strong); box-shadow: var(--shadow); color: var(--text-2);
}
.to-bottom:hover { color: var(--text); }
.drop-zone {
  position: absolute; inset: 12px; z-index: 40; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(4px);
  font-size: 18px; font-weight: 600; color: var(--accent-ink); pointer-events: none;
}

/* ---------- dialog ---------- */
.dialog {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 20px;
  background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-lg);
}
.dialog[open] { animation: pop .16s ease-out; }
.dialog::backdrop { background: rgba(8, 8, 16, .5); backdrop-filter: blur(3px); }
.dialog-inner { display: flex; flex-direction: column; max-height: calc(100dvh - 50px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 22px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { padding: 10px 10px; font-size: 14px; font-weight: 500; color: var(--text-3); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-panel { padding: 20px 22px 22px; overflow-y: auto; }
.router-status { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; padding: 10px 14px; border-radius: 12px; background: var(--bg-soft); border: 1px solid var(--border); font-size: 14px; overflow-wrap: anywhere; }
.router-status .status-dot { margin: 0; flex: none; }

/* ---------- toast ---------- */
.toasts { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: calc(100vw - 32px); }
.toast {
  max-width: 520px; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow-lg);
  animation: pop .18s ease-out; pointer-events: auto; overflow-wrap: anywhere;
}
.toast.error { background: var(--danger); color: #fff; }

/* image lightbox */
.lightbox { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 24px; background: rgba(5, 5, 12, .82); cursor: zoom-out; animation: pop .15s; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 12px; box-shadow: var(--shadow-lg); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .app, .app.collapsed { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg);
  }
  .app.collapsed .sidebar { visibility: visible; opacity: 1; }
  .app.side-open .sidebar { transform: none; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(8, 8, 16, .45); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .app.side-open .backdrop { opacity: 1; pointer-events: auto; }
  #menuBtn { display: inline-grid; }
  #collapseBtn { display: none; }
  .new-chat kbd { display: none; }
  .chat-title { display: none; }
  .model-btn { max-width: none; }
  .topbar .model-picker { flex: 1; min-width: 0; display: flex; justify-content: center; }
  .model-menu { left: 50%; transform: translateX(-50%); }
  .chat-item .item-actions { display: flex; }
  .msg-actions { opacity: 1; }
}
@media (max-width: 560px) {
  .thread { padding: 4px 14px 16px; }
  .composer-wrap { padding: 0 10px calc(8px + env(safe-area-inset-bottom)); }
  .suggestions { grid-template-columns: 1fr; }
  .suggestion:nth-child(n+3) { display: none; }
  .msg.assistant { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .msg.assistant > .model-avatar { display: none; }
  .msg.user .bubble { max-width: 92%; }
  .composer-hint { visibility: hidden; }
  .disclaimer { font-size: 11px; }
  .row-between { flex-direction: column; align-items: stretch; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
