/* Нейро (ai.slarp.gg) — hosts/ai/ai.css.
   Visual language of the site (docs/areas/SITE.md «Внешний вид», DECISIONS 2026-09-27): graphite
   ladder #121315 → #1b1d20 → #25282c → #303338, one gold button per screen (in the chat it is
   «Отправить», on the balance — «Пополнить»), selected = a lighter .08 box with a gold label, keyboard
   focus = a 2px ring in the text colour. The shell header, dock and account sheet come from
   site/src/shell (shell.css); this sheet styles only the app and overrides the header height. */

:root {
  --bg: #121315;
  --surface: #1b1d20;
  --surface-2: #25282c;
  --surface-3: #303338;
  --surface-sunken: #0e0f11;
  --overlay: rgba(20, 21, 24, .98);
  --scrim: rgba(8, 9, 12, .58);
  --fill-rest: rgba(255, 255, 255, .035);
  --fill-hover: rgba(255, 255, 255, .06);
  --fill-selected: rgba(255, 255, 255, .08);
  --fill-selected-hover: rgba(255, 255, 255, .10);
  --text: #F4EFE4;
  --muted: #B3AA98;
  --muted-2: #a39c8c;
  --line: #282b2f;
  --line-strong: #36393e;
  --gold: #E9C87C;
  --gold-strong: #D9B45E;
  --gold-ink: #171310;
  --danger: #ffb4ab;
  --ok: #a6d5a7;
  --display: "Geologica", "Segoe UI", system-ui, sans-serif;
  --body: "Golos Text", "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --radius: 14px;
  --radius-lg: 20px;
  --side-w: 296px;
  --thread-w: 800px;
  --dock-space: 0px;
  --ai-head: calc(var(--shell-header-h, 72px) + var(--shell-header-top, 6px));
}

/* The shell header is shorter on Нейро so the chat gets the height (same markup, same chip). */
/* The top air lives inside the header (no margin): a collapsed margin would move the body when the
   phone app hides the header, which counts as a layout shift. */
body.ai-page { --shell-header-h: 78px; --shell-header-top: 0px; background: var(--bg); color: var(--text); font-family: var(--body); }
body.ai-page .site-header { margin-top: 0; }
@media (max-width: 780px) { body.ai-page { --shell-header-h: 68px; } }

.ai-page *, .ai-page *::before, .ai-page *::after { box-sizing: border-box; }
/* The base the shell expects from next.css (not loaded here: the chat needs none of its 700 KB). */
:where(.ai-page) a { color: inherit; text-decoration: none; }
:where(.ai-page) img { display: block; max-width: 100%; }
:where(.ai-page) :is(button, input, textarea, select) { font: inherit; }
body.ai-page main { display: block; }
.ai-page [hidden] { display: none !important; }
.ai-page :focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* A stable header (CLS 0): the shell swaps «Войти» for the account chip after account/me. On this
   host the slot has one width in both states, the nav is centred independently of it, and the forum
   inbox icons (which arrive later still) stay off — the chat keeps its chrome quiet; the forum is
   one tap away in the account sheet. */
@media (min-width: 781px) {
  .ai-page .header-actions :is(.header-login, .header-account) { box-sizing: border-box; width: 176px; max-width: 176px; }
  .ai-page .header-actions .header-account { justify-content: flex-start; }
}
@media (min-width: 1101px) {
  .ai-page .header-main { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); }
  .ai-page .header-actions { justify-self: end; }
}
.ai-page .site-header .inbox-chrome { display: none !important; }

/* Footer and the IP notice belong to the landing only (they would sit under the app frame). */
body.ai-page:not([data-view="landing"]) .site-footer,
body.ai-page:not([data-view="landing"]) .site-ip-notice { display: none; }

/* ------------------------------------------------------------------ shared controls */

.ai-ico { display: inline-grid; place-items: center; width: 20px; height: 20px; flex: none; }
.ai-ico svg { width: 20px; height: 20px; display: block; }

.ai-gold {
  min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 22px; border: 0; border-radius: 13px; background: var(--gold); color: var(--gold-ink);
  font: 800 15px/1.1 var(--display); letter-spacing: .01em; text-decoration: none; cursor: pointer;
}
.ai-gold:hover { background: var(--gold-strong); }
.ai-gold:disabled { opacity: .45; cursor: default; }
.ai-gold[aria-busy="true"] { opacity: .7; cursor: progress; }
.ai-wide { width: 100%; }

.ai-strong-btn, .ai-quiet-btn, .ai-danger-btn {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 16px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--fill-selected);
  color: var(--text); font: 700 14px/1.15 var(--body); text-decoration: none; cursor: pointer;
}
.ai-quiet-btn { background: transparent; border-color: var(--line); color: var(--muted); }
.ai-strong-btn:hover, .ai-quiet-btn:hover { background: var(--fill-selected-hover); color: var(--text); }
.ai-danger-btn { border-color: rgba(255, 180, 171, .4); color: var(--danger); background: rgba(255, 180, 171, .06); }
.ai-danger-btn:hover { background: rgba(255, 180, 171, .1); }
.ai-strong-btn:disabled, .ai-quiet-btn:disabled { opacity: .5; cursor: default; }

.ai-link-btn {
  min-height: 32px; padding: 4px 2px; border: 0; background: none; color: var(--text); font: 700 14px/1.3 var(--body);
  text-decoration: underline; text-decoration-color: rgba(244, 239, 228, .4); text-underline-offset: 3px; cursor: pointer;
}
.ai-link-btn:hover { text-decoration-color: var(--text); }
.ai-quiet-link { color: var(--muted); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; min-height: 44px; display: inline-flex; align-items: center; }
.ai-quiet-link:hover { color: var(--text); }

.ai-icon-btn {
  width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center; padding: 0;
  border: 0; border-radius: 11px; background: transparent; color: var(--muted); cursor: pointer;
}
.ai-icon-btn:hover { background: var(--fill-hover); color: var(--text); }
.ai-icon-btn:disabled { opacity: .35; cursor: default; background: transparent; }
.ai-icon-btn.is-done { color: var(--ok); }

