:root {
  --bg: #FAF9F5;
  --surface: #FFFFFF;
  --surface-2: #F0EEE6;
  --surface-3: #E8E6DC;
  --text: #1F1E1D;
  --text-2: #3D3D3A;
  --muted: #7A7974;
  --border: rgba(31, 30, 29, .10);
  --border-strong: rgba(31, 30, 29, .18);
  --accent: #C96442;
  --accent-press: #B5573A;
  --accent-soft: rgba(201, 100, 66, .12);
  --ok: #2F8F5B;
  --ok-soft: rgba(47, 143, 91, .12);
  --warn: #B7791F;
  --warn-soft: rgba(183, 121, 31, .13);
  --danger: #C0392B;
  --danger-soft: rgba(192, 57, 43, .10);
  --code-bg: #F4F3EE;
  --user-bubble: #EFEDE5;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.06);
  --shadow-lg: 0 -8px 40px rgba(0,0,0,.14);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, "JetBrains Mono", Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --app-h: 100dvh;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #262624;
    --surface: #30302E;
    --surface-2: #383835;
    --surface-3: #45453F;
    --text: #F3F2EC;
    --text-2: #DAD9D2;
    --muted: #A09F98;
    --border: rgba(255, 255, 255, .08);
    --border-strong: rgba(255, 255, 255, .16);
    --accent: #D97757;
    --accent-press: #E4876A;
    --accent-soft: rgba(217, 119, 87, .16);
    --ok: #5BC48A;
    --ok-soft: rgba(91, 196, 138, .14);
    --warn: #E3B35A;
    --warn-soft: rgba(227, 179, 90, .14);
    --danger: #EF7B6E;
    --danger-soft: rgba(239, 123, 110, .13);
    --code-bg: #1E1E1C;
    --user-bubble: #3A3A37;
    --shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 16px rgba(0,0,0,.25);
    --shadow-lg: 0 -8px 40px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow: hidden;
  position: fixed; inset: 0;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger); font-size: 14px; margin: 4px 0 0; }
.link { color: var(--accent); }

/* ── кнопки ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 14px;
  background: var(--surface-2); color: var(--text); font-weight: 560;
  transition: transform .12s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:active { background: var(--accent-press); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.big { min-height: 52px; font-size: 17px; border-radius: 16px; width: 100%; }
.btn.block { width: 100%; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-2);
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.soft { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--border-strong); }
.icon-btn.soft svg { width: 18px; height: 18px; }

/* ── вход ── */
#login {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 24px;
  padding-top: calc(24px + var(--sat)); background: var(--bg);
}
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-logo { width: 76px; height: 76px; border-radius: 20px; margin: 0 auto 6px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 14px; }
.login-card input {
  height: 52px; border-radius: 16px; border: 1px solid var(--border-strong);
  background: var(--surface); padding: 0 16px; font-size: 17px; outline: none;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* ── каркас ── */
#app { position: fixed; left: 0; right: 0; top: 0; height: var(--app-h); display: flex; overflow: hidden; }
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; height: 100%; }

.topbar {
  flex: none; display: flex; align-items: center; gap: 4px;
  padding: calc(var(--sat) + 4px) 6px 4px; min-height: calc(56px + var(--sat));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid transparent; transition: border-color .2s; z-index: 5;
}
.topbar.scrolled { border-bottom-color: var(--border); }
.top-title { flex: 1; min-width: 0; text-align: center; }
#title { font-weight: 620; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#subtitle { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: -2px; }

#banner {
  flex: none; margin: 4px 12px 0; padding: 10px 12px; border-radius: 14px;
  display: flex; align-items: center; gap: 10px; font-size: 14px; line-height: 1.35;
  background: var(--warn-soft); color: var(--text);
}
#banner svg { color: var(--warn); width: 20px; height: 20px; }
#banner.busy svg { animation: pulse 1.4s ease-in-out infinite; }
#banner b { font-weight: 620; }

#scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain; scroll-behavior: auto;
}
#thread { max-width: 760px; margin: 0 auto; padding: 12px 16px 24px; }

/* ── сообщения ── */
.msg-user { display: flex; flex-direction: column; align-items: flex-end; margin: 18px 0 14px; gap: 6px; }
.bubble {
  max-width: 86%; background: var(--user-bubble); color: var(--text);
  padding: 10px 14px; border-radius: 20px 20px 6px 20px;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; font-size: 16px;
}
.bubble.pending { opacity: .7; }
.user-imgs { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 86%; }
.user-imgs img { width: 96px; height: 96px; object-fit: cover; border-radius: 14px; background: var(--surface-2); }
.doc-chip { font-size: 13px; padding: 6px 10px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }

.md { font-size: 16px; line-height: 1.6; color: var(--text); overflow-wrap: anywhere; margin: 6px 0; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .75em; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.3; margin: 1.1em 0 .45em; letter-spacing: -.01em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.07em; } .md h4 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.35em; margin: 0 0 .8em; }
.md li { margin: .22em 0; }
.md li::marker { color: var(--muted); }
.md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.md strong { font-weight: 650; }
.md blockquote { margin: 0 0 .8em; padding: 2px 0 2px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }
.md code { font-family: var(--mono); font-size: .86em; background: var(--code-bg); padding: .12em .38em; border-radius: 6px; border: 1px solid var(--border); }
.md pre { margin: 0 0 .9em; border-radius: 14px; background: var(--code-bg); border: 1px solid var(--border); overflow: hidden; }
.md pre code { display: block; padding: 12px 14px; overflow-x: auto; border: 0; background: none; font-size: 13.5px; line-height: 1.5; white-space: pre; }
.code-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--border); font-family: var(--mono); }
.copy-btn { font-size: 12px; padding: 4px 10px; border-radius: 8px; color: var(--muted); font-family: var(--font); }
.copy-btn:active { background: var(--surface-3); }
.md .table-wrap { overflow-x: auto; margin: 0 0 .9em; border: 1px solid var(--border); border-radius: 12px; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.md th, .md td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.md th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
.md img { max-width: 100%; border-radius: 12px; }

.divider { display: flex; align-items: center; gap: 10px; margin: 18px 0; color: var(--muted); font-size: 12.5px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ── размышления ── */
.thinking { margin: 6px 0; }
.thinking > summary, .steps > summary {
  list-style: none; display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  color: var(--muted); font-size: 14px; padding: 4px 0; user-select: none;
}
.thinking > summary::-webkit-details-marker, .steps > summary::-webkit-details-marker { display: none; }
.thinking > summary svg, .steps > summary .chev { width: 16px; height: 16px; transition: transform .2s; }
.thinking[open] > summary .chev, .steps[open] > summary .chev { transform: rotate(180deg); }
.thinking .think-body { margin: 4px 0 8px; padding-left: 12px; border-left: 2px solid var(--border-strong); color: var(--muted); font-size: 14.5px; white-space: pre-wrap; }

/* ── шаги (инструменты) ── */
.steps { margin: 8px 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.steps > summary { display: flex; width: 100%; padding: 11px 14px; color: var(--text-2); gap: 10px; }
.steps > summary .s-icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-2); color: var(--text-2); flex: none; }
.steps > summary .s-icon svg { width: 16px; height: 16px; }
.steps > summary .s-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14.5px; }
.steps > summary .s-count { color: var(--muted); font-size: 13px; flex: none; }
.steps.live > summary .s-icon { background: var(--accent-soft); color: var(--accent); }
.step-list { border-top: 1px solid var(--border); }
.step { border-bottom: 1px solid var(--border); }
.step:last-child { border-bottom: 0; }
.step-head { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px; text-align: left; min-height: 44px; }
.step-head .t-icon { color: var(--muted); }
.step-head .t-icon svg { width: 17px; height: 17px; }
.step-head .t-name { font-weight: 600; font-size: 13.5px; flex: none; }
.step-head .t-sum { flex: 1; min-width: 0; font-size: 13.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }
.step-head .t-state { flex: none; width: 18px; height: 18px; display: grid; place-items: center; }
.step-head .t-state svg { width: 16px; height: 16px; }
.t-ok { color: var(--ok); } .t-err { color: var(--danger); }
.step-body { padding: 0 14px 12px; }
.step-body .label { font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 6px 0 4px; }
.pre {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5; background: var(--code-bg); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 11px; white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto; margin: 0;
}
.pre.err { color: var(--danger); }
.diff { font-family: var(--mono); font-size: 12.5px; line-height: 1.45; border-radius: 10px; overflow: auto; max-height: 360px; border: 1px solid var(--border); }
.diff div { padding: 0 10px; white-space: pre-wrap; word-break: break-word; }
.diff .del { background: var(--danger-soft); color: var(--text); }
.diff .add { background: var(--ok-soft); color: var(--text); }
.diff .del::before { content: "− "; color: var(--danger); }
.diff .add::before { content: "+ "; color: var(--ok); }
.file-path { font-family: var(--mono); font-size: 12.5px; color: var(--muted); word-break: break-all; margin-bottom: 6px; }

