:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --border: #e3e1da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --grid: #ebe9e3;
  --sink: #2a78d6;
  --source: #eb6834;
  --band: #1baf7a;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --pos: #0b7a3e;
  --neg: #b42318;
  --input: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --border: #2e2d2a;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --grid: #262624;
    --sink: #3987e5;
    --source: #d95926;
    --band: #199e70;
    --accent: #3987e5;
    --accent-ink: #ffffff;
    --pos: #4cc38a;
    --neg: #f97066;
    --input: #121211;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --border: #2e2d2a;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8f8e86;
  --grid: #262624;
  --sink: #3987e5;
  --source: #d95926;
  --band: #199e70;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --pos: #4cc38a;
  --neg: #f97066;
  --input: #121211;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { margin: 0; font-size: 22px; }
h2 { margin: 0; font-size: 15px; }
.sub, .hint, .muted { color: var(--text-2); }
.hint { margin: 4px 0 10px; font-size: 13px; }
.muted { color: var(--muted); }

.top, main, footer { max-width: 1280px; margin: 0 auto; padding: 16px; }
.top { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: end; justify-content: space-between; }
.sub { margin: 4px 0 0; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ref { display: flex; gap: 6px; align-items: center; color: var(--text-2); }
.ref input { width: 90px; }
main { display: flex; flex-direction: column; gap: 16px; padding-top: 0; }
footer { font-size: 12px; }

button, .button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
button:hover, .button:hover { border-color: var(--text-2); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost, .button.ghost { background: transparent; }
button.icon { padding: 2px 8px; color: var(--muted); }
button:focus-visible, input:focus-visible, .button:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

input {
  font: inherit;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  width: 100%;
  min-width: 72px;
}
input[type="text"] { min-width: 130px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 14px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; }
.card-head h2 { margin-right: auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.kpi span { color: var(--text-2); font-size: 13px; }
.kpi b { font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi.hero b { font-size: 28px; }
.kpi small { color: var(--muted); }

.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 16px; }
@media (max-width: 420px) { .grid3 { grid-template-columns: 1fr; } }

.scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--grid); text-align: left; white-space: nowrap; }
th { color: var(--text-2); font-weight: 500; font-size: 12px; }
td .tag { display: inline-block; font-size: 11px; padding: 0 5px; border-radius: 4px; border: 1px solid var(--border); color: var(--text-2); }
.num { text-align: right; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.empty { color: var(--muted); padding: 8px 0; margin: 0; }
.error { color: var(--neg); width: 100%; margin: 0; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--text-2); font-size: 12px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.swatch.sink { background: var(--sink); }
.swatch.source { background: var(--source); }
.swatch.band { background: var(--band); opacity: 0.45; }

.chart { position: relative; margin-top: 10px; }
.chart svg { display: block; max-width: 100%; }
.chart .grid { stroke: var(--grid); }
.chart .tick { fill: var(--muted); font-size: 11px; }
.chart .axis { fill: var(--text-2); font-size: 12px; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .line.sink { stroke: var(--sink); }
.chart .line.source { stroke: var(--source); }
.chart .direct { font-size: 12px; fill: var(--text); }
.chart .band { fill: var(--band); opacity: 0.3; }
.chart .ref { stroke: var(--text-2); stroke-dasharray: 4 4; }
.chart .cut { stroke: var(--muted); stroke-dasharray: 2 3; }
.chart .cross { stroke: var(--text-2); stroke-width: 1; }
.chart .hit { fill: transparent; }
.tip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  max-width: 280px;
  box-shadow: 0 4px 16px rgb(0 0 0 / 0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tip-head { color: var(--text-2); }

.swatch.link { background: none; border: 2px dashed var(--text-2); }
.wb-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.wb-tools [aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.wb-hint { font-size: 12px; }
.wb-view {
  height: 560px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--grid) 1.2px, transparent 1.3px);
  cursor: grab;
  touch-action: none;
}
.wb-view:active { cursor: grabbing; }
.wb-view.linking .wb-node { cursor: crosshair; }
.wb-svg { width: 100%; height: 100%; display: block; user-select: none; }
.wb-node { cursor: move; }
.wb-node rect { fill: var(--surface); stroke: var(--border); stroke-width: 1.5; }
.wb-node.hub rect { stroke: var(--text-2); stroke-width: 2; }
.wb-node.sel rect { stroke: var(--accent); stroke-width: 3; }
.wb-node.dim { opacity: 0.45; }
.wb-name { fill: var(--text); font-size: 13px; font-weight: 600; }
.wb-sub { fill: var(--text-2); font-size: 11.5px; }
.wb-tag { fill: var(--muted); font-size: 11px; font-weight: 500; }
.wb-profit { fill: var(--pos); font-size: 15px; font-weight: 600; }
.wb-edge { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.wb-edge.source { stroke: var(--source); }
.wb-edge.sink { stroke: var(--sink); }
.wb-arrow.source { fill: var(--source); }
.wb-arrow.sink { fill: var(--sink); }
.wb-label { fill: var(--text); font-size: 11.5px; paint-order: stroke; stroke: var(--bg); stroke-width: 4px; stroke-linejoin: round; }
.wb-link { stroke: var(--text-2); stroke-width: 2; stroke-dasharray: 6 5; }
.wb-link-hit { stroke: transparent; stroke-width: 14; cursor: pointer; }
@media (max-width: 600px) { .wb-view { height: 420px; } }
