/* Агент в штате: веб-чат. Регистр: product. Светлая бумажная тема по
   умолчанию, тёмная по prefers-color-scheme. Один акцент (ржавчина курса). */

@font-face {
  font-family: "PT Serif";
  src: url("/static/vendor/fonts/pt-serif-cyrillic-400-normal.woff2") format("woff2");
  font-weight: 400;
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
  font-display: swap;
}
@font-face {
  font-family: "PT Serif";
  src: url("/static/vendor/fonts/pt-serif-latin-400-normal.woff2") format("woff2");
  font-weight: 400;
  unicode-range: U+0000-00FF;
  font-display: swap;
}
@font-face {
  font-family: "PT Serif";
  src: url("/static/vendor/fonts/pt-serif-cyrillic-700-normal.woff2") format("woff2");
  font-weight: 700;
  unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
  font-display: swap;
}
@font-face {
  font-family: "PT Serif";
  src: url("/static/vendor/fonts/pt-serif-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  unicode-range: U+0000-00FF;
  font-display: swap;
}

:root {
  --bg: oklch(97.5% 0.006 85);
  --bg-panel: oklch(95% 0.009 85);
  --bg-raised: oklch(99% 0.004 85);
  --bg-user: oklch(92.5% 0.014 80);
  --bg-hover: oklch(92.5% 0.01 85);
  --ink: oklch(25% 0.015 265);
  --ink-2: oklch(43% 0.014 265);
  --ink-3: oklch(56% 0.012 265);
  --line: oklch(88% 0.009 85);
  --line-strong: oklch(80% 0.01 85);
  --accent: oklch(49% 0.115 45);
  --accent-hover: oklch(44% 0.115 45);
  --accent-ink: oklch(98.5% 0.005 85);
  --accent-soft: oklch(93.5% 0.03 50);
  --danger: oklch(48% 0.15 27);
  --danger-soft: oklch(94% 0.03 27);
  --ok: oklch(50% 0.1 150);
  --code-bg: oklch(93.5% 0.008 85);
  --shadow: 0 1px 2px oklch(25% 0.02 265 / 0.07), 0 4px 16px oklch(25% 0.02 265 / 0.05);
  --serif: "PT Serif", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: oklch(22% 0.009 75);
    --bg-panel: oklch(19.5% 0.009 75);
    --bg-raised: oklch(26% 0.01 75);
    --bg-user: oklch(29% 0.014 75);
    --bg-hover: oklch(28% 0.011 75);
    --ink: oklch(90% 0.009 85);
    --ink-2: oklch(72% 0.011 85);
    --ink-3: oklch(60% 0.011 85);
    --line: oklch(31% 0.011 75);
    --line-strong: oklch(40% 0.012 75);
    --accent: oklch(68% 0.115 48);
    --accent-hover: oklch(73% 0.115 48);
    --accent-ink: oklch(17% 0.02 48);
    --accent-soft: oklch(30% 0.045 48);
    --danger: oklch(68% 0.14 27);
    --danger-soft: oklch(30% 0.05 27);
    --code-bg: oklch(27% 0.01 75);
    --shadow: 0 1px 2px oklch(0% 0 0 / 0.3), 0 4px 16px oklch(0% 0 0 / 0.25);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior-y: none;
}
h1, h2, h3, p { text-wrap: pretty; }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: var(--ink); }
[hidden] { display: none !important; }

.icon {
  width: 17px; height: 17px; flex: none;
  stroke-width: 1.5;
  vertical-align: -3px;
}

:is(button, input, textarea, select, a, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ------------------------------------------------------------- кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 14px;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  border-radius: 8px;
  padding: 8px 16px;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: none; color: var(--ink-2);
  border-radius: 6px; padding: 5px;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--ink); }

