/* Macro & Fiscal Monitor. Colour tokens follow a validated categorical palette
   (light and dark steps chosen separately; see README). */

:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #76746e;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --band: rgba(11, 11, 11, 0.04);
  --bar: #c3c2b7;
  --warn-ink: #8a5a00;
  --error-ink: #b42828;
  --ok-ink: #006300;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --own-outright: #184f95; --own-mortgage: #6da7ec;
  --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: #242423;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #9a988f;
    --grid: #2c2c2a;
    --axis: #45453f;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --band: rgba(255, 255, 255, 0.045);
    --bar: #5c5b56;
    --warn-ink: #fab219;
    --error-ink: #e66767;
    --ok-ink: #0ca30c;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --own-outright: #9ec5f4; --own-mortgage: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #242423;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #9a988f;
  --grid: #2c2c2a;
  --axis: #45453f;
  --border: rgba(255, 255, 255, 0.1);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --band: rgba(255, 255, 255, 0.045);
  --bar: #5c5b56;
  --warn-ink: #fab219;
  --error-ink: #e66767;
  --ok-ink: #0ca30c;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --own-outright: #9ec5f4; --own-mortgage: #3987e5;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent-ink); }

button, select { font: inherit; color: inherit; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */

.site-header { padding-top: 20px; padding-bottom: 8px; }
.site-header .topline {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px; color: var(--ink-2);
}
.site-header .topline a { color: var(--ink-2); text-decoration: none; }
.site-header .topline a:hover { color: var(--ink); text-decoration: underline; }
.site-header h1 { font-size: 26px; font-weight: 650; margin: 14px 0 4px; letter-spacing: -0.01em; }
.site-header .lede { margin: 0; color: var(--ink-2); max-width: 70ch; }
.updated { font-size: 13px; color: var(--muted); margin-top: 6px; }
.updated .stale { color: var(--warn-ink); }

.icon-btn {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 4px 10px; cursor: pointer; font-size: 13px; color: var(--ink-2);
}
.icon-btn:hover { color: var(--ink); }

/* ---------- filter bar ---------- */

.filters {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
}
.filters .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.filter-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 3px 4px 3px 10px; font-size: 13px; white-space: nowrap;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip button {
  border: 0; background: transparent; cursor: pointer; color: var(--muted);
  width: 22px; height: 22px; border-radius: 50%; line-height: 1; font-size: 15px;
}
.chip button:hover { background: var(--surface-2); color: var(--ink); }

.select {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 4px 8px; font-size: 13px; max-width: 100%;
}

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented button {
  border: 0; background: transparent; padding: 4px 10px; font-size: 13px; cursor: pointer; color: var(--ink-2);
  border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: 0; }
.segmented button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.segmented button:hover { color: var(--ink); }

/* ---------- tabs ---------- */

.tabs {
  display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
  border-bottom: 1px solid var(--border); margin-top: 16px;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: transparent; padding: 10px 12px; cursor: pointer; white-space: nowrap;
  color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 14px;
}
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs button:hover { color: var(--ink); }

.panel { padding: 18px 0 40px; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 14px; }
.panel-head h2 { font-size: 18px; margin: 0; font-weight: 600; }
.panel-head .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.note { font-size: 13px; color: var(--ink-2); margin: 0 0 14px; max-width: 90ch; }

/* ---------- cards & grid ---------- */

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px 12px; min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card h3 { font-size: 15px; margin: 0; font-weight: 600; }
.card .sub { font-size: 12.5px; color: var(--ink-2); margin: 2px 0 0; }
.card .src { font-size: 12px; color: var(--muted); margin-top: 6px; }
.card .src a { color: var(--muted); }
.view-toggle { font-size: 12px; padding: 2px 8px; white-space: nowrap; flex: none; }
.empty { color: var(--muted); font-size: 13px; padding: 30px 0; text-align: center; }

/* ---------- charts ---------- */

.chart { position: relative; margin-top: 8px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart svg:focus { outline: none; }
.chart svg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.axis text, .tick-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.zeroline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.band { fill: var(--band); }
.band-label { fill: var(--muted); font-size: 11px; }
.series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series-line.proj { stroke-dasharray: 4 3; }
.end-label { fill: var(--ink-2); font-size: 11px; }
.crosshair { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.hover-dot { stroke: var(--surface); stroke-width: 2; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .key { width: 14px; height: 2px; border-radius: 1px; display: inline-block; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px; font-size: 12.5px; min-width: 150px; max-width: 260px;
}
.tooltip .t-head { color: var(--muted); margin-bottom: 4px; font-size: 12px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; line-height: 1.6; }
.tooltip .t-row .key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tooltip .t-row .v { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; min-width: 44px; }
.tooltip .t-row .n { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; margin-top: 8px; }
.table-wrap.scroll { max-height: 320px; overflow-y: auto; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 6px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data thead th {
  position: sticky; top: 0; background: var(--surface); color: var(--ink-2);
  font-weight: 600; font-size: 12px; vertical-align: bottom;
}
table.data td { font-variant-numeric: tabular-nums; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--ink); }
table.data th .th-sub { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
table.data td .per { display: block; font-size: 11px; color: var(--muted); }
table.data td.na { color: var(--muted); }
table.data .country { display: inline-flex; align-items: center; gap: 8px; }
table.data .country .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
table.data tbody tr:hover td { background: var(--surface-2); }

.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; min-width: 130px; }
.bar-cell .bar-track { flex: 1; height: 10px; position: relative; }
.bar-cell .bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--bar); border-radius: 0 3px 3px 0; }
.bar-cell .bar-val { min-width: 42px; text-align: right; }

/* ---------- horizontal bar lists & stacked bars ---------- */

.bars { position: relative; margin-top: 10px; display: grid; gap: 4px; }
.bar-row {
  display: grid; grid-template-columns: minmax(96px, 36%) 1fr; align-items: center; gap: 10px;
  min-height: 24px; border-radius: 6px; padding: 0 4px; outline: none;
}
.bar-row:hover, .bar-row:focus-visible { background: var(--surface-2); }
.bar-row .bar-label { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-area { position: relative; padding-right: 58px; height: 16px; }
.bar-row .bar-inner { position: relative; height: 100%; }
.bar-row .bar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 0 4px 4px 0; }
.bar-row .bar-value {
  position: absolute; top: 50%; transform: translateY(-50%); font-size: 12.5px; color: var(--ink);
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
.bars-foot { font-size: 12px; color: var(--muted); margin-top: 6px; }

.stack-row { grid-template-columns: minmax(96px, 30%) 1fr 48px; }
.stack-row .stack { display: flex; gap: 2px; height: 14px; }
.stack-row .seg { height: 100%; min-width: 0; }
.stack-row .seg:last-child { border-radius: 0 4px 4px 0; }
.stack-row .stack-total { font-size: 12.5px; text-align: right; font-variant-numeric: tabular-nums; }
.bar-row.emph { background: var(--surface-2); }
.bar-row.emph .bar-label { color: var(--ink); font-weight: 650; }
.bar-row.ref .bar-label { font-style: italic; }
.legend .rect-key { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

/* ---------- stat tiles ---------- */

.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr)); margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 26px; font-weight: 650; margin-top: 2px; letter-spacing: -0.01em; }
.tile .value .unit { font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 2px; }
.tile .meta { font-size: 12px; color: var(--muted); }
.tile .delta { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }
.tile svg { display: block; width: 100%; height: 34px; margin-top: 6px; }
.spark-line { fill: none; stroke: var(--axis); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.spark-dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

/* ---------- sources ---------- */

.sources-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.sources-list li { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; }
.status-ok { color: var(--ok-ink); }
.status-err { color: var(--error-ink); }

.site-footer { border-top: 1px solid var(--border); padding-top: 16px; padding-bottom: 32px; font-size: 12.5px; color: var(--muted); }

.loading { opacity: 0.6; }

@media (max-width: 640px) {
  .site-header h1 { font-size: 22px; }
  .tile .value { font-size: 22px; }
  .filters { position: static; }
}