.todos { list-style: none; padding: 0; margin: 4px 0; }
.todos li { display: flex; gap: 8px; align-items: flex-start; font-size: 14.5px; padding: 3px 0; }
.todos li svg { width: 18px; height: 18px; margin-top: 2px; color: var(--muted); }
.todos li.completed { color: var(--muted); text-decoration: line-through; }
.todos li.completed svg { color: var(--ok); }
.todos li.in_progress { font-weight: 600; }
.todos li.in_progress svg { color: var(--accent); }

.spin { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ── набор ответа ── */
.typing { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--muted); font-size: 14.5px; }
.typing .spark { width: 22px; height: 22px; color: var(--accent); animation: spin 2.4s linear infinite; }
.shimmer {
  background: linear-gradient(90deg, var(--muted) 0%, var(--text) 50%, var(--muted) 100%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.8s linear infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.live-cursor::after { content: ""; display: inline-block; width: 8px; height: 1.05em; vertical-align: -0.15em; margin-left: 2px; border-radius: 2px; background: var(--accent); animation: pulse 1s infinite; }

/* ── карточка разрешения ── */
.perm {
  margin: 12px 0; padding: 14px; border-radius: 18px; background: var(--surface);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border)); box-shadow: var(--shadow);
  animation: rise .25s ease;
}
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.perm-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.perm-head .p-icon { width: 34px; height: 34px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.perm-head .p-icon svg { width: 18px; height: 18px; }
.perm-head .p-title { font-weight: 650; font-size: 15.5px; line-height: 1.3; }
.perm-head .p-sub { font-size: 13px; color: var(--muted); }
.perm .pre { max-height: 220px; margin-bottom: 12px; }
.perm-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; }
.perm-actions .btn { min-height: 48px; }
.perm-always { width: 100%; margin-top: 8px; min-height: 40px; font-size: 14px; }
.q-block { margin-bottom: 14px; }
.q-title { font-weight: 600; margin-bottom: 8px; font-size: 15px; }
.q-opts { display: flex; flex-direction: column; gap: 6px; }
.q-opt { text-align: left; padding: 11px 13px; border-radius: 13px; border: 1px solid var(--border-strong); background: var(--bg); }
.q-opt .q-desc { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; line-height: 1.35; }
.q-opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.q-other { width: 100%; margin-top: 6px; padding: 11px 13px; border-radius: 13px; border: 1px solid var(--border-strong); background: var(--bg); outline: none; font-size: 16px; }
.plan-box { max-height: 360px; overflow: auto; padding: 10px 12px; background: var(--bg); border-radius: 12px; border: 1px solid var(--border); margin-bottom: 12px; }

.error-card { margin: 12px 0; padding: 12px 14px; border-radius: 14px; background: var(--danger-soft); color: var(--danger); font-size: 14px; white-space: pre-wrap; }

