/* FIX: elements with an explicit display rule ignore the hidden attribute */
[hidden] { display: none !important; }

/* ==========================================================================
   AFINA v4 — minimalist UI (DeepSeek / ChatGPT / Claude feel)
   Plain CSS, no framework. Light + dark via prefers-color-scheme.
   Accent orange is reserved for the primary action only.
   ========================================================================== */

:root {
  /* Neutral surfaces + type scale follow the reference design system,
     but the brand accent stays AFINA orange. */
  --accent: #e8590c;
  --accent-hover: #d94e00;
  --accent-soft: rgba(232, 89, 12, .12);

  /* light */
  --bg: #f9f9f7;          /* surface-0 */
  --bg-side: #fcfcfb;     /* surface-1 */
  --bg-elev: #ffffff;     /* surface-3 */
  --bg-hover: #f0efec;
  --bg-code: #f4f3f0;
  --border: rgba(32, 32, 31, .10);
  --border-strong: rgba(32, 32, 31, .20);
  --text: #20201f;
  --text-soft: #52514e;
  --text-faint: #898781;
  --danger: #c0392b;
  --ok: #2f8f52;
  --warn: #b9770e;
  --shadow: 0 4px 20px rgba(0, 0, 0, .06);
  --radius: 12px;
  --radius-sm: 8px;
  --prose: 16px;
  --sidebar-w: 272px;
  --measure: 768px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --serif: "Georgia", "Times New Roman", "Noto Serif", serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0b0b;        /* surface-0 */
    --bg-side: #151515;   /* surface-1 */
    --bg-elev: #20201f;   /* surface-3 */
    --bg-hover: #2a2a28;
    --bg-code: #171717;
    --border: rgba(240, 239, 236, .10);
    --border-strong: rgba(240, 239, 236, .18);
    --text: #f0efec;
    --text-soft: #c3c2b7;
    --text-faint: #898781;
    --shadow: 0 4px 24px rgba(0, 0, 0, .45);
  }
}

/* Explicit theme overrides from the user settings panel.
   .theme-dark/.theme-light win over prefers-color-scheme. */
:root.theme-dark {
  --bg: #0b0b0b; --bg-side: #151515; --bg-elev: #20201f;
  --bg-hover: #2a2a28; --bg-code: #171717;
  --border: rgba(240, 239, 236, .10); --border-strong: rgba(240, 239, 236, .18);
  --text: #f0efec; --text-soft: #c3c2b7; --text-faint: #898781;
  --shadow: 0 4px 24px rgba(0, 0, 0, .45);
}
:root.theme-light {
  --bg: #f9f9f7; --bg-side: #fcfcfb; --bg-elev: #ffffff;
  --bg-hover: #f0efec; --bg-code: #f4f3f0;
  --border: rgba(32, 32, 31, .10); --border-strong: rgba(32, 32, 31, .20);
  --text: #20201f; --text-soft: #52514e; --text-faint: #898781;
  --shadow: 0 4px 20px rgba(0, 0, 0, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--accent-soft); }

/* thin scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.ico { width: 20px; height: 20px; fill: none; stroke: currentColor;
       stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico.mini { width: 16px; height: 16px; }

/* ============================ layout ============================ */
.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--bg-side);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: margin-left .18s ease;
}
.app.side-collapsed .sidebar { margin-left: calc(-1 * var(--sidebar-w)); }

.brand { display: flex; align-items: center; gap: 9px; padding: 14px 14px 8px; }
.brand-logo { width: 26px; height: 26px; }
.brand-name { font-weight: 600; letter-spacing: .04em; flex: 1; }
.collapse-btn { color: var(--text-faint); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  color: var(--text-soft); transition: background .12s, color .12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.new-btn {
  display: flex; align-items: center; gap: 9px;
  margin: 8px 12px; padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--accent); color: #fff;
  font-weight: 500;
  transition: background .12s;
}
.new-btn:hover { background: var(--accent-hover); }

.side-nav { display: flex; flex-direction: column; padding: 4px 8px; gap: 1px; }
.side-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-size: 14px; text-align: left;
  transition: background .12s, color .12s;
}
.side-link:hover { background: var(--bg-hover); color: var(--text); }
.side-link.active { background: var(--bg-hover); color: var(--text); font-weight: 500; }

