:root {
  --bg: #F6F6F4; --surface: #FFFFFF; --surface-2: #FAFAF8; --muted-bg: #F1F1EE;
  --ink: #111113; --ink-2: #4A4A52; --muted: #66666E; --faint: #A1A1A8;
  --line: #E7E7E3; --line-2: #EFEFEC; --line-3: #DCDCD7;
  --accent: #5B21B6; --accent-bg: #F1ECFB; --accent-line: #5B21B6;
  --warn: #9A3412; --warn-bg: #FDF3E7; --run: #1D4ED8; --run-bg: #EAF0FE; --ok: #15803D;
  --btn: #111113; --btn-ink: #FFFFFF; --live-bg: #111113; --live-ink: #FFFFFF; --live-muted: #C9C9CF;
  --hatch-1: #E4E4E0; --hatch-2: #F6F6F4;
  --shadow: 0 1px 2px rgba(17,17,19,.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E0E10; --surface: #17171A; --surface-2: #1B1B1F; --muted-bg: #232327;
    --ink: #F2F2F3; --ink-2: #C9C9CF; --muted: #A1A1A8; --faint: #6E6E76;
    --line: #26262B; --line-2: #232327; --line-3: #33333A;
    --accent: #C4B1F7; --accent-bg: #2A2140; --accent-line: #9B7FEA;
    --warn: #F5A97F; --warn-bg: #3A2416; --run: #93B4FA; --run-bg: #172440; --ok: #4ADE80;
    --btn: #F2F2F3; --btn-ink: #0E0E10; --live-bg: #1C1726; --live-ink: #F2F2F3; --live-muted: #A1A1A8;
    --hatch-1: #2A2A2F; --hatch-2: #17171A;
    --shadow: 0 1px 2px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font-family: Onest, system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 15px; line-height: 1.4;
  -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -0.015em; }
button, input, select { font: inherit; color: inherit; }
.tn { font-variant-numeric: tabular-nums; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* шапка */
.top { height: 60px; display: flex; align-items: center; gap: 32px; padding: 0 48px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--ink); color: var(--bg);
  display: flex; align-items: center; justify-content: center; }
.brand b { font-size: 16px; }
.brand small { white-space: nowrap; font-size: 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; }
.nav { display: flex; gap: 4px; }
.nav a { font-size: 14px; font-weight: 500; text-decoration: none; padding: 8px 12px; border-radius: 8px; color: var(--muted); }
.nav a.on { background: var(--muted-bg); color: var(--ink); }
.nav a:hover { color: var(--ink); }
.grow { flex-grow: 1; }
.api-state { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--faint); flex-shrink: 0; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--warn); }
.dry { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); }

