:root {
  color-scheme: light;
  --page: #f6f5f2;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6e6c66;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #e6f0fc;
  --good: #0ca30c;
  --good-ink: #006300;
  --warn: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --up: #b3361f;
  --down: #b3361f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-other: #898781;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 2px 8px rgba(11, 11, 11, 0.04);
  --radius: 12px;
  --font: 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: #242422;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --line: #2c2c2a;
    --line-strong: #383835;
    --accent: #3987e5;
    --accent-soft: #16263a;
    --good-ink: #0ca30c;
    --up: #f08a6e;
    --down: #f08a6e;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a988f;
  --line: #2c2c2a; --line-strong: #383835; --accent: #3987e5; --accent-soft: #16263a; --good-ink: #0ca30c;
  --up: #f08a6e; --down: #f08a6e; --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; }
h2 { font-size: 1rem; font-weight: 650; margin-bottom: 12px; }
p { margin: 0 0 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }

/* layout */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 20px; padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; color: var(--ink); font-weight: 700; font-size: 1.1rem; text-decoration: none !important; }
.brand svg { width: 28px; height: 28px; }
.brand svg rect { fill: var(--accent); }
.brand svg path { fill: none; stroke: #fff; stroke-width: 2.2; stroke-linejoin: round; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 550; text-decoration: none; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.side-foot { margin-top: auto; padding: 0 8px; color: var(--muted); font-size: 0.8rem; }
main { padding: 24px 32px 64px; max-width: 1240px; width: 100%; min-width: 0; }
#view:focus { outline: none; }

.banner { margin-bottom: 16px; padding: 10px 14px; border-radius: 10px; background: var(--accent-soft); color: var(--ink-2); font-size: 0.9rem; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.sub { color: var(--muted); margin: 4px 0 0; }
.page-head .row { flex-wrap: wrap; }
.back { display: inline-block; font-size: 0.85rem; margin-bottom: 6px; }
.lede { color: var(--ink-2); }
.section-title { margin: 28px 0 12px; }

/* cards & tiles */
.card { min-width: 0; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.flush { padding: 0; overflow-x: auto; }
.card.narrow { max-width: 720px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-2 .card { margin-bottom: 0; }
.span-2 { grid-column: span 2; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile { display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.t-label { color: var(--muted); font-size: 0.82rem; font-weight: 550; }
.t-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.t-foot { color: var(--muted); font-size: 0.82rem; }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 0.8rem; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.data td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data tbody tr:last-child td { border-bottom: none; }
.data tfoot td { border-top: 1px solid var(--line-strong); border-bottom: none; font-weight: 600; }
.data.compact td, .data.compact th { padding: 7px 8px; }
.card:not(.flush) .data td:first-child, .card:not(.flush) .data th:first-child { padding-left: 0; }
.card:not(.flush) .data td:last-child, .card:not(.flush) .data th:last-child { padding-right: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data.clickable tbody tr { cursor: pointer; }
.data.clickable tbody tr:hover { background: var(--surface-2); }
tr.flag td { background: color-mix(in srgb, var(--serious) 9%, transparent); }
tr.group td { background: var(--surface-2); font-weight: 600; font-size: 0.8rem; color: var(--ink-2); padding-top: 6px; padding-bottom: 6px; }
.up { color: var(--up); }
.down { color: var(--down); }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.pad { padding: 16px 20px; margin: 0; }
.empty { color: var(--muted); margin: 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }

.status { font-size: 0.82rem; font-weight: 600; white-space: nowrap; color: var(--ink-2); }
.status.good { color: var(--good-ink); }
.status.warn::first-letter { color: var(--warn); }
.status.serious::first-letter { color: var(--serious); }
.status.big { font-size: 0.95rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 0.92rem; }
.list li:last-child { border-bottom: none; }
.list a { color: var(--ink); }

.alert { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); margin-bottom: 16px; font-size: 0.92rem; }
.alert.serious { background: color-mix(in srgb, var(--serious) 12%, var(--surface)); border-color: color-mix(in srgb, var(--serious) 45%, var(--surface)); }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.check { margin-top: 6px; font-size: 0.82rem; color: var(--ink); font-weight: 550; }

/* forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--critical); border-color: var(--critical); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.danger-text { color: var(--critical) !important; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.file-btn { position: relative; }
.icon-btn { width: 30px; height: 30px; border: none; border-radius: 8px; background: transparent; color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--critical); }

label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--ink-2); }
label.inline { flex-direction: row; align-items: center; gap: 8px; }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); font-weight: 400; min-width: 0; }
input[type="search"] { min-width: 220px; }
.num-in { width: 84px; text-align: right; }
.num-in.wide { width: 100px; }
.unit-in { width: 80px; }
.note-in { width: 100%; min-width: 140px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
fieldset { border: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
legend { font-weight: 650; margin-bottom: 8px; }
.radio { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; color: var(--ink); flex-wrap: wrap; }
.check-row { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; color: var(--ink-2); margin-bottom: 16px; }
.check-row input { margin-top: 3px; }

.row { display: flex; align-items: center; gap: 10px; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
.gap-s { gap: 8px; }
.grow { flex: 1; margin: 0; }
.top-gap { margin-top: 16px; }
.bottom-gap { margin-bottom: 16px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tabs a.active { color: var(--accent); border-color: var(--accent); }

/* charts */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; list-style: none; padding: 0; margin: 0 0 8px; font-size: 0.82rem; color: var(--ink-2); }
.legend .key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .grid.base { stroke: var(--line-strong); }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .val { fill: var(--ink-2); font-size: 11px; font-weight: 600; }
.chart .seg { stroke: var(--surface); stroke-width: 2; paint-order: stroke; }
.chart .seg:hover { filter: brightness(1.1); }
.table-view { margin-top: 8px; font-size: 0.85rem; }
.table-view summary { cursor: pointer; color: var(--muted); }
.table-view table { margin-top: 8px; }
.chart-tip { position: fixed; z-index: 50; pointer-events: none; padding: 8px 10px; border-radius: 8px; background: var(--ink); color: var(--surface); font-size: 0.8rem; line-height: 1.4; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2); max-width: 260px; }

.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.hbars li { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; font-size: 0.88rem; }
.hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hb-track { height: 14px; }
.hb-bar { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.hb-val { font-variant-numeric: tabular-nums; font-weight: 600; }

.preview { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }

/* toast & dialog */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--surface); font-weight: 550; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); max-width: calc(100vw - 32px); }
.toast.good::before { content: "✓ "; color: var(--good); }
.toast.warn::before { content: "⚠ "; color: var(--warn); }
dialog { border: none; border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(10, 10, 10, 0.45); }
.dialog-body { padding: 22px; }
.dialog-body h2 { font-size: 1.15rem; margin-bottom: 10px; }
.dialog-text { color: var(--ink-2); margin-bottom: 18px; }

/* responsive */
@media (max-width: 980px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .form-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { min-width: 0; position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; gap: 12px; padding: 10px 16px; border-right: none; border-bottom: 1px solid var(--line); }
  .brand span { display: none; }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; min-width: 0; flex: 1; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .side-foot { display: none; }
  main { padding: 16px 16px 48px; }
  h1 { font-size: 1.35rem; }
  .tiles, .tiles.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .t-value { font-size: 1.35rem; }
  .form-grid, .form-grid.two, .form-grid.four { grid-template-columns: minmax(0, 1fr); }
  input[type="search"] { min-width: 0; width: 100%; }
}

/* print: the monthly report as a clean document */
@media print {
  .side, .banner, .no-print, .toast, .table-view summary, .skip { display: none !important; }
  .app { display: block; }
  main { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .card, .tile { box-shadow: none; break-inside: avoid; }
  .grid-2 { grid-template-columns: 1fr 1fr; }
}