.search-wrap {
  display: flex; align-items: center; gap: 7px;
  margin: 8px 12px; padding: 7px 10px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.search-ico { color: var(--text-faint); }
.search-input { border: none; background: none; outline: none; width: 100%; }

.hist-section { padding: 4px 8px; display: flex; flex-direction: column; min-height: 0; }
.hist-section.grow { flex: 1; }
.proj-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 10px 4px; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--text-faint);
}
.proj-add { color: var(--text-faint); padding: 2px; border-radius: 6px; }
.proj-add:hover { background: var(--bg-hover); color: var(--text); }
.history { overflow-y: auto; min-height: 0; }

/* Date group headers inside the chat list (Сегодня / Вчера / 7 дней / 2026-09). */
.chat-group {
  font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: none;
  color: var(--text-faint); padding: 12px 10px 4px; user-select: none;
}
.history .chat-group:first-child { padding-top: 4px; }

.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-size: 14px; text-align: left;
  width: 100%; transition: background .12s, color .12s;
}
.chat-item:hover { background: var(--bg-hover); color: var(--text); }
.chat-item.active { background: var(--bg-hover); color: var(--text); font-weight: 500; }
.chat-item .ct { flex: 1; white-space: nowrap; overflow: hidden;
                 text-overflow: ellipsis; min-width: 0; }
.chat-item .gen-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: pulse 1.4s infinite; flex: 0 0 7px;
}
.chat-item .row-act { opacity: 0; color: var(--text-faint); }
.chat-item:hover .row-act { opacity: 1; }
.chat-item .row-act:hover { color: var(--danger); }
@keyframes pulse { 0%,100% { opacity: .35 } 50% { opacity: 1 } }

.sidebar-bottom { padding: 8px; border-top: 1px solid var(--border); }
.account {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text);
}
.account:hover { background: var(--bg-hover); }
.acc-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; display: flex;
  align-items: center; justify-content: center; font-size: 13px; font-weight: 600;
}
.acc-text { flex: 1; text-align: left; font-size: 14px; }
.acc-caret { color: var(--text-faint); }

.scrim { display: none; }

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

.topbar {
  display: flex; align-items: center; gap: 6px;
  height: 52px; padding: 0 10px; border-bottom: 1px solid var(--border);
  flex: 0 0 52px;
}
.menu-btn { display: none; }
.desktop-menu-btn { color: var(--text-faint); }
.session-title {
  flex: 1; text-align: left; font-weight: 600; font-size: 15px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 6px 8px; border-radius: var(--radius-sm); color: var(--text);
  max-width: 100%;
}
.session-title:hover { background: var(--bg-hover); }
.topbar-right { display: flex; align-items: center; gap: 4px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.conn-dot.on { background: var(--ok); }
.conn-dot.off { background: var(--danger); }

.chat {
  flex: 1; overflow-y: auto; min-height: 0;
  scroll-behavior: smooth;
}
.empty-state {
  /* Compact centred greeting (never a full-height empty hero): the sheet
     stops growing once it has the logo + heading + suggestion chips. */
  max-width: 720px; margin: 0 auto; padding: 12vh 22px 28px;
  text-align: center; display: flex; flex-direction: column;
  align-items: center; gap: 16px;
}
.empty-logo { width: 48px; height: 48px; opacity: .9; }
.greeting {
  font-family: var(--serif); font-weight: 400; letter-spacing: -.01em;
  font-size: 30px; margin: 0;
}
.suggest-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggest {
  padding: 9px 14px; border: 1px solid var(--border);
  border-radius: 999px; color: var(--text-soft); font-size: 13.5px;
  transition: background .12s, border-color .12s;
}
.suggest:hover { background: var(--bg-hover); border-color: var(--border-strong); }

.thread { max-width: 820px; margin: 0 auto; padding: 30px 24px 48px; }
/* Messages: no avatars, no names. The user speaks in a bubble on the right,
   the assistant is full-width plain text. Bubble side is the only signal. */
.msg { display: flex; margin-bottom: 22px; animation: msg-in 180ms ease-out; }
.msg .body { flex: 1; min-width: 0; }
.msg.user { justify-content: flex-end; }
.msg.user .body {
  flex: 0 1 auto; max-width: 72%;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 16px 16px 4px 16px; padding: 10px 14px;
  text-align: left;
}
/* Assistant answers are full-width plain text (no accent bar, no avatar):
   the reference keeps the AI side clean and unadorned. */
.msg.assistant .body { position: relative; }
/* New messages rise up into place (from below), matching the direction the
   thread grows. */
@keyframes msg-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
  * { scroll-behavior: auto !important; }
}