.ai-input {
  width: 100%; min-height: 44px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 11px;
  background: var(--surface-2); color: var(--text); font: 500 15px/1.3 var(--body);
}
.ai-input:focus { outline: none; border-color: var(--text); }
.ai-input::placeholder { color: var(--muted-2); }
.ai-input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.ai-input[type="number"]::-webkit-inner-spin-button, .ai-input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.ai-tag {
  display: inline-flex; align-items: center; min-height: 20px; padding: 0 7px; border-radius: 6px;
  background: var(--fill-selected); color: var(--muted); font: 700 11px/1 var(--body); white-space: nowrap;
}

.ai-skel { border-radius: 10px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; }
.ai-skel-row { height: 36px; margin: 6px 4px; }
.ai-skel-msg { height: 64px; margin: 18px 0; }
.ai-skel-msg.is-user { margin-left: auto; height: 44px; }
@media (prefers-reduced-motion: no-preference) { .ai-skel { animation: ai-shimmer 1.4s linear infinite; } }
@keyframes ai-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ------------------------------------------------------------------ boot frame */

.ai-boot { height: calc(var(--ai-vvh, 100dvh) - var(--ai-head)); display: grid; grid-template-columns: var(--side-w) 1fr; gap: 12px; padding: 4px 24px 16px; }
.ai-boot-side { border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); }
.ai-boot-main { display: grid; align-content: end; padding: 0 0 4px; }
.ai-boot-composer { max-width: var(--thread-w); width: 100%; margin: 0 auto; height: 60px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); }
@media (max-width: 780px) { .ai-boot { grid-template-columns: 1fr; padding: 4px 12px calc(96px + env(safe-area-inset-bottom)); } .ai-boot-side { display: none; } }

/* ------------------------------------------------------------------ landing */

.ai-landing { width: min(calc(100% - 48px), 1180px); margin: 0 auto; padding: 18px 0 72px; }
.ai-hero { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 48px; align-items: center; padding: 28px 0 40px; }
.ai-eyebrow { margin: 0 0 14px; color: var(--gold); font: 800 13px/1 var(--display); letter-spacing: .08em; text-transform: uppercase; }
.ai-hero h1 { margin: 0 0 18px; font: 800 clamp(36px, 6vw, 66px)/0.98 var(--display); letter-spacing: .005em; text-transform: uppercase; }
.ai-lead { margin: 0 0 28px; max-width: 34em; color: var(--muted); font-size: 18px; line-height: 1.55; }
.ai-cta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 18px; }
.ai-cta-row .ai-gold { min-height: 54px; padding: 0 28px; font-size: 16px; }
.ai-cta-note { margin: 16px 0 0; color: var(--muted-2); font-size: 14px; }
.ai-soon { margin: 18px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--fill-rest); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }

.ai-preview { position: relative; padding: 20px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); box-shadow: 0 30px 60px rgba(0, 0, 0, .28); }
.ai-preview::before { content: ""; position: absolute; inset: -1px; border-radius: 24px; pointer-events: none; background: radial-gradient(ellipse 60% 50% at 85% 0%, rgba(233, 200, 124, .06), transparent 70%); }
.ai-preview-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.ai-preview-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border-radius: 9px; background: var(--surface-2); color: var(--text); font: 700 12.5px/1 var(--body); }
.ai-preview-chip.is-muted { color: var(--muted); background: transparent; border: 1px solid var(--line); }
.ai-preview-user { margin: 0 0 14px auto; max-width: 82%; padding: 10px 14px; border-radius: 16px 16px 6px 16px; background: var(--surface-2); font-size: 14.5px; line-height: 1.5; }
.ai-preview-bot { font-size: 14.5px; line-height: 1.6; color: var(--text); }
.ai-preview-bot p { margin: 0 0 10px; }
.ai-preview-bot ul { margin: 0 0 12px; padding-left: 18px; color: var(--muted); }
.ai-preview-code { margin: 0 0 12px; border-radius: 12px; background: var(--surface-sunken); border: 1px solid var(--line); overflow: hidden; }
.ai-preview-code span { display: block; padding: 7px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font: 600 12px/1 var(--body); }
.ai-preview-code code { display: block; padding: 10px 12px; font: 500 13px/1.5 var(--mono); color: var(--text); }
.ai-preview-tools { display: flex; align-items: center; gap: 10px; color: var(--muted); font: 600 12.5px/1 var(--body); }
.ai-preview-tools b { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--line); font-weight: 700; color: var(--text); }

.ai-section { padding: 40px 0 0; }
.ai-section h2 { margin: 0 0 10px; font: 800 clamp(24px, 3.2vw, 34px)/1.08 var(--display); text-transform: uppercase; letter-spacing: .01em; }
.ai-section-lead { margin: 0 0 22px; color: var(--muted); max-width: 46em; font-size: 16px; }
.ai-features { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 0; list-style: none; }
.ai-feature { padding: 20px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); }
.ai-feature h3 { margin: 0 0 8px; font: 800 17px/1.2 var(--display); }
.ai-feature p { margin: 0; color: var(--muted); font-size: 15px; line-height: 1.5; }
.ai-steps { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; counter-reset: step; }
.ai-steps li { position: relative; padding: 20px 20px 20px 62px; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--line); color: var(--text); font-size: 15px; line-height: 1.5; counter-increment: step; }
.ai-steps li::before { content: counter(step); position: absolute; left: 18px; top: 18px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-2); font: 800 14px/1 var(--display); }
.ai-honest { margin: 0; max-width: 52em; color: var(--muted); font-size: 15.5px; line-height: 1.6; }
.ai-landing-cta { margin-top: 28px; }

