/* Тёмная тема по умолчанию, светлая — по системной настройке. */
:root {
  --bg: #0d1210;
  --panel: #141b18;
  --panel-2: #1a231f;
  --line: #24312b;
  --text: #e8efea;
  --muted: #8fa298;
  --accent: #3ddc84;
  --accent-dim: #1f7a4a;
  --danger: #ff6b6b;
  --warn: #ffb84d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.25);
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f7f5; --panel: #fff; --panel-2: #f0f4f1; --line: #e0e7e2;
    --text: #16201b; --muted: #66776e; --accent: #10864f; --accent-dim: #b9e6cd;
    --shadow: 0 1px 2px rgba(20,40,30,.06), 0 8px 24px rgba(20,40,30,.06);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
.loading { padding: 60px; text-align: center; color: var(--muted); }

/* ── Вход ───────────────────────────────────────────────────────────────── */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px; box-shadow: var(--shadow);
}
.auth h1 { margin: 0 0 4px; font-size: 22px; }
.auth p.sub { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

/* ── Каркас ─────────────────────────────────────────────────────────────── */
header.top {
  position: sticky; top: 0; z-index: 20; background: color-mix(in oklab, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.top-inner { max-width: 1180px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 650; letter-spacing: -.2px; margin-right: auto; display: flex; align-items: center; gap: 8px; }
.brand small { color: var(--muted); font-weight: 400; }
nav.tabs { display: flex; gap: 4px; overflow-x: auto; max-width: 1180px; margin: 0 auto;
  padding: 0 12px 10px; scrollbar-width: none; }
nav.tabs::-webkit-scrollbar { display: none; }
nav.tabs button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font: inherit; white-space: nowrap;
}
nav.tabs button:hover { color: var(--text); }
nav.tabs button.on { background: var(--panel); border-color: var(--line); color: var(--text); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 18px 16px 80px; }
section { display: none; }
section.on { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } }

h2 { font-size: 17px; margin: 26px 0 12px; letter-spacing: -.2px; }
h2:first-child { margin-top: 4px; }

/* ── Карточки-числа ─────────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.kpi .label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 27px; font-weight: 640; margin-top: 6px; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.pos { color: var(--accent); } .neg { color: var(--danger); } .warn { color: var(--warn); }

/* ── Панели и таблицы ───────────────────────────────────────────────────── */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden; }
.panel .head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex;
  align-items: center; gap: 10px; flex-wrap: wrap; }
.panel .head h3 { margin: 0; font-size: 15px; }
.panel .head .sp { margin-left: auto; }
.scroll-x { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
tbody tr:hover { background: var(--panel-2); }
.note { color: var(--muted); font-size: 13px; max-width: 460px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ── Формы ──────────────────────────────────────────────────────────────── */
label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 5px; }
input, select, textarea {
  width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 64px; resize: vertical; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
button.btn {
  background: var(--accent); color: #06110b; border: 0; border-radius: 10px; padding: 11px 18px;
  font: inherit; font-weight: 640; cursor: pointer; margin-top: 16px;
}
button.btn:hover { filter: brightness(1.06); }
button.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.btn.sm { padding: 7px 12px; margin-top: 0; font-size: 13.5px; font-weight: 550; }
button.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit;
  text-decoration: underline; padding: 0; }
.err { color: var(--danger); font-size: 13.5px; margin-top: 12px; min-height: 18px; }
.ok { color: var(--accent); font-size: 13.5px; margin-top: 12px; }

/* ── График ─────────────────────────────────────────────────────────────── */
.chart { padding: 18px; }
.chart svg { width: 100%; height: 220px; display: block; overflow: visible; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: 12.5px; padding: 0 18px 16px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); }
.badge.red { color: var(--danger); border-color: color-mix(in oklab, var(--danger) 40%, var(--line)); }
.badge.green { color: var(--accent); border-color: var(--accent-dim); }

dialog {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: var(--radius); padding: 22px; max-width: 460px; width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 6px; font-size: 17px; }
.copy-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
  word-break: break-all; margin-top: 10px; }

