:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --sidebar: #eff1f5;
  --hover: rgba(20, 24, 40, .06);
  --active: rgba(91, 91, 214, .12);
  --text: #161a23;
  --muted: #646b7a;
  --faint: #9298a6;
  --border: #e2e5eb;
  --accent: #5b5bd6;
  --accent-text: #ffffff;
  --accent-soft: #ecebfd;
  --teal: #0f9f97;
  --user-bubble: #eceff6;
  --code-bg: #f3f4f8;
  --danger: #d23f3f;
  --danger-soft: #fdecec;
  --warn: #b26b00;
  --warn-soft: #fff4e0;
  --ok: #178a52;
  --ok-soft: #e5f6ec;
  --shadow: 0 1px 2px rgba(16, 20, 35, .05), 0 8px 24px rgba(16, 20, 35, .07);
  --radius: 14px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --panel: #161922; --sidebar: #12141b; --hover: rgba(255, 255, 255, .06); --active: rgba(139, 139, 255, .16);
    --text: #e7e9ee; --muted: #9aa1b0; --faint: #6c7383; --border: #262a36; --accent: #8282ff; --accent-text: #0f1117; --accent-soft: #23233f;
    --teal: #2dd4bf; --user-bubble: #1e2230; --code-bg: #1a1d27; --danger: #f07070; --danger-soft: #3a1e22; --warn: #f0b04a; --warn-soft: #3a2c14;
    --ok: #4ade80; --ok-soft: #173024; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --panel: #161922; --sidebar: #12141b; --hover: rgba(255, 255, 255, .06); --active: rgba(139, 139, 255, .16);
  --text: #e7e9ee; --muted: #9aa1b0; --faint: #6c7383; --border: #262a36; --accent: #8282ff; --accent-text: #0f1117; --accent-soft: #23233f;
  --teal: #2dd4bf; --user-bubble: #1e2230; --code-bg: #1a1d27; --danger: #f07070; --danger-soft: #3a1e22; --warn: #f0b04a; --warn-soft: #3a2c14;
  --ok: #4ade80; --ok-soft: #173024; --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.55 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Кнопки и поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s; }
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; color: var(--muted); transition: background .15s, color .15s; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.on { color: var(--accent); background: var(--accent-soft); }
.input, .textarea, .select { width: 100%; border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 9px 12px; outline: none; transition: border-color .15s, box-shadow .15s; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 90px; }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label { font-weight: 600; font-size: 14px; }
.field .hint { font-size: 13px; color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: 99px; border: 1px solid var(--border); font-size: 13px; color: var(--muted); background: var(--panel); }
.chip.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--accent-soft); color: var(--accent); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.spinner { width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Каркас ---------- */
.layout { display: flex; height: 100dvh; }
.sidebar { width: 272px; flex: none; background: var(--sidebar); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; transition: margin-left .2s; }
.layout.side-collapsed .sidebar { margin-left: -272px; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 10px 16px; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.logo img { width: 28px; height: 28px; }
.side-actions { padding: 4px 12px 8px; display: grid; gap: 6px; }
.new-chat { justify-content: flex-start; width: 100%; height: 40px; }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--faint); width: 16px; height: 16px; }
.search input { padding-left: 32px; height: 36px; background: var(--panel); }
.side-nav { display: grid; padding: 2px 8px 6px; gap: 1px; }
.nav-item { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 9px; color: var(--text); font-weight: 500; text-align: left; width: 100%; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active); color: var(--accent); }
.side-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; min-height: 0; }
.side-group { font-size: 12px; font-weight: 600; color: var(--faint); padding: 14px 10px 4px; text-transform: uppercase; letter-spacing: .04em; }
.conv-item { position: relative; display: flex; align-items: center; gap: 8px; width: 100%; height: 34px; padding: 0 8px 0 10px; border-radius: 8px; text-align: left; color: var(--text); font-size: 14px; }
.conv-item { cursor: pointer; user-select: none; }
.conv-item:hover { background: var(--hover); }
.conv-item.active { background: var(--active); }
.conv-item .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conv-item .more { opacity: 0; width: 26px; height: 26px; }
.conv-item:hover .more, .conv-item.active .more { opacity: 1; }
.conv-item .live { width: 8px; height: 8px; border-radius: 50%; background: var(--teal); animation: pulse 1.2s infinite; flex: none; }
@keyframes pulse { 50% { opacity: .3; } }
.side-foot { border-top: 1px solid var(--border); padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.side-foot .nav-item { flex: 1; }
.side-foot > .nav-item, .side-foot > .icon-btn { align-self: stretch; }
.side-foot { position: relative; }
.side-foot::before { content: ''; }

/* Остаток недельного лимита в низу панели */
.side-spend { padding: 8px 10px; border-radius: 10px; background: var(--bg-soft, rgba(127,127,127,.08)); display: flex; flex-direction: column; gap: 5px; }
.side-spend:empty { display: none; }
.side-spend-top { display: flex; align-items: baseline; justify-content: space-between; font-size: 12px; color: var(--muted); }
.side-spend-top b { font-size: 15px; font-weight: 650; letter-spacing: -.2px; }
.side-spend-bar { height: 5px; border-radius: 99px; background: var(--border); overflow: hidden; }
.side-spend-bar i { display: block; height: 100%; border-radius: 99px; transition: width .3s ease; }
.side-spend-sub { font-size: 11px; color: var(--muted); line-height: 1.25; }

/* кнопки внизу — в ряд */
.side-foot { flex-direction: column; }
.side-foot .row-btns { display: flex; gap: 4px; align-items: center; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--bg); }
.topbar { height: 54px; flex: none; display: flex; align-items: center; gap: 6px; padding: 0 12px; border-bottom: 1px solid transparent; }
.topbar.bordered { border-bottom-color: var(--border); }
.topbar .title { font-weight: 600; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; padding: 4px 8px; border-radius: 8px; max-width: 50vw; }
.topbar .title:hover { background: var(--hover); }
.topbar .crumb { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 4px; }
.ctx-meter { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 4px 8px; border-radius: 8px; }
.ctx-meter:hover { background: var(--hover); }
.ctx-meter svg { width: 18px; height: 18px; transform: rotate(-90deg); }

