/* ---------- Токены ---------- */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #141a21;
  --muted: #5d6874;
  --faint: #8a94a0;
  --line: #e0e5eb;
  --line-strong: #cbd3dc;
  --accent: #0a7570;
  --accent-hover: #075e5a;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1ef;
  --ok: #1d8a4c;
  --warn: #a8700f;
  --bad: #c22f2f;
  --code-bg: #10171f;
  --code-text: #d5dee8;
  --code-dim: #7c8a99;
  --code-str: #7fd6c9;
  --radius-s: 6px;
  --radius-m: 10px;
  --font: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1217; --panel: #151a21; --text: #e5e9ee; --muted: #97a2ae; --faint: #6d7884;
    --line: #242b34; --line-strong: #323b46; --accent: #3cc2b8; --accent-hover: #5fd3ca;
    --accent-ink: #062321; --accent-soft: #12302d; --ok: #4cc27f; --warn: #e0a846; --bad: #f06a6a;
    --code-bg: #0a0e13; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1217; --panel: #151a21; --text: #e5e9ee; --muted: #97a2ae; --faint: #6d7884;
  --line: #242b34; --line-strong: #323b46; --accent: #3cc2b8; --accent-hover: #5fd3ca;
  --accent-ink: #062321; --accent-soft: #12302d; --ok: #4cc27f; --warn: #e0a846; --bad: #f06a6a;
  --code-bg: #0a0e13; color-scheme: dark;
}

/* ---------- База ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 15px/1.55 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; letter-spacing: -0.015em; }
h1 { font-size: clamp(28px, 4vw, 40px); }
h2 { font-size: 21px; }
h3 { font-size: 16px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code, pre, .mono { font-family: var(--mono); font-size: 13px; }
code.inline { background: var(--accent-soft); color: var(--text); padding: 1px 6px; border-radius: 4px; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Элементы управления ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; font: 500 14px/1 var(--font); padding: 10px 16px;
       border-radius: var(--radius-s); border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
       cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn.quiet { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn.quiet:hover { background: var(--panel); border-color: var(--faint); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--line-strong); }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line-strong);
                          border-radius: var(--radius-s); padding: 9px 11px; width: 100%; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: auto; accent-color: var(--accent); }
.copy { cursor: pointer; border: 0; background: none; color: var(--faint); padding: 2px 4px; font-size: 13px; }
.copy:hover { color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: 999px; background: var(--panel);
        color: var(--text); cursor: pointer; }
.chip:hover { border-color: var(--faint); text-decoration: none; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.tag { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }

/* ---------- Поверхности ---------- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 20px; }
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.alert { padding: 12px 14px; border-radius: var(--radius-s); border: 1px solid var(--line-strong); background: var(--panel); margin-bottom: 16px; }
.alert.ok { border-color: var(--ok); }
.alert.bad { border-color: var(--bad); color: var(--bad); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.status.ok::before { background: var(--ok); }
.status.warn::before { background: var(--warn); }
.status.bad::before { background: var(--bad); }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 500; color: var(--muted); font-size: 13px; white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }

/* ---------- Код ---------- */
.code { background: var(--code-bg); color: var(--code-text); border-radius: var(--radius-m); overflow: hidden; }
.code-tabs { display: flex; gap: 2px; padding: 8px 10px 0; border-bottom: 1px solid #1f2a36; }
.code-tabs button { font: 500 13px var(--font); color: var(--code-dim); background: none; border: 0; padding: 8px 10px; cursor: pointer;
                    border-bottom: 2px solid transparent; }
.code-tabs button.on { color: var(--code-text); border-bottom-color: var(--code-str); }
.code-tabs .copy { margin-left: auto; color: var(--code-dim); }
.code pre { margin: 0; padding: 16px 18px; overflow-x: auto; line-height: 1.6; }
.code .s { color: var(--code-str); }
.code .c { color: var(--code-dim); }

/* ---------- Публичный макет ---------- */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar .inner { max-width: 1160px; margin: 0 auto; padding: 0 16px; height: 60px; display: flex; align-items: center; gap: 24px; }
.logo { font-weight: 700; font-size: 18px; color: var(--text); letter-spacing: -0.02em; display: inline-flex; align-items: center; gap: 8px; }
.logo:hover { text-decoration: none; }
.logo-mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: grid; place-items: center; }
.logo-mark::after { content: ""; width: 10px; height: 2px; background: var(--accent-ink); box-shadow: 0 -4px 0 var(--accent-ink), 0 4px 0 var(--accent-ink); }
.topnav { display: flex; gap: 20px; font-size: 14px; }
.topnav a { color: var(--muted); }
.topnav a:hover, .topnav a.on { color: var(--text); text-decoration: none; }
.topbar .right { margin-left: auto; display: flex; gap: 10px; align-items: center; }
.page { max-width: 1160px; margin: 0 auto; padding: 32px 16px 72px; }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.footer .inner { max-width: 1160px; margin: 0 auto; padding: 24px 16px; display: flex; gap: 20px; flex-wrap: wrap; }