/* --------------------------------------------------------------- вход */
#login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card { width: 100%; max-width: 360px; }
.login-brand {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  margin: 0 0 2px;
  letter-spacing: -0.01em;
}
.login-company { color: var(--ink-2); margin: 0 0 32px; font-size: 15px; }
.login-card label { display: block; font-weight: 600; margin: 0 0 6px; }
.field {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
}
.field::placeholder { color: var(--ink-3); }
.field:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.suggest { position: relative; }
.suggest-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 5;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.suggest-list button {
  display: block; width: 100%; text-align: left;
  padding: 9px 12px; border: 0; background: none;
}
.suggest-list button:hover, .suggest-list button.sel { background: var(--bg-hover); }
.login-actions { margin-top: 16px; }
.login-actions .btn-primary { width: 100%; padding: 11px 16px; font-size: 15px; }
.login-hint { color: var(--ink-2); font-size: 13px; margin-top: 14px; }
.login-error { color: var(--danger); font-size: 13.5px; margin-top: 12px; }
.code-field {
  letter-spacing: 0.45em;
  text-align: center;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
}
.login-back { margin-top: 18px; }
.login-back button { background: none; border: 0; color: var(--ink-2); padding: 0; }
.login-back button:hover { color: var(--ink); text-decoration: underline; }

/* ------------------------------------------------------------ каркас */
#app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100dvh;
}

#sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.side-head { padding: 16px 16px 10px; }
.brand {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.005em;
}
.brand-sub { color: var(--ink-2); font-size: 12.5px; margin-top: 1px; }

.tabs {
  display: flex;
  gap: 2px;
  margin: 6px 12px 10px;
  padding: 3px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.tabs button {
  flex: 1;
  border: 0;
  background: none;
  color: var(--ink-2);
  padding: 5px 4px;
  border-radius: 6px;
  font-size: 13px;
}
.tabs button[aria-selected="true"] {
  background: var(--bg-raised);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px oklch(25% 0.02 265 / 0.08);
}

.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0 12px 10px; }
.side-top { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.search-wrap { position: relative; }
.search-wrap .icon {
  position: absolute; left: 9px; top: 50%; translate: 0 -50%;
  color: var(--ink-3); width: 15px; height: 15px;
}
.search-wrap input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 7px;
  padding: 6px 10px 6px 30px;
  font-size: 13px;
}
.scroll { flex: 1; overflow-y: auto; min-height: 0; scrollbar-width: thin; }

.group-label {
  color: var(--ink-3);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 12px 6px 4px;
}
.chat-item {
  display: flex; align-items: center; gap: 4px;
  border-radius: 7px;
  padding: 7px 6px 7px 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-raised); border-color: var(--line); }
.chat-item .title {
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 13.5px;
}
.chat-item .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--accent);
  flex: none;
  animation: pulse 1.2s ease-in-out infinite;
}
.chat-item .row-actions { display: none; gap: 2px; }
.chat-item:hover .row-actions, .chat-item.active .row-actions,
.chat-item.confirming .row-actions { display: flex; }
.chat-item .row-actions .icon { width: 14px; height: 14px; }
.chat-item input.rename {
  flex: 1; min-width: 0;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--bg-raised);
  padding: 2px 6px;
  font-size: 13.5px;
}
.confirm-del { color: var(--danger); font-size: 12.5px; display: flex; align-items: center; gap: 2px; }

.empty-note { color: var(--ink-3); font-size: 13px; text-align: center; padding: 28px 10px; }

.skeleton { border-radius: 7px; height: 30px; margin: 6px 0; background: var(--bg-hover); animation: shimmer 1.1s linear infinite alternate; }
.skeleton-lg { height: 48px; }
.bubble-files { opacity: 0.75; }
@keyframes shimmer { from { opacity: 0.55; } to { opacity: 1; } }

