:root {
  --bg: #0f1117;
  --bg-2: #151821;
  --bg-3: #1c2030;
  --bg-hover: #232839;
  --border: #2a3042;
  --text: #e6e8ef;
  --text-2: #a3a9bb;
  --text-3: #6f7689;
  --accent: #6366f1;
  --accent-2: #14b8a6;
  --accent-soft: rgba(99, 102, 241, .16);
  --danger: #ef4444;
  --danger-soft: rgba(239, 68, 68, .12);
  --warn: #f59e0b;
  --ok: #22c55e;
  --user-bubble: #262c40;
  --code-bg: #0b0d12;
  --shadow: 0 10px 40px rgba(0, 0, 0, .45);
  --radius: 14px;
  --sidebar-w: 290px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #ffffff;
  --bg-2: #f6f7fb;
  --bg-3: #eceef5;
  --bg-hover: #e4e7f0;
  --border: #dde1ea;
  --text: #171a23;
  --text-2: #4d5466;
  --text-3: #858b9b;
  --accent-soft: rgba(99, 102, 241, .12);
  --user-bubble: #eef0f8;
  --code-bg: #0f1117;
  --shadow: 0 10px 40px rgba(20, 24, 40, .16);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: #8b8ff8; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--bg-3); color: var(--text);
  padding: 8px 14px; border-radius: 10px; transition: background .15s, border-color .15s; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-hover); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: none; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-2); flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn svg, .btn svg { width: 20px; height: 20px; }
.input, .textarea, .select {
  width: 100%; background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 12px; outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { resize: vertical; min-height: 90px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }

/* ---------- раскладка ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--bg-2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding-top: var(--safe-top);
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.sidebar-head { padding: 14px 12px 8px; display: flex; gap: 8px; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; flex: 1; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.sidebar .new-chat { margin: 4px 12px 10px; }
.sidebar .search { margin: 0 12px 8px; width: auto; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv-group { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 12px 8px 6px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 8px 8px 8px 10px; border-radius: 10px;
  cursor: pointer; position: relative;
}
.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--accent-soft); }
.conv-item .ci-body { flex: 1; min-width: 0; }
.conv-item .ci-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.conv-item .ci-meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .ci-actions { display: none; }
.conv-item:hover .ci-actions, .conv-item.active .ci-actions { display: flex; }
.conv-item .ci-actions .icon-btn { width: 28px; height: 28px; }
.conv-item .ci-actions svg { width: 16px; height: 16px; }
.pin-mark { color: var(--warn); font-size: 11px; }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; padding-bottom: calc(12px + var(--safe-bottom)); display: grid; gap: 8px; }
.balance-card {
  border-radius: 12px; padding: 12px 14px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.balance-card .bl-label { font-size: 12px; opacity: .85; display: flex; justify-content: space-between; align-items: center; }
.balance-card .bl-value { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.balance-card .bl-refresh { background: rgba(255,255,255,.18); border: none; color: #fff; border-radius: 8px; width: 26px; height: 26px; display: inline-flex; align-items: center; justify-content: center; }
.balance-card .bl-refresh svg { width: 15px; height: 15px; }
.balance-card .bl-refresh.spin svg { animation: spin 1s linear infinite; }
.foot-row { display: flex; gap: 8px; }
.foot-row .btn { flex: 1; }

/* ---------- верхняя панель ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; padding-top: calc(10px + var(--safe-top));
  border-bottom: 1px solid var(--border); background: var(--bg); min-height: 58px;
}
.model-btn {
  display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 460px;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 6px 12px; text-align: left;
}
.model-btn:hover { border-color: var(--accent); }
.model-btn .mb-text { min-width: 0; }
.model-btn .mb-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.model-btn .mb-price { font-size: 11.5px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.model-btn svg { width: 16px; height: 16px; color: var(--text-3); flex-shrink: 0; }
.topbar .spacer { flex: 1; }
.stats { display: flex; gap: 6px; align-items: stretch; }
.stat {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 4px 10px; line-height: 1.25;
  white-space: nowrap;
}
.stat .st-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); }
.stat .st-value { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat.balance .st-value { color: var(--accent-2); }
.stat.low .st-value { color: var(--danger); }
.stat .est { color: var(--warn); font-size: 11px; margin-left: 2px; }
.mobile-only { display: none !important; }
.ctx-bar { height: 3px; border-radius: 2px; background: var(--bg-3); overflow: hidden; margin-top: 3px; min-width: 70px; }
.ctx-bar i { display: block; height: 100%; width: 0; background: var(--ok); border-radius: 2px; transition: width .3s, background .3s; }
.ctx.warn .ctx-bar i { background: var(--warn); }
.ctx.full .ctx-bar i { background: var(--danger); }
.ctx.warn .st-value, .ctx.warn b { color: var(--warn); }
.ctx.full .st-value, .ctx.full b { color: var(--danger); }

/* ---------- сообщения ---------- */
.messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: auto; }
.messages-inner { max-width: 860px; margin: 0 auto; padding: 20px 18px 30px; }
.empty-state { text-align: center; margin-top: 12vh; color: var(--text-2); padding: 0 20px; }
.empty-state img { width: 64px; height: 64px; border-radius: 18px; margin-bottom: 14px; }
.empty-state h2 { color: var(--text); margin: 0 0 6px; font-size: 22px; }
.empty-state .chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 18px; }