.ai-price-table { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--line); background: var(--surface); }
.ai-price-table table { width: 100%; border-collapse: collapse; min-width: 560px; }
.ai-price-table th, .ai-price-table td { padding: 12px 16px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14.5px; vertical-align: middle; }
.ai-price-table thead th { color: var(--muted); font: 700 12.5px/1.3 var(--body); background: var(--fill-rest); }
.ai-price-table tbody tr:last-child > * { border-bottom: 0; }
.ai-price-table .is-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ai-pt-name { font-weight: 700; margin-right: 8px; }
.ai-pt-vendor { color: var(--muted-2); font-size: 13px; margin-right: 8px; }
.ai-price-note { margin: 12px 2px 0; color: var(--muted-2); font-size: 13.5px; line-height: 1.5; }

@media (max-width: 980px) {
  .ai-hero { grid-template-columns: 1fr; gap: 28px; padding-top: 12px; }
  .ai-features, .ai-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .ai-landing { width: calc(100% - 32px); padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  .ai-lead { font-size: 16.5px; }
  .ai-features, .ai-steps { grid-template-columns: 1fr; }
  .ai-cta-row .ai-gold { width: 100%; }
  .ai-preview { padding: 16px; border-radius: 20px; }
}

/* ------------------------------------------------------------------ gate screens */

.ai-gate { min-height: calc(var(--ai-vvh, 100dvh) - var(--ai-head)); display: grid; place-items: center; padding: 16px 16px 40px; }
.ai-gate-card { width: min(100%, 540px); padding: 32px; border-radius: 24px; background: var(--surface); border: 1px solid var(--line); text-align: left; }
.ai-gate-mark { width: 40px; height: 30px; margin: 0 0 22px; }
.ai-gate-title { margin: 0 0 14px; font: 800 clamp(26px, 5vw, 34px)/1.05 var(--display); text-transform: uppercase; letter-spacing: .01em; }
.ai-gate-text { margin: 0 0 12px; color: var(--muted); font-size: 16px; line-height: 1.55; }
.ai-gate-list { margin: 8px 0 4px; }
.ai-gate-docs, .ai-gate-gift { margin: 0 0 12px; font-size: 15px; line-height: 1.55; color: var(--text); }
.ai-gate-docs a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.ai-gate-gift { padding: 12px 14px; border-radius: 12px; background: var(--fill-rest); border: 1px solid var(--line); }
.ai-gate-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; margin-top: 22px; }
.ai-gate-error { margin: 16px 0 0; color: var(--danger); font-size: 14.5px; }
@media (max-width: 640px) {
  .ai-gate { align-items: start; padding-top: 12px; padding-bottom: calc(110px + env(safe-area-inset-bottom)); }
  .ai-gate-card { padding: 24px 20px; border-radius: 20px; }
  .ai-gate-actions .ai-gold { width: 100%; }
}

/* ------------------------------------------------------------------ the app frame */

body[data-view="app"] { overflow: hidden; }
.ai-app {
  height: calc(var(--ai-vvh, 100dvh) - var(--ai-head)); display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr);
  gap: 12px; padding: 4px 24px 14px; min-height: 0;
}