.load-more { display: block; margin: 4px auto 12px; font-size: 14px; color: var(--accent); padding: 8px 14px; border-radius: 12px; }
.load-more:active { background: var(--accent-soft); }

/* ── пустой экран ── */
#empty { min-height: 100%; display: grid; place-items: center; padding: 24px 20px; }
.hello { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.hello img { width: 56px; height: 56px; border-radius: 16px; box-shadow: var(--shadow); }
.hello h2 { margin: 0; font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.folder-chip {
  display: inline-flex; align-items: center; gap: 8px; max-width: 100%;
  padding: 9px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border-strong);
  font-size: 14.5px; font-family: var(--mono);
}
.folder-chip svg { width: 18px; height: 18px; color: var(--muted); }
.folder-chip .chev { width: 15px; height: 15px; }
.folder-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── поле ввода ── */
#composer { flex: none; padding: 6px 12px calc(10px + var(--sab)); background: linear-gradient(to bottom, transparent, var(--bg) 18px); }
.keyboard #composer { padding-bottom: 8px; }
.composer-card {
  max-width: 760px; margin: 0 auto; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 24px; box-shadow: var(--shadow); padding: 8px 8px 8px 14px;
  transition: border-color .15s, box-shadow .15s;
}
.composer-card:focus-within { border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong)); }
#input {
  display: block; width: 100%; border: 0; outline: none; resize: none; background: transparent;
  font-size: 16px; line-height: 1.45; max-height: 38vh; padding: 6px 4px 6px 0; min-height: 32px;
}
#input::placeholder { color: var(--muted); }
.composer-row { display: flex; align-items: center; gap: 8px; margin-top: 2px; margin-left: -6px; }
.spacer { flex: 1; }
.mode-chip { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 10px; border-radius: 999px; font-size: 13.5px; color: var(--text-2); background: var(--surface-2); }
.mode-chip .chev { width: 14px; height: 14px; }
.mode-chip.warn { background: var(--warn-soft); color: var(--warn); }
.send-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; transition: transform .12s, opacity .15s, background .15s;
}
.send-btn svg { width: 20px; height: 20px; stroke-width: 2.2; }
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { opacity: .35; }
.send-btn .i-stop { display: none; fill: currentColor; stroke: none; }
.send-btn.stop { background: var(--text); color: var(--bg); }
.send-btn.stop .i-stop { display: block; }
.send-btn.stop .i-send { display: none; }
.attachments { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 8px; }
.att { position: relative; flex: none; }
.att img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; display: block; }
.att button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.att button svg { width: 12px; height: 12px; stroke-width: 2.6; }
.busy-hint { max-width: 760px; margin: 0 auto 6px; font-size: 13px; color: var(--muted); text-align: center; }

.fab {
  position: absolute; right: 16px; bottom: calc(110px + var(--sab)); width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); border: 1px solid var(--border-strong); box-shadow: var(--shadow);
  display: grid; place-items: center; z-index: 4; color: var(--text-2);
}
.fab svg { width: 18px; height: 18px; }