.page { max-width: 1440px; margin: 0 auto; padding: 32px 48px 64px; display: flex; flex-direction: column; gap: 24px; }
.page-head { display: flex; align-items: flex-end; gap: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 32px; font-weight: 700; letter-spacing: -0.025em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { text-decoration: none; }

/* кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 18px;
  border-radius: 10px; border: 0; background: var(--btn); color: var(--btn-ink); font-size: 14px; font-weight: 600;
  text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { opacity: .88; }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line-3); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.big { min-height: 52px; font-size: 15px; border-radius: 12px; width: 100%; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:focus-visible, .seg button:focus-visible, .tab:focus-visible, input:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--muted-bg); flex-wrap: wrap; }
.seg button { min-height: 36px; padding: 0 14px; border-radius: 8px; border: 0; background: transparent;
  color: var(--ink-2); font-size: 13px; font-weight: 600; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg label { display: flex; cursor: pointer; }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg label span { min-height: 36px; padding: 0 14px; border-radius: 8px; display: flex; align-items: center;
  color: var(--ink-2); font-size: 13px; font-weight: 600; }
.seg label input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg label input:focus-visible + span { outline: 2px solid var(--accent-line); outline-offset: 2px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; }
.pad { padding: 20px 24px; }
.card h2 { font-size: 17px; font-weight: 600; }
.card h3 { font-size: 15px; font-weight: 600; }
.sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.pill { display: inline-flex; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-run { background: var(--run-bg); color: var(--run); }
.pill-win { background: var(--accent-bg); color: var(--accent); }
.pill-low { background: var(--warn-bg); color: var(--warn); }
.pill-done, .pill-plan { background: var(--muted-bg); color: var(--ink-2); }

.badge { display: inline-flex; font-size: 12px; font-weight: 600; padding: 4px 8px; border-radius: 6px; }
.badge.leader { background: var(--accent-bg); color: var(--accent); }
.badge.worse { background: var(--warn-bg); color: var(--warn); }
.badge.same, .badge.nodata { background: var(--muted-bg); color: var(--ink-2); }


/* ===== Дизайны ===== */
:root { --good: #15803D; --good-bg: #E7F5EC; --bad: #B91C1C; --bad-bg: #FDECEC; --warn-2: #A16207; --warn-2-bg: #FEF6DA; }
@media (prefers-color-scheme: dark) {
  :root { --good: #4ADE80; --good-bg: #12301E; --bad: #F87171; --bad-bg: #3A1616; --warn-2: #FACC15; --warn-2-bg: #33290C; }
}
.t-good { --c: var(--good); --cb: var(--good-bg); }
.t-bad { --c: var(--bad); --cb: var(--bad-bg); }
.t-warn { --c: var(--warn-2); --cb: var(--warn-2-bg); }
.t-neutral { --c: var(--ink-2); --cb: var(--muted-bg); }
.demo { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--warn-bg); color: var(--warn); }
.seg a { min-height: 36px; padding: 0 14px; border-radius: 8px; display: flex; align-items: center; color: var(--ink-2);
  font-size: 13px; font-weight: 600; text-decoration: none; }
.seg a.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.note { font-size: 13px; color: var(--muted); }
.note b { color: var(--ink-2); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi .v { font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }
.kpi .l { font-size: 13px; color: var(--muted); }

.sec-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: -8px; }
.sec-head h2 { font-size: 20px; font-weight: 700; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.tile { display: flex; flex-direction: column; gap: 8px; padding: 18px 20px; text-decoration: none; position: relative;
  border-left: 4px solid var(--c); }
.tile:hover { background: var(--surface-2); }
.tile .n { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; color: var(--c); }
.tile .t { font-size: 15px; font-weight: 600; }
.tile .x { font-size: 13px; color: var(--muted); line-height: 1.4; }
.tile.zero .n { color: var(--faint); }
.dist { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; }
.dist i { display: block; background: var(--c); min-width: 3px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend span::before { content: ''; width: 10px; height: 10px; border-radius: 3px; background: var(--c); }

/* список */
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--line-2); }
.input { min-height: 40px; padding: 0 12px; border: 1px solid var(--line-3); border-radius: 10px; background: var(--surface);
  font-size: 14px; }
.toolbar .input { width: auto; max-width: 100%; }
.toolbar input.input { width: 300px; }
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: right; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 8px; white-space: nowrap;
  border-bottom: 1px solid var(--line-2); cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); }
.tbl th.l, .tbl td.l { text-align: left; }
.tbl th.sorted { color: var(--ink); }
.tbl th.sorted::after { content: ' ↓'; }
.tbl th.sorted.asc::after { content: ' ↑'; }
.tbl td { padding: 10px 8px; border-bottom: 1px solid var(--line-2); text-align: right; white-space: nowrap;
  font-variant-numeric: tabular-nums; }
