/* ---------- fonts (vendored, SIL OFL) ---------- */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(fonts/inter-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: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url(fonts/inter-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+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url(fonts/source-serif-4-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: "Source Serif"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url(fonts/source-serif-4-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+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Serif"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url(fonts/source-serif-4-cyrillic-wght-italic.woff2) format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Source Serif"; font-style: italic; font-weight: 200 900; font-display: swap;
  src: url(fonts/source-serif-4-latin-wght-italic.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- tokens ---------- */
:root {
  --bg: #faf9f5;
  --side: #f5f4ed;
  --surface: #ffffff;
  --surface-2: #f0eee6;
  --hover: rgba(31, 30, 29, 0.06);
  --active: rgba(31, 30, 29, 0.09);
  --fg: #141413;
  --fg-2: #3d3d3a;
  --muted: #73726c;
  --faint: #a3a29b;
  --border: rgba(31, 30, 29, 0.12);
  --border-strong: rgba(31, 30, 29, 0.22);
  --accent: #c6613f;
  --accent-hover: #b4532f;
  --accent-soft: rgba(198, 97, 63, 0.12);
  --on-accent: #ffffff;
  --danger: #b3261e;
  --user-bubble: #f0eee6;
  --code-bg: #262624;
  --code-head: #30302e;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --shadow-lg: 0 2px 6px rgba(0,0,0,.05), 0 16px 48px rgba(0,0,0,.12);
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "Source Serif", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --side-w: 288px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #262624;
    --side: #1f1e1d;
    --surface: #30302e;
    --surface-2: #3a3936;
    --hover: rgba(250, 249, 245, 0.06);
    --active: rgba(250, 249, 245, 0.1);
    --fg: #faf9f5;
    --fg-2: #dedcd1;
    --muted: #9c9a92;
    --faint: #6f6d66;
    --border: rgba(222, 220, 209, 0.14);
    --border-strong: rgba(222, 220, 209, 0.26);
    --accent: #d97757;
    --accent-hover: #e3896b;
    --accent-soft: rgba(217, 119, 87, 0.16);
    --danger: #f2706a;
    --user-bubble: #141413;
    --code-bg: #1a1a18;
    --code-head: #222220;
    --shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 16px rgba(0,0,0,.2);
    --shadow-lg: 0 2px 6px rgba(0,0,0,.3), 0 20px 50px rgba(0,0,0,.45);
    color-scheme: dark;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
::selection { background: var(--accent-soft); }

.ico { width: 18px; height: 18px; flex-shrink: 0; display: block; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 10px;
  padding: 7px 14px;
  font-weight: 500; font-size: 14px;
  text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--fg); border-color: var(--fg); color: var(--bg); }
.btn.primary:hover { opacity: .88; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--hover); color: var(--fg); }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 9px;
  background: none; border: 0; color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }

input, select, textarea {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 12px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; width: 100%; line-height: 1.55; }

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

.sidebar {
  width: var(--side-w); flex-shrink: 0;
  background: var(--side);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 10px 10px 8px;
  transition: margin-left .25s ease;
}
body.side-collapsed .sidebar { margin-left: calc(-1 * var(--side-w)); }

.side-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 10px 8px; }
.brand { font-family: var(--serif); font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }

.new-chat {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 8px; margin-bottom: 4px;
  background: none; border: 0; border-radius: 10px;
  font-weight: 500; color: var(--fg); text-align: left;
  transition: background .15s;
}
.new-chat:hover { background: var(--hover); }
.new-chat-icon {
  display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent);
  transition: transform .2s;
}
.new-chat-icon .ico { width: 16px; height: 16px; stroke-width: 2.4; }
.new-chat:hover .new-chat-icon { transform: rotate(90deg); }

.search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px; margin: 2px 0 10px; border-radius: 10px;
  color: var(--muted); border: 1px solid transparent;
  transition: background .15s, border-color .15s;
}
.search:hover { background: var(--hover); }
.search:focus-within { background: var(--surface); border-color: var(--border-strong); }
.search .ico { width: 16px; height: 16px; }
.search input { border: 0; background: none; padding: 8px 0; width: 100%; box-shadow: none; }