.side-foot {
  border-top: 1px solid var(--line);
  padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  color: var(--ink-2); font-size: 13px;
}
.side-foot .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* панель Навыки / Файлы */
.panel-item { padding: 9px 8px; border-radius: 7px; }
.panel-item:hover { background: var(--bg-hover); }
.panel-item .p-name { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 8px; }
.panel-item .p-cat { color: var(--ink-3); font-size: 11.5px; margin-left: auto; font-weight: 400; }
.panel-item .p-desc { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }
.file-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 7px; text-decoration: none; color: inherit; }
.file-item:hover { background: var(--bg-hover); }
.file-item .icon { color: var(--ink-3); }
.file-item .f-name { flex: 1; min-width: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .f-meta { color: var(--ink-3); font-size: 11.5px; flex: none; }

.retry-box { text-align: center; padding: 20px 8px; color: var(--ink-2); font-size: 13px; }
.retry-box .btn { margin-top: 10px; }

/* ---------------------------------------------------------------- чат */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  min-height: 49px;
}
.chat-head .menu-btn { display: none; }
.chat-head .head-title {
  font-weight: 600; font-size: 14.5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

#messages { flex: 1; overflow-y: auto; min-height: 0; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  #messages { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
}
.msg-col { max-width: 760px; margin: 0 auto; padding: 20px 20px 10px; }

.msg { margin: 0 0 22px; }
.msg-user { display: flex; justify-content: flex-end; }
.msg-user .bubble {
  background: var(--bg-user);
  border-radius: 14px 14px 4px 14px;
  padding: 10px 14px;
  max-width: 85%;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 15px;
  line-height: 1.55;
}
.msg-agent { font-size: 15px; line-height: 1.62; overflow-wrap: break-word; }
.msg-agent > :first-child { margin-top: 0; }
.msg-agent p, .msg-agent li { max-width: 72ch; }
.msg-agent h1, .msg-agent h2, .msg-agent h3 { line-height: 1.3; margin: 1.2em 0 0.5em; }
.msg-agent h1 { font-size: 1.35em; } .msg-agent h2 { font-size: 1.2em; } .msg-agent h3 { font-size: 1.08em; }
.msg-agent a { color: var(--accent); }
.msg-agent code {
  font-family: var(--mono); font-size: 0.86em;
  background: var(--code-bg);
  padding: 1.5px 5px; border-radius: 4px;
}
.msg-agent pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px 14px;
  overflow-x: auto;
  position: relative;
}
.msg-agent pre code { background: none; padding: 0; font-size: 12.8px; line-height: 1.5; }
.copy-btn {
  position: absolute; top: 6px; right: 6px;
  border: 1px solid var(--line); background: var(--bg-raised); color: var(--ink-2);
  border-radius: 6px; padding: 3px 8px; font-size: 11.5px;
  display: inline-flex; align-items: center; gap: 5px;
  opacity: 0; transition: opacity 0.12s;
}
.msg-agent pre:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn .icon { width: 12px; height: 12px; }
.msg-agent table { border-collapse: collapse; margin: 0.6em 0; display: block; overflow-x: auto; max-width: 100%; }
.msg-agent th, .msg-agent td { border: 1px solid var(--line-strong); padding: 5px 10px; font-size: 13.5px; }
.msg-agent th { background: var(--code-bg); }
.msg-agent blockquote { border-left: 1px solid var(--line-strong); margin: 0.6em 0; padding: 0 0 0 12px; color: var(--ink-2); }
.msg-agent hr { border: 0; border-top: 1px solid var(--line); }

.stopped-note, .interim {
  color: var(--ink-3); font-size: 12.5px; font-style: italic; margin-top: 6px;
}
.msg-error {
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--ink);
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 13.5px;
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
}
.msg-error .icon { color: var(--danger); }

.file-card {
  display: inline-flex; align-items: center; gap: 10px;
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  border-radius: 10px;
  padding: 9px 14px;
  margin: 6px 8px 2px 0;
  text-decoration: none; color: inherit;
  max-width: 100%;
}
.file-card:hover { border-color: var(--accent); }
.file-card .icon { color: var(--accent); width: 20px; height: 20px; }
.file-card .fc-name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .fc-size { color: var(--ink-3); font-size: 12px; }
.file-card .fc-dl { color: var(--ink-3); margin-left: 4px; }

