:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1b2330; --muted: #657084; --line: #e3e7ee;
  --up: #12805c; --down: #c0392b; --accent: #2f5fd0;
  --c0: #2f5fd0; --c1: #17a18c; --c2: #e0a020; --c3: #8d97a8; --c4: #b05ad0;
  --sel: rgba(47, 95, 208, .10);
  /* статусы команд (как на образце: тёмно-зелёный, красный, светло-зелёный, светло-красный, зелёный, тёмно-красный) */
  --s-retained: #1f7a46; --s-lost: #d6303a; --s-new: #5ccb82; --s-newInactive: #f2a1a6;
  --s-resumed: #26a64a; --s-resumedInactive: #8f1d2c; --s-idle: #8d97a8; --s-none: #b9c0cc;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d; --card: #1a2029; --ink: #e8ecf3; --muted: #98a3b5; --line: #2a3340;
    --up: #46c79b; --down: #ef7d70; --accent: #7aa2ff;
    --c0: #6f95ff; --c1: #3fc4ad; --c2: #efbb4a; --c3: #8e99ab; --c4: #c98cea;
    --sel: rgba(122, 162, 255, .14);
    --s-retained: #2f9a5d; --s-lost: #e5484f; --s-new: #62d68a; --s-newInactive: #e58a91;
    --s-resumed: #34c15c; --s-resumedInactive: #b8394a; --s-idle: #8e99ab; --s-none: #586072;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 22px; } h2 { font-size: 16px; }
a { color: var(--accent); }
.muted { color: var(--muted); } .pad { padding: 24px; }
.app { max-width: 1240px; margin: 0 auto; padding: 16px; }
.num { font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); } .warn { color: var(--down); }