.tbl tr { content-visibility: auto; contain-intrinsic-size: auto 70px; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl .ph { width: 44px; padding-right: 0; }
.ph img, .ph .noimg { width: 40px; height: 53px; border-radius: 6px; object-fit: cover; display: block; background: var(--muted-bg); }
.tbl .name { min-width: 180px; max-width: 250px; white-space: normal; }
.tbl td.l .flags { margin-top: 0; min-width: 120px; max-width: 200px; }
.tbl .name a { text-decoration: none; font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tbl .name a:hover { text-decoration: underline; }
.tbl .name .meta { margin-top: 3px; }
.tbl .sub-v { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.pill.cat { background: var(--cb); color: var(--c); }
.flags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.flag { font-size: 11px; font-weight: 600; padding: 2px 6px; border-radius: 5px; background: var(--cb); color: var(--c); white-space: nowrap; }
.neg { color: var(--bad); } .pos { color: var(--good); }
.more-row td { text-align: center; padding: 16px; }

/* страница дизайна */
.dz-head { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; align-items: start; }
.dz-photo { width: 100%; aspect-ratio: 3 / 4; border-radius: 16px; overflow: hidden; background: var(--muted-bg); }
.dz-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.dz-info { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.dz-info h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.links { display: flex; gap: 10px; flex-wrap: wrap; }
.verdict { padding: 18px 20px; border-left: 4px solid var(--c); display: flex; flex-direction: column; gap: 6px; }
.verdict .t { font-size: 18px; font-weight: 700; color: var(--c); }
.verdict .x { color: var(--ink-2); font-size: 14px; }
.verdict .why { font-size: 13px; color: var(--muted); }
.flag-list { display: flex; flex-direction: column; gap: 8px; }
.flag-list .flag { font-size: 12px; }
.flag-list div { display: flex; gap: 10px; align-items: baseline; font-size: 13px; color: var(--muted); }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.facts div { padding: 14px 16px; }
.facts b { display: block; font-size: 20px; margin-top: 4px; }
.facts small { font-size: 12px; color: var(--muted); }
.chart { padding: 8px 20px 16px; }
.chart svg { width: 100%; height: 160px; display: block; }
.chart rect.bar { fill: var(--ink-2); opacity: .75; }
.chart rect.bar:hover { opacity: 1; fill: var(--accent-line); }
.chart .axis { font-size: 11px; fill: var(--muted); }

/* настройки */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.fset { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.frow { display: flex; align-items: center; gap: 10px; justify-content: space-between; font-size: 14px; }
.frow label { color: var(--ink-2); }
.frow .unit { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.frow .input { width: 96px; text-align: right; }
.ok-msg { font-size: 14px; color: var(--good); font-weight: 600; }
.jobs { display: flex; flex-direction: column; }
.job { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 12px 20px; border-top: 1px solid var(--line-2); font-size: 14px; }
.job .e { grid-column: 1 / -1; font-size: 12px; color: var(--bad); word-break: break-word; }

/* вход */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 360px; max-width: 100%; padding: 28px; display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.err { color: var(--bad); font-size: 14px; }

@media (max-width: 900px) {
  .top { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px 12px; }
  .top .nav { order: 3; width: 100%; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .toolbar input.input { width: 100%; }
  .brand small { display: none; }
  .page { padding: 20px 16px 48px; }
  .page-head h1 { font-size: 26px; }
  .kpis, .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dz-head { grid-template-columns: 1fr; }
  .dz-photo { max-width: 260px; }
}
.meta { font-size: 12px; color: var(--muted); }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }
.tokrow { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line-2); }
.tokrow .tokinfo { flex: 1 1 320px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.tokrow .tokinfo b { color: var(--ink); font-weight: 600; }
.tokrow .input { flex: 1 1 260px; }
.tbl th.c, .tbl td.c { text-align: center; }
.adi { display: inline-flex; vertical-align: middle; }
.adi-on circle:first-child { fill: var(--good); }
.adi-money circle:first-child { fill: #D97706; }
.adi-pause circle:first-child { fill: var(--faint); }
.adi-none circle { fill: var(--bad); }
.adline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); margin-right: 8px; }
.ph img { cursor: zoom-in; }
.zoom-pop { position: fixed; z-index: 50; width: 270px; height: 360px; border-radius: 14px; overflow: hidden; pointer-events: none;
  background: var(--muted-bg); box-shadow: 0 12px 32px rgba(17,17,19,.22), 0 0 0 1px var(--line); }
.zoom-pop img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tbl .sub-v.neg { color: var(--bad); }
