:root {
  color-scheme: light;
  --surface-0: #f5f5f3; --surface-1: #fcfcfb; --surface-2: #f0efec;
  --line: #e2e1dc; --grid: #ebeae6;
  --text-primary: #0b0b0b; --text-secondary: #52514e; --text-muted: #77766f;
  --series-1: #2a78d6; --series-2: #eb6834;
  --seq-bar: #86b6ef; --seq-bar-2: #f3b293;
  --good: #0ca30c; --good-text: #006300; --critical: #d03b3b; --critical-text: #b02a2a;
  --accent: #2a78d6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #232321;
    --line: #34342f; --grid: #2a2a27;
    --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #96958c;
    --series-1: #3987e5; --series-2: #d95926;
    --seq-bar: #1c5cab; --seq-bar-2: #8a3a1a;
    --good-text: #5fd35f; --critical-text: #f08080;
    --accent: #5598e7;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #121211; --surface-1: #1a1a19; --surface-2: #232321;
  --line: #34342f; --grid: #2a2a27;
  --text-primary: #f0efec; --text-secondary: #c3c2b7; --text-muted: #96958c;
  --series-1: #3987e5; --series-2: #d95926;
  --seq-bar: #1c5cab; --seq-bar-2: #8a3a1a;
  --good-text: #5fd35f; --critical-text: #f08080;
  --accent: #5598e7;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--surface-0); color: var(--text-primary);
  font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.num, td.n, .tile .v { font-variant-numeric: tabular-nums; }
header.top { display: flex; align-items: center; gap: 24px; padding: 12px 24px;
  border-bottom: 1px solid var(--line); background: var(--surface-1); flex-wrap: wrap; }
header.top .brand { font-weight: 650; letter-spacing: -.2px; }
header.top nav { display: flex; gap: 4px; }
header.top nav a { color: var(--text-secondary); text-decoration: none; padding: 6px 12px; border-radius: 6px; }
header.top nav a:hover { background: var(--surface-2); }
header.top nav a[aria-current="page"] { color: var(--text-primary); background: var(--surface-2); font-weight: 600; }
header.top .meta { margin-left: auto; color: var(--text-muted); font-size: 12px; display: flex; gap: 12px; align-items: center; }
header.top button.theme { background: none; border: 1px solid var(--line); color: var(--text-secondary);
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font: inherit; }
main { padding: 20px 24px 48px; max-width: 1480px; margin: 0 auto; }
h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -.2px; }
h2 { font-size: 15px; margin: 0 0 4px; }
.sub { color: var(--text-secondary); margin: 0 0 16px; max-width: 900px; }
.small { font-size: 12px; color: var(--text-muted); }
.card { background: var(--surface-1); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 0 0 16px; }
.tile { background: var(--surface-1); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.tile .l { color: var(--text-secondary); font-size: 12px; }
.tile .v { font-size: 26px; font-weight: 650; letter-spacing: -.4px; margin-top: 2px; }
.tile .d { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.tile.hero .v { font-size: 32px; }
.pos { color: var(--good-text); } .neg { color: var(--critical-text); }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0 10px; }
.controls input[type=search] { flex: 1 1 200px; min-width: 0; padding: 7px 10px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--surface-0); color: var(--text-primary); font: inherit; }
.controls label { color: var(--text-secondary); font-size: 13px; display: flex; gap: 6px; align-items: center; }
.tablewrap { max-height: 70vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { position: sticky; top: 0; background: var(--surface-2); color: var(--text-secondary); font-weight: 600;
  text-align: left; padding: 7px 8px; font-size: 12px; white-space: nowrap; z-index: 1; cursor: default; }
th.n, td.n { text-align: right; }
td { padding: 6px 8px; border-top: 1px solid var(--grid); white-space: nowrap; }
td.name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
td.mgr { color: var(--text-secondary); max-width: 150px; overflow: hidden; text-overflow: ellipsis; }
tr:hover td { background: var(--surface-2); }
.depth { position: relative; min-width: 96px; }
.depth .bar { position: absolute; left: 0; top: 4px; bottom: 4px; border-radius: 0 4px 4px 0; background: var(--seq-bar); opacity: .55; }
.depth .bar.b2 { background: var(--seq-bar-2); }
.depth span { position: relative; }
.pill { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 10px; border: 1px solid var(--line); color: var(--text-secondary); }
.empty { padding: 32px 16px; text-align: center; color: var(--text-secondary); }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { fill: var(--text-muted); font-size: 11px; }
.chart .grid line { stroke: var(--grid); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--text-secondary); margin: 4px 0 8px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 14px; height: 2px; vertical-align: middle; margin-right: 6px; border-radius: 1px; }
.tip { position: absolute; pointer-events: none; background: var(--surface-1); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); display: none;
  z-index: 5; white-space: nowrap; }
.tip b { font-weight: 600; }
.tip .row { display: flex; gap: 12px; justify-content: space-between; }
.tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.sliders { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px 20px; }
.slider label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-secondary); }
.slider label b { color: var(--text-primary); font-weight: 600; }
.slider input[type=range] { width: 100%; accent-color: var(--accent); }
.slider .hint { font-size: 11px; color: var(--text-muted); }
details summary { cursor: pointer; color: var(--text-secondary); }
.note { border-left: 3px solid var(--line); padding: 6px 12px; color: var(--text-secondary); font-size: 13px; margin: 8px 0; }
@media (max-width: 900px) {
  header.top { padding: 10px 16px; gap: 12px; }
  header.top .meta { margin-left: 0; width: 100%; }
  main { padding: 16px 16px 40px; }
  .grid2 { grid-template-columns: 1fr; }
  .tile .v { font-size: 22px; } .tile.hero .v { font-size: 26px; }
}
/* Ячейки сетки с широкими таблицами не должны раздвигать страницу: скроллится только .tablewrap. */
.grid2 > *, .card, main { min-width: 0; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); }
.sliders { grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); }
#comp td:first-child, #base td:first-child { white-space: normal; }

/* --- приложение --- */
.btn { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface-1);
  color: var(--text-primary); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--critical-text); }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input.f, select.f, textarea.f { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface-0); color: var(--text-primary); min-width: 0; }
textarea.f { width: 100%; resize: vertical; }
.form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin: 8px 0; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-secondary); flex: 1 1 160px; min-width: 0; }
.tabs { display: flex; gap: 4px; margin: 0 0 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px;
  color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--accent); font-weight: 600; }
.stack > * + * { margin-top: 16px; }
.status { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--surface-2);
  color: var(--text-secondary); white-space: nowrap; }
.status.act { background: var(--accent); color: #fff; }
.status.ok { color: var(--good-text); } .status.bad { color: var(--critical-text); }
.todo { border: 1px solid var(--accent); border-radius: 10px; padding: 14px 16px; background: var(--surface-1); }
.todo h3 { margin: 0 0 6px; font-size: 15px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; font-size: 13px; }
.kv dt { color: var(--text-secondary); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.copy { cursor: pointer; border-bottom: 1px dashed var(--text-muted); }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 360px; overflow-y: auto; padding: 4px; }
.msg { max-width: 85%; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); font-size: 13px; }
.msg.mine { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.mine a { color: #fff; }
.msg.op { border: 1px solid var(--accent); }
.msg .who { font-size: 11px; opacity: .75; margin-bottom: 2px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text-primary);
  color: var(--surface-1); padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 50; max-width: calc(100% - 32px); }
.toast.err { background: var(--critical); color: #fff; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.warn { border-left: 3px solid var(--critical); padding: 8px 12px; background: var(--surface-1); margin: 0 0 16px; }
tr.click { cursor: pointer; }