/* reasoning block */
.reasoning {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-side); margin-bottom: 14px; overflow: hidden;
}
.reasoning summary {
  cursor: pointer; padding: 9px 12px; font-size: 13px;
  color: var(--text-soft); user-select: none;
  display: flex; align-items: center; gap: 8px;
}
.reasoning summary .rb-icon { color: var(--text-faint); }
.reasoning summary::-webkit-details-marker { display: none; }
.reasoning summary { list-style: none; }
.reasoning .rchev { transition: transform .18s; color: var(--text-faint); margin-left: 2px; }
.reasoning[open] .rchev { transform: rotate(90deg); }
.reasoning .rmeta { margin-left: auto; font-size: 12px; color: var(--text-faint);
                    font-variant-numeric: tabular-nums; }
.reasoning .rbody {
  padding: 4px 13px 12px 13px; font-size: 13px; line-height: 1.6;
  color: var(--text-soft);
  white-space: pre-wrap; max-height: 320px; overflow-y: auto;
  border-top: 1px solid var(--border);
}
.reasoning .rbody-empty { display: none; }

/* markdown content */
.content {
  word-wrap: break-word; overflow-wrap: anywhere;
  font-size: var(--prose); line-height: 1.62;
}
.content > *:first-child { margin-top: 0; }
.content > *:last-child { margin-bottom: 0; }
.content p { margin: 0 0 16px; }
.content h1, .content h2, .content h3, .content h4 {
  margin: 26px 0 12px; line-height: 1.28; font-weight: 600;
  letter-spacing: -.005em;
}
.content h1 { font-size: 24px; }
.content h2 { font-size: 20px; }
.content h3 { font-size: 17.5px; }
.content ul, .content ol { margin: 0 0 16px; padding-left: 24px; }
.content li { margin: 6px 0; }
.content blockquote {
  margin: 0 0 16px; padding: 4px 16px; border-left: 2.5px solid var(--border-strong);
  color: var(--text-soft);
}
.content a { word-break: break-word; }
.content table { border-collapse: collapse; margin: 0 0 12px; display: block;
                 overflow-x: auto; max-width: 100%; }
.content th, .content td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.content th { background: var(--bg-code); font-weight: 600; }
.content hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.content code {
  font-family: var(--mono); font-size: 13px;
  background: var(--bg-code); border: 1px solid var(--border);
  border-radius: 5px; padding: 1px 5px;
}
.content pre {
  background: var(--bg-code); border: 1px solid var(--border);
  border-radius: var(--radius-sm); margin: 0 0 12px; position: relative;
  display: grid; grid-template-columns: auto 1fr; overflow: hidden;
}
.content pre .code-head {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 12px; border-bottom: 1px solid var(--border);
  font-size: 12px; color: var(--text-faint);
}
.content pre .code-lang { font-family: var(--mono); text-transform: lowercase; }
.content pre .code-tools { display: flex; gap: 2px; }
.content pre .code-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border: none; background: none; cursor: pointer;
  color: var(--text-faint); border-radius: 6px; padding: 0;
}
.content pre .code-btn:hover { color: var(--text); background: var(--bg-hover); }
.content pre .code-btn.active { color: var(--accent); }
.content pre .code-btn .ico { width: 15px; height: 15px; }
.content pre .code-gutter {
  padding: 12px 8px 12px 12px; text-align: right; user-select: none;
  font-family: var(--mono); font-size: 13px; line-height: 1.5;
  color: var(--text-faint); opacity: .55; background: var(--bg-code);
  border-right: 1px solid var(--border);
}
.content pre .code-gutter span { display: block; }
.content pre code {
  display: block; padding: 12px 14px; background: none; border: none;
  overflow-x: auto; font-size: 13px; line-height: 1.5; min-width: 0;
}
.content pre:not(.has-gutter) code { grid-column: 1 / -1; }
.content pre.wrap code { white-space: pre-wrap; word-break: break-word; }

/* web-search "found N pages" chip in the answer */
.found-chip {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 14px;
  padding: 7px 12px; border-radius: 10px; font-size: 13.5px;
  background: var(--bg-side); border: 1px solid var(--border);
  color: var(--text-soft); transition: background .12s, border-color .12s;
}
.found-chip:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.found-chip .ico { color: var(--text-faint); }
.found-chip .fc-favs { display: inline-flex; align-items: center; }
.found-chip .fc-fav {
  width: 16px; height: 16px; border-radius: 4px; margin-left: -4px;
  background: var(--bg-elev); border: 1px solid var(--border);
}
.found-chip .fc-fav:first-child { margin-left: 0; }

