:root {
  --bg: #ffffff;
  --bg-soft: #f6f6f9;
  --bg-elev: #ffffff;
  --sidebar: #f4f4f7;
  --border: #e4e4ea;
  --text: #16161d;
  --muted: #6b6b7b;
  --accent: #6d5dfc;
  --accent-2: #b14cf0;
  --accent-text: #ffffff;
  --user-bubble: #efeefe;
  --danger: #d92d4b;
  --ok: #1f9d63;
  --code-bg: #f3f3f7;
  --hl-bg: #fafafc;
  --hl-head: #f0f0f5;
  --hl-text: #24292f;
  --hl-comment: #6e7781;
  --hl-keyword: #cf222e;
  --hl-string: #0a3069;
  --hl-number: #0550ae;
  --hl-function: #8250df;
  --hl-type: #953800;
  --hl-attr: #116329;
  --hl-variable: #e36209;
  --hl-meta: #57606a;
  --hl-add-bg: #e6ffec;
  --hl-del-bg: #ffebe9;
  --shadow: 0 10px 40px rgba(20, 20, 40, .12);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b10;
    --bg-soft: #14141c;
    --bg-elev: #181822;
    --sidebar: #101017;
    --border: #262634;
    --text: #ececf3;
    --muted: #9696a8;
    --accent: #8b7dff;
    --accent-2: #c57bff;
    --user-bubble: #22223a;
    --danger: #ff5c7a;
    --ok: #3ccf8e;
    --code-bg: #15151e;
  --hl-bg: #13131b;
  --hl-head: #1b1b26;
  --hl-text: #abb2bf;
  --hl-comment: #7f848e;
  --hl-keyword: #c678dd;
  --hl-string: #98c379;
  --hl-number: #d19a66;
  --hl-function: #61afef;
  --hl-type: #e5c07b;
  --hl-attr: #56b6c2;
  --hl-variable: #e06c75;
  --hl-meta: #8a90a0;
  --hl-add-bg: rgba(152, 195, 121, .15);
  --hl-del-bg: rgba(224, 108, 117, .15);
    --hl-bg: #13131b;
    --hl-head: #1b1b26;
    --hl-text: #abb2bf;
    --hl-comment: #7f848e;
    --hl-keyword: #c678dd;
    --hl-string: #98c379;
    --hl-number: #d19a66;
    --hl-function: #61afef;
    --hl-type: #e5c07b;
    --hl-attr: #56b6c2;
    --hl-variable: #e06c75;
    --hl-meta: #8a90a0;
    --hl-add-bg: rgba(152, 195, 121, .15);
    --hl-del-bg: rgba(224, 108, 117, .15);
    --shadow: 0 10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0b0b10;
  --bg-soft: #14141c;
  --bg-elev: #181822;
  --sidebar: #101017;
  --border: #262634;
  --text: #ececf3;
  --muted: #9696a8;
  --accent: #8b7dff;
  --accent-2: #c57bff;
  --user-bubble: #22223a;
  --danger: #ff5c7a;
  --ok: #3ccf8e;
  --code-bg: #15151e;
  --shadow: 0 10px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
#app { height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.tight { gap: 4px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg-elev); font-weight: 500; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--bg-soft); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn.ghost { background: transparent; }
.btn.link { border: 0; background: none; color: var(--muted); padding: 4px; }
.btn.link:hover { color: var(--text); }
.btn.block { width: 100%; }
.btn.small { padding: 6px 12px; font-size: 13px; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.input {
  width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-elev); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- auth ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(600px 400px at 15% 10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent),
    radial-gradient(600px 400px at 90% 90%, color-mix(in srgb, var(--accent-2) 16%, transparent), transparent),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 16px;
  padding: 32px; border-radius: 24px; background: var(--bg-elev); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 26px; letter-spacing: -.02em; }
.auth-card p { margin: 0; }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 20px; }
.brand img { border-radius: 14px; }
.brand.small { font-size: 17px; gap: 10px; }
.brand.small img { border-radius: 8px; }
.providers { gap: 10px; }
.btn.provider { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 500; }
.provider-icon { display: inline-flex; width: 18px; height: 18px; }
.provider-icon svg { width: 100%; height: 100%; }
.provider-wrap { position: relative; }
/* Google's own button sits invisibly on top of ours and receives the click. */
.google-overlay {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  overflow: hidden; opacity: .01;
}
.provider-wrap.ready .google-overlay { display: flex; }
.provider-wrap.ready:hover .btn { background: var(--bg-soft); }
.provider-wrap:focus-within .btn { outline: 2px solid var(--accent); outline-offset: 2px; }
.provider-wrap.busy { pointer-events: none; }
.provider-wrap.busy .btn { opacity: .7; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.input.code { font: 600 24px/1 "JetBrains Mono", monospace; letter-spacing: .5em; text-align: center; padding-left: calc(14px + .5em); }
.form-error { color: var(--danger); font-size: 14px; min-height: 1em; margin: 0; }
.form-error:empty { display: none; }

/* ---------- shell ---------- */
.shell {
  --sidebar-w: 280px;
  position: relative; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); height: 100%;
  overflow: hidden; transition: grid-template-columns .22s ease;
}
/* The sidebar keeps its full width and slides off to the left when its column shrinks to 0. */
.sidebar {
  display: flex; flex-direction: column; gap: 12px; min-height: 0; width: var(--sidebar-w); justify-self: end;
  padding: 14px 10px; background: var(--sidebar); border-right: 1px solid var(--border);
  transition: visibility 0s;
}
.shell.resizing { transition: none; cursor: col-resize; user-select: none; }
.shell.resizing * { cursor: col-resize !important; }