.msg { margin: 0 0 22px; display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg .bubble { max-width: 100%; min-width: 0; }
.msg.user .bubble {
  background: var(--user-bubble); border-radius: 18px 18px 4px 18px; padding: 10px 15px; max-width: 85%;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg.assistant .bubble { width: 100%; }
.msg-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-3); margin-bottom: 4px; }
.msg-head .model-tag { color: var(--text-2); font-weight: 600; }
.msg-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; font-size: 12px; color: var(--text-3);
  margin-top: 6px; min-height: 28px;
}
.msg-foot .icon-btn { width: 28px; height: 28px; }
.msg-foot .icon-btn svg { width: 15px; height: 15px; }
.msg-foot .sep { opacity: .4; }
.msg.user .msg-foot { justify-content: flex-end; }
.msg-error {
  background: var(--danger-soft); border: 1px solid rgba(239,68,68,.35); color: #fca5a5; border-radius: 12px;
  padding: 10px 14px; white-space: pre-wrap; word-break: break-word; font-size: 14px;
}
:root[data-theme="light"] .msg-error { color: #b91c1c; }
.msg-stopped { color: var(--warn); font-size: 12px; }
.status-line { color: var(--text-2); font-size: 14px; display: flex; align-items: center; gap: 8px; }

.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); animation: blink 1.2s infinite both; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@keyframes spin { to { transform: rotate(360deg); } }

details.reasoning {
  border: 1px solid var(--border); border-radius: 12px; margin-bottom: 10px; background: var(--bg-2); font-size: 13.5px;
}
details.reasoning summary { cursor: pointer; padding: 8px 12px; color: var(--text-2); user-select: none; }
details.reasoning .reasoning-body { padding: 0 14px 10px; color: var(--text-2); white-space: pre-wrap; max-height: 400px; overflow-y: auto; }

.att-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.msg.user .att-list { justify-content: flex-end; }
.att-thumb { width: 120px; height: 120px; border-radius: 12px; object-fit: cover; border: 1px solid var(--border); cursor: zoom-in; background: var(--bg-2); }
.gen-image { max-width: min(100%, 560px); border-radius: 14px; border: 1px solid var(--border); cursor: zoom-in; display: block; margin: 6px 0; }
.att-file {
  display: inline-flex; align-items: center; gap: 8px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 11px; font-size: 13px; color: var(--text); text-decoration: none; max-width: 260px;
}
.att-file .af-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file .af-size { color: var(--text-3); font-size: 11.5px; }
.att-file svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--accent); }
.att-media { max-width: 100%; border-radius: 12px; }

.sources { margin-top: 10px; font-size: 13px; }
.sources ol { margin: 4px 0 0; padding-left: 20px; }
.sources a { word-break: break-all; }

