/* SNG portal v0.1 — one stylesheet. Tokens first (light + dark), then layout, then components. */
:root {
  color-scheme: light;
  --page: #f9f9f7; --surface: #fcfcfb; --surface-2: #f3f3f0;
  --ink: #0b0b0b; --ink-2: #52514e; --muted: #898781;
  --hair: #e1e0d9; --line: #c3c2b7; --ring: rgba(11,11,11,0.10);
  --accent: #2a78d6; --accent-soft: #cde2fb; --accent-track: #e3eefb;
  --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --neg: #e34948; --pos-text: #006300;
  --good: #0ca30c; --warn: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --mid: #f0efec;
  --radius: 10px; --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232322;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --hair: #2c2c2a; --line: #383835; --ring: rgba(255,255,255,0.10);
    --accent: #3987e5; --accent-soft: #184f95; --accent-track: #22344d;
    --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --neg: #e66767; --pos-text: #0ca30c; --mid: #383835;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--sans); color: var(--ink); background: var(--page); font-size: 14px; line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
h3 { font-size: 13px; font-weight: 600; margin: 0 0 6px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.neg { color: var(--neg); }
.pos { color: var(--pos-text); }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--hair); padding: 18px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 8px 14px; letter-spacing: 0.01em; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; margin-top: 2px; }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink-2); font-weight: 500; }
.nav a.active { background: var(--surface-2); color: var(--ink); }
.nav a:hover { text-decoration: none; color: var(--ink); }
.nav .group { margin: 10px 10px 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.side .foot { margin-top: auto; padding: 8px 10px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--hair); }
.side .foot b { color: var(--ink-2); display: block; }
.main { padding: 22px 28px 60px; max-width: 1240px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.period { display: flex; align-items: center; gap: 8px; }
select, input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; }
input[type=number] { text-align: right; font-variant-numeric: tabular-nums; }
input[readonly] { color: var(--muted); background: var(--surface-2); }
textarea { width: 100%; min-height: 90px; }
button, .btn { font: inherit; font-weight: 600; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.quiet { border-color: transparent; background: transparent; color: var(--accent); padding: 4px 6px; }
button:disabled { opacity: 0.5; cursor: default; }
button.small { padding: 4px 9px; font-size: 12px; }

/* ---------- cards, tiles */
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 16px 18px; }
.card.pad0 { padding: 0; overflow: hidden; }
.card h2 { display: flex; justify-content: space-between; align-items: baseline; }
.card h2 .muted { font-weight: 500; font-size: 12px; }
.tile { background: var(--surface); border: 1px solid var(--hair); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { font-size: 12px; color: var(--ink-2); }
.tile .value { font-size: 22px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.tile .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.hero { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-end; }
.hero .hero-value { font-size: 44px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.05; }
.hero .hero-label { font-size: 13px; color: var(--ink-2); }
.hero .delta { font-size: 13px; color: var(--ink-2); }
.section { margin-top: 18px; }

/* ---------- tables */
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--ink-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t th.num { text-align: right; }
table.t td { padding: 7px 10px; border-bottom: 1px solid var(--hair); vertical-align: middle; }
table.t tr.sub td { color: var(--ink-2); padding-left: 22px; }
table.t tr.total td { font-weight: 600; border-top: 1px solid var(--line); background: var(--surface-2); }
table.t tr.group td { font-weight: 600; color: var(--ink-2); background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t tr.selected td { background: var(--accent-track); }
table.t input, table.t select { padding: 4px 7px; width: 100%; }
table.t td.w-num { width: 130px; }
.table-wrap { overflow-x: auto; }

/* ---------- bars (single-hue magnitude bars, thin, rounded data-end, square baseline) */
.bar-row { display: grid; grid-template-columns: 200px 1fr 150px; align-items: center; gap: 10px; padding: 5px 0; }
.bar-row .lbl { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { position: relative; height: 22px; }
.bar-fill { position: absolute; left: 0; top: 2px; height: 18px; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-fill.neg { background: var(--neg); }
.bar-target { position: absolute; top: 0; width: 2px; height: 22px; background: var(--ink-2); }
.bar-val { font-variant-numeric: tabular-nums; text-align: right; font-size: 13px; }
.meter { position: relative; height: 10px; background: var(--accent-track); border-radius: 5px; overflow: hidden; margin: 6px 0; }
.meter > span { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 5px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); margin: 4px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* ---------- chips, alerts, forms */
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid var(--ring); background: var(--surface-2); color: var(--ink-2); }
.chip.good { color: #06600a; background: #e6f6e6; border-color: transparent; }
.chip.warn { color: #6b4b00; background: #fff1cc; border-color: transparent; }
.chip.crit { color: #7a1d1d; background: #fbe1e1; border-color: transparent; }
.chip.info { color: #1c4f8f; background: #dbe9fb; border-color: transparent; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.good { color: #9fe39f; background: #123d12; } :root:not([data-theme="light"]) .chip.warn { color: #ffd77a; background: #4a3400; } :root:not([data-theme="light"]) .chip.crit { color: #ffb3b3; background: #521818; } :root:not([data-theme="light"]) .chip.info { color: #a9cbf6; background: #14365f; } }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--ring); background: var(--surface-2); margin-bottom: 8px; font-size: 13px; }
.alert b { font-weight: 600; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.form label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.form input, .form select, .form textarea { width: 100%; }
.form .wide { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.msg { font-size: 12px; margin-top: 8px; color: var(--ink-2); }
.msg.err { color: var(--critical); }
.toast { position: fixed; right: 20px; bottom: 20px; background: var(--ink); color: var(--page); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 6px 24px rgba(0,0,0,0.2); z-index: 50; max-width: 420px; }
.toast.err { background: var(--critical); color: #fff; }
.narrative p { margin: 0 0 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { min-width: 140px; }
.two { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--hair); margin-bottom: 12px; }
.tabs button { border: 0; background: transparent; border-radius: 0; padding: 8px 12px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }

/* ---------- sign-in */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.signin .card { width: 360px; max-width: 100%; }
.signin h1 { margin-bottom: 14px; }
.signin .form { grid-template-columns: 1fr; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; }
  .side .foot { margin-top: 0; border: 0; margin-left: auto; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; } .nav .group { display: none; }
  .main { padding: 16px; }
  .grid.cols-3, .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 120px 1fr 100px; }
}
@media (max-width: 560px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } .hero .hero-value { font-size: 34px; } }

/* ---------- charts */
.chart { width: 100%; height: auto; display: block; font-family: var(--sans); }
.chart-stack { height: 28px; }
.chart .mark { cursor: default; }
.chart .mark:hover { opacity: 0.85; }
.charttip { position: fixed; z-index: 60; background: var(--ink); color: var(--page); font-size: 12px; padding: 5px 8px; border-radius: 6px; pointer-events: none; max-width: 320px; box-shadow: 0 4px 16px rgba(0,0,0,0.2); }
.chart-empty { padding: 20px 0; }
.card h2 .quiet { font-weight: 500; font-size: 12px; }

/* ---------- presentation mode: no navigation, larger type, one page per screen */
body.present .side { display: none; }
body.present .shell { grid-template-columns: 1fr; }
body.present .main { max-width: 1500px; margin: 0 auto; padding: 28px 40px 60px; font-size: 15px; }
body.present h1 { font-size: 28px; }
body.present .tile .value { font-size: 26px; }
body.present .hero .hero-value { font-size: 54px; }
body.present table.t { font-size: 14px; }
body.present .present-only { display: inline-flex; }
.present-only { display: none; }
.present-nav { display: flex; gap: 6px; align-items: center; }
@media print {
  .side, .period, .topbar button, .tabs, .actions, button, .filters { display: none !important; }
  .shell { grid-template-columns: 1fr; }
  .main { padding: 0; max-width: none; }
  .card, .tile { break-inside: avoid; border-color: #ccc; }
  body { background: #fff; color: #000; }
}