/* ── Главный экран: работа против пассива ───────────────────────────────── */
.duel { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: stretch; }
.duel .side {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); position: relative;
}
.duel .side.win { border-color: color-mix(in oklab, var(--accent) 45%, var(--line)); }
.duel .side.win::after {
  content: ""; position: absolute; inset: -1px; border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--accent) inset; pointer-events: none; opacity: .55;
}
.side-label { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.side-value { font-size: 44px; font-weight: 660; letter-spacing: -1.5px; margin: 6px 0 2px;
  font-variant-numeric: tabular-nums; line-height: 1.05; }
.side-hint { color: var(--muted); font-size: 13px; min-height: 34px; }
.side-rows { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.side-rows div { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0;
  font-size: 13.5px; font-variant-numeric: tabular-nums; }
.side-rows span { color: var(--muted); }
.versus { align-self: center; color: var(--muted); font-size: 12.5px; text-transform: uppercase;
  letter-spacing: .06em; writing-mode: vertical-rl; transform: rotate(180deg); padding: 8px 0; }

.verdict-line {
  margin: 12px 0 4px; padding: 12px 18px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--line); font-size: 14.5px; font-weight: 550;
}
.verdict-line.good { border-color: var(--accent-dim); color: var(--accent); }
.verdict-line.bad { border-color: color-mix(in oklab, var(--danger) 35%, var(--line)); color: var(--danger); }

/* Вывод, ради которого раздел и существует — выделен, но не кричит. */
.insight {
  margin: 0 18px 4px; margin-top: 16px; padding: 14px 16px; border-radius: 12px;
  background: color-mix(in oklab, var(--warn) 10%, var(--panel-2));
  border: 1px solid color-mix(in oklab, var(--warn) 30%, var(--line));
  font-size: 14px; line-height: 1.55;
}
.insight b { color: var(--text); }

/* ── Строка диктовки ────────────────────────────────────────────────────── */
.dictate { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.dictate input { flex: 1; min-width: 200px; background: var(--panel); }
.dictate button { margin-top: 0; }
.dictate-echo { flex-basis: 100%; font-size: 13px; color: var(--muted); min-height: 18px; }
.dictate-echo.ok { color: var(--accent); }
.dictate-echo.err { color: var(--danger); }

/* ── Вопрос дня ─────────────────────────────────────────────────────────── */
.ask {
  background: var(--panel); border: 1px solid var(--accent-dim); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.ask-title { font-size: 14.5px; font-weight: 600; margin-bottom: 10px; }
.ask-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.ask-row input { flex: 1; min-width: 120px; }
.ask-row button { margin-top: 0; }

/* ── «Для подумать» ─────────────────────────────────────────────────────── */
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.lib-grid.dim { opacity: .55; }
.lib-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.lib-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.lib-title { font-weight: 620; font-size: 15px; line-height: 1.35; }
.lib-title a { color: var(--text); text-decoration: none; }
.lib-title a:hover { color: var(--accent); }
.lib-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.lib-pct { font-size: 24px; font-weight: 650; text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; line-height: 1.1; }
.lib-pct span { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.lib-summary { margin-top: 12px; font-size: 14px; line-height: 1.5; color: var(--text); }
.lib-compare { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line);
  display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.lib-actions { margin-top: auto; padding-top: 12px; display: flex; gap: 8px; }
/* Дело, где есть люди, помечено сразу — по правилу оно не рассматривается. */
.lib-card.lib-out { border-color: color-mix(in oklab, var(--danger) 25%, var(--line)); }

/* ── «Куда уйти» ────────────────────────────────────────────────────────── */
/* Номер места слева: список читается сверху вниз, порядок и есть главный смысл. */
.dir-card { display: grid; grid-template-columns: 44px 1fr; column-gap: 14px; row-gap: 12px; }
.dir-place { font-size: 26px; font-weight: 650; color: var(--muted);
  font-variant-numeric: tabular-nums; line-height: 1.1; }
.dir-body { min-width: 0; }
.dir-actions { grid-column: 2; display: flex; gap: 8px; margin-top: auto; }

/* ── Точка свободы ──────────────────────────────────────────────────────── */
.freedom-bar { height: 12px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 999px; overflow: hidden; }
.freedom-fill { height: 100%; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); }
.freedom-legend { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px;
  font-size: 13.5px; color: var(--muted); }
.freedom-legend b { color: var(--text); }

@media (max-width: 720px) {
  .duel { grid-template-columns: 1fr; }
  .versus { writing-mode: horizontal-tb; transform: none; text-align: center; padding: 2px 0; }
  .side-value { font-size: 36px; }
}

@media (max-width: 640px) {
  .kpi .value { font-size: 23px; }
  main { padding: 14px 12px 60px; }
  td, th { padding: 9px 11px; }
}