.ai-side {
  min-height: 0; display: flex; flex-direction: column; border-radius: var(--radius-lg); background: var(--surface);
  border: 1px solid var(--line); overflow: hidden;
}
.ai-side-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; }
.ai-new {
  flex: 1; min-height: 44px; display: inline-flex; align-items: center; gap: 10px; padding: 0 14px;
  border: 1px solid var(--line-strong); border-radius: 12px; background: var(--fill-selected); color: var(--text);
  font: 800 14.5px/1 var(--display); cursor: pointer;
}
.ai-new:hover { background: var(--fill-selected-hover); }
.ai-side-close { display: none; }
.ai-side-title { display: none; }
.ai-chatlist { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 8px 12px; overscroll-behavior: contain; }
.ai-group { margin-top: 10px; }
.ai-group-title { margin: 0; padding: 8px 10px 4px; color: var(--muted-2); font: 700 12px/1.2 var(--body); letter-spacing: .02em; }
.ai-group-list { margin: 0; padding: 0; list-style: none; }
.ai-item { position: relative; display: flex; align-items: center; border-radius: 11px; }
.ai-item:hover { background: var(--fill-hover); }
.ai-item.is-current { background: var(--fill-selected); }
.ai-item-link { flex: 1; min-width: 0; min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 4px 0 10px; color: var(--text); text-decoration: none; font-size: 14px; }
.ai-item.is-current .ai-item-title { color: var(--gold); }
.ai-item-title { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ai-item-cost { flex: none; color: var(--muted-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.ai-item-pin { width: 16px; height: 16px; color: var(--muted-2); }
.ai-item-pin svg { width: 16px; height: 16px; }
.ai-item-more { width: 34px; height: 34px; opacity: 0; }
.ai-item:hover .ai-item-more, .ai-item-more:focus-visible, .ai-item.is-current .ai-item-more, .ai-item-more[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .ai-item-more { opacity: 1; } }
.ai-folder-head { display: flex; align-items: center; border-radius: 11px; }
.ai-folder-head:hover { background: var(--fill-hover); }
.ai-folder-head .ai-item-more { opacity: 1; }
.ai-folder-toggle { flex: 1; min-width: 0; min-height: 40px; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 10px; border: 0; background: none; color: var(--text); font: 700 14px/1 var(--body); cursor: pointer; text-align: left; }
.ai-folder-toggle .ai-ico { color: var(--muted); }
.ai-folder-name { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.ai-folder-count { color: var(--muted-2); font-size: 12px; font-weight: 600; }
.ai-folder .ai-group-list { padding-left: 14px; }
.ai-folder-empty { padding: 6px 10px; color: var(--muted-2); font-size: 13px; }
.ai-list-empty { margin: 16px 10px; color: var(--muted); font-size: 14px; }
.ai-list-more { margin: 10px 8px; }
.ai-rename { padding: 4px; }
.ai-rename .ai-input { min-height: 38px; font-size: 14px; }
.ai-side-foot { display: grid; gap: 2px; padding: 8px; border-top: 1px solid var(--line); }
.ai-side-link {
  min-height: 40px; display: flex; align-items: center; gap: 10px; padding: 0 10px; border: 0; border-radius: 10px;
  background: none; color: var(--muted); font: 600 14px/1 var(--body); text-align: left; cursor: pointer;
}
.ai-side-link:hover { background: var(--fill-hover); color: var(--text); }
.ai-side-ext:empty { display: none; }
.ai-scrim { display: none; }

/* the chat column */
.ai-chat { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.ai-bar { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 0 6px; }
.ai-bar-menu, .ai-bar-new { display: none; }
.ai-model-btn {
  min-width: 0; max-width: 100%; min-height: 46px; display: inline-flex; align-items: center; gap: 10px; padding: 0 10px 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); cursor: pointer; text-align: left;
}
.ai-model-btn:hover { background: var(--surface-2); }
.ai-model-text { min-width: 0; display: grid; gap: 2px; }
.ai-model-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font: 800 14.5px/1.15 var(--display); }
.ai-model-price { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); font-size: 12px; line-height: 1.2; }
.ai-model-btn .ai-ico { color: var(--muted); }
.ai-bar-spacer { flex: 1; }
.ai-bar-more.is-off { visibility: hidden; }
.ai-chat-cost { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ai-balance {
  min-height: 46px; display: inline-flex; flex-direction: column; justify-content: center; align-items: flex-end; gap: 2px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); cursor: pointer; font-variant-numeric: tabular-nums;
}
.ai-balance:hover { background: var(--surface-2); }
.ai-balance-main { font: 800 14.5px/1.1 var(--display); white-space: nowrap; }
.ai-balance-sub { color: var(--muted); font-size: 11.5px; line-height: 1.1; white-space: nowrap; }
.ai-balance-sub.is-debt { color: var(--danger); }

.ai-notice { display: flex; align-items: center; gap: 10px; margin: 0 auto 8px; width: min(100%, var(--thread-w)); padding: 10px 14px; border-radius: 12px; background: var(--fill-rest); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }

.ai-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scroll-padding-bottom: 24px; }
.ai-thread { width: min(100%, var(--thread-w)); margin: 0 auto; padding: 8px 4px 28px; }
.ai-thread[data-empty] { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1fr); align-content: center; }
.ai-thread-head { position: relative; padding: 10px 44px 14px 0; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.ai-thread-title { margin: 0 0 4px; font: 800 20px/1.2 var(--display); overflow-wrap: anywhere; }
.ai-thread-meta { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 13px; }
.ai-thread-more { position: absolute; right: 0; top: 8px; }

.ai-tobottom {
  position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%); width: 40px; height: 40px;
  display: grid; place-items: center; border: 1px solid var(--line-strong); border-radius: 50%; background: var(--surface-2);
  color: var(--text); cursor: pointer; box-shadow: 0 8px 20px rgba(0, 0, 0, .35);
}