/* ---------- Кабинет ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.app > *, .catalog > *, .docs > *, .two-col > *, .hero > * { min-width: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.sidebar .logo { padding: 18px 20px; }
.sidenav { display: grid; gap: 2px; padding: 6px 10px; }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-s); color: var(--muted); font-size: 14px; }
.sidenav a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.sidenav a.on { background: var(--accent-soft); color: var(--text); font-weight: 500; }
.sidenav svg { width: 17px; height: 17px; flex: none; }
.sidenav .sep { height: 1px; background: var(--line); margin: 8px 10px; }
.side-foot { margin-top: auto; padding: 16px; border-top: 1px solid var(--line); display: grid; gap: 10px; }
.side-balance { display: flex; justify-content: space-between; align-items: baseline; }
.side-balance b { font-size: 18px; font-variant-numeric: tabular-nums; }
.side-balance b.bad { color: var(--bad); }
.side-user { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); gap: 8px; }
.side-user span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.side-user button:hover { color: var(--text); }
.main { min-width: 0; }
.main-inner { max-width: 1120px; padding: 28px 32px 64px; }
.main-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.theme-toggle { background: none; border: 1px solid var(--line-strong); color: var(--muted); border-radius: var(--radius-s);
                width: 32px; height: 32px; cursor: pointer; display: grid; place-items: center; }
.theme-toggle:hover { color: var(--text); }

/* ---------- Лендинг ---------- */
.hero { display: grid; grid-template-columns: 1fr 1.1fr; gap: 48px; align-items: center; padding: 24px 0 56px; }
.hero h1 { font-size: clamp(32px, 4.4vw, 50px); letter-spacing: -0.03em; line-height: 1.08; }
.hero .lead { font-size: 18px; color: var(--muted); max-width: 30em; margin: 18px 0 26px; }
.hero .actions { display: flex; gap: 10px; flex-wrap: wrap; }
.switch { background: var(--code-bg); color: var(--code-text); border-radius: 14px; overflow: hidden; }
.switch-bar { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid #1f2a36; color: var(--code-dim); font-size: 13px; }
.switch pre { margin: 0; padding: 18px 20px; font-size: 13.5px; line-height: 1.7; overflow-x: auto; }
.switch .line-model { background: color-mix(in srgb, var(--code-str) 12%, transparent); margin: 0 -20px; padding: 0 20px; display: block; }
.switch select { font: inherit; font-family: var(--mono); color: var(--code-str); background: transparent; border: 0; border-bottom: 1px dashed var(--code-str);
                 border-radius: 0; padding: 0 2px; width: auto; max-width: 100%; cursor: pointer; field-sizing: content; }
.switch select:focus { box-shadow: none; outline: 1px solid var(--code-str); }
.switch select option { background: var(--code-bg); color: var(--code-text); }
.switch-price { display: flex; gap: 24px; padding: 12px 20px 16px; border-top: 1px solid #1f2a36; font-size: 13px; color: var(--code-dim); flex-wrap: wrap; }
.switch-price b { color: var(--code-text); font-weight: 500; font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); margin-bottom: 48px; }
.facts div { padding: 20px 0; }
.facts div + div { padding-left: 24px; border-left: 1px solid var(--line); }
.facts b { display: block; font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 16px 0 48px; padding: 0; counter-reset: step; }
.steps li { list-style: none; padding: 18px; border-left: 2px solid var(--accent); background: var(--panel); border-radius: 0 var(--radius-m) var(--radius-m) 0; }
.steps li::before { counter-increment: step; content: "Шаг " counter(step); display: block; font-size: 13px; color: var(--accent); margin-bottom: 4px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 14px; gap: 12px; }

/* ---------- Каталог ---------- */
.catalog { display: grid; grid-template-columns: 240px 1fr; gap: 24px; align-items: start; }
.filters { position: sticky; top: 16px; display: grid; gap: 20px; }
.filters h3 { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 8px; }
.filters .opts { display: grid; gap: 6px; }
.catalog-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.catalog-bar input[type=search] { flex: 1; min-width: 200px; }
.catalog-bar select { width: auto; }
.model-cell { display: grid; gap: 2px; }
.model-cell a { color: var(--text); font-weight: 500; }
.model-cell .mono { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mods { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- Страница модели ---------- */
.model-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 20px; }
.model-id { display: inline-flex; align-items: center; gap: 4px; margin-top: 8px; color: var(--muted); }
.specs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0; border: 1px solid var(--line); border-radius: var(--radius-m); background: var(--panel); margin-bottom: 16px; }
.specs div { padding: 14px 16px; }
.specs div + div { border-left: 1px solid var(--line); }
.specs dt { font-size: 13px; color: var(--muted); }
.specs dd { margin: 4px 0 0; font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.desc { max-width: 72ch; color: var(--muted); }
.two-col { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; align-items: start; }

/* ---------- Дашборд ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); margin-bottom: 16px; }
.kpis div { padding: 16px 18px; }
.kpis div + div { border-left: 1px solid var(--line); }
.kpis span { font-size: 13px; color: var(--muted); }
.kpis b { display: block; font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; letter-spacing: -0.01em; }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 160px; padding-top: 8px; }
.chart .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; min-width: 4px; }
.chart .bar i { display: block; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; opacity: .85; }
.chart .bar:hover i { opacity: 1; }
.chart .bar.zero i { background: var(--line-strong); }
.chart-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--faint); margin-top: 6px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 13px; color: var(--muted); }

/* ---------- Плейграунд ---------- */
.pg { display: grid; grid-template-columns: 220px 1fr 280px; height: 100vh; }
.pg-list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.pg-list .head { padding: 14px; border-bottom: 1px solid var(--line); }
.pg-chats { overflow-y: auto; padding: 8px; display: grid; gap: 2px; align-content: start; flex: 1; }
.pg-chats button { text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: var(--radius-s); color: var(--muted);
                   font: 14px var(--font); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pg-chats button:hover { background: var(--bg); color: var(--text); }
.pg-chats button.on { background: var(--accent-soft); color: var(--text); }
.pg-list .foot { padding: 12px 14px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); display: flex; justify-content: space-between; }
.pg-list .foot button { background: none; border: 0; color: var(--faint); cursor: pointer; font: inherit; padding: 0; }
.pg-list .foot button:hover { color: var(--bad); }
.pg-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.pg-msgs { flex: 1; overflow-y: auto; padding: 24px 28px; display: grid; gap: 18px; align-content: start; }
.pg-empty { margin: auto; text-align: center; color: var(--muted); max-width: 34ch; padding-top: 18vh; }
.msg { max-width: 760px; width: 100%; }
.msg.user { justify-self: end; max-width: 620px; width: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 10px 14px; }
.msg .body { overflow-wrap: anywhere; }
.msg .body p:last-child { margin-bottom: 0; }
.msg .body pre { background: var(--code-bg); color: var(--code-text); padding: 12px 14px; border-radius: var(--radius-s); overflow-x: auto; }
.msg .body code:not(pre code) { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.msg .meta { display: flex; gap: 12px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--faint); }
.msg .meta button { background: none; border: 0; color: var(--faint); cursor: pointer; font: inherit; padding: 0; }
.msg .meta button:hover { color: var(--accent); }
.msg.error .body { color: var(--bad); }
.cursor::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }
.pg-input { border-top: 1px solid var(--line); padding: 14px 28px 18px; background: var(--bg); }
.pg-input form { display: flex; gap: 10px; align-items: flex-end; max-width: 820px; }
.pg-input textarea { min-height: 46px; max-height: 240px; resize: none; }
.pg-params { border-left: 1px solid var(--line); background: var(--panel); padding: 16px; overflow-y: auto; display: grid; gap: 18px; align-content: start; }
.pg-params .row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.pg-params input[type=range] { padding: 0; border: 0; accent-color: var(--accent); }
.pg-model-info { font-size: 13px; color: var(--muted); display: grid; gap: 2px; }

/* ---------- Документация ---------- */
.docs { display: grid; grid-template-columns: 200px 1fr; gap: 32px; align-items: start; }
.docs-nav { position: sticky; top: 16px; display: grid; gap: 4px; font-size: 14px; }
.docs-nav a { color: var(--muted); padding: 4px 0; }
.docs section { margin-bottom: 36px; max-width: 78ch; }
.docs section h2 { margin-bottom: 12px; }
.docs dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; font-size: 14px; }
.docs dt { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.docs dd { margin: 0; color: var(--muted); }
.method { font-family: var(--mono); font-size: 12px; font-weight: 600; padding: 2px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--accent); }