.content { flex: 1; display: flex; min-height: 0; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; }
.thread { max-width: 800px; margin: 0 auto; padding: 18px 20px 30px; }

/* ---------- Пустой экран ---------- */
.hello { max-width: 760px; margin: 0 auto; padding: 12vh 20px 20px; text-align: center; }
.hello h1 { font-size: 30px; font-weight: 650; letter-spacing: -.02em; margin: 14px 0 6px; }
.hello p { color: var(--muted); margin: 0 0 26px; }
.hello .orb { width: 54px; height: 54px; }
.suggests { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; text-align: left; margin-top: 18px; }
.suggest { border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 12px 14px; font-size: 14px; color: var(--text); text-align: left; transition: border-color .15s, transform .15s; }
.suggest:hover { border-color: var(--accent); transform: translateY(-1px); }
.suggest b { display: block; font-weight: 600; margin-bottom: 2px; }
.suggest span { color: var(--muted); }

/* ---------- Сообщения ---------- */
.msg { margin: 0 0 22px; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { background: var(--user-bubble); border-radius: 18px 18px 6px 18px; padding: 10px 15px; max-width: 85%; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg-actions { display: flex; gap: 2px; margin-top: 4px; opacity: 0; transition: opacity .15s; align-items: center; }
.msg:hover .msg-actions, .msg-actions.show { opacity: 1; }
.msg-actions .icon-btn { width: 30px; height: 30px; }
.msg-actions .icon-btn svg { width: 16px; height: 16px; }
.msg-actions .meta { font-size: 12px; color: var(--faint); margin-left: 6px; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-bottom: 6px; max-width: 85%; }
.att { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel); border-radius: 10px; padding: 5px 9px; font-size: 13px; max-width: 220px; }
.att span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.att img { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; }
.att-img { max-width: 220px; max-height: 180px; border-radius: 12px; border: 1px solid var(--border); display: block; }
.edit-box { width: min(100%, 640px); }
.edit-box .textarea { min-height: 80px; }

.msg-ai { position: relative; }
.ai-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.ai-head img { width: 22px; height: 22px; }
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md table, .md pre { margin: 0 0 12px; }
.md h1, .md h2, .md h3, .md h4 { margin: 20px 0 8px; line-height: 1.3; letter-spacing: -.01em; }
.md h1 { font-size: 1.45em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.1em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: 3px 0; }
.md blockquote { border-left: 3px solid var(--border); padding-left: 12px; color: var(--muted); }
.md code { font-family: var(--mono); font-size: .88em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.md pre code { background: none; padding: 0; font-size: 13px; }
.md table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.md th { background: var(--code-bg); font-weight: 600; }
.md img { max-width: 100%; border-radius: 10px; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.code { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin: 0 0 12px; background: var(--code-bg); }
.code-head { display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); }
.code-head .lang { flex: 1; font-family: var(--mono); }
.code-head button { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 6px; font-size: 12px; color: var(--muted); }
.code-head button:hover { background: var(--hover); color: var(--text); }
.code-head button svg { width: 14px; height: 14px; }
.code pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.code pre code.hljs { background: none; padding: 0; }
.artifact-card { display: flex; align-items: center; gap: 12px; border: 1px solid var(--border); background: var(--panel); border-radius: 12px; padding: 12px 14px; margin: 0 0 12px; text-align: left; width: 100%; max-width: 440px; transition: border-color .15s; }
.artifact-card:hover { border-color: var(--accent); }
.artifact-card .ico { width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.artifact-card b { display: block; font-weight: 600; }
.artifact-card span { font-size: 13px; color: var(--muted); }

.think { margin: 0 0 10px; }
.think summary, .tool summary, .agent summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.think summary::-webkit-details-marker, .tool summary::-webkit-details-marker, .agent summary::-webkit-details-marker { display: none; }
.think summary { font-size: 13px; color: var(--muted); padding: 4px 0; }
.think .body { border-left: 2px solid var(--border); padding: 4px 0 4px 12px; margin: 4px 0 0 6px; font-size: 13.5px; color: var(--muted); white-space: pre-wrap; max-height: 320px; overflow: auto; }
.chev { width: 14px; height: 14px; transition: transform .15s; }
details[open] > summary .chev { transform: rotate(90deg); }

.tool { border: 1px solid var(--border); background: var(--panel); border-radius: 11px; margin: 0 0 8px; font-size: 13.5px; }
.tool summary { padding: 8px 12px; min-height: 38px; }
.tool .tname { font-weight: 600; }
.tool .targ { color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; min-width: 0; font-family: var(--mono); font-size: 12px; }
.tool .ticon { width: 24px; height: 24px; border-radius: 7px; background: var(--code-bg); display: grid; place-items: center; color: var(--muted); flex: none; }
.tool .ticon svg { width: 14px; height: 14px; }
.tool.ok .ticon { color: var(--ok); background: var(--ok-soft); }
.tool.err .ticon { color: var(--danger); background: var(--danger-soft); }
.tool .tbody { border-top: 1px solid var(--border); padding: 10px 12px; display: grid; gap: 8px; }
.tool pre { margin: 0; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow: auto; background: var(--code-bg); border-radius: 8px; padding: 8px 10px; }
.tool .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; }

.approval { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 12px; padding: 12px 14px; margin: 0 0 10px; }
.approval .q { font-weight: 600; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.approval pre { margin: 0 0 10px; font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow: auto; background: var(--panel); border-radius: 8px; padding: 8px 10px; }
.approval.resolved { border-color: var(--border); background: var(--panel); opacity: .8; }

.status-line { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; margin: 4px 0 10px; }
.status-meta { font-variant-numeric: tabular-nums; opacity: .75; font-size: 12.5px; }
.status-line.slow .status-meta { opacity: 1; color: var(--warn); }
.status-line.slow::after { content: '— модель думает долго, это нормально'; font-size: 12px; color: var(--warn); opacity: .9; }
.notice { font-size: 13px; color: var(--muted); background: var(--code-bg); border-radius: 10px; padding: 8px 12px; margin: 0 0 10px; }
.error-box { border: 1px solid var(--danger); background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 14px; margin: 0 0 10px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.error-box .grow { white-space: pre-wrap; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12px; margin: 6px 0 22px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px dashed var(--border); }
.divider button { color: var(--accent); font-size: 12px; }
.cursor::after { content: ""; display: inline-block; width: 8px; height: 15px; background: var(--accent); border-radius: 2px; margin-left: 3px; vertical-align: -2px; animation: pulse 1s infinite; }

.team { border: 1px solid var(--border); background: var(--panel); border-radius: 14px; margin: 0 0 14px; overflow: hidden; }
.team-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-weight: 600; border-bottom: 1px solid var(--border); }
.team-head .badge { margin-left: auto; }
.agent { border-bottom: 1px solid var(--border); }
.agent:last-child { border-bottom: 0; }
.agent summary { padding: 10px 14px; }
.agent .av { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #fff; flex: none; }
.agent .role { font-weight: 600; font-size: 14px; }
.agent .task { font-size: 12.5px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.agent .abody { padding: 0 14px 12px 52px; font-size: 14px; }
.agent .steps { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 8px; }
.agent .step { font-family: var(--mono); font-size: 11.5px; padding: 2px 7px; border-radius: 6px; background: var(--code-bg); color: var(--muted); }
.agent .step.err { color: var(--danger); }
.agent .out { max-height: 360px; overflow: auto; }

/* ---------- Поле ввода ---------- */
.composer-wrap { padding: 0 16px calc(14px + env(safe-area-inset-bottom)); flex: none; }
.composer { max-width: 800px; margin: 0 auto; background: var(--panel); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow); transition: border-color .15s; }
.composer.drag { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.composer textarea { display: block; width: 100%; border: 0; outline: none; resize: none; background: transparent; padding: 14px 16px 6px; max-height: 40vh; min-height: 52px; line-height: 1.5; }
.composer .pending-atts { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 0; }
.composer .pending-atts .att { padding-right: 4px; }
.composer .pending-atts .att button { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; color: var(--muted); }
.composer .pending-atts .att button:hover { background: var(--hover); }
.comp-bar { display: flex; align-items: center; gap: 4px; padding: 6px 8px 8px; }
.modes { display: inline-flex; background: var(--code-bg); border-radius: 10px; padding: 3px; gap: 2px; }
.modes button { height: 28px; padding: 0 10px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.modes button svg { width: 15px; height: 15px; }
.modes button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.model-btn { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; border-radius: 9px; font-size: 13px; color: var(--muted); max-width: 220px; }
.model-btn:hover { background: var(--hover); color: var(--text); }
.model-btn span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.send { width: 36px; height: 36px; border-radius: 11px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; flex: none; transition: opacity .15s; }
.send:disabled { opacity: .35; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); }
.comp-note { text-align: center; font-size: 12px; color: var(--faint); margin-top: 8px; }

/* ---------- Правая панель ---------- */
.panel { width: min(46vw, 760px); flex: none; border-left: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-width: 0; }
.panel-head { height: 54px; display: flex; align-items: center; gap: 4px; padding: 0 8px 0 12px; border-bottom: 1px solid var(--border); flex: none; }
.panel-tabs { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; }
.panel-tabs button { height: 32px; padding: 0 12px; border-radius: 8px; font-size: 14px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.panel-tabs button.on { background: var(--hover); color: var(--text); }
.panel-body { flex: 1; min-height: 0; overflow: auto; position: relative; }

/* ---------- Панель на весь экран: браузер занимает весь монитор ---------- */
.panel.full {
  position: fixed; inset: 0; z-index: 60;
  width: 100vw; height: 100vh; height: 100dvh;
  border-left: 0; background: var(--bg);
}
.panel.full .panel-body { overflow: hidden; }
.panel.full .browser-bar { padding: 6px 10px; }
.panel.full .live-top { padding: 6px 10px; }
.panel.full .live-holder { overflow: hidden; align-items: center; justify-content: center; background: #0f1115; min-height: 0; }
.panel.full .live-canvas { max-width: 100%; max-height: 100%; }
body.panel-full { overflow: hidden; }
.full-btn.on { background: var(--hover); color: var(--text); }
.icon-btn.on { background: var(--hover); color: var(--accent); }
.preview-frame { width: 100%; height: 100%; border: 0; background: #fff; display: block; }
.preview-tools { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.preview-tools .name { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.preview-src { margin: 0; padding: 14px; font-family: var(--mono); font-size: 12.5px; white-space: pre; overflow: auto; height: 100%; background: var(--code-bg); }
.files { padding: 8px; }
.file-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; text-align: left; font-size: 14px; }
.file-row:hover { background: var(--hover); }
.file-row .sz { margin-left: auto; color: var(--faint); font-size: 12px; white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 14px; }

/* ---------- Страницы: проекты ---------- */
.page { max-width: 960px; margin: 0 auto; padding: 24px 20px 60px; width: 100%; }
.page h1 { font-size: 26px; margin: 4px 0 18px; letter-spacing: -.02em; }
.page-head { display: flex; align-items: center; gap: 10px; }
.page-head h1 { flex: 1; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card { border: 1px solid var(--border); background: var(--panel); border-radius: var(--radius); padding: 16px; text-align: left; transition: border-color .15s, box-shadow .15s; }
button.card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0; color: var(--muted); font-size: 13.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.proj-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; align-items: start; }
.box { border: 1px solid var(--border); background: var(--panel); border-radius: var(--radius); padding: 16px; }
.box h3 { margin: 0 0 10px; font-size: 15px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; width: 100%; text-align: left; }
.list-row:hover { background: var(--hover); }
.list-row .t { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ---------- Модальные окна ---------- */
.overlay { position: fixed; inset: 0; background: rgba(8, 10, 18, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); width: min(560px, 100%); max-height: min(86dvh, 860px); display: flex; flex-direction: column; animation: pop .18s; }
.modal.wide { width: min(860px, 100%); }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px 20px; }
.modal-head h2 { margin: 0; font-size: 18px; flex: 1; }
.modal-body { padding: 4px 20px 20px; overflow: auto; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
.settings { display: grid; grid-template-columns: 190px 1fr; min-height: 0; flex: 1; }
.settings-nav { border-right: 1px solid var(--border); padding: 4px 8px 16px; display: grid; align-content: start; gap: 2px; overflow: auto; }
.settings-body { padding: 4px 22px 22px; overflow: auto; min-height: 0; }
.settings-body h3 { margin: 4px 0 14px; font-size: 17px; }
.radio-card { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { margin-top: 4px; accent-color: var(--accent); }
.radio-card b { display: block; font-weight: 600; font-size: 14px; }
.radio-card span { font-size: 13px; color: var(--muted); }
.mcp-item { border: 1px solid var(--border); border-radius: 12px; padding: 12px; margin-bottom: 8px; }
.mcp-item .row { align-items: flex-start; }
.mcp-item .tools-list { font-size: 12px; color: var(--muted); margin-top: 6px; font-family: var(--mono); }

.model-search { position: sticky; top: 0; background: var(--panel); padding-bottom: 10px; z-index: 1; }
.model-row { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px; width: 100%; text-align: left; }
.model-row:hover { background: var(--hover); }
.model-row.sel { background: var(--active); }
.model-row .nm { font-weight: 600; font-size: 14px; }
.model-row .id { font-size: 12px; color: var(--faint); font-family: var(--mono); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.model-row .props { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; font-size: 12px; color: var(--muted); text-align: right; flex: none; max-width: 45%; }
.star { color: var(--faint); }
.star.on { color: #f5b301; }
.star.on svg { fill: currentColor; }

/* ---------- Вход и мастер настройки ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1000px 500px at 50% -10%, var(--accent-soft), transparent), var(--bg); overflow: auto; }
.auth-card { width: min(460px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 28px; box-shadow: var(--shadow); }
.auth-card .logo { justify-content: center; font-size: 22px; margin-bottom: 6px; }
.auth-card .logo img { width: 40px; height: 40px; }
.auth-card h2 { text-align: center; margin: 10px 0 4px; font-size: 20px; }
.auth-card .sub { text-align: center; color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.steps-dots { display: flex; justify-content: center; gap: 6px; margin-bottom: 18px; }
.steps-dots i { width: 28px; height: 4px; border-radius: 4px; background: var(--border); }
.steps-dots i.on { background: var(--accent); }
.err-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }
.howto { background: var(--code-bg); border-radius: 12px; padding: 12px 14px; font-size: 13.5px; margin-bottom: 16px; }
.howto ol { margin: 0; padding-left: 18px; }
.rec-models { display: grid; gap: 6px; margin-bottom: 14px; }

/* ---------- Уведомления ---------- */
#toast-root { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; pointer-events: none; justify-items: center; }
#toast-root > .toast { pointer-events: none; }
#toast-root > .chat-done { pointer-events: auto; }
.toast { background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .2s; }
.menu { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; min-width: 190px; animation: fade .1s; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; font-size: 14px; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px; }
.backdrop { display: none; }

/* ---------- Телефон и планшет ---------- */
@media (max-width: 1100px) {
  .panel { position: absolute; inset: 0; width: auto; z-index: 30; border-left: 0; }
}
@media (max-width: 820px) {
  body { font-size: 15.5px; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(300px, 86vw); margin-left: 0; transform: translateX(-100%); transition: transform .22s; box-shadow: var(--shadow); }
  .layout.side-open .sidebar { transform: none; }
  .layout.side-collapsed .sidebar { margin-left: 0; }
  .layout.side-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(8, 10, 18, .45); z-index: 35; }
  .thread { padding: 12px 16px 24px; }
  .hello { padding-top: 7vh; }
  .hello h1 { font-size: 24px; }
  .suggests { grid-template-columns: 1fr; }
  .suggest:nth-child(n+4) { display: none; }
  .composer-wrap { padding: 0 8px calc(8px + env(safe-area-inset-bottom)); }
  .composer { border-radius: 18px; }
  .modes button .lbl { display: none; }
  .modes button { padding: 0 9px; }
  .model-btn { max-width: 130px; }
  .comp-note { display: none; }
  .bubble, .atts { max-width: 92%; }
  .msg-actions { opacity: 1; }
  .conv-item .more { opacity: 1; }
  .topbar .title { max-width: 46vw; }
  .ctx-meter .txt { display: none; }
  .modal { max-height: 92dvh; border-radius: 18px 18px 0 0; align-self: end; width: 100%; }
  .overlay { padding: 0; place-items: end center; }
  .settings { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .settings-nav { border-right: 0; border-bottom: 1px solid var(--border); display: flex; overflow-x: auto; padding: 4px 8px 8px; }
  .settings-nav .nav-item { width: auto; white-space: nowrap; }
  .settings-body { padding: 14px 16px 22px; }
  .proj-grid { grid-template-columns: 1fr; }
  .model-row .props { max-width: 38%; }
}
@media (min-width: 821px) {
  .only-mobile { display: none !important; }
}

/* ---------- Папка чата и «Спутник» ---------- */
.folder-btn.on { color: var(--accent); background: var(--accent-soft); }
.list-row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); margin-bottom: 6px; width: 100%; text-align: left; }
.list-row .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list-row:hover { background: var(--hover); }

/* ---------- Выбор папки на компьютере ---------- */
.folder-list { display: grid; gap: 2px; max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 4px; }
.folder-list .file-row { border-radius: 8px; }
.file-row.sel { background: var(--accent-soft); }
.folder-path { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; margin-bottom: 6px; }
.mode-tag { font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 0 4px; margin-left: 4px; flex: none; }

/* ---------- Подпись папки у значка ---------- */
.folder-wrap { display: inline-flex; align-items: center; gap: 4px; max-width: 220px; flex: none; }
.folder-name { font-size: 12px; color: var(--muted); max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-name::after { content: ''; }
.folder-btn.offline { color: var(--warn); }
.folder-btn.offline::after { background: var(--warn); }

/* ---------- Переключатель устройства ---------- */
.device-btn.on { color: var(--teal); background: var(--ok-soft); }
.device-btn.offline { color: var(--warn); }
.device-btn.offline::after { content: ''; position: absolute; right: 5px; bottom: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--warn); }
.device-btn { position: relative; }

/* ---------- Живой браузер в панели ---------- */
.browser-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.browser-url { font: 12px/1.4 var(--mono); color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browser-shot { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; }
.browser-img { width: 100%; display: block; cursor: zoom-in; border-radius: 0; }
.panel-tabs button .i { width: 15px; height: 15px; margin-right: 4px; vertical-align: -2px; }

/* ---------- Живой браузер в панели ---------- */
.live-wrap { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.live-top { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.live-holder { flex: 1; min-height: 0; overflow: hidden; background: #0f1115; display: flex; justify-content: center; align-items: center; }
.live-canvas { display: block; cursor: default; outline: none; background: #fff; max-width: 100%; max-height: 100%; box-shadow: 0 6px 24px rgba(0,0,0,.35); }
.live-canvas:focus { box-shadow: inset 0 0 0 2px var(--accent); }
.live-hint { padding: 14px 12px; }
.browser-addr { flex: 1; min-width: 120px; height: 30px; font: 12px/1.3 var(--mono); }
.browser-bar { flex-wrap: nowrap; }

/* ---------- Плашка «чат закончил работу» ---------- */
.chat-done {
  display: flex; align-items: flex-start; gap: 10px;
  max-width: 380px; padding: 12px 14px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-left: 3px solid var(--teal);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.22);
  cursor: pointer; animation: chatDoneIn .22s ease-out;
}
.chat-done:hover { border-color: var(--teal); }
.chat-done-ico { color: var(--teal); flex: none; margin-top: 1px; }
.chat-done-ico svg { width: 18px; height: 18px; }
.chat-done-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.chat-done-text b { font-size: 13px; font-weight: 600; }
.chat-done-text span { font-size: 12px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chat-done .icon-btn { margin-left: auto; flex: none; }
@keyframes chatDoneIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.chat-done.stopped { border-left-color: var(--warn, #d97706); }
.chat-done.stopped .chat-done-ico { color: var(--warn, #d97706); }
.chat-done.failed { border-left-color: var(--danger, #dc2626); }
.chat-done.failed .chat-done-ico { color: var(--danger, #dc2626); }
.chat-done-open { flex: none; align-self: center; white-space: nowrap; }
.chat-done .icon-btn { align-self: flex-start; }
@media (max-width: 640px) { .chat-done { max-width: calc(100vw - 32px); flex-wrap: wrap; } }

/* ---------- Остаток средств на OpenRouter ---------- */
.balance-chip {
  display: inline-flex; align-items: center; gap: 1px;
  height: 28px; padding: 0 9px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--panel);
  font: 600 12.5px/1 var(--mono); color: var(--text);
  cursor: pointer; white-space: nowrap; flex: none;
  transition: border-color .15s, color .15s;
}
.balance-chip:hover { border-color: var(--teal); }
.balance-chip .cur { color: var(--muted); font-weight: 500; }
.balance-chip .amt { letter-spacing: -.2px; }
.balance-chip.mid { color: var(--warn, #b26b00); }
.balance-chip.mid .cur { color: var(--warn, #b26b00); opacity: .7; }
.balance-chip.low { color: var(--danger, #d23f3f); border-color: color-mix(in srgb, var(--danger, #d23f3f) 45%, var(--border)); }
.balance-chip.low .cur { color: var(--danger, #d23f3f); opacity: .7; }
.balance-chip.err { color: var(--muted); }
.balance-chip.err svg { width: 13px; height: 13px; }
.balance-chip svg { width: 13px; height: 13px; }
.balance-chip.spin { opacity: .6; }
.balance-chip.hidden { display: none; }
@media (max-width: 560px) { .balance-chip { padding: 0 7px; font-size: 12px; } }

/* ---------- Плашка «Скачать файл» в чате ---------- */
.dl-card {
  display: flex; align-items: center; gap: 11px;
  max-width: 340px; width: 100%; margin: 10px 0;
  padding: 11px 13px;
  background: var(--panel); color: var(--text);
  border: 1px solid var(--border); border-radius: 13px;
  text-decoration: none; cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.dl-card:hover { border-color: var(--teal); box-shadow: 0 4px 16px rgba(0,0,0,.10); }
.dl-card:active { transform: scale(.99); }
.dl-ico {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font: 700 10.5px/1 var(--mono); letter-spacing: .3px;
  background: var(--accent-soft); color: var(--accent);
}
.dl-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.dl-text b { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-text span { font-size: 11.5px; color: var(--muted); }
.dl-arrow { flex: none; color: var(--teal); font-size: 17px; font-weight: 700; }
/* на телефоне — во всю ширину и крупнее */
@media (max-width: 820px) {
  .dl-card { max-width: 100%; padding: 13px 14px; border-radius: 14px; }
  .dl-ico { width: 42px; height: 42px; font-size: 11px; }
  .dl-text b { font-size: 14.5px; }
  .dl-text span { font-size: 12.5px; }
}