/* ── боковая панель ── */
#drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 340px); z-index: 30;
  background: var(--bg); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding-top: var(--sat);
  transform: translateX(-102%); transition: transform .3s cubic-bezier(.32,.72,0,1);
  will-change: transform;
}
.drawer-open #drawer { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.18); }
#scrim { position: fixed; inset: 0; background: rgba(0,0,0,.32); opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 25; }
.drawer-open #scrim { opacity: 1; pointer-events: auto; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.new-chat {
  margin: 8px 12px 6px; display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 46px;
  border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600;
}
.new-chat:active { background: var(--accent-press); }
.new-chat svg { width: 20px; height: 20px; stroke-width: 2.2; }
.search { margin: 6px 12px 4px; display: flex; align-items: center; gap: 8px; padding: 0 12px; height: 40px; border-radius: 12px; background: var(--surface-2); color: var(--muted); }
.search svg { width: 17px; height: 17px; }
.search input { flex: 1; border: 0; outline: none; background: transparent; font-size: 16px; color: var(--text); min-width: 0; }
.session-list { flex: 1; overflow-y: auto; padding: 4px 8px 12px; -webkit-overflow-scrolling: touch; }
.group-label { font-size: 12px; font-weight: 600; color: var(--muted); padding: 14px 10px 6px; letter-spacing: .02em; }
.s-item { display: block; width: 100%; text-align: left; padding: 10px 10px; border-radius: 12px; position: relative; }
.s-item:active { background: var(--surface-2); }
.s-item.active { background: var(--surface-2); }
.s-title { font-size: 15px; font-weight: 520; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 4px; }
.s-meta { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-top: 2px; min-width: 0; }
.s-meta .proj { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); font-size: 12px; min-width: 0; flex: 0 1 auto; }
.s-meta > span:not(.proj) { flex: none; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; flex: none; }
.badge.vs { background: var(--ok-soft); color: var(--ok); }
.badge.vs.busy { background: var(--warn-soft); color: var(--warn); }
.badge.ph { background: var(--accent-soft); color: var(--accent); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.busy .dot, .badge.ph .dot { animation: pulse 1.2s infinite; }
.drawer-foot { border-top: 1px solid var(--border); padding: 10px 16px calc(10px + var(--sab)); }
.usage { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.usage:empty { display: none; }
.u-row { font-size: 12.5px; color: var(--muted); }
.u-row .u-top { display: flex; justify-content: space-between; margin-bottom: 3px; }
.u-bar { height: 4px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.u-bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.foot-row { display: flex; justify-content: space-between; align-items: center; }
.empty-list { padding: 30px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.skeleton { height: 52px; margin: 6px 4px; border-radius: 12px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }

/* ── нижний лист ── */
#sheetWrap { position: fixed; inset: 0; z-index: 50; }
.sheet-scrim { position: absolute; inset: 0; background: rgba(0,0,0,.35); animation: fade .2s ease; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 86vh; overflow-y: auto;
  background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  padding: 8px 18px calc(18px + var(--sab)); animation: up .32s cubic-bezier(.32,.72,0,1);
  max-width: 640px; margin: 0 auto;
}
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--border-strong); margin: 0 auto 12px; }
.sheet h3 { margin: 4px 0 6px; font-size: 19px; letter-spacing: -.01em; }
.sheet .sheet-icon { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; margin-bottom: 10px; background: var(--warn-soft); color: var(--warn); }
.sheet p { margin: 0 0 14px; color: var(--text-2); font-size: 15px; line-height: 1.5; }
.sheet .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.opt { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px; border-radius: 14px; }
.opt:active { background: var(--surface-2); }
.opt.sel { background: var(--accent-soft); }
.opt .o-icon { width: 36px; height: 36px; border-radius: 11px; background: var(--surface-2); display: grid; place-items: center; flex: none; }
.opt.sel .o-icon { background: var(--accent); color: #fff; }
.opt .o-icon svg { width: 18px; height: 18px; }
.opt .o-title { font-weight: 600; font-size: 15px; }
.opt .o-desc { font-size: 13px; color: var(--muted); line-height: 1.35; }
.dir-path { font-family: var(--mono); font-size: 13px; color: var(--muted); padding: 4px 2px 8px; word-break: break-all; }
.dir-list { max-height: 46vh; overflow-y: auto; margin: 0 -6px 10px; }
.dir-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 10px; border-radius: 12px; font-family: var(--mono); font-size: 14px; }
.dir-item:active { background: var(--surface-2); }
.dir-item svg { width: 18px; height: 18px; color: var(--muted); }
.sec-label { font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 2px 4px; text-transform: uppercase; letter-spacing: .04em; }

#toast {
  position: fixed; left: 50%; bottom: calc(110px + var(--sab)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 14px; font-size: 14px;
  z-index: 60; box-shadow: var(--shadow); animation: rise .2s ease; max-width: calc(100vw - 32px);
}

/* ── ноутбук/планшет: боковая панель всегда видна ── */
@media (min-width: 980px) {
  #drawer { position: relative; transform: none; width: 300px; flex: none; }
  #scrim, #menuBtn, #drawerClose { display: none; }
  .drawer-open #drawer { box-shadow: none; }
}

/* ── модель, контекст, slash-команды, usage, аккаунт ── */
.model-chip { max-width: 46vw; }
.model-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-row { min-width: 0; }

.sub-row { display: flex; align-items: center; justify-content: center; gap: 6px; min-width: 0; margin-top: -2px; }
.sub-row #subtitle { margin-top: 0; min-width: 0; }
.ctx-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); padding: 1px 7px 1px 4px; border-radius: 999px; flex: none; }
.ctx-pill:active { background: var(--surface-2); }
.ctx-ring { width: 13px; height: 13px; border-radius: 50%; background: conic-gradient(var(--ctx-c, var(--accent)) calc(var(--p, 0) * 1%), var(--surface-3) 0); display: grid; place-items: center; }
.ctx-ring i { width: 7px; height: 7px; border-radius: 50%; background: var(--bg); }
.ctx-pill.warn { color: var(--warn); --ctx-c: var(--warn); }
.ctx-pill.hot { color: var(--danger); --ctx-c: var(--danger); }