.sidebar-handle {
  position: absolute; top: 0; bottom: 0; left: calc(var(--sidebar-w) - 5px); z-index: 25;
  width: 10px; cursor: col-resize; touch-action: none; transition: left .22s ease;
}
.sidebar-handle::after {
  content: ""; position: absolute; top: 0; bottom: 0; left: 4px; width: 2px;
  background: var(--accent); opacity: 0; transition: opacity .15s .05s;
}
.sidebar-handle:hover::after, .sidebar-handle:focus-visible::after, .shell.resizing .sidebar-handle::after { opacity: .7; }
.sidebar-handle:focus-visible { outline: none; }
.shell.resizing .sidebar-handle { transition: none; }

.when-collapsed { display: none; }
@media (min-width: 821px) {
  .shell.sidebar-collapsed { grid-template-columns: 0px minmax(0, 1fr); }
  .shell.sidebar-collapsed .sidebar { visibility: hidden; transition: visibility 0s .22s; }
  .shell.sidebar-collapsed .sidebar-handle { left: 0; }
  .shell.sidebar-collapsed .when-collapsed { display: inline-grid; }
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; }
.new-chat { justify-content: flex-start; border-radius: 12px; }
.chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.empty-list { color: var(--muted); font-size: 14px; padding: 8px 10px; }
.chat-item { position: relative; display: flex; align-items: center; border-radius: 10px; }
.chat-item:hover, .chat-item.active { background: color-mix(in srgb, var(--text) 7%, transparent); }
.chat-link {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
  padding: 9px 10px; border: 0; background: none; text-align: left; font-size: 14px;
}
.chat-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-link .icon { width: 14px; height: 14px; color: var(--muted); }
.chat-more { width: 30px; height: 30px; opacity: 0; }
.chat-item:hover .chat-more, .chat-item.active .chat-more, .chat-more:focus-visible { opacity: 1; }
.menu {
  position: absolute; right: 4px; top: 100%; z-index: 20; min-width: 150px; padding: 6px;
  display: flex; flex-direction: column; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
}
.menu button { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.menu button:hover { background: var(--bg-soft); }
.menu .danger { color: var(--danger); }

.profile-btn {
  display: flex; align-items: center; gap: 10px; padding: 8px; border: 0; border-radius: 12px;
  background: none; text-align: left;
}
.profile-btn:hover { background: color-mix(in srgb, var(--text) 7%, transparent); }
.avatar-img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; }
.initials { display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; font-weight: 600; }
.profile-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.profile-meta strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-meta small { color: var(--muted); font-size: 12px; }