/* right-hand sources panel */
.sources-panel {
  width: 380px; flex: 0 0 380px; border-left: 1px solid var(--border);
  background: var(--bg-side); display: flex; flex-direction: column;
  min-width: 0; overflow: hidden;
}
.sp-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
.sp-title { font-size: 14px; font-weight: 600; }
.sp-body { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.sp-item {
  display: block; padding: 10px 10px; border-radius: 10px; color: var(--text);
}
.sp-item:hover { background: var(--bg-hover); text-decoration: none; }
.sp-src-head { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.sp-fav { width: 16px; height: 16px; border-radius: 4px; }
.sp-src-name { font-size: 12px; color: var(--text-faint); flex: 1;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-idx { font-size: 12px; color: var(--text-faint); }
.sp-title-line, .sp-item .sp-title { font-size: 14px; font-weight: 500; line-height: 1.35; }
.sp-snippet { font-size: 12.5px; color: var(--text-soft); margin-top: 3px; line-height: 1.45;
              display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
              overflow: hidden; }

/* tool confirmation card */
.tool-card {
  margin-top: 12px; border: 1px solid var(--accent);
  border-radius: var(--radius-sm); overflow: hidden;
  background: var(--accent-soft);
}
.tool-head { padding: 8px 12px; font-size: 13px; font-weight: 600;
             color: var(--accent); }
.tool-cmd {
  margin: 0; padding: 8px 12px; font-family: var(--mono); font-size: 12.5px;
  background: var(--bg-code); border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border); white-space: pre-wrap;
  word-break: break-word;
}
.tool-reason { padding: 6px 12px; font-size: 12px; color: var(--text-soft); }
.tool-actions { display: flex; gap: 8px; padding: 8px 12px; align-items: center; }

/* ============================ composer ============================ */
.composer-wrap { padding: 0 20px 16px; }
.attachments { max-width: 820px; margin: 0 auto 8px; display: flex;
               flex-wrap: wrap; gap: 6px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg-code); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 10px; font-size: 12.5px;
}
.att-chip .rm { color: var(--text-faint); }
.att-chip .rm:hover { color: var(--danger); }

.composer {
  max-width: 820px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg-elev); border: 1px solid var(--border-strong);
  border-radius: 14px; padding: 8px 10px;
  box-shadow: 0 2px 14px rgba(0,0,0,.05);
  transition: border-color .12s, box-shadow .12s;
}
.composer:focus-within { border-color: var(--text-faint);
                         box-shadow: 0 4px 20px rgba(0,0,0,.08); }
@media (prefers-color-scheme: dark) {
  :root:not(.theme-light) .composer { box-shadow: none; }
}
.plus-btn, .send-btn, .web-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; flex: 0 0 34px;
  color: var(--text-soft);
}
.plus-btn:hover { background: var(--bg-hover); color: var(--text); }
.send-btn { background: var(--accent); color: #fff; transition: background .15s, transform .15s; }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { background: var(--border-strong); cursor: default; }
.send-btn.stop { background: var(--bg-hover); color: var(--text); }
.send-btn.stop:hover { background: var(--border); }
.web-btn { color: var(--text-faint); }
.web-btn:hover { background: var(--bg-hover); color: var(--text); }
.web-btn.active { background: var(--accent-soft); color: var(--accent); }
.input {
  flex: 1; border: none; background: none; outline: none; resize: none;
  padding: 7px 6px; max-height: 200px; line-height: 1.5;
}
.composer-meta {
  max-width: 820px; margin: 8px auto 0;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--text-faint);
}
.composer-meta .meta-right { display: flex; align-items: center; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: 12.5px;
  color: var(--text-soft); border: 1px solid transparent;
}
.chip:hover { background: var(--bg-hover); }
.chip .caret { color: var(--text-faint); }

/* popover */
.popover {
  position: absolute; bottom: 92px; right: 20px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
  padding: 6px; min-width: 300px; max-width: 340px; z-index: 40;
}
.pop-title { font-size: 12px; font-weight: 600; color: var(--text-faint);
             text-transform: uppercase; letter-spacing: .05em; padding: 8px 10px 4px; }
