@font-face { font-family: "Rubik"; font-weight: 300 900; font-display: swap;
  src: url("/fonts/rubik-cyrillic-wght-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Rubik"; font-weight: 300 900; font-display: swap;
  src: url("/fonts/rubik-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap;
  src: url("/fonts/jetbrains-mono-cyrillic-400-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "JetBrains Mono"; font-weight: 400; font-display: swap;
  src: url("/fonts/jetbrains-mono-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+2000-206F; }

:root {
  --bg: #f4f7f5;
  --panel: #e9efeb;
  --surface: #ffffff;
  --sunken: #eef3f0;
  --text: #17251e;
  --subtext: #3c4f46;
  --muted: #5c6a61;
  --line: rgba(23, 37, 30, .12);
  --line-strong: rgba(23, 37, 30, .22);
  --brand-ink: #267354;
  --brand: #267354;
  --on-brand: #ffffff;
  --brand-soft: rgba(38, 115, 84, .10);
  --user-bg: #dcebe3;
  --ok-ink: #1f7a5a; --warn-ink: #836609; --danger-ink: #b33a31; --info-ink: #1c6f9b;
  --danger-bg: rgba(179, 58, 49, .08); --danger-line: rgba(179, 58, 49, .28);
  --warn-bg: rgba(131, 102, 9, .09);
  --focus: #267354;
  --radius: 8px;
  --font: "Rubik", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141916; --panel: #0f1311; --surface: #1b221e; --sunken: #181e1b;
    --text: #e8ede9; --subtext: #c7d6cd; --muted: #93a79b;
    --line: rgba(232, 237, 233, .14); --line-strong: rgba(232, 237, 233, .26);
    --brand-ink: #5fc99d; --brand: #349f74; --on-brand: #08130d; --brand-soft: rgba(52, 159, 116, .16);
    --user-bg: #233a2f;
    --ok-ink: #4fc39a; --warn-ink: #e0a82e; --danger-ink: #e8695e; --info-ink: #5cb8e8;
    --danger-bg: rgba(232, 105, 94, .10); --danger-line: rgba(232, 105, 94, .34); --warn-bg: rgba(224, 168, 46, .10);
    --focus: #5fc99d;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141916; --panel: #0f1311; --surface: #1b221e; --sunken: #181e1b;
  --text: #e8ede9; --subtext: #c7d6cd; --muted: #93a79b;
  --line: rgba(232, 237, 233, .14); --line-strong: rgba(232, 237, 233, .26);
  --brand-ink: #5fc99d; --brand: #349f74; --on-brand: #08130d; --brand-soft: rgba(52, 159, 116, .16);
  --user-bg: #233a2f;
  --ok-ink: #4fc39a; --warn-ink: #e0a82e; --danger-ink: #e8695e; --info-ink: #5cb8e8;
  --danger-bg: rgba(232, 105, 94, .10); --danger-line: rgba(232, 105, 94, .34); --warn-bg: rgba(224, 168, 46, .10);
  --focus: #5fc99d;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand-ink); }
code, kbd, pre { font-family: var(--mono); font-size: .88em; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--brand-soft); }

.boot { position: fixed; inset: 0; display: grid; place-items: center; color: var(--muted); }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); font-weight: 500;
  transition: background-color .15s, border-color .15s, color .15s; }
.btn:hover { border-color: var(--brand-ink); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: color-mix(in srgb, var(--brand) 88%, var(--text)); border-color: transparent; }
.btn-wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--subtext); text-decoration: none; transition: background-color .15s, color .15s; }
.icon-btn:hover { background: var(--brand-soft); color: var(--text); }
input[type="search"], input:not([type]), input[type="password"], input[name], select, textarea {
  border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
select { min-height: 36px; padding: 0 30px 0 10px; appearance: none; max-width: 100%;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 15px) 52%, calc(100% - 10px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
select:hover, input:hover { border-color: var(--muted); }
kbd { padding: 1px 5px; border: 1px solid var(--line-strong); border-radius: 4px; background: var(--surface); font-size: .8em; }

/* ---------- forged mark ---------- */
.forged a { display: inline-flex; align-items: center; gap: 8px; min-height: 28px; color: var(--muted); text-decoration: none; font-size: 13px; }
.forged a:hover { color: var(--brand-ink); }
.forged img { border-radius: 4px; }
.forged-center { text-align: center; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; grid-template-rows: 1fr auto; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 6px; }
.login-mark { border-radius: 14px; margin-bottom: 10px; }
.login h1 { margin: 0; font-size: 34px; line-height: 1.1; font-weight: 700; letter-spacing: -.02em; }
.login-sub { margin: 0 0 22px; color: var(--muted); }
#login-form { display: grid; gap: 14px; }
#login-form label { display: grid; gap: 6px; font-size: 14px; font-weight: 500; color: var(--subtext); }
#login-form input { min-height: 44px; padding: 0 12px; font-size: 16px; width: 100%; }
.pw { position: relative; display: block; }
.pw input { padding-right: 44px !important; }
.pw .icon-btn { position: absolute; right: 4px; top: 4px; }
.form-error { margin: 0; padding: 10px 12px; border: 1px solid var(--danger-line); border-radius: var(--radius); background: var(--danger-bg); color: var(--danger-ink); font-size: 14px; }
.login .btn-primary { min-height: 46px; margin-top: 4px; }
.login-hint { margin: 18px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- app layout ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: 288px minmax(0, 1fr); }
.sidebar { display: flex; flex-direction: column; gap: 12px; min-height: 0; padding: 14px 12px 10px; background: var(--panel); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 4px 4px; }
.brand-text { display: grid; line-height: 1.15; flex: 1; }
.brand-text strong { font-size: 18px; font-weight: 700; letter-spacing: -.01em; }
.brand-text span { font-size: 12px; color: var(--muted); }
.search { position: relative; display: block; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { width: 100%; min-height: 36px; padding: 0 10px 0 32px; background: var(--surface); }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.chat-group { margin: 14px 0 4px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.chat-group:first-child { margin-top: 2px; }
.chat-item { position: relative; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 38px; padding: 6px 8px;
  border: 0; border-radius: var(--radius); background: transparent; text-align: left; color: var(--subtext); }
.chat-item:hover { background: var(--brand-soft); color: var(--text); }
.chat-item[aria-current="true"] { background: var(--surface); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.chat-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.chat-item .tag { font-size: 11px; color: var(--muted); }
.chat-item .tgmark { width: 14px; height: 14px; color: var(--info-ink); }
.chat-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand-ink); animation: pulse 1.2s ease-in-out infinite; }
.chat-item .del { display: none; width: 28px; height: 28px; }
.chat-item:hover .del, .chat-item:focus-within .del { display: inline-grid; }
.empty-list { margin: 16px 8px; color: var(--muted); font-size: 14px; }
.side-foot { display: grid; gap: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
.side-tools { display: flex; gap: 2px; }
.workspace { display: flex; align-items: center; gap: 6px; margin: 0; padding: 0 6px; font-size: 12px; color: var(--muted); }
.workspace svg { width: 14px; height: 14px; }
.workspace span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 11px; }
.side-foot .forged { padding: 0 6px; }

.main { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; min-height: 0; background: var(--bg); }

/* ---------- status bar ---------- */
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--bg); }
.status-row { display: flex; align-items: center; gap: 6px; flex: 1 1 220px; min-width: 0; }
.chat-title { min-width: 0; max-width: 100%; padding: 4px 8px; margin-left: -8px; border: 0; border-radius: var(--radius); background: none;
  font-size: 17px; font-weight: 600; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: auto; }
.chat-title:hover { background: var(--brand-soft); }
.status-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.field { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.field-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); }
.seg button { min-height: 30px; padding: 0 12px; border: 0; border-radius: 6px; background: none; color: var(--subtext); font-size: 13px; font-weight: 500; }
.seg button[aria-checked="true"] { background: var(--brand); color: var(--on-brand); }
.seg button:disabled { cursor: default; opacity: .6; }
#model { min-width: 150px; font-size: 13px; }
.meter .bar { position: relative; width: 72px; height: 6px; border-radius: 3px; background: var(--sunken); box-shadow: inset 0 0 0 1px var(--line); overflow: hidden; }
.meter .fill { position: absolute; inset: 0; background: var(--brand-ink); transform-origin: left; transform: scaleX(0); transition: transform .3s ease-out; }
.meter[data-level="warn"] .fill { background: var(--warn-ink); }
.meter[data-level="danger"] .fill { background: var(--danger-ink); }
.meter-val, #usage-val { font-variant-numeric: tabular-nums; color: var(--subtext); }
.model-desc { flex-basis: 100%; margin: -2px 0 0; font-size: 12px; color: var(--muted); }
.model-desc:empty { display: none; }

/* ---------- thread ---------- */
.thread { overflow-y: auto; padding: 24px 20px 8px; scroll-behavior: smooth; }
.thread > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.msg { margin-bottom: 22px; }
.msg-user { display: flex; flex-direction: column; align-items: flex-end; }
.bubble { max-width: min(620px, 92%); padding: 10px 14px; border-radius: 14px 14px 4px 14px; background: var(--user-bg); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.msg-meta svg { width: 13px; height: 13px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; justify-content: flex-end; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 12px; color: var(--subtext); }
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip svg { width: 14px; height: 14px; }
.file-chip button { display: grid; place-items: center; width: 24px; height: 24px; margin: -4px -6px -4px 0; border: 0; background: none; color: var(--muted); border-radius: 4px; }
.file-chip button:hover { color: var(--danger-ink); }

.agent-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.agent-head img { border-radius: 6px; }
.agent-head b { font-weight: 600; }
.agent-head .engine { font-size: 12px; color: var(--muted); }
.agent-head time { margin-left: auto; font-size: 12px; color: var(--muted); }

.process { margin: 0 0 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.process > summary { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 6px 12px; list-style: none; cursor: pointer; font-size: 13px; color: var(--subtext); }
.process > summary::-webkit-details-marker { display: none; }
.process > summary::after { content: ""; width: 7px; height: 7px; margin-left: auto; border-right: 1.6px solid var(--muted); border-bottom: 1.6px solid var(--muted); transform: rotate(45deg) translateY(-2px); transition: transform .15s; }
.process[open] > summary::after { transform: rotate(225deg) translateY(-2px); }
.process .now { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.process .now code { color: var(--subtext); }
.steps { margin: 0; padding: 4px 12px 10px; list-style: none; border-top: 1px solid var(--line); }
.step { display: flex; align-items: flex-start; gap: 8px; padding: 5px 0; font-size: 13px; color: var(--subtext); }
.step svg { width: 15px; height: 15px; margin-top: 2px; }
.step .ico-run { color: var(--brand-ink); animation: spin 1s linear infinite; }
.step.done > svg:first-child { color: var(--ok-ink); }
.step.error > svg:first-child { color: var(--danger-ink); }
.step b { font-weight: 500; color: var(--text); }
.step code { overflow-wrap: anywhere; font-size: 12px; }

.working { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; padding: 4px 0; }
.working .dots { display: inline-flex; gap: 4px; }
.working .dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--brand-ink); animation: pulse 1.2s ease-in-out infinite; }
.working .dots i:nth-child(2) { animation-delay: .15s; } .working .dots i:nth-child(3) { animation-delay: .3s; }

.alert { display: flex; gap: 10px; align-items: flex-start; margin: 8px 0; padding: 10px 12px; border: 1px solid var(--danger-line); border-radius: var(--radius); background: var(--danger-bg); color: var(--danger-ink); font-size: 14px; overflow-wrap: anywhere; }
.alert svg { margin-top: 1px; }
.note { margin-bottom: 22px; padding: 10px 14px; border: 1px dashed var(--line-strong); border-radius: var(--radius); color: var(--subtext); font-size: 13px; white-space: pre-wrap; font-family: var(--font); }

/* markdown */
.prose { overflow-wrap: anywhere; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose pre, .prose table, .prose blockquote { margin: 0 0 12px; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 20px 0 8px; line-height: 1.3; font-weight: 600; }
.prose h1 { font-size: 20px; } .prose h2 { font-size: 18px; } .prose h3 { font-size: 16px; } .prose h4 { font-size: 15px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li + li { margin-top: 4px; }
.prose :not(pre) > code { padding: 1px 5px; border-radius: 4px; background: var(--sunken); box-shadow: inset 0 0 0 1px var(--line); }
.prose pre { padding: 12px 14px; border-radius: var(--radius); background: var(--sunken); box-shadow: inset 0 0 0 1px var(--line); overflow-x: auto; line-height: 1.45; }
.prose table { border-collapse: collapse; display: block; overflow-x: auto; font-size: 14px; }
.prose th, .prose td { padding: 6px 10px; border: 1px solid var(--line); text-align: left; }
.prose th { background: var(--sunken); font-weight: 600; }
.prose blockquote { padding: 2px 14px; color: var(--subtext); background: var(--sunken); border-radius: var(--radius); }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.prose a { overflow-wrap: anywhere; }

/* empty state */
.empty { padding: 7vh 0 20px; }
.empty h2 { margin: 0 0 8px; font-size: 26px; line-height: 1.2; letter-spacing: -.015em; font-weight: 700; }
.empty > p { margin: 0 0 22px; color: var(--subtext); max-width: 60ch; }
.examples { display: grid; gap: 8px; margin-bottom: 26px; }
.example { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-align: left; color: var(--text); transition: border-color .15s; }
.example:hover { border-color: var(--brand-ink); }
.example svg { color: var(--brand-ink); }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 28px; margin: 0; padding-top: 16px; border-top: 1px solid var(--line); }
.facts div { padding: 6px 0; }
.facts dt { font-size: 13px; font-weight: 600; }
.facts dd { margin: 2px 0 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

/* ---------- composer ---------- */
.composer { position: relative; padding: 8px 20px max(12px, env(safe-area-inset-bottom)); background: var(--bg); }
.composer > * { max-width: 780px; margin-left: auto; margin-right: auto; }
.composer-box { display: flex; align-items: flex-end; gap: 6px; padding: 6px; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--surface); transition: border-color .15s; }
.composer-box:focus-within { border-color: var(--brand-ink); }
.composer textarea { flex: 1; min-height: 36px; max-height: 40vh; padding: 7px 4px; border: 0; background: none; resize: none; outline: none; line-height: 1.45; font-size: 15px; }
.attach { cursor: pointer; }
.send { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 10px; background: var(--brand); color: var(--on-brand); transition: background-color .15s, opacity .15s; }
.send:disabled { opacity: .4; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); }
.composer-hint { margin-top: 6px; font-size: 12px; color: var(--muted); text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:not(:empty) { margin-bottom: 8px; }
.drop-hint { position: absolute; inset: -60px 20px 10px; display: grid; place-items: center; border: 2px dashed var(--brand-ink); border-radius: 14px; background: var(--brand-soft); color: var(--brand-ink); font-weight: 500; z-index: 3; }
.slash { position: absolute; left: 20px; right: 20px; bottom: calc(100% - 4px); max-height: 300px; overflow-y: auto; padding: 4px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); z-index: 4; }
.slash button { display: flex; gap: 12px; align-items: baseline; width: 100%; min-height: 36px; padding: 6px 10px; border: 0; border-radius: 6px; background: none; text-align: left; }
.slash button[aria-selected="true"], .slash button:hover { background: var(--brand-soft); }
.slash code { min-width: 92px; color: var(--brand-ink); }
.slash span { font-size: 13px; color: var(--subtext); }

/* ---------- drawer ---------- */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100%); display: flex; flex-direction: column; background: var(--surface); border-left: 1px solid var(--line-strong); z-index: 20; }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; }
.doc-list { display: grid; gap: 2px; margin: 0 0 16px; padding: 0; list-style: none; }
.doc-list button { width: 100%; min-height: 36px; padding: 6px 10px; border: 0; border-radius: 6px; background: none; text-align: left; font-family: var(--mono); font-size: 13px; color: var(--subtext); }
.doc-list button:hover { background: var(--brand-soft); color: var(--text); }
.back { margin-bottom: 12px; }
.help h3 { margin-top: 18px; }

.scrim { position: fixed; inset: 0; background: rgba(10, 16, 13, .45); z-index: 9; }
.only-mobile { display: none; }

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

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .only-mobile { display: inline-grid; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(320px, 86vw); z-index: 10; transform: translateX(-102%); transition: transform .22s cubic-bezier(.2, .8, .2, 1); }
  .app.side-open .sidebar { transform: none; }
  .status { padding: 8px 12px; gap: 8px; }
  .status-controls { display: none; flex-basis: 100%; gap: 10px 16px; padding: 4px 0 2px; }
  .status.expanded .status-controls { display: flex; }
  .model-desc { display: none; }
  .status.expanded .model-desc:not(:empty) { display: block; }
  .thread { padding: 16px 14px 8px; }
  .composer { padding: 6px 10px max(10px, env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .slash { left: 10px; right: 10px; }
  .composer textarea { font-size: 16px; }
  .chat-item .del { display: inline-grid; }
  .empty h2 { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