/* ---------- Оферта, FAQ ---------- */
.legal-text { max-width: 76ch; }
.legal-text h2 { font-size: 17px; margin: 22px 0 8px; }
.legal-text h2:first-child { margin-top: 0; }
.faq { display: grid; gap: 4px; max-width: 76ch; margin: 0; }
.faq dt { font-weight: 600; margin-top: 12px; }
.faq dd { margin: 0; color: var(--muted); }

/* ---------- Адаптив ---------- */
@media (max-width: 1100px) {
  .pg { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .pg-list, .pg-params { border: 0; border-bottom: 1px solid var(--line); }
  .pg-list { max-height: 180px; }
  .pg-msgs { min-height: 50vh; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .logo { padding: 12px 16px; }
  .sidenav { display: flex; overflow-x: auto; padding: 0 8px 8px; width: 100%; min-width: 0; }
  .sidenav .sep { display: none; }
  .sidenav a { white-space: nowrap; }
  .side-foot { width: 100%; grid-template-columns: 1fr auto; border-top: 1px solid var(--line); padding: 10px 16px; }
  .side-user { display: none; }
  .main-inner { padding: 20px 16px 48px; }
  .hero, .two-col, .catalog, .docs { grid-template-columns: 1fr; }
  .filters { position: static; }
  .docs-nav { position: static; display: flex; flex-wrap: wrap; gap: 12px; }
  .kpis, .specs { grid-template-columns: repeat(2, 1fr); }
  .kpis div:nth-child(3), .specs div:nth-child(3) { border-left: 0; }
  .kpis div:nth-child(n+3), .specs div:nth-child(n+3) { border-top: 1px solid var(--line); }
  .facts, .steps, .key-form-row { grid-template-columns: 1fr !important; }
  .facts div + div { padding-left: 0; border-left: 0; border-top: 1px solid var(--line); }
  .topnav { display: none; }
}
@media (prefers-reduced-motion: reduce) { .cursor::after { animation: none; } }