.pop-list { display: flex; flex-direction: column; }
.pop-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 9px 10px; border-radius: 10px; text-align: left; width: 100%;
}
.pop-item:has(.ico) {
  flex-direction: row; align-items: center; gap: 10px;
}
.pop-item:has(.ico) .ico { color: var(--text-soft); }
.pop-item:hover { background: var(--bg-hover); }
.pop-item.active { background: var(--bg-hover); }
.pop-item .pi-left { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.pop-item .pi-title { font-size: 14px; font-weight: 500; }
.pop-item .pi-desc { font-size: 12.5px; color: var(--text-faint); }
.pop-item .pi-check { color: var(--accent); }
.pop-sep { height: 1px; background: var(--border); margin: 6px 4px; }

/* reasoning slider inside the model panel */
.reason-slider { padding: 4px 12px 12px; }
.reason-slider input[type=range] {
  width: 100%; -webkit-appearance: none; appearance: none; background: transparent;
  margin: 6px 0 2px;
}
.reason-slider input[type=range]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--border-strong);
}
.reason-slider input[type=range]::-moz-range-track {
  height: 4px; border-radius: 2px; background: var(--border-strong);
}
.reason-slider input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px;
  margin-top: -6px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg-elev); box-shadow: 0 1px 3px rgba(0,0,0,.25);
  cursor: pointer;
}
.reason-slider input[type=range]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  border: 2px solid var(--bg-elev); cursor: pointer;
}
.reason-slider .rs-labels {
  display: flex; justify-content: space-between; margin-top: 6px;
}
.reason-slider .rs-tick {
  font-size: 11.5px; color: var(--text-faint); cursor: pointer;
  padding: 2px 4px; border-radius: 5px;
}
.reason-slider .rs-tick:hover { color: var(--text-soft); }
.reason-slider .rs-tick.active { color: var(--accent); font-weight: 600; }
.reason-slider .rs-value { display: none; }

/* ============================ modal ============================ */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 60; padding: 18px;
}
.modal-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 640px; max-height: 86vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-body { padding: 16px; overflow-y: auto; }

/* shared form bits */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--text-soft);
               margin-bottom: 5px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg); outline: none;
}
.field textarea { resize: vertical; min-height: 90px; font-family: inherit; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent);
}
.btn-primary {
  background: var(--accent); color: #fff; padding: 9px 16px;
  border-radius: var(--radius-sm); font-weight: 500;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); color: var(--text);
}
.btn-ghost:hover { background: var(--bg-hover); }
.btn-danger { color: var(--danger); border: 1px solid var(--border-strong);
              padding: 9px 16px; border-radius: var(--radius-sm); }
.btn-danger:hover { background: var(--bg-hover); }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 8px;
}
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 500; }
.list-item .li-sub { font-size: 12.5px; color: var(--text-faint);
                     white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px;
         background: var(--bg-code); border: 1px solid var(--border); color: var(--text-soft); }
.badge.ok { color: var(--ok); border-color: var(--ok); }
.badge.err { color: var(--danger); border-color: var(--danger); }
.muted { color: var(--text-faint); font-size: 13px; }
.hint { font-size: 12.5px; color: var(--text-faint); margin-top: 4px; }
.divider { border-top: 1px solid var(--border); margin: 16px 0; }
.switch { display: flex; align-items: center; gap: 8px; }
.switch input { width: auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { padding: 7px 12px; border-radius: var(--radius-sm); font-size: 13.5px;
       color: var(--text-soft); }
.tab:hover { background: var(--bg-hover); }
.tab.active { background: var(--bg-hover); color: var(--text); font-weight: 500; }
.code-view {
  font-family: var(--mono); font-size: 12.5px; white-space: pre-wrap;
  background: var(--bg-code); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; max-height: 420px;
  overflow: auto;
}

/* toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
          display: flex; flex-direction: column; gap: 8px; z-index: 80;
          align-items: center; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--border);
  box-shadow: var(--shadow); border-radius: var(--radius-sm);
  padding: 10px 16px; font-size: 13.5px; max-width: 90vw;
}
.toast.err { border-color: var(--danger); color: var(--danger); }

/* typing caret */
.caret-blink { display: inline-block; width: 8px; height: 15px;
               background: var(--text); margin-left: 2px; vertical-align: text-bottom;
               animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0 } }