.conv-list { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; scrollbar-width: thin; }
.conv-group {
  font-size: 12px; font-weight: 500; color: var(--muted);
  padding: 14px 10px 4px; position: sticky; top: 0; background: var(--side); z-index: 1;
}
.conv-group:first-child { padding-top: 2px; }
.conv {
  display: block; padding: 6px 10px; border-radius: 8px;
  color: var(--fg-2); text-decoration: none; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .12s;
}
.conv:hover { background: var(--hover); color: var(--fg); }
.conv.active { background: var(--active); color: var(--fg); font-weight: 500; }
.conv-empty { color: var(--faint); font-size: 13px; padding: 12px 10px; }

.user-wrap { position: relative; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 6px; }
.user-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; border-radius: 10px; padding: 6px 8px; text-align: left;
  transition: background .15s;
}
.user-btn:hover { background: var(--hover); }
.user-btn > .ico { color: var(--muted); width: 16px; }
.avatar {
  display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--fg); color: var(--bg); font-weight: 600; font-size: 14px; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.uname { font-weight: 500; font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.urole { font-size: 12px; color: var(--muted); }

/* dropdown menus */
.menu {
  position: absolute; z-index: 20; min-width: 220px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 5px; box-shadow: var(--shadow-lg);
  animation: pop .14s ease-out;
}
.menu.up { bottom: calc(100% + 6px); left: 0; right: 0; }
.menu button, .menu a {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px 10px; border: 0; background: none; border-radius: 8px;
  font-size: 14px; color: var(--fg); text-decoration: none; text-align: left; cursor: pointer;
}
.menu button:hover, .menu a:hover { background: var(--hover); }
.menu .ico { width: 16px; height: 16px; color: var(--muted); }
.menu .danger, .menu .danger .ico { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 4px; }
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }

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

.topbar { display: flex; align-items: center; gap: 6px; padding: 8px 12px; min-height: 52px; }
#menuBtn { display: none; }
body.side-collapsed #menuBtn { display: inline-grid; }
.title-wrap { position: relative; min-width: 0; }
.title-btn {
  display: flex; align-items: center; gap: 4px; max-width: 100%;
  background: none; border: 0; border-radius: 9px; padding: 6px 8px 6px 10px;
  font-weight: 500; color: var(--fg); transition: background .15s;
}
.title-btn:hover { background: var(--hover); }
.title-btn > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title-btn .ico { width: 16px; color: var(--muted); }
.title-wrap .menu { top: calc(100% + 4px); left: 0; }
.main.is-empty .title-wrap { visibility: hidden; }

.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: 768px; margin: 0 auto; padding: 16px 24px 32px; }
.main.is-empty .messages { display: none; }

/* stage: hero + composer. Centred when the chat is empty, docked at the bottom otherwise */
.stage { display: flex; flex-direction: column; align-items: center; }
.main.is-empty .stage { flex: 1; justify-content: center; padding-bottom: 14vh; }
.hero {
  display: none; align-items: center; gap: 14px; margin-bottom: 28px; padding: 0 20px;
  animation: rise .5s ease-out;
}
.main.is-empty .hero { display: flex; }
.hero h1 {
  margin: 0; font-family: var(--serif); font-weight: 400;
  font-size: clamp(30px, 4.4vw, 42px); letter-spacing: -0.02em; line-height: 1.15; text-align: center;
}
.hero-mark {
  width: 38px; height: 38px; flex-shrink: 0; border-radius: 11px;
  background: url(favicon.svg) center/cover;
  animation: breathe 6s ease-in-out infinite;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes breathe { 50% { transform: rotate(-8deg) scale(1.04); } }

/* ---------- composer ---------- */
.composer-wrap { width: 100%; max-width: 768px; padding: 0 24px 10px; }
.main.is-empty .composer-wrap { max-width: 720px; }
.composer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 14px 14px 10px 18px;
  transition: border-color .2s, box-shadow .2s;
}
.composer:focus-within { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
.composer textarea {
  display: block; width: 100%; border: 0; background: none; box-shadow: none; padding: 2px 0 8px;
  resize: none; min-height: 28px; max-height: 320px; font-size: 16px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--faint); }