/* шапка и управление */
.top { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.top .tools { display: flex; gap: 8px; align-items: center; }
select, input[type=search], input[type=text], input[type=password], button {
  font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.accent { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.controls { padding: 12px 14px; }
.crow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
.crow.end { justify-content: flex-end; margin: 12px 0 0; }
.lbl { color: var(--muted); font-size: 13px; min-width: 64px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.seg button[aria-pressed="true"], .stbtn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.tabs { display: flex; gap: 4px; margin: 0 0 14px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 16px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

/* карточки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.card > h2 { margin-bottom: 10px; }
.sub { color: var(--muted); font-size: 13px; margin: 4px 0 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(138px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi.static { cursor: default; } .kpi.static:hover { border-color: var(--line); }
.kpi .lbl { min-width: 0; }
.kpi .val { font-size: 23px; font-weight: 650; }
.kpi .note { font-size: 13px; color: var(--muted); }
.kpi .note.up { color: var(--up); } .kpi .note.down { color: var(--down); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 14px; margin-bottom: 14px; align-items: start; }
.cols > .card { margin-bottom: 0; }

/* график */
.chart { width: 100%; }
.chart svg { display: block; max-width: 100%; }
svg .grid { stroke: var(--line); stroke-width: 1; }
svg .axis { fill: var(--muted); font-size: 11px; }
svg .sel { fill: var(--sel); }
svg .hit { fill: transparent; cursor: pointer; }
svg .hit:focus-visible { outline: none; stroke: var(--accent); stroke-width: 2; }
svg .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; font-size: 13px; }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }

/* списки */
.bars { display: grid; gap: 7px; }
.brow { display: grid; grid-template-columns: minmax(90px, 1.2fr) 2fr auto; gap: 10px; align-items: center; font-size: 14px; }
.tl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-decoration: none; }
.tl:hover { text-decoration: underline; }
.track { background: var(--line); border-radius: 5px; height: 10px; overflow: hidden; }
.track.mt { margin: 8px 0; }
.fill { height: 100%; border-radius: 5px; background: var(--accent); }
.brow .v { text-align: right; white-space: nowrap; }
.mv { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.mv li { display: flex; justify-content: space-between; gap: 10px; }
.mv .v { white-space: nowrap; }
.mvh { font-size: 13px; color: var(--muted); margin: 0 0 6px; } .mvh.gap { margin-top: 12px; }

/* подсказки */
.ins { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.ins li { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.ins li.warn { border-left: 4px solid var(--down); } .ins li.good { border-left: 4px solid var(--up); } .ins li.info { border-left: 4px solid var(--c3); }
.ins .ins-t { flex: 1 1 280px; } .ins button { padding: 3px 10px; font-size: 13px; }
.ins.small { margin: 10px 0; font-size: 14px; }
.tag { font-size: 12px; border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; color: var(--muted); white-space: nowrap; }
.tag.lvl-warn { color: var(--down); border-color: var(--down); } .tag.lvl-good { color: var(--up); border-color: var(--up); }

/* статусы */
.st-retained { --st: var(--s-retained); } .st-lost { --st: var(--s-lost); } .st-new { --st: var(--s-new); }
.st-newInactive { --st: var(--s-newInactive); } .st-resumed { --st: var(--s-resumed); }
.st-resumedInactive { --st: var(--s-resumedInactive); } .st-idle { --st: var(--s-idle); } .st-none { --st: var(--s-none); }
.chip { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 999px; margin-right: 4px; border: 1px solid var(--st, var(--line)); background: color-mix(in srgb, var(--st, var(--muted)) 20%, transparent); white-space: nowrap; }
.chip.dormant { --st: var(--s-lost); } .chip.drop { --st: var(--c2); }
.stlist, .stlegend { display: flex; flex-wrap: wrap; gap: 6px; }
.stlist { flex-direction: column; }
.stbtn { display: inline-flex; gap: 8px; align-items: center; text-align: left; font-size: 13px; padding: 5px 10px; }
.stlist .stbtn { justify-content: space-between; width: 100%; }
.stbtn .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--st); display: inline-block; flex: none; }
.stbtn .stn { flex: 1; }
.stlegend { margin-bottom: 10px; }

/* таблица */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.r, th.r { text-align: right; }
td.wrap { white-space: normal; min-width: 130px; max-width: 240px; }
th button { border: 0; background: none; padding: 0; font-weight: 600; color: var(--muted); }
th button:hover { color: var(--ink); }
th[aria-sort="ascending"] button::after { content: " ▲"; } th[aria-sort="descending"] button::after { content: " ▼"; }
tbody tr[class*="st-"] { background: color-mix(in srgb, var(--st) 13%, transparent); }
tbody tr[class*="st-"] td:first-child { box-shadow: inset 4px 0 0 var(--st); }
tfoot td { font-weight: 650; border-top: 2px solid var(--line); border-bottom: 0; }
tr.inperiod { background: var(--sel); }
td.barcell { min-width: 120px; }
.spark { display: block; } .spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; }

/* касты */
.caste h2 { display: flex; align-items: center; }
.big { font-size: 24px; font-weight: 650; }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; margin: 10px 0; font-size: 14px; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; text-align: right; }

/* карточка команды */
.thead { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.back { text-decoration: none; }

.foot { color: var(--muted); font-size: 13px; padding: 4px 2px 20px; }
.tip { position: fixed; z-index: 30; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.18); pointer-events: none; max-width: 270px; }
.tip b { display: block; margin-bottom: 4px; }
.tip div { display: flex; justify-content: space-between; gap: 14px; }
.error { padding: 24px; }

/* выбор команд */
dialog.picker { width: min(720px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
dialog.picker::backdrop { background: rgba(0, 0, 0, .45); }
.pklist { overflow-y: auto; max-height: 46vh; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }
.pkrow { display: grid; grid-template-columns: auto 1fr auto auto; gap: 10px; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; }
.pkrow:last-child { border-bottom: 0; } .pkname { overflow: hidden; text-overflow: ellipsis; }
.pkv { min-width: 90px; text-align: right; }

/* вход */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 26px; width: 100%; max-width: 360px; }
.login-card h1 { margin-bottom: 4px; }
.login-card form { display: grid; gap: 6px; margin-top: 14px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.login-card input { width: 100%; padding: 9px 11px; }
.login-card button { margin-top: 14px; background: var(--accent); color: #fff; border-color: var(--accent); padding: 10px; font-weight: 600; }
.err { color: var(--down); background: color-mix(in srgb, var(--down) 10%, transparent); border-radius: 8px; padding: 8px 10px; margin: 12px 0 0; font-size: 14px; }

@media (max-width: 560px) {
  .app { padding: 10px; }
  .kpi .val { font-size: 20px; }
  .brow { grid-template-columns: 1fr auto; }
  .brow .track { grid-column: 1 / -1; order: 3; }
  .pkrow { grid-template-columns: auto 1fr auto; } .pkrow > .muted { display: none; }
}
