:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --ink: #1c1c1e;
  --muted: #5d5d63;
  --faint: #85858b;
  --line: #e3e1db;
  --line-strong: #cfccc4;
  --accent: #a4161a;
  --accent-ink: #ffffff;
  --accent-soft: #f7e9e8;
  --ok: #2c7a4b;
  --warn: #9a5b00;
  --fail: #b42318;
  --focus: #1d5fd1;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
a { color: inherit; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #8a1013; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.link { border: 0; background: none; padding: 0; height: auto; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.btn.link:hover { text-decoration-color: var(--ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 38px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
}
textarea.input { resize: vertical; line-height: 1.5; }
.input:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px rgba(29, 95, 209, .15); }

/* ---------- вход ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login form {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 32px 28px; display: grid; gap: 16px;
}
.login h1 { font-size: 22px; margin: 0; line-height: 1.25; }
.login p { margin: 0; color: var(--muted); }
.form-error { color: var(--fail); font-size: 14px; min-height: 20px; }

/* ---------- каркас ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 24px;
  height: 56px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand b { font-size: 15px; }
.brand span { font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 4px; }
.nav button {
  height: 36px; padding: 0 12px; border: 0; background: none; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav button:hover { color: var(--ink); background: var(--bg); }
.nav button[aria-current="page"] { color: var(--ink); background: var(--bg); }
.top .user { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); }

.layout { display: grid; grid-template-columns: 340px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.side {
  border-right: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 56px; height: calc(100vh - 56px); display: flex; flex-direction: column;
}
.side-head { padding: 14px 16px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1 1 auto; height: 32px; padding: 0 10px; white-space: nowrap; border: 0; background: var(--surface); font-size: 13px; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--line-strong); }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.list { overflow-y: auto; flex: 1; }
.rec {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 11px 16px; border-bottom: 1px solid var(--line);
}
.rec:hover { background: #faf9f6; }
.rec[aria-current="true"] { background: var(--accent-soft); }
.rec .when { font-weight: 600; font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.rec .when small { font-weight: 400; color: var(--muted); font-size: 13px; }
.rec .what { font-size: 13px; color: var(--ink); margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rec .what.none { color: var(--faint); font-style: italic; }
.rec .meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.rec.off { opacity: .55; }
.list-empty { padding: 24px 16px; color: var(--muted); font-size: 14px; }

.main { padding: 24px 28px 64px; min-width: 0; }
.page { max-width: 1180px; }
.page-narrow { max-width: 860px; }
h2.title { font-size: 24px; line-height: 1.2; margin: 0 0 4px; }
h3 { font-size: 16px; margin: 0; }
.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 12px; }

/* ---------- запись ---------- */
.quote { font-size: 17px; margin: 6px 0 0; }
.quote.none { color: var(--muted); font-style: italic; font-size: 15px; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.facts b { color: var(--ink); font-weight: 500; }
.note { margin-top: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfaf7; font-size: 14px; }
.metrics { width: 100%; border-collapse: collapse; margin-top: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.metrics th, .metrics td { padding: 8px 12px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--line); }
.metrics th { font-weight: 500; color: var(--muted); width: 1%; white-space: nowrap; }
.metrics tr:last-child td, .metrics tr:last-child th { border-bottom: 0; }
.mgrid { display: flex; flex-wrap: wrap; margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mcell { flex: 1 1 120px; padding: 10px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-right: -1px; margin-bottom: -1px; }
.mcell .k { font-size: 12px; color: var(--muted); }
.mcell .v { font-size: 18px; font-weight: 600; }
.mcell .v small { font-size: 12px; font-weight: 400; color: var(--muted); margin-left: 3px; }
.mcell .s { font-size: 12px; color: var(--fail); }
.mcell.out .v { color: var(--fail); }

/* ---------- запуск ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; }
.run-form { display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 24px; }
.mgroups { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; }
.mgroup h4 { margin: 0 0 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.check { display: flex; align-items: flex-start; gap: 8px; padding: 4px 0; font-size: 14px; cursor: pointer; }
.check input { margin: 3px 0 0; accent-color: var(--accent); }
.check small { color: var(--muted); }
.check.off { color: var(--faint); cursor: not-allowed; }
.run-side { display: grid; gap: 14px; align-content: start; }
.run-actions { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- ответы ---------- */
.batch { margin-top: 22px; }
.batch-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin-bottom: 10px; }
.batch-head h3 { font-size: 15px; }
.batch-head .hint { font-size: 13px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); align-items: start; gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; min-width: 0; scroll-snap-align: start; }
.card-head { padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.card-head .name { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-head .name b { font-size: 15px; }
.card-head .name span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.card-head .stats { font-size: 12px; color: var(--muted); margin-top: 3px; }
.state { font-size: 13px; color: var(--muted); padding: 14px; }
.state.err { color: var(--fail); }
.answer { padding: 14px 16px; font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.answer p { margin: 0 0 10px; }
.answer h4 { font-size: 15px; margin: 14px 0 6px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer li { margin: 2px 0; }
.answer blockquote { margin: 0 0 10px; padding-left: 10px; border-left: 2px solid var(--line-strong); color: var(--muted); }
.answer hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.answer code { font-family: var(--mono); font-size: 13px; }
.md-table { overflow-x: auto; margin: 0 0 10px; }
.md-table table { border-collapse: collapse; font-size: 13px; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.answer.streaming::after { content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.card-foot { border-top: 1px solid var(--line); padding: 12px 14px; display: grid; gap: 12px; }
.checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: 13px; }
.checks li { display: grid; grid-template-columns: 92px 1fr; gap: 8px; }
.checks .st { font-weight: 600; }
.checks .fail .st { color: var(--fail); }
.checks .warn .st { color: var(--warn); }
.checks .ok .st { color: var(--ok); }
.checks .det { color: var(--muted); }
.rate { display: grid; gap: 8px; }
.rate-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.rate-row .lbl { font-size: 13px; color: var(--muted); margin-right: 4px; }
.score { width: 34px; height: 32px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--surface); font-weight: 600; }
.score[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tag { height: 28px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--surface); font-size: 12px; color: var(--ink); }
.tag[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.tag:disabled { opacity: .5; cursor: not-allowed; }
.saved { font-size: 12px; color: var(--ok); }
.others { font-size: 13px; color: var(--muted); }

/* ---------- промпт ---------- */
.two { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 24px; }
.vlist { display: grid; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; align-self: start; }
.vitem { text-align: left; border: 0; background: none; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.vitem:last-child { border-bottom: 0; }
.vitem[aria-current="true"] { background: var(--accent-soft); }
.vitem b { display: block; font-size: 14px; }
.vitem span { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.prompt-text { max-width: 86ch; white-space: pre-wrap; font-size: 14px; line-height: 1.55; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin: 0; font-family: var(--font); }
.diff { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 0; font-size: 14px; line-height: 1.55; }
.diff div { padding: 1px 20px; white-space: pre-wrap; }
.diff .add { background: #e7f4ec; }
.diff .del { background: #fbeaea; text-decoration: line-through; color: #7a2a2a; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

/* ---------- итоги ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
table.sum { border-collapse: collapse; width: 100%; font-size: 14px; }
table.sum th, table.sum td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.sum th:first-child, table.sum td:first-child, table.sum td.l, table.sum th.l { text-align: left; }
table.sum th { font-weight: 500; color: var(--muted); font-size: 13px; vertical-align: bottom; white-space: normal; min-width: 70px; }
table.sum tr:last-child td { border-bottom: 0; }
table.sum td.wrap { white-space: normal; min-width: 180px; font-size: 13px; color: var(--muted); }

/* ---------- окно ---------- */
.modal { position: fixed; inset: 0; background: rgba(20, 20, 22, .45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal-box { background: var(--surface); border-radius: 14px; width: 100%; max-width: 920px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-body { padding: 16px 20px 20px; overflow-y: auto; }
.modal-body pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; background: #faf9f6; border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 6px 0 18px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 60; max-width: calc(100vw - 40px); }

/* ---------- телефон и узкие экраны ---------- */
.back { display: none; }
@media (max-width: 900px) {
  .top { gap: 12px; padding: 0 12px; }
  .brand span { display: none; }
  .top .user .who { display: none; }
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; border-right: 0; }
  .layout.has-record .side { display: none; }
  .layout:not(.has-record) .main { display: none; }
  .back { display: inline-flex; margin-bottom: 12px; }
  .main { padding: 16px 14px 48px; }
  .run-form { grid-template-columns: 1fr; }
  .cards { grid-template-columns: 1fr; }
  .two { grid-template-columns: 1fr; }
  .answer { max-height: none; }
}
@media (max-width: 520px) {
  .nav button { padding: 0 8px; font-size: 14px; }
  .mcell { flex-basis: 30%; }
}

/* ---------- служебные (без inline-стилей: их запрещает CSP) ---------- */
.stack { display: grid; gap: 12px; }
.mono-area { font-family: var(--mono); font-size: 13px; }
.lead { margin: 0 0 18px; }
.metrics.in-modal { margin: 0 0 18px; }
.mt6 { margin-top: 6px; }
.mt8 { margin-top: 8px; }
.mt10 { margin-top: 10px; }
.mt12 { margin-top: 12px; }
select.input.inline { width: auto; min-height: 32px; padding: 4px 8px; }
.mgroup-title { font-size: 13px; color: var(--muted); margin: 18px 0 0; font-weight: 500; }
.check .t { display: flex; flex-direction: column; line-height: 1.3; }
.rate-hint { font-size: 12px; color: var(--muted); }
.page-wide { max-width: none; }
.brand .short { display: none; }
@media (max-width: 520px) {
  .brand .full, .brand span { display: none; }
  .brand .short { display: inline; }
}
.nw { white-space: nowrap; }
.tag { border-color: #bdbab2; }