.composer-bar { display: flex; align-items: center; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 11px 0 9px; margin-left: -6px;
  background: none; border: 1px solid var(--border); border-radius: 9px;
  color: var(--muted); font-size: 13px; transition: all .15s;
}
.chip:hover { color: var(--fg); background: var(--hover); }
.chip .ico { width: 16px; height: 16px; }
.chip.on { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, transparent); background: var(--accent-soft); }
.spacer { flex: 1; }
.model-pick {
  position: relative; display: inline-flex; align-items: center;
  border-radius: 9px; color: var(--muted); transition: background .15s, color .15s;
}
.model-pick:hover { background: var(--hover); color: var(--fg); }
.model-pick select {
  appearance: none; -webkit-appearance: none; border: 0; background: none; box-shadow: none;
  padding: 6px 26px 6px 10px; font-size: 13px; font-weight: 500; max-width: 220px;
  text-overflow: ellipsis; cursor: pointer;
}
.model-pick > span { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); display: flex; pointer-events: none; }
.model-pick .ico { width: 15px; height: 15px; }
.send {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: var(--accent); color: var(--on-accent); border: 0;
  transition: background .15s, transform .1s, opacity .15s;
}
.send:hover { background: var(--accent-hover); }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .35; cursor: default; background: var(--accent); }
.send .ico { width: 18px; height: 18px; stroke-width: 2.2; }
.send.stop { background: var(--fg); color: var(--bg); }
.disclaimer { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--faint); }
.main.is-empty .disclaimer { visibility: hidden; }

/* ---------- messages ---------- */
.msg { margin: 0 0 28px; animation: rise .3s ease-out; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; }
.msg.user .body {
  background: var(--user-bubble);
  border-radius: 18px 18px 6px 18px;
  padding: 10px 16px;
  max-width: 85%;
  white-space: pre-wrap; overflow-wrap: anywhere;
  font-size: 15.5px;
}
.msg.assistant .body {
  font-family: var(--serif);
  font-size: 17px; line-height: 1.68;
  color: var(--fg);
  overflow-wrap: anywhere;
}
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 0.85em; }
.body h1, .body h2, .body h3, .body h4 { font-weight: 600; line-height: 1.3; margin: 1.4em 0 .5em; letter-spacing: -0.01em; }
.body h1 { font-size: 1.45em; } .body h2 { font-size: 1.25em; } .body h3 { font-size: 1.1em; }
.body ul, .body ol { padding-left: 1.4em; margin: 0 0 .9em; }
.body li { margin: .25em 0; }
.body li::marker { color: var(--muted); }
.body a { color: var(--accent); text-underline-offset: 3px; }
.body strong { font-weight: 650; }
.body hr { border: 0; border-top: 1px solid var(--border); margin: 1.6em 0; }
.body blockquote { margin: 0 0 1em; padding: 2px 0 2px 16px; border-left: 3px solid var(--accent-soft); color: var(--fg-2); font-style: italic; }
.body :not(pre) > code {
  font-family: var(--mono); font-size: .82em;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: .1em .35em; border-radius: 5px;
}
.body table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 1em; font-family: var(--sans); font-size: 14px; }
.body th, .body td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.body th { background: var(--surface-2); font-weight: 600; }