.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main.dragging::after {
  content: "Drop images to attach"; position: absolute; inset: 12px; z-index: 30;
  display: grid; place-items: center; border: 2px dashed var(--accent); border-radius: 20px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); font-weight: 600; color: var(--accent);
}
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  border-bottom: 1px solid var(--border); min-height: 57px;
}
.chat-title { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* ---------- model picker ---------- */
.model-picker { position: relative; flex: none; }
.model-trigger {
  display: flex; align-items: center; gap: 8px; max-width: 280px; padding: 5px 12px 5px 5px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg-elev);
  font-size: 14px; font-weight: 600; transition: background .15s, border-color .15s;
}
.model-trigger:hover, .model-picker.open .model-trigger { background: var(--bg-soft); border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.model-trigger-mark { display: flex; }
.model-trigger-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron {
  width: 8px; height: 8px; margin: 0 2px 3px 2px; flex: none;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s;
}
.model-picker.open .chevron { transform: translateY(3px) rotate(-135deg); }
.model-picker.saving .model-trigger { opacity: .6; }

.model-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 9px;
  color: #fff; font-size: 14px; font-weight: 700; line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12);
}
.model-mark.sm { width: 26px; height: 26px; border-radius: 50%; font-size: 12px; }

.model-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 50;
  width: 380px; max-height: min(520px, calc(100dvh - 90px)); display: flex; flex-direction: column;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  overflow: hidden; animation: pop .14s ease-out; transform-origin: top right;
}
.model-panel[hidden], .model-scrim[hidden] { display: none; }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(-4px); } }
.model-search-wrap { padding: 10px; border-bottom: 1px solid var(--border); }
.model-search {
  width: 100%; padding: 9px 12px 9px 34px; border-radius: 10px; border: 1px solid transparent; outline: none;
  background: var(--bg-soft) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='M20 20l-3.5-3.5'/%3E%3C/svg%3E") no-repeat 11px center / 16px;
  font-size: 14px;
}
.model-search:focus { border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.model-list { overflow-y: auto; padding: 6px; overscroll-behavior: contain; }
.model-group + .model-group { margin-top: 4px; }
.model-group-title {
  position: sticky; top: -6px; z-index: 1; padding: 10px 10px 6px; background: var(--bg-elev);
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.model-option {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px;
  border: 0; border-radius: 12px; background: none; text-align: left;
}
.model-option.active { background: var(--bg-soft); }
.model-option.selected { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.model-option-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.model-option-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-option-desc { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-tags { display: flex; gap: 4px; flex: none; }
.model-tag { padding: 2px 7px; border-radius: 999px; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; }
.model-tag.premium { color: #b7791f; background: color-mix(in srgb, #f6ad55 20%, transparent); }
.model-tag.voice { color: #0e9f9a; background: color-mix(in srgb, #2ec4b6 18%, transparent); }
.model-tag.image { color: #d53f8c; background: color-mix(in srgb, #ed64a6 18%, transparent); }
.model-tag.free { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.model-tag.reasoning { color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.model-check { width: 16px; flex: none; color: var(--accent); font-weight: 700; text-align: center; }
.model-empty { padding: 24px; text-align: center; color: var(--muted); margin: 0; }
.model-scrim { display: none; }

.scroller { flex: 1; overflow-y: auto; }
.thread { max-width: 780px; margin: 0 auto; padding: 24px 16px 12px; display: flex; flex-direction: column; gap: 22px; }
.welcome { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 12vh 0 0; }
.welcome img { border-radius: 18px; }
.welcome h1 { font-size: 28px; letter-spacing: -.02em; }
.welcome p { max-width: 420px; margin: 0; }
.loading { display: grid; place-items: center; padding: 40px; }

.msg { display: flex; gap: 12px; }
.msg.user { flex-direction: column; align-items: flex-end; gap: 6px; }
.msg.user .bubble {
  max-width: 85%; padding: 10px 16px; border-radius: 20px 20px 6px 20px;
  background: var(--user-bubble); white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-images { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.msg-images img { width: 120px; height: 120px; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); }
.msg .avatar { flex: none; width: 30px; height: 30px; }
.msg .avatar img { border-radius: 8px; }
.msg-body { flex: 1; min-width: 0; }
.msg-model { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.msg-error { color: var(--danger); margin: 4px 0; }
.gen-audio { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.gen-audio audio { width: min(100%, 420px); height: 40px; }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; }
.gen-image img, .gen-video { display: block; max-width: min(100%, 512px); border-radius: 14px; border: 1px solid var(--border); margin-top: 6px; }

.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: .6em 0; }
.md h1, .md h2, .md h3 { margin: 1em 0 .4em; font-size: 1.15em; }
.md a { color: var(--accent); }
.md code { font: .9em "JetBrains Mono", monospace; background: var(--code-bg); padding: .15em .35em; border-radius: 6px; }
/* ---------- code blocks ---------- */
.code-block {
  margin: .8em 0; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--hl-bg);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 8px 6px 14px; background: var(--hl-head); border-bottom: 1px solid var(--border);
}
.code-lang { font: 600 12px/1 Inter, sans-serif; color: var(--muted); letter-spacing: .02em; }
.code-copy {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border: 0; border-radius: 8px;
  background: none; color: var(--muted); font-size: 12px; font-weight: 500;
}
.code-copy:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.code-copy.done { color: var(--ok); }
.code-copy .icon { width: 14px; height: 14px; }
.md .code-block pre { margin: 0; padding: 14px 16px; overflow-x: auto; background: none; }
.md .code-block code {
  display: block; padding: 0; background: none; border-radius: 0; color: var(--hl-text);
  font: 13.5px/1.6 "JetBrains Mono", ui-monospace, monospace; white-space: pre; overflow-wrap: normal; tab-size: 4;
}

/* highlight.js token colors (theme follows light/dark via --hl-* tokens) */
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-doctag, .hljs-template-tag { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-meta .hljs-string, .hljs-template-variable { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-link { color: var(--hl-number); }
.hljs-title, .hljs-title.function_, .hljs-section { color: var(--hl-function); }
.hljs-title.class_, .hljs-type, .hljs-built_in, .hljs-class .hljs-title { color: var(--hl-type); }
.hljs-attr, .hljs-attribute, .hljs-name, .hljs-selector-id, .hljs-selector-class, .hljs-property { color: var(--hl-attr); }
.hljs-variable, .hljs-subst, .hljs-selector-attr, .hljs-selector-pseudo { color: var(--hl-variable); }
.hljs-meta, .hljs-meta .hljs-keyword { color: var(--hl-meta); }
.hljs-tag { color: var(--hl-text); }
.hljs-addition { background: var(--hl-add-bg); color: var(--hl-string); display: inline-block; width: 100%; }
.hljs-deletion { background: var(--hl-del-bg); color: var(--hl-variable); display: inline-block; width: 100%; }
.hljs-emphasis { font-style: italic; }
.hljs-strong { font-weight: 700; }

.md blockquote { margin: .6em 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.md table { border-collapse: collapse; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }

.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.composer-wrap { padding: 8px 16px calc(12px + env(safe-area-inset-bottom)); }
.composer {
  max-width: 780px; margin: 0 auto; padding: 8px; border-radius: 22px;
  background: var(--bg-elev); border: 1px solid var(--border); box-shadow: 0 2px 12px rgba(0, 0, 0, .05);
  transition: border-color .15s;
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; }
.composer-input {
  flex: 1; resize: none; border: 0; outline: none; background: transparent;
  padding: 8px 4px; max-height: 220px; line-height: 1.45;
}
.send-btn {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none; border: 0; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
}
.send-btn:disabled { opacity: .5; cursor: default; }
.previews { display: flex; flex-wrap: wrap; gap: 8px; }
.previews:not(:empty) { padding: 4px 4px 8px; }
.preview { position: relative; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); display: block; }
.preview button {
  position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; display: grid; place-items: center;
  border-radius: 50%; border: 0; background: var(--text); color: var(--bg); padding: 0;
}
.preview .icon { width: 12px; height: 12px; }
.quota { max-width: 780px; margin: 6px auto 0; text-align: center; font-size: 12px; color: var(--muted); }

/* ---------- modal ---------- */
.modal {
  width: min(420px, calc(100vw - 32px)); padding: 20px; border: 1px solid var(--border); border-radius: 20px;
  background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow);
}
.modal.wide { width: min(560px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(0, 0, 0, .45); backdrop-filter: blur(2px); }
.modal header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal h2 { font-size: 18px; }
.modal h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin-top: 6px; }
.modal p { margin: 0; }
.profile-head { display: flex; gap: 16px; align-items: center; }
.avatar-lg { width: 72px; height: 72px; flex: none; padding: 0; border: 0; border-radius: 50%; overflow: hidden; background: none; position: relative; }
.avatar-lg img, .avatar-lg .initials { width: 100%; height: 100%; object-fit: cover; font-size: 28px; }
.avatar-lg::after { content: "Edit"; position: absolute; inset: auto 0 0; padding: 2px; font-size: 11px; background: rgba(0, 0, 0, .55); color: #fff; opacity: 0; transition: opacity .15s; }
.avatar-lg:hover::after { opacity: 1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stat { padding: 12px; border-radius: 12px; background: var(--bg-soft); display: flex; flex-direction: column; gap: 2px; }
.stat span { font-size: 12px; color: var(--muted); }
.stat strong { font-size: 18px; }
.devices { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.devices li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--bg-soft); }
.devices li > div { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-width: 0; }
.devices small { flex-basis: 100%; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); font-weight: 600; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 100; transform: translate(-50%, 20px);
  max-width: calc(100vw - 32px); padding: 12px 18px; border-radius: 12px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--danger); color: #fff; }
.toast[data-kind="ok"] { background: var(--ok); color: #fff; }

/* ---------- mobile ---------- */
.only-mobile { display: none; }
.scrim { display: none; }
@media (max-width: 820px) {
  .only-mobile { display: inline-grid; }
  .only-desktop, .sidebar-handle { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, 85vw);
    transform: translateX(-100%); transition: transform .2s ease;
  }
  .shell.sidebar-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .shell.sidebar-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, .4); }
  .chat-more { opacity: 1; }
  .topbar { padding: 8px 10px; }
  .model-trigger { max-width: 52vw; }
  .model-scrim:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 49; background: rgba(0, 0, 0, .4); }
  .model-panel {
    position: fixed; inset: auto 0 0 0; top: auto; width: auto; max-height: 75dvh;
    border-radius: 20px 20px 0 0; padding-bottom: env(safe-area-inset-bottom);
    animation: sheet .2s ease-out;
  }
  .model-panel::before { content: ""; align-self: center; width: 36px; height: 4px; margin-top: 8px; border-radius: 2px; background: var(--border); }
  .model-option { padding: 10px; }
  .auth-card { padding: 24px 20px; }
  .msg.user .bubble { max-width: 92%; }
}
@keyframes sheet { from { transform: translateY(100%); } }

/* ---------- text-to-speech studio ---------- */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tts { flex: 1; display: none; flex-direction: column; min-height: 0; }
.main.tts-mode .chat-view { display: none; }
.main.tts-mode .tts { display: flex; }
.tts-body { flex: 1; display: grid; grid-template-columns: minmax(0, 1fr) 360px; min-height: 0; }

.tts-work { display: flex; flex-direction: column; gap: 18px; min-height: 0; padding: 24px 32px 18px; }
.tts-editor-wrap { flex: 1; min-height: 0; }
.tts-editor {
  width: 100%; height: 100%; resize: none; border: 0; outline: none; background: transparent;
  font-size: 17px; line-height: 1.7; color: var(--text);
}
.tts-editor::placeholder { color: var(--muted); }

.tts-gens { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.tts-gens[hidden] { display: none; }
.tts-card {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 18px 12px 14px 14px;
  border: 1px solid var(--border); border-radius: 16px; background: var(--bg-elev); min-width: 0;
  transition: border-color .15s, box-shadow .15s;
}
.tts-card.active { border-color: color-mix(in srgb, var(--text) 35%, var(--border)); box-shadow: 0 4px 18px rgba(0, 0, 0, .06); }
.tts-card-label { position: absolute; top: -9px; left: 14px; padding: 0 6px; background: var(--bg); font-size: 12px; color: var(--muted); }
.tts-play, .tts-play-lg {
  display: grid; place-items: center; flex: none; border: 0; border-radius: 50%;
  background: var(--text); color: var(--bg); transition: transform .1s;
}
.tts-play { width: 40px; height: 40px; }
.tts-play.sm { width: 32px; height: 32px; }
.tts-play .icon { width: 16px; height: 16px; }
.tts-play.sm .icon { width: 13px; height: 13px; }
.tts-play:active, .tts-play-lg:active { transform: scale(.94); }
.tts-wave { flex: 1; min-width: 0; height: 38px; display: flex; align-items: center; gap: 2px; cursor: pointer; }
.tts-wave span {
  flex: 1; height: var(--h); min-height: 3px; border-radius: 2px;
  background: color-mix(in srgb, var(--text) 22%, transparent); transition: background .1s;
}
.tts-wave span.on { background: var(--text); }
.tts-wave.loading { cursor: default; }
.tts-wave.loading span { animation: wave-pulse 1s ease-in-out infinite; }
@keyframes wave-pulse { 50% { transform: scaleY(.35); opacity: .45; } }
.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tts-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); }
.tts-credits { display: inline-flex; align-items: center; gap: 8px; }
.tts-ring {
  width: 16px; height: 16px; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--v) * 360deg), var(--border) 0);
  -webkit-mask: radial-gradient(circle, transparent 4.5px, #000 5px);
  mask: radial-gradient(circle, transparent 4.5px, #000 5px);
}
.tts-count { font-variant-numeric: tabular-nums; }
.tts-count.over { color: var(--danger); font-weight: 600; }
.tts-generate { padding: 11px 20px; border-radius: 12px; border-color: transparent; background: var(--text); color: var(--bg); font-weight: 600; }
.tts-generate:hover:not(:disabled) { background: var(--text); opacity: .88; }

.tts-panel { min-height: 0; overflow-y: auto; padding: 14px 22px 24px; border-left: 1px solid var(--border); }
.tts-tabs { display: flex; gap: 22px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tts-tab {
  margin-bottom: -1px; padding: 10px 0; border: 0; border-bottom: 2px solid transparent;
  background: none; color: var(--muted); font-weight: 600;
}
.tts-tab:hover { color: var(--text); }
.tts-tab.active { color: var(--text); border-bottom-color: var(--text); }
.tts-settings { display: flex; flex-direction: column; gap: 22px; }
.tts-field-head { margin-bottom: 8px; font-weight: 600; }
.tts-options { display: flex; flex-direction: column; gap: 6px; }
.tts-option {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg-elev); text-align: left;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.tts-option:hover { background: var(--bg-soft); }
.tts-option.selected {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}
.tts-option-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.tts-option-text strong { font-size: 14px; }
.tts-option-text small { font-size: 12px; color: var(--muted); }
.tts-check { color: var(--accent); font-weight: 700; }
.voice-avatar { width: 30px; height: 30px; flex: none; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25); }
.tts-hint { display: flex; align-items: flex-start; gap: 10px; margin: -8px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--bg-soft); font-size: 13px; }
.tts-hint .icon { width: 18px; height: 18px; color: var(--muted); }
.tts-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 600; }
.tts-pill { padding: 5px 12px; border-radius: 999px; background: var(--bg-soft); font-size: 13px; font-weight: 500; white-space: nowrap; }
.tts-empty { padding: 48px 12px; text-align: center; color: var(--muted); }
.tts-empty .icon { width: 32px; height: 32px; }
.tts-history { display: flex; flex-direction: column; gap: 4px; }
.tts-history-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; }
.tts-history-item:hover, .tts-history-item.active { background: var(--bg-soft); }
.tts-history-text { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 0; border: 0; background: none; text-align: left; }
.tts-history-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.tts-history-text small { font-size: 12px; color: var(--muted); }

.tts-player {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr); align-items: center; gap: 16px;
  padding: 10px 20px; border-top: 1px solid var(--border); background: var(--bg-elev);
}
.tts-player[hidden] { display: none; }
.tts-player-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.tts-player-info strong, .tts-player-info small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tts-player-info small { color: var(--muted); font-size: 12px; }
.tts-player-center { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tts-player-controls { display: flex; align-items: center; gap: 14px; }
.tts-play-lg { width: 44px; height: 44px; }
.tts-play-lg .icon { width: 18px; height: 18px; }
.tts-player-progress { display: flex; align-items: center; gap: 10px; width: 100%; }
.tts-time { min-width: 34px; font-size: 12px; color: var(--muted); text-align: center; font-variant-numeric: tabular-nums; }
.tts-seek { flex: 1; accent-color: var(--text); cursor: pointer; }
.tts-player-actions { display: flex; justify-content: flex-end; }

@media (max-width: 820px) {
  .tts-body { grid-template-columns: 1fr; overflow-y: auto; }
  .tts-work { padding: 16px; }
  .tts-editor-wrap { min-height: 220px; }
  .tts-gens { grid-template-columns: 1fr; }
  .tts-generate { width: 100%; }
  .tts-panel { overflow: visible; border-left: 0; border-top: 1px solid var(--border); padding: 12px 16px 24px; }
  .tts-player { grid-template-columns: 1fr; gap: 4px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); }
  .tts-player-info, .tts-player-actions { display: none; }
}