.note { margin: 10px 0; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); color: var(--text-2); font-family: var(--mono); font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; max-height: 360px; overflow: auto; }
.note.err { color: var(--danger); background: var(--danger-soft); }

.slash {
  max-width: 760px; margin: 0 auto 8px; background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 18px; box-shadow: var(--shadow); max-height: 42vh; overflow-y: auto; padding: 6px; animation: rise .15s ease;
}
.slash-item { display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left; padding: 9px 10px; border-radius: 12px; }
.slash-item:active, .slash-item.hl { background: var(--surface-2); }
.slash-item .sl-name { font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--text); }
.slash-item .sl-name em { font-style: normal; color: var(--muted); font-weight: 400; margin-left: 6px; }
.slash-item .sl-desc { font-size: 12.5px; color: var(--muted); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.usage-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .02em; margin-bottom: 8px; }
.usage { margin-bottom: 12px; gap: 10px; }
.u-row .u-top b { color: var(--text); font-weight: 600; }
.u-bar { height: 6px; }
.u-bar i.warn { background: var(--warn); }
.u-bar i.hot { background: var(--danger); }
.u-reset { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.account { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px; margin: 0 -8px; border-radius: 12px; width: calc(100% + 16px); }
.account:active { background: var(--surface-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 650; font-size: 15px; flex: none; }
.acc-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.acc-email { font-size: 14px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account .chev { width: 16px; height: 16px; color: var(--muted); }

.seg { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); margin-bottom: 6px; overflow-x: auto; }
.seg button { flex: 1; min-width: 56px; height: 36px; border-radius: 10px; font-size: 13.5px; color: var(--text-2); white-space: nowrap; padding: 0 8px; }
.seg button.sel { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.sheet .hint { font-size: 12.5px; color: var(--muted); margin: 2px 2px 10px; line-height: 1.4; }
.more-toggle { font-size: 13.5px; color: var(--accent); padding: 8px 12px; }
.opt .o-check { margin-left: auto; color: var(--accent); }
.opt .o-check svg { width: 18px; height: 18px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14.5px; margin: 6px 0 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; word-break: break-all; }
.ctx-big { height: 10px; border-radius: 6px; background: var(--surface-3); overflow: hidden; margin: 6px 0 8px; }
.ctx-big i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.cat-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 5px 2px; border-bottom: 1px solid var(--border); }
.cat-row:last-child { border-bottom: 0; }
.cat-row span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.note.md-note { font-family: var(--font); font-size: 14px; white-space: normal; background: var(--surface); border: 1px solid var(--border); max-height: 420px; padding: 12px 14px; }
.note.md-note .md { font-size: 14px; margin: 0; }