.codeblock {
  margin: 0 0 1em; border-radius: 12px; overflow: hidden;
  background: var(--code-bg); border: 1px solid var(--border);
  font-family: var(--sans);
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 8px 6px 14px; background: var(--code-head);
  font-size: 12px; color: #a3a29b;
}
.code-head button {
  display: inline-flex; align-items: center; gap: 5px;
  background: none; border: 0; color: #a3a29b; font-size: 12px; padding: 4px 8px; border-radius: 6px;
}
.code-head button:hover { background: rgba(255,255,255,.08); color: #faf9f5; }
.code-head .ico { width: 14px; height: 14px; }
.codeblock pre, .body pre { margin: 0; padding: 14px 16px; overflow-x: auto; color: #e8e6dc; background: var(--code-bg); }
.body pre code, .body pre code.hljs { font-family: var(--mono); font-size: 13px; line-height: 1.6; background: none; padding: 0; }

/* actions under a message */
.actions {
  display: flex; align-items: center; gap: 2px; margin-top: 6px; min-height: 30px;
  opacity: 0; transition: opacity .15s;
  font-size: 12px; color: var(--faint);
}
.msg:hover .actions, .msg:last-child .actions, .msg:focus-within .actions { opacity: 1; }
.msg.user .actions { justify-content: flex-end; }
.actions .icon-btn { width: 28px; height: 28px; border-radius: 7px; }
.actions .icon-btn .ico { width: 15px; height: 15px; }
.actions .meta { margin-left: 6px; }

/* typing indicator */
.thinking { display: flex; align-items: center; gap: 5px; height: 28px; }
.thinking span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  animation: dot 1.2s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }
.msg.streaming .body > :last-child::after {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-left: 4px;
  border-radius: 50%; background: var(--accent); vertical-align: middle;
  animation: dot 1s ease-in-out infinite;
}

/* ---------- dialogs ---------- */
dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0;
  background: var(--bg); color: var(--fg);
  width: min(600px, calc(100vw - 32px)); max-height: calc(100dvh - 40px);
  box-shadow: var(--shadow-lg);
}
dialog[open] { animation: pop .18s ease-out; }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20, 20, 19, .45); backdrop-filter: blur(3px); }
.dialog { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.dialog-head h3 { margin: 0; font-family: var(--serif); font-weight: 500; font-size: 22px; letter-spacing: -0.01em; }
.hint { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.dialog h4 { margin: 0 0 10px; font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--fg-2); }
.field + .field { margin-top: 10px; }
.select-wrap { position: relative; display: block; }
.select-wrap select { appearance: none; -webkit-appearance: none; width: 100%; padding-right: 34px; }
.select-wrap .ico { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--muted); pointer-events: none; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row .dialog-head { min-width: 0; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.panel .row { margin-top: 12px; }
.error { color: var(--danger); margin: 0; font-size: 14px; }

.table-wrap { overflow-x: auto; margin: 0 -4px; }
.users { width: 100%; border-collapse: collapse; font-size: 14px; }
.users th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); }
.users td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.users tr:last-child td { border-bottom: 0; }
.users .who { display: flex; align-items: center; gap: 10px; }
.users .avatar { width: 28px; height: 28px; font-size: 12px; }
.users .tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }
.users .tag.off { background: var(--surface-2); color: var(--muted); }
.users tr.inactive .who > span:not(.tag) { color: var(--muted); text-decoration: line-through; }
.users td.num { font-variant-numeric: tabular-nums; color: var(--fg-2); }
.users .row-actions { white-space: nowrap; text-align: right; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.link-btn:hover { color: var(--fg); background: var(--hover); }
.new-user { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; align-items: center; }
.new-user input:not([type=checkbox]) { flex: 1; min-width: 150px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%);
  background: var(--fg); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: min(520px, 90vw);
  box-shadow: var(--shadow-lg); z-index: 50; animation: rise .2s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; padding: 24px; min-height: 100dvh; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; animation: rise .5s ease-out; }