/* ============================ responsive ============================ */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    transform: translateX(0); box-shadow: var(--shadow);
  }
  .app:not(.side-open) .sidebar { transform: translateX(-100%); }
  .app.side-collapsed .sidebar { margin-left: 0; }
  .scrim {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4);
    z-index: 45; opacity: 0; pointer-events: none; transition: opacity .18s;
  }
  .app.side-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; }
  .desktop-menu-btn { display: none; }
}

@media (max-width: 400px) {
  body { font-size: 14.5px; }
  .composer-wrap { padding: 0 10px 10px; }
  .thread { padding: 16px 14px 30px; }
  .greeting { font-size: 22px; }
  .side-nav { padding: 4px 6px; }
  .chat-item { padding: 9px 8px; }
  .popover { right: 10px; left: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ============================ login ============================ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; min-height: 100dvh; background: var(--bg-side); padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 32px 28px; box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-logo { width: 52px; height: 52px; }
.login-title { font-size: 24px; font-weight: 700; margin: 10px 0 4px;
               letter-spacing: .04em; }
.login-sub { color: var(--text-soft); font-size: 14px; margin: 0; }
.login-field { display: block; margin-bottom: 16px; }
.login-field span { display: block; font-size: 13px; color: var(--text-soft);
                    margin-bottom: 6px; font-weight: 500; }
.login-field input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg); outline: none;
}
.login-field input:focus { border-color: var(--accent); }
.login-submit {
  width: 100%; padding: 12px; border-radius: var(--radius-sm);
  background: var(--accent); color: #fff; font-weight: 600; font-size: 15px;
  transition: background .12s;
}
.login-submit:hover { background: var(--accent-hover); }
.login-submit:disabled { background: var(--border-strong); cursor: default; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 12px;
             text-align: center; min-height: 18px; }

/* ============================ live stats / thoughts ============================ */
.reasoning .rlabel { font-weight: 600; }
.reasoning .rlabel.thinking::after {
  content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 7px;
  border-radius: 50%; background: var(--accent); vertical-align: middle;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.15); } }
.reasoning[open] summary { color: var(--text-soft); }
.reasoning .rbody { max-height: 320px; }

/* admin link pinned above the account row */
.sidebar-bottom { display: flex; flex-direction: column; gap: 4px; padding: 8px; }
.admin-bottom {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: var(--radius-sm); color: var(--text-soft); font-size: 14px;
  text-decoration: none;
}
.admin-bottom:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }

/* ============================ settings view ============================ */
.settings-grid { display: flex; flex-direction: column; gap: 4px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 4px; border-bottom: 1px solid var(--border);
}
.set-row:last-child { border-bottom: none; }
.set-row .set-label { font-size: 14px; }
.set-row .set-desc { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.set-row select, .set-row input[type=text], .set-row input[type=password] {
  min-width: 180px; padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--bg); color: var(--text);
}

/* ============================ full-page panels (admin/settings) ============================ */
.page-wrap { max-width: 980px; margin: 0 auto; padding: 24px 20px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between;
             margin-bottom: 18px; gap: 12px; }
.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
              gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg-elev); border: 1px solid var(--border);
             border-radius: var(--radius); padding: 14px 16px; }
.stat-card .sc-num { font-size: 26px; font-weight: 700; }
.stat-card .sc-lbl { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th, .admin-table td { text-align: left; padding: 10px 12px;
                                   border-bottom: 1px solid var(--border); }
.admin-table th { color: var(--text-soft); font-weight: 600; font-size: 13px; }
.admin-table tr:hover td { background: var(--bg-hover); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px;
        font-size: 12px; border: 1px solid var(--border); color: var(--text-soft); }
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.err { color: var(--danger); border-color: var(--danger); }
.row-actions.left { justify-content: flex-start; }

/* ============================ icons ============================ */
.ico { width: 20px; height: 20px; flex: 0 0 auto; }
.ico.mini { width: 15px; height: 15px; }

/* ============================ theme slide switch ============================ */
.theme-switch {
  margin-left: auto; width: 40px; height: 22px; border-radius: 999px;
  background: var(--border-strong); border: none; cursor: pointer; padding: 0;
  position: relative; flex: 0 0 auto; transition: background .18s;
}
.theme-switch .knob {
  position: absolute; top: 2px; left: 2px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3);
  transition: transform .18s;
}
.theme-switch.on { background: var(--accent); }
.theme-switch.on .knob { transform: translateX(18px); }
.pop-item.theme-row { cursor: default; }