/* markdown */
.md { word-wrap: break-word; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 20px 0 10px; line-height: 1.3; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.28em; } .md h3 { font-size: 1.12em; }
.md ul, .md ol { padding-left: 24px; margin: 0 0 12px; }
.md li { margin: 3px 0; }
.md blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--text-2); }
.md code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .88em; background: var(--bg-3); padding: 2px 6px; border-radius: 6px; }
.md pre { position: relative; background: var(--code-bg); border: 1px solid var(--border); border-radius: 12px; margin: 0 0 14px; overflow: hidden; }
.md pre .code-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px 6px 14px; font-size: 12px; color: #8b93a7; background: rgba(255,255,255,.04); border-bottom: 1px solid rgba(255,255,255,.06); }
.md pre .code-head button { background: none; border: none; color: #a3a9bb; font-size: 12px; display: inline-flex; gap: 5px; align-items: center; padding: 2px 6px; border-radius: 6px; }
.md pre .code-head button:hover { background: rgba(255,255,255,.08); color: #fff; }
.md pre code { display: block; padding: 12px 14px; overflow-x: auto; background: none; font-size: 13px; line-height: 1.5; color: #e6e8ef; }
.md table { border-collapse: collapse; margin: 0 0 14px; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.md th { background: var(--bg-2); }
.md hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
.md img { max-width: 100%; border-radius: 10px; }
.md .katex-display { overflow-x: auto; overflow-y: hidden; padding: 4px 0; }

/* ---------- поле ввода ---------- */
.composer-wrap { padding: 8px 14px 14px; padding-bottom: calc(12px + var(--safe-bottom)); background: var(--bg); }
.composer {
  max-width: 860px; margin: 0 auto; background: var(--bg-2); border: 1px solid var(--border); border-radius: 18px;
  padding: 8px; transition: border-color .15s;
}
.composer:focus-within { border-color: var(--accent); }
.composer.drag { border-color: var(--accent-2); border-style: dashed; background: var(--accent-soft); }
.composer textarea {
  width: 100%; border: none; background: transparent; outline: none; resize: none; padding: 6px 8px;
  max-height: 40vh; min-height: 26px; line-height: 1.5; font-size: 15px;
}
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer-row textarea { flex: 1; }
.composer-tools { display: flex; align-items: center; gap: 6px; padding: 2px 4px 0; flex-wrap: wrap; }
.send-btn { width: 38px; height: 38px; border-radius: 12px; background: var(--accent); color: #fff; border: none; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-btn:disabled { opacity: .4; cursor: default; }
.send-btn.stop { background: var(--danger); }
.send-btn svg { width: 18px; height: 18px; }
.toggle-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 4px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: transparent; color: var(--text-2);
}
.toggle-chip svg { width: 14px; height: 14px; }
.toggle-chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.composer-hint { font-size: 11.5px; color: var(--text-3); margin-left: auto; padding-right: 4px; }
.pending-atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px 4px 8px; }
.pending-att {
  position: relative; display: flex; align-items: center; gap: 8px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 10px; padding: 5px 30px 5px 6px; font-size: 12.5px; max-width: 240px;
}
.pending-att.warn { border-color: var(--warn); }
.pending-att img { width: 40px; height: 40px; object-fit: cover; border-radius: 7px; }
.pending-att .pa-icon { width: 40px; height: 40px; border-radius: 7px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; color: var(--accent); }
.pending-att .pa-icon svg { width: 20px; height: 20px; }
.pending-att .pa-text { min-width: 0; }
.pending-att .pa-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pending-att .pa-sub { color: var(--text-3); font-size: 11px; }
.pending-att .pa-sub.warn { color: var(--warn); }
.pending-att .pa-remove { position: absolute; top: 4px; right: 4px; width: 22px; height: 22px; border-radius: 6px; border: none; background: transparent; color: var(--text-3); display: flex; align-items: center; justify-content: center; }
.pending-att .pa-remove:hover { background: var(--bg-hover); color: var(--text); }
.pending-att.uploading { opacity: .6; }

/* ---------- модальные окна ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(5, 7, 12, .6); backdrop-filter: blur(3px); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--bg); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* каталог */
.catalog { max-width: 1280px; height: 92vh; max-height: 92vh; }
.cat-toolbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.cat-toolbar .input { flex: 1; min-width: 200px; }
.cat-toolbar .select { width: auto; }
.cat-tabs { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px 0; }
.cat-tab { border: 1px solid var(--border); background: transparent; color: var(--text-2); border-radius: 999px; padding: 4px 12px; font-size: 13px; }
.cat-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.cat-tab .cnt { opacity: .7; font-size: 11.5px; margin-left: 3px; }
.cat-filters { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 16px 10px; border-bottom: 1px solid var(--border); align-items: center; font-size: 13px; }
.cat-filters .lbl { color: var(--text-3); margin-right: 2px; }
.cat-body { flex: 1; display: grid; grid-template-columns: 230px 1fr; min-height: 0; }
.cat-providers { border-right: 1px solid var(--border); overflow-y: auto; padding: 8px; }
.prov-item { display: flex; justify-content: space-between; align-items: center; width: 100%; text-align: left; padding: 7px 10px; border-radius: 9px; border: none; background: transparent; font-size: 14px; }
.prov-item:hover { background: var(--bg-hover); }
.prov-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.prov-item .cnt { color: var(--text-3); font-size: 12px; font-weight: 400; }
.cat-list { overflow-y: auto; padding: 10px 14px 16px; }
.cat-crumbs { font-size: 13px; color: var(--text-2); margin: 2px 2px 10px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cat-crumbs button { background: none; border: none; color: var(--accent); padding: 0; }
.model-card {
  border: 1px solid var(--border); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
  background: var(--bg-2); transition: border-color .15s;
}
.model-card:hover { border-color: var(--accent); }
.model-card.current { border-color: var(--accent-2); }
.mc-top { display: flex; align-items: flex-start; gap: 10px; }
.mc-title { flex: 1; min-width: 0; }
.mc-name { font-weight: 600; }
.mc-id { font-size: 12px; color: var(--text-3); word-break: break-all; }
.mc-prices { text-align: right; font-size: 12.5px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mc-prices b { font-size: 13.5px; }
.mc-prices .pl { color: var(--text-3); }
.mc-desc { font-size: 13px; color: var(--text-2); margin-top: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mc-badges { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--bg-3); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.acc { background: var(--accent-soft); color: var(--text); border-color: transparent; }
.badge.warn { color: var(--warn); }
.star { background: none; border: none; color: var(--text-3); font-size: 18px; line-height: 1; padding: 2px; }
.star.on { color: var(--warn); }
.cat-empty { color: var(--text-2); text-align: center; padding: 40px 0; }
.price-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0 14px; }
.price-table td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.price-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.detail-desc { white-space: pre-wrap; color: var(--text-2); font-size: 14px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin: 10px 0 14px; }
.detail-grid .dg { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.detail-grid .dg span { display: block; font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin: 14px 0 6px; }

/* lightbox, toast */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lightbox .lb-actions { position: absolute; top: calc(14px + var(--safe-top)); right: 14px; display: flex; gap: 8px; }
.lightbox .lb-actions a, .lightbox .lb-actions button { background: rgba(255,255,255,.12); color: #fff; border: none; border-radius: 10px; padding: 8px 12px; text-decoration: none; font-size: 14px; }
.toasts { position: fixed; bottom: calc(90px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); z-index: 90; display: grid; gap: 8px; width: min(92vw, 460px); }
.toast { background: var(--bg-3); border: 1px solid var(--border); color: var(--text); padding: 10px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: fadein .2s; }
.toast.error { border-color: rgba(239,68,68,.5); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
.scroll-down {
  position: absolute; right: 22px; bottom: 120px; width: 38px; height: 38px; border-radius: 50%;
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text); display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow); z-index: 5;
}
.scroll-down svg { width: 18px; height: 18px; }
.overlay { display: none; }

/* ---------- мобильная версия ---------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 330px); z-index: 40; transform: translateX(-102%);
    transition: transform .22s ease; box-shadow: var(--shadow);
  }
  .app.drawer-open .sidebar { transform: none; }
  .app.drawer-open .overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 39; }
  .mobile-only { display: inline-flex !important; }
  .desktop-only { display: none !important; }
  .topbar { padding: 8px 8px; padding-top: calc(8px + var(--safe-top)); gap: 6px; min-height: 52px; }
  .model-btn { flex: 1; max-width: none; padding: 5px 10px; }
  .topbar .spacer { display: none; }
  .stats-bar {
    display: grid !important; grid-template-columns: 1.15fr 1.1fr 0.9fr 1fr; gap: 6px; padding: 5px 10px 6px;
    border-bottom: 1px solid var(--border); background: var(--bg-2); font-size: 12.5px;
  }
  .stats-bar .sb-item { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
  .stats-bar .sb-item span { color: var(--text-3); font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }
  .stats-bar .sb-item b { font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .stats-bar .sb-item.balance b { color: var(--accent-2); }
  .stats-bar .sb-item .ctx-bar { min-width: 0; margin-top: 2px; }
  .messages-inner { padding: 14px 12px 24px; }
  .msg.user .bubble { max-width: 92%; }
  .composer-wrap { padding: 6px 8px; padding-bottom: calc(8px + var(--safe-bottom)); }
  .composer textarea { font-size: 16px; } /* iOS не зумит поле при фокусе */
  .composer-hint { display: none; }
  .modal-backdrop { padding: 0; align-items: stretch; }
  .modal { max-width: none !important; max-height: none; height: 100%; border-radius: 0; border: none; padding-top: var(--safe-top); }
  .modal-foot { padding-bottom: calc(12px + var(--safe-bottom)); flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; }
  .catalog { height: 100%; max-height: none; }
  .cat-body { grid-template-columns: 1fr; }
  .cat-providers { display: none; }
  .cat-toolbar .select { flex: 1; }
  .mc-top { flex-wrap: wrap; }
  .mc-prices { text-align: left; width: 100%; display: flex; gap: 12px; }
  .att-thumb { width: 96px; height: 96px; }
  .scroll-down { bottom: 100px; right: 14px; }
  .input, .select, .textarea { font-size: 16px; }
}
@media (min-width: 861px) {
  .stats-bar { display: none !important; }
  .cat-provider-select { display: none !important; }
}
@media (max-width: 1100px) and (min-width: 861px) {
  .stat .st-label { display: none; }
}