.login-card .hero-mark { width: 46px; height: 46px; border-radius: 13px; margin: 0 auto 6px; }
.login-card h1 { margin: 0 0 10px; text-align: center; font-family: var(--serif); font-weight: 400; font-size: 34px; letter-spacing: -0.02em; }
.login-card .sub { margin: -14px 0 14px; text-align: center; color: var(--muted); }
.login-card input { width: 100%; padding: 12px 14px; font-size: 15px; }
.login-card .btn { justify-content: center; padding: 12px; font-size: 15px; background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.login-card .btn:hover { background: var(--accent-hover); opacity: 1; }

/* ---------- mobile ---------- */
.scrim { display: none; }
@media (max-width: 820px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; margin-left: 0 !important;
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg);
  }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(20,20,19,.4); }
  #menuBtn { display: inline-grid !important; }
  #collapseBtn { display: none; }
  .thread { padding: 8px 16px 24px; }
  .composer-wrap { padding: 0 12px calc(8px + env(safe-area-inset-bottom)); }
  .chip-label { display: none; }
  .chip { padding: 0 8px; }
  .model-pick select { max-width: 140px; }
  .msg.assistant .body { font-size: 16.5px; }
  .main.is-empty .stage { padding-bottom: 8vh; }
}

/* ---------- tool activity ---------- */
.tools-trace { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.tool-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--fg-2);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 99px; padding: 4px 10px 4px 8px;
  animation: rise .2s ease-out;
}
.tool-chip .ico { width: 14px; height: 14px; color: var(--muted); }
.tool-chip.ok .ico { color: #3f8f5a; }
.tool-chip.err { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.tool-chip.err .ico { color: var(--danger); }
.spin {
  width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--accent-soft); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tools-summary {
  display: inline-flex; align-items: center; gap: 6px; margin: 0 0 10px;
  background: none; border: 0; padding: 2px 0; color: var(--muted); font-size: 12.5px;
}
.tools-summary:hover { color: var(--fg); }
.tools-summary .ico { width: 14px; height: 14px; }

/* ---------- connections ---------- */
.conn-list { display: flex; flex-direction: column; gap: 10px; }
.conn-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px 16px;
}
.conn-icon {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent);
}
.conn-icon .ico { width: 20px; height: 20px; }
.conn-info { flex: 1; min-width: 0; }
.conn-title { font-weight: 600; }
.conn-desc { font-size: 13px; color: var(--muted); }
.conn-status { font-size: 13px; color: #3f8f5a; display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.conn-status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.conn-status.off { color: var(--faint); }
.link-box {
  margin-top: 10px; padding: 12px; border-radius: 10px; background: var(--surface-2);
  font-size: 13.5px; line-height: 1.6;
}
.link-box code { font-family: var(--mono); font-size: 15px; font-weight: 600; letter-spacing: .08em; }
.link-box a { color: var(--accent); }
.chip.connected { color: var(--fg-2); }
.chip.connected .ico { color: #3f8f5a; }

/* ---------- admin: telegram ---------- */
.tg-table input[type=time] { padding: 4px 8px; font-size: 13px; width: 118px; }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; vertical-align: middle; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 99px; background: var(--border-strong); cursor: pointer;
  transition: background .2s;
}
.switch span::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(16px); }
.digest-cell { display: flex; align-items: center; gap: 8px; }

.dialog > .row:first-child { flex-wrap: nowrap; align-items: flex-start; }
.dialog > .row:first-child .dialog-head { flex: 1; }
.dialog > .row:first-child .spacer { display: none; }