/* статус запуска */
.status-line {
  display: flex; align-items: center; gap: 9px;
  color: var(--ink-2); font-size: 13px;
  margin: 2px 0 10px;
  min-height: 20px;
}
.spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { rotate: 1turn; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* пустой чат */
.hello { max-width: 640px; margin: 10vh auto 0; padding: 0 20px; text-align: center; }
.hello h2 { font-family: var(--serif); font-size: 23px; font-weight: 700; margin: 0 0 6px; }
.hello p { color: var(--ink-2); margin: 0 0 26px; }
.examples { display: flex; flex-direction: column; gap: 9px; max-width: 460px; margin: 0 auto; }
.examples button {
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  border-radius: 10px;
  padding: 11px 16px;
  text-align: left;
  font-size: 13.5px;
  color: var(--ink-2);
}
.examples button:hover { border-color: var(--accent); color: var(--ink); }

/* ----------------------------------------------------------- composer */
.composer-wrap { border-top: 1px solid var(--line); background: var(--bg); }
.composer-inner { max-width: 760px; margin: 0 auto; padding: 10px 20px 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  border-radius: 7px;
  padding: 4px 8px;
  font-size: 12.5px;
  max-width: 260px;
}
.chip .c-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .c-meta { color: var(--ink-3); flex: none; }
.chip.err { border-color: var(--danger); color: var(--danger); }
.chip button { border: 0; background: none; padding: 0; color: var(--ink-3); display: flex; }
.chip button:hover { color: var(--danger); }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  border: 1px solid var(--line-strong);
  background: var(--bg-raised);
  border-radius: 12px;
  padding: 8px;
  box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1;
  border: 0; background: none; resize: none;
  font-size: 15px; line-height: 1.5;
  max-height: 180px;
  padding: 6px 4px;
  outline: none;
}
.composer textarea::placeholder { color: var(--ink-3); }
.send-btn {
  width: 36px; height: 36px; flex: none;
  border: 0; border-radius: 9px;
  background: var(--accent); color: var(--accent-ink);
  display: inline-flex; align-items: center; justify-content: center;
}
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.4; cursor: default; }
.send-btn.stop { background: var(--ink); color: var(--bg); }
.model-sel {
  border: 0; background: none; color: var(--ink-3);
  font-size: 12.5px; padding: 8px 2px; max-width: 110px;
}
.model-sel:hover { color: var(--ink); }
.compose-note {
  color: var(--ink-3);
  font-size: 11.8px;
  text-align: center;
  margin: 7px 0 6px;
}
.busy-note { color: var(--ink-2); font-size: 12.5px; text-align: center; margin: 6px 0 0; display: flex; justify-content: center; align-items: center; gap: 8px; }

.notice {
  max-width: 760px; margin: 14px auto; padding: 0 20px;
  color: var(--ink-2); font-size: 13.5px;
}

/* -------------------------------------------------------------- toast */
#toast {
  position: fixed; left: 50%; bottom: 24px; translate: -50% 0; z-index: 50;
  background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 9px; font-size: 13.5px;
  box-shadow: var(--shadow);
}

/* ------------------------------------------------------------- мобильный */
.scrim { display: none; }
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #sidebar {
    position: fixed; inset: 0 72px 0 0; z-index: 30;
    max-width: 320px;
    translate: -102% 0;
    transition: translate 0.2s ease-out;
    box-shadow: none;
  }
  #app.side-open #sidebar { translate: 0 0; box-shadow: var(--shadow); }
  #app.side-open .scrim {
    display: block; position: fixed; inset: 0; z-index: 25;
    background: oklch(20% 0.01 265 / 0.4);
  }
  .chat-head .menu-btn { display: inline-flex; }
  .msg-col { padding: 14px 14px 8px; }
  .composer-inner { padding: 8px 10px 6px; }
  .hello { margin-top: 5vh; }
}

/* ------------------------------------------------------------- статус */
.status-page { max-width: 560px; margin: 40px auto; padding: 0 20px; }
.status-page h1 { font-family: var(--serif); font-size: 24px; }
.status-grid { display: grid; grid-template-columns: 1fr auto; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.status-grid > div { background: var(--bg-raised); padding: 11px 16px; font-size: 14px; }
.status-grid .v { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.status-ok { color: var(--ok); }
.status-bad { color: var(--danger); }

/* composer: рамку даёт контейнер, внутренний контур не нужен */
.composer textarea:focus-visible { outline: none; }