/* empty state */
.ai-empty { min-width: 0; padding: 12px 0 8px; }
.ai-empty-title { margin: 0 0 18px; font: 800 clamp(26px, 4vw, 34px)/1.1 var(--display); text-transform: uppercase; letter-spacing: .01em; }
.ai-banner { display: flex; align-items: center; gap: 10px; margin: 0 0 20px; padding: 12px 14px; border-radius: 12px; background: var(--fill-rest); border: 1px solid var(--line); color: var(--text); font-size: 14.5px; line-height: 1.45; }
.ai-banner-gift .ai-ico { color: var(--gold); }
.ai-agents { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 16px; }
.ai-agent {
  min-height: 70px; display: grid; align-content: start; gap: 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); color: var(--text); text-align: left; cursor: pointer;
}
.ai-agent:hover { background: var(--surface-2); }
.ai-agent.is-on { background: var(--fill-selected); border-color: var(--line-strong); }
.ai-agent.is-on .ai-agent-name { color: var(--gold); }
.ai-agent-name { font: 800 14.5px/1.2 var(--display); }
.ai-agent-desc { color: var(--muted); font-size: 13px; line-height: 1.35; }
.ai-starters { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.ai-starter { min-height: 40px; padding: 8px 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: transparent; color: var(--text); font: 600 14px/1.25 var(--body); cursor: pointer; text-align: left; }
.ai-starter:hover { background: var(--fill-hover); }
.ai-empty-model { margin: 0; color: var(--muted); font-size: 14px; }

/* messages */
.ai-msg { margin: 0 0 22px; }
.ai-msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.ai-bubble { max-width: min(82%, 620px); padding: 11px 16px; border-radius: 18px 18px 6px 18px; background: var(--surface-2); }
.ai-user-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15.5px; line-height: 1.55; }
.ai-msg-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-top: 4px; min-height: 40px; }
.ai-msg-user .ai-msg-tools { opacity: .0; }
.ai-msg-user:hover .ai-msg-tools, .ai-msg-user:focus-within .ai-msg-tools { opacity: 1; }
@media (hover: none) { .ai-msg-user .ai-msg-tools { opacity: 1; } }
.ai-msg-head { margin: 0 0 6px; }
.ai-msg-model { color: var(--muted); font: 700 12.5px/1 var(--body); }
.ai-tool-btn { min-height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font: 600 13.5px/1 var(--body); cursor: pointer; }
.ai-tool-btn:hover { background: var(--fill-hover); color: var(--text); }
.ai-tool-btn:disabled { opacity: .4; cursor: default; background: none; }
.ai-tool-btn .ai-ico, .ai-tool-btn .ai-ico svg { width: 18px; height: 18px; }
.ai-msg-cost { margin-left: auto; padding-left: 8px; color: var(--muted-2); font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ai-msg-note { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 8px 0 0; padding: 10px 14px; border-radius: 12px; background: var(--fill-rest); border: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.ai-msg-note.is-error { border-color: rgba(255, 180, 171, .3); color: var(--text); }
.ai-branch { display: inline-flex; align-items: center; gap: 0; margin-right: 4px; }
.ai-branch-btn { width: 32px; height: 36px; }
.ai-branch-count { min-width: 30px; text-align: center; color: var(--muted); font: 700 13px/1 var(--body); font-variant-numeric: tabular-nums; }
.ai-typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.ai-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; }
@media (prefers-reduced-motion: no-preference) {
  .ai-typing i { animation: ai-dot 1.1s ease-in-out infinite; }
  .ai-typing i:nth-child(2) { animation-delay: .15s; }
  .ai-typing i:nth-child(3) { animation-delay: .3s; }
}
@keyframes ai-dot { 0%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.ai-msg-bot.is-streaming .ai-md > .md-p:last-child::after,
.ai-msg-bot.is-streaming .ai-md > .md-list:last-child > li:last-child::after { content: ""; display: inline-block; width: 8px; height: 1.05em; margin-left: 2px; vertical-align: -2px; border-radius: 2px; background: var(--muted); opacity: .7; }
.ai-state { margin: 24px 0; padding: 16px; border-radius: 14px; background: var(--fill-rest); border: 1px solid var(--line); color: var(--muted); }
.ai-state p { margin: 0 0 10px; }

/* editing */
.ai-edit { width: min(100%, 680px); padding: 10px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line-strong); }
.ai-edit-input { width: 100%; min-height: 72px; resize: none; padding: 6px 8px; border: 0; background: transparent; color: var(--text); font: 500 15.5px/1.55 var(--body); }
.ai-edit-input:focus { outline: none; }
.ai-edit-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ai-edit-est { color: var(--muted); font-size: 13px; }
.ai-edit-hint { flex: 1; color: var(--muted-2); font-size: 12.5px; }

/* composer */
.ai-composer { position: relative; width: min(100%, var(--thread-w)); margin: 0 auto; padding-bottom: var(--dock-space); }
.ai-composer-alert { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; margin: 0 0 8px; padding: 9px 14px; border-radius: 12px; background: var(--fill-rest); border: 1px solid var(--line); color: var(--text); font-size: 14px; line-height: 1.4; }
.ai-composer-alert.is-soft { color: var(--muted); }
.ai-composer-alert.is-error { border-color: rgba(255, 180, 171, .35); }
.ai-composer-box { display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 16px; border: 1px solid var(--line-strong); border-radius: 18px; background: var(--surface); }
.ai-composer-box:focus-within { border-color: var(--muted-2); }
.ai-composer-ext:empty { display: none; }
.ai-composer textarea {
  flex: 1; min-width: 0; min-height: 40px; max-height: 40vh; resize: none; padding: 9px 0; border: 0; background: transparent; color: var(--text);
  font: 500 16px/1.45 var(--body); overflow-y: hidden;
}
.ai-composer textarea:focus { outline: none; }
.ai-composer textarea::placeholder { color: var(--muted-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-send {
  flex: none; min-width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 10px;
  border: 0; border-radius: 12px; background: var(--gold); color: var(--gold-ink); font: 800 14px/1 var(--display); cursor: pointer;
}
.ai-send:hover { background: var(--gold-strong); }
.ai-send:disabled { background: var(--surface-3); color: var(--muted-2); cursor: default; }
.ai-send.is-topup { padding: 0 16px; }
.ai-send.is-topup .ai-ico { display: none; }
.ai-send-label:empty { display: none; }
.ai-stop {
  flex: none; height: 42px; display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; border: 1px solid var(--line-strong);
  border-radius: 12px; background: var(--surface-2); color: var(--text); font: 800 14px/1 var(--display); cursor: pointer;
}
.ai-stop:hover { background: var(--surface-3); }
.ai-composer-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 26px; padding: 5px 6px 0; color: var(--muted-2); font-size: 12.5px; }
.ai-est { color: var(--muted); font-variant-numeric: tabular-nums; }
.ai-kbd-hint { text-align: right; }
@media (pointer: coarse), (max-width: 780px) { .ai-kbd-hint { display: none; } }

/* ------------------------------------------------------------------ Markdown */

.ai-md { font-size: 15.5px; line-height: 1.68; overflow-wrap: anywhere; }
.ai-md > :first-child { margin-top: 0; }
.ai-md > :last-child { margin-bottom: 0; }
.md-p { margin: 0 0 14px; white-space: pre-line; }
.md-h { margin: 22px 0 10px; font-family: var(--display); font-weight: 800; line-height: 1.25; letter-spacing: 0; text-transform: none; }
.md-h1 { font-size: 22px; }
.md-h2 { font-size: 19px; }
.md-h3 { font-size: 17px; }
.md-h4, .md-h5, .md-h6 { font-size: 15.5px; }
.md-hr { margin: 22px 0; border: 0; border-top: 1px solid var(--line-strong); }
.md-link { color: var(--text); text-decoration: underline; text-decoration-color: rgba(233, 200, 124, .6); text-underline-offset: 3px; }
.md-link:hover { text-decoration-color: var(--gold); }
.md-inline-code { padding: 1px 6px; border-radius: 6px; background: var(--surface-2); font: 400 .9em/1.4 var(--mono); }
.md-quote { margin: 0 0 14px; padding: 2px 0 2px 16px; border-left: 3px solid var(--line-strong); color: var(--muted); }
.md-quote > :last-child { margin-bottom: 0; }
.md-list { margin: 0 0 14px; padding-left: 24px; }
.md-list li { margin: 4px 0; padding-left: 2px; }
.md-list .md-list { margin: 4px 0; }
.md-list li::marker { color: var(--muted); }
.md-li-text { margin: 0 0 4px; }
.md-task { list-style: none; position: relative; }
.md-check { display: inline-block; width: 15px; height: 15px; margin: 0 8px 0 -22px; vertical-align: -2px; border: 1.5px solid var(--muted); border-radius: 4px; }
.md-check.is-on { background: var(--muted); }
.md-code { margin: 0 0 16px; border-radius: 14px; background: var(--surface-sunken); border: 1px solid var(--line); overflow: hidden; }
.md-code-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 40px; padding: 0 6px 0 14px; border-bottom: 1px solid var(--line); }
.md-code-lang { color: var(--muted); font: 600 12.5px/1 var(--body); }
.md-copy { min-height: 32px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 9px; background: transparent; color: var(--text); font: 700 12.5px/1 var(--body); cursor: pointer; }
.md-copy:hover { background: var(--fill-hover); }
.md-copy.is-done { color: var(--ok); border-color: rgba(166, 213, 167, .4); }
.md-pre { margin: 0; padding: 14px 16px; overflow-x: auto; font: 400 13.5px/1.6 var(--mono); color: #e7e2da; tab-size: 4; }
.md-pre code { font: inherit; white-space: pre; }
.md-table { margin: 0 0 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.md-table table { border-collapse: collapse; min-width: 100%; font-size: 14.5px; }
.md-table th, .md-table td { padding: 9px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md-table thead th { background: var(--surface-2); font-weight: 700; white-space: nowrap; }
.md-table tbody tr:last-child td { border-bottom: 0; }
.md-math { font-family: var(--mono); font-size: .95em; }
.md-math[data-done] { font-family: inherit; font-size: 1em; }
.md-math-block { display: block; margin: 0 0 14px; padding: 6px 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
.md-math-block[data-open] { color: var(--muted); }
.ai-md .katex { font-size: 1.08em; }
.ai-md .katex-display { margin: 0; }
/* code tokens: muted, distinct, never the gold of the action button */
.tk-keyword { color: #e6b673; }
.tk-string { color: #a6d5a7; }
.tk-number, .tk-literal { color: #f2a68e; }
.tk-comment { color: #8b8578; font-style: italic; }
.tk-fn { color: #9fc3e6; }
.tk-type { color: #e7d6a8; }
.tk-attr { color: #b8c7e0; }
.tk-var { color: #d7b8f5; }
.tk-add { color: #a6d5a7; }
.tk-del { color: #ffb4ab; }

/* ------------------------------------------------------------------ sheets, menus, toast */

body.ai-sheet-open { overflow: hidden; }
.ai-sheet-back { position: fixed; inset: 0; z-index: 400; background: var(--scrim); opacity: 0; }
.ai-sheet-back.is-open { opacity: 1; }
.ai-sheet {
  position: fixed; z-index: 410; left: 50%; top: 50%; width: min(calc(100% - 32px), 540px); max-height: min(86dvh, 820px);
  display: flex; flex-direction: column; border: 1px solid rgba(255, 255, 255, .12); border-radius: 22px; background: var(--overlay);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5); -webkit-backdrop-filter: blur(18px) saturate(1.1); backdrop-filter: blur(18px) saturate(1.1);
  opacity: 0; transform: translate(-50%, -48%) scale(.98);
}
.ai-sheet.is-open { opacity: 1; transform: translate(-50%, -50%); }
.ai-sheet:focus { outline: none; }
.ai-sheet-models, .ai-sheet-prices, .ai-sheet-balance { width: min(calc(100% - 32px), 640px); }
.ai-sheet-menu, .ai-sheet-confirm { width: min(calc(100% - 32px), 440px); }
.ai-sheet-grab { display: none; }
.ai-sheet-close { position: absolute; top: 12px; right: 12px; z-index: 1; }
.ai-sheet-body { overflow-y: auto; padding: 24px 24px 24px; overscroll-behavior: contain; }
.ai-sheet-title { margin: 0 44px 10px 0; font: 800 22px/1.15 var(--display); text-transform: uppercase; letter-spacing: .01em; }
.ai-sheet-title-sm { font-size: 16px; text-transform: none; margin-bottom: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ai-sheet-text { margin: 0 0 14px; color: var(--muted); font-size: 15px; line-height: 1.55; }
.ai-sheet-text a { color: var(--text); }
.ai-sheet-sub { margin: 22px 0 8px; font: 800 15px/1.2 var(--display); }
.ai-sheet-note { margin: 10px 0 0; color: var(--muted-2); font-size: 13px; }
.ai-sheet-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.ai-sheet-link { margin-top: 16px; }
.ai-sheet-links { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
@media (prefers-reduced-motion: no-preference) {
  .ai-sheet { transition: opacity 160ms ease, transform 220ms cubic-bezier(.2, .8, .2, 1); }
  .ai-sheet-back { transition: opacity 200ms ease; }
}

.ai-menu {
  position: fixed; z-index: 420; min-width: 220px; max-width: 320px; padding: 6px; border: 1px solid rgba(255, 255, 255, .12); border-radius: 16px;
  background: var(--overlay); box-shadow: 0 18px 40px rgba(0, 0, 0, .45); -webkit-backdrop-filter: blur(16px) saturate(1.05); backdrop-filter: blur(16px) saturate(1.05);
  opacity: 0; transform: translateY(-4px);
}
.ai-menu.is-open { opacity: 1; transform: none; }
@media (prefers-reduced-motion: no-preference) { .ai-menu { transition: opacity 120ms ease, transform 140ms ease; } }
.ai-menu-list { display: grid; gap: 2px; }
.ai-menu-item { min-height: 44px; display: flex; align-items: center; gap: 12px; padding: 0 12px; border: 0; border-radius: 11px; background: none; color: var(--text); font: 600 14.5px/1.2 var(--body); text-align: left; cursor: pointer; }
.ai-menu-item:hover, .ai-menu-item:focus-visible { background: var(--fill-selected); }
.ai-menu-item .ai-ico { color: var(--muted); }
.ai-menu-item.is-danger, .ai-menu-item.is-danger .ai-ico { color: var(--danger); }
.ai-menu-div { height: 1px; margin: 4px 8px; background: var(--line); }

.ai-toast {
  position: fixed; z-index: 450; left: 50%; bottom: 24px; max-width: min(calc(100% - 32px), 520px); display: flex; align-items: center; gap: 14px;
  padding: 12px 14px 12px 16px; border: 1px solid rgba(255, 255, 255, .12); border-radius: 14px; background: var(--overlay); color: var(--text);
  font-size: 14.5px; box-shadow: 0 16px 40px rgba(0, 0, 0, .45); opacity: 0; transform: translate(-50%, 8px);
}
.ai-toast.is-on { opacity: 1; transform: translate(-50%, 0); }
.ai-toast-btn { flex: none; min-height: 36px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--fill-selected); color: var(--text); font: 700 13.5px/1 var(--body); cursor: pointer; }
@media (prefers-reduced-motion: no-preference) { .ai-toast { transition: opacity 180ms ease, transform 200ms ease; } }

/* model picker */
.ai-models { display: grid; gap: 6px; }
.ai-model {
  display: grid; gap: 4px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface);
  color: var(--text); text-align: left; cursor: pointer;
}
.ai-model:hover { background: var(--surface-2); }
.ai-model.is-on { background: var(--fill-selected); border-color: var(--line-strong); }
.ai-model.is-on .ai-model-name { color: var(--gold); }
.ai-model:disabled { opacity: .5; cursor: default; }
.ai-model-top { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.ai-model .ai-model-name { font: 800 15px/1.2 var(--display); }
.ai-model-vendor { color: var(--muted-2); font-size: 13px; }
.ai-model-desc { color: var(--muted); font-size: 13.5px; line-height: 1.4; }
.ai-model .ai-model-price { display: flex; flex-wrap: wrap; gap: 2px 12px; color: var(--muted-2); font-size: 12.5px; white-space: normal; }
.ai-model .ai-model-price b { color: var(--text); font-weight: 700; }
.ai-model-off { color: var(--muted); font-size: 12.5px; }
.ai-switch { position: relative; display: flex; align-items: flex-start; gap: 12px; margin-top: 16px; padding: 12px 14px; border-radius: 14px; background: var(--fill-rest); border: 1px solid var(--line); cursor: pointer; }
.ai-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.ai-switch-track { flex: none; position: relative; width: 40px; height: 24px; margin-top: 1px; border-radius: 999px; background: var(--surface-3); }
.ai-switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--muted); }
.ai-switch input:checked + .ai-switch-track { background: rgba(244, 239, 228, .28); }
.ai-switch input:checked + .ai-switch-track::after { left: 19px; background: var(--text); }
.ai-switch input:focus-visible + .ai-switch-track { outline: 2px solid var(--text); outline-offset: 2px; }
.ai-switch-text { display: grid; gap: 2px; font-size: 13.5px; color: var(--muted); line-height: 1.4; }
.ai-switch-text b { color: var(--text); font-size: 14.5px; }
@media (prefers-reduced-motion: no-preference) { .ai-switch-track::after { transition: left 160ms ease; } }
.ai-agent-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-chip { min-height: 38px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 999px; background: transparent; color: var(--text); font: 700 13.5px/1 var(--body); cursor: pointer; }
.ai-chip:hover { background: var(--fill-hover); }
.ai-chip.is-on { background: var(--fill-selected); color: var(--gold); }

/* balance */
.ai-bal-total { display: flex; align-items: baseline; gap: 10px; margin: 6px 0 16px; }
.ai-bal-total b { font: 800 34px/1 var(--display); font-variant-numeric: tabular-nums; }
.ai-bal-total span { color: var(--muted); font-size: 14px; }
.ai-bal-rows { margin: 0 0 16px; padding: 4px 14px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); }
.ai-bal-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0 2px; }
.ai-bal-row dt { font-weight: 700; }
.ai-bal-row dd { margin: 0; font-variant-numeric: tabular-nums; font-weight: 700; }
.ai-bal-hint { margin: 0; padding: 0 0 10px; border-bottom: 1px solid var(--line); color: var(--muted-2); font-size: 13px; line-height: 1.4; }
.ai-bal-rows > .ai-bal-hint:last-child { border-bottom: 0; }
.ai-sheet-balance .ai-strong-btn { width: 100%; margin-bottom: 10px; }
.ai-limits { margin-top: 6px; }
.ai-field { display: grid; gap: 6px; margin: 0 0 12px; }
.ai-field label { color: var(--muted); font-size: 13.5px; font-weight: 600; }
.ai-input-rub { position: relative; }
.ai-input-rub .ai-input { padding-right: 34px; }
.ai-input-rub span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.ai-limits-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.ai-sheet-balance .ai-limits .ai-strong-btn { width: auto; margin: 0; }
.ai-field-status { margin: 0; color: var(--muted); font-size: 13.5px; }
.ai-field-status.is-error { color: var(--danger); }

/* top-up */
.ai-amounts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; }
.ai-amount { min-height: 50px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font: 800 16px/1 var(--display); cursor: pointer; font-variant-numeric: tabular-nums; }
.ai-amount:hover { background: var(--surface-2); }
.ai-amount.is-on { background: var(--fill-selected); border-color: var(--line-strong); color: var(--gold); }
.ai-methods { display: grid; gap: 6px; margin: 0 0 14px; }
.ai-method { min-height: 50px; display: grid; gap: 2px; align-content: center; padding: 8px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; }
.ai-method:hover { background: var(--surface-2); }
.ai-method.is-on { background: var(--fill-selected); border-color: var(--line-strong); }
.ai-method.is-on .ai-method-name { color: var(--gold); }
.ai-method-name { font: 700 15px/1.2 var(--body); }
.ai-method-hint { color: var(--muted); font-size: 12.5px; }
.ai-topup-facts { margin: 0 0 10px; color: var(--muted); font-size: 13.5px; line-height: 1.5; }
.ai-legal { margin: 0 0 14px; color: var(--muted-2); font-size: 13px; line-height: 1.5; }
.ai-legal a { color: var(--muted); text-decoration: underline; text-underline-offset: 2px; }
.ai-choice-list { display: grid; gap: 6px; }
.ai-choice { min-height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); font: 600 14.5px/1.2 var(--body); text-align: left; cursor: pointer; }
.ai-choice.is-on { background: var(--fill-selected); border-color: var(--line-strong); color: var(--gold); }

/* ------------------------------------------------------------------ phone */

@media (max-width: 1080px) and (min-width: 781px) {
  :root { --side-w: 256px; }
  .ai-chat-cost { display: none; }
  .ai-agents { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 780px) {
  /* The app is the whole screen: no site header (the dock keeps the navigation and the account). */
  body[data-view="app"] .site-header { display: none; }
  body.ai-page { --dock-space: calc(84px + env(safe-area-inset-bottom)); }
  body.ai-typing, body.ai-kbd { --dock-space: env(safe-area-inset-bottom); }
  body.ai-typing .mobile-dock, body.ai-kbd .mobile-dock { visibility: hidden; }
  .ai-app { position: fixed; inset: 0 0 auto 0; height: var(--ai-vvh, 100dvh); grid-template-columns: 1fr; gap: 0; padding: 0 12px 10px; }
  .ai-bar { min-height: 56px; padding: env(safe-area-inset-top) 0 4px; gap: 6px; }
  .ai-bar-menu, .ai-bar-new { display: inline-grid; width: 44px; height: 44px; }
  .ai-bar-menu { margin-left: -6px; }
  .ai-bar-new { margin-right: -6px; }
  .ai-model-btn { flex: 1; min-height: 44px; padding: 0 8px 0 12px; }
  .ai-model-name { font-size: 14px; }
  .ai-chat-cost, .ai-bar-more, .ai-bar-spacer { display: none; }
  .ai-balance { min-height: 44px; padding: 0 10px; }
  .ai-balance-main { font-size: 14px; }
  .ai-balance-sub { font-size: 10.5px; }
  .ai-thread { padding: 4px 0 20px; }
  .ai-thread-head { padding-top: 4px; }
  .ai-thread-title { font-size: 18px; }
  .ai-bubble { max-width: 88%; }
  .ai-agents { display: flex; overflow-x: auto; margin: 0 -12px 14px; padding: 0 12px 4px; scroll-snap-type: x proximity; scroll-padding-inline: 12px; scrollbar-width: none; }
  .ai-agents::-webkit-scrollbar { display: none; }
  .ai-agent { flex: 0 0 auto; width: 168px; min-height: 76px; scroll-snap-align: start; }
  .ai-empty-title { font-size: 24px; margin-bottom: 14px; }
  .ai-composer-box { border-radius: 16px; padding: 6px 6px 6px 14px; }
  .ai-composer-meta { padding-top: 4px; min-height: 22px; }
  .md-pre { font-size: 13px; padding: 12px; }

  /* the chat list: a bottom sheet like the account sheet */
  .ai-side {
    position: fixed; z-index: 380; left: 0; right: 0; bottom: 0; height: min(88dvh, 760px); border-radius: 22px 22px 0 0; border-bottom: 0;
    background: var(--overlay); box-shadow: 0 -18px 40px rgba(0, 0, 0, .42); transform: translateY(102%); visibility: hidden;
    padding-bottom: env(safe-area-inset-bottom);
  }
  body.ai-side-open .ai-side { transform: none; visibility: visible; }
  /* .ai-app is fixed (its own stacking layer): lift it over the dock while the list is open. */
  body.ai-side-open .ai-app { z-index: 200; }
  .ai-scrim { position: fixed; inset: 0; z-index: 370; display: block; background: var(--scrim); }
  .ai-side-close { display: inline-grid; }
  .ai-side-head { padding-top: 14px; }
  .ai-item-link, .ai-folder-toggle { min-height: 46px; font-size: 15px; }
  .ai-side-link { min-height: 46px; font-size: 15px; }

  /* sheets slide up from the bottom */
  .ai-sheet, .ai-sheet-models, .ai-sheet-prices, .ai-sheet-balance, .ai-sheet-menu, .ai-sheet-confirm {
    left: 0; right: 0; top: auto; bottom: 0; width: 100%; max-height: 90dvh; border-radius: 22px 22px 0 0; border-bottom: 0;
    transform: translateY(100%); opacity: 1;
  }
  .ai-sheet.is-open { transform: none; }
  .ai-sheet.is-dragging { transition: none !important; }
  .ai-sheet-grab { display: block; flex: none; width: 40px; height: 4px; margin: 10px auto 2px; border-radius: 999px; background: rgba(255, 255, 255, .22); touch-action: none; }
  .ai-sheet-grab::before { content: ""; display: block; height: 24px; margin: -10px -60px 0; }
  .ai-sheet-close { top: 8px; right: 8px; }
  .ai-sheet-body { padding: 12px 16px calc(20px + env(safe-area-inset-bottom)); }
  .ai-sheet-title { font-size: 19px; }
  .ai-sheet-actions { justify-content: stretch; }
  .ai-sheet-actions > * { flex: 1; }
  .ai-amounts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .ai-toast { bottom: calc(var(--dock-space) + 128px); width: calc(100% - 24px); }
}
@media (max-width: 780px) and (prefers-reduced-motion: no-preference) {
  .ai-side { transition: transform 300ms cubic-bezier(.32, .72, 0, 1), visibility 300ms; }
  .ai-sheet { transition: transform 300ms cubic-bezier(.32, .72, 0, 1); }
}
@media (max-width: 420px) {
  .ai-bar .ai-model-price { display: none; }
}
@media (max-width: 360px) {
  .ai-balance-sub { display: none; }
  .ai-amounts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-page *, .ai-page *::before, .ai-page *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .ai-sheet, .ai-sheet-back, .ai-menu, .ai-toast { -webkit-backdrop-filter: none; backdrop-filter: none; }
}