/* ---------- attachments ---------- */
.attach-btn { margin-left: -8px; width: 32px; height: 32px; }
.att-tray { display: flex; flex-wrap: wrap; gap: 8px; margin: -2px 0 10px; }
.att {
  position: relative; display: flex; align-items: center; gap: 9px;
  max-width: 240px; height: 52px; padding: 6px 30px 6px 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  animation: pop .15s ease-out;
}
.att.image { padding: 0; width: 52px; overflow: hidden; }
.att.image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-icon {
  display: grid; place-items: center; width: 38px; height: 38px; border-radius: 9px; flex-shrink: 0;
  background: var(--accent); color: var(--on-accent); font-size: 10px; font-weight: 700; letter-spacing: .03em;
}
.att-meta { min-width: 0; line-height: 1.25; }
.att-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-size { font-size: 11.5px; color: var(--muted); }
.att.err { border-color: var(--danger); }
.att.err .att-size { color: var(--danger); }
.att-x {
  position: absolute; top: 4px; right: 4px; display: grid; place-items: center;
  width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: var(--fg); color: var(--bg); opacity: .75; padding: 0;
}
.att-x:hover { opacity: 1; }
.att-x .ico { width: 12px; height: 12px; stroke-width: 2.6; }
.att-progress {
  position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent);
  transition: width .15s; border-radius: 0 3px 3px 0;
}
.att.uploading::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; background: rgba(255,255,255,.35);
}
@media (prefers-color-scheme: dark) { .att.uploading::after { background: rgba(0,0,0,.3); } }

.msg-atts { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; margin-bottom: 6px; max-width: 85%; }
.msg-atts a { text-decoration: none; color: inherit; }
.msg-atts .att { padding-right: 12px; cursor: pointer; transition: border-color .15s; }
.msg-atts .att:hover { border-color: var(--border-strong); }
.msg-atts .att.image { width: auto; height: auto; padding: 0; max-width: 260px; }
.msg-atts .att.image img { max-height: 200px; width: auto; max-width: 260px; }

.drop-overlay {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(4px);
  animation: rise .15s ease-out;
}
.drop-card {
  display: flex; align-items: center; gap: 12px; padding: 28px 36px;
  border: 2px dashed var(--accent); border-radius: 20px; background: var(--surface);
  font-family: var(--serif); font-size: 22px; box-shadow: var(--shadow-lg);
}
.drop-card .ico { width: 26px; height: 26px; color: var(--accent); }

/* ---------- sharing ---------- */
.share-badge {
  display: inline-flex; align-items: center; gap: 5px; margin-left: 6px;
  font-size: 12px; color: var(--muted); background: var(--surface-2);
  border-radius: 99px; padding: 3px 10px 3px 8px; white-space: nowrap;
}
.share-badge .ico { width: 13px; height: 13px; }
.title-wrap { display: flex; align-items: center; }
.title-wrap .menu { left: auto; }
.conv { display: flex; align-items: center; gap: 6px; }
.conv .conv-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.conv .ico { width: 14px; height: 14px; color: var(--faint); flex-shrink: 0; }
.conv .conv-owner { font-size: 11.5px; color: var(--faint); flex-shrink: 0; max-width: 40%; overflow: hidden; text-overflow: ellipsis; }
.share-list { display: flex; flex-direction: column; max-height: 50vh; overflow-y: auto; margin: 0 -6px; }
.share-row { display: flex; align-items: center; gap: 12px; padding: 8px 6px; border-radius: 10px; }
.share-row:hover { background: var(--hover); }
.share-row .avatar { width: 32px; height: 32px; font-size: 13px; }
.share-row .who { flex: 1; font-weight: 500; }
.share-row select { padding: 6px 30px 6px 10px; font-size: 13px; }
.share-row.on select { border-color: var(--accent); color: var(--accent); }
.msg-author { font-size: 12px; color: var(--muted); margin: 0 4px 4px; font-weight: 500; }
.readonly-bar {
  display: flex; align-items: center; gap: 10px; width: 100%; max-width: 768px;
  margin: 0 auto 12px; padding: 12px 16px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border); color: var(--fg-2); font-size: 14px;
}
.readonly-bar .ico { color: var(--muted); }
.stage:has(.readonly-bar:not([hidden])) { padding: 0 24px; }
#sysText[readonly] { background: var(--surface-2); color: var(--fg-2); }
@media (max-width: 820px) {
  .readonly-bar { flex-wrap: wrap; margin: 0 12px 10px; width: auto; }
  .readonly-bar .btn { width: 100%; justify-content: center; }
  .share-badge { display: none !important; }
}