/* ============================ answer action row ============================ */
.msg-actions { margin-top: 8px; display: flex; align-items: center; gap: 14px;
               min-height: 30px; flex-wrap: nowrap; }
.ma-bar { display: flex; align-items: center; gap: 2px; position: relative; }
.ma-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 8px; color: var(--text-faint);
  transition: background .12s, color .12s;
}
.ma-btn:hover { background: var(--bg-hover); color: var(--text); }
.ma-btn.on { color: var(--accent); }
/* The stats sit to the right of the buttons and only appear on hover, like the
   reference: speed + wall time for the finished answer. */
.msg-stats {
  display: flex; align-items: center; gap: 12px; opacity: 0; white-space: nowrap;
  flex: 0 0 auto;
  transition: opacity .15s; font-size: 12px; color: var(--text-faint);
  font-variant-numeric: tabular-nums; pointer-events: none;
}
.msg.assistant:hover .msg-stats { opacity: 1; }
.msg-stats:empty { display: none; }
.msg-stats .stat { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.msg-stats .stat .ico { width: 13px; height: 13px; }
.msg-stats .stat.live { color: var(--accent); }
.msg-stats .stat.warn { color: var(--warn, #b9770e); }
.msg-stats .stat.cache { color: var(--ok); }

/* scroll-to-bottom button */
.scroll-down {
  position: absolute; right: 24px; bottom: 96px; width: 36px; height: 36px;
  border-radius: 50%; background: var(--bg-elev); border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  box-shadow: var(--shadow); color: var(--text-soft); z-index: 30;
}
.scroll-down:hover { color: var(--text); }
.scroll-down .badge-n {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px;
  padding: 0 4px; border-radius: 9px; background: var(--accent); color: #fff;
  font-size: 11px; display: flex; align-items: center; justify-content: center;
}

/* ============================ highlight.js theme (dark + light) ============================ */
.content pre code.hljs { color: var(--text); }
.hljs-comment, .hljs-quote { color: #7d7d8a; font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-built_in, .hljs-literal, .hljs-type {
  color: #c678dd;
}
.hljs-string, .hljs-attr, .hljs-template-tag, .hljs-addition { color: #98c379; }
.hljs-number, .hljs-symbol, .hljs-bullet, .hljs-meta { color: #d19a66; }
.hljs-title, .hljs-title.function_, .hljs-section, .hljs-name { color: #61afef; }
.hljs-variable, .hljs-template-variable, .hljs-params { color: #e06c75; }
.hljs-attribute, .hljs-tag { color: #e06c75; }
.hljs-regexp, .hljs-link { color: #56b6c2; }
.hljs-deletion { color: #e06c75; }
:root.theme-light .hljs-comment, :root.theme-light .hljs-quote { color: #8a8a94; }
:root.theme-light .hljs-keyword, :root.theme-light .hljs-selector-tag,
:root.theme-light .hljs-built_in, :root.theme-light .hljs-literal,
:root.theme-light .hljs-type { color: #a626a4; }
:root.theme-light .hljs-string, :root.theme-light .hljs-attr,
:root.theme-light .hljs-addition { color: #50a14f; }
:root.theme-light .hljs-number, :root.theme-light .hljs-symbol,
:root.theme-light .hljs-bullet, :root.theme-light .hljs-meta { color: #986801; }
:root.theme-light .hljs-title, :root.theme-light .hljs-section,
:root.theme-light .hljs-name { color: #4078f2; }
:root.theme-light .hljs-variable, :root.theme-light .hljs-template-variable,
:root.theme-light .hljs-params, :root.theme-light .hljs-attribute,
:root.theme-light .hljs-tag { color: #e45649; }
:root.theme-light .hljs-regexp, :root.theme-light .hljs-link { color: #0184bc; }
@media (prefers-color-scheme: light) {
  :root:not(.theme-dark) .hljs-comment, :root:not(.theme-dark) .hljs-quote { color: #8a8a94; }
}

/* --- fixes 2026-11-08 --- */
/* "Пока нет чатов": same left inset as the section heading above it */
.side-empty { padding: 4px 8px; }
/* note for models that always think (no depth slider) */
.pop-note { font-size: 12.5px; color: var(--text-faint); padding: 4px 12px 10px; }
/* [hidden] must win over component display rules */
.chip[hidden], #reasonSection[hidden], .reason-slider[hidden], .pop-note[hidden] { display: none !important; }
