/* World Economy Data Warehouse — stylesheet.
   Served as a first-party file so the CSP can be style-src 'self' with no
   'unsafe-inline'. Palette values come from a validated categorical set:
   all six slots pass the adjacent-pair CVD and normal-vision gates in both
   light and dark mode (compare allows up to six series); the first three also
   clear the stricter all-pairs gate used by the scatter view. Aqua, yellow and
   magenta sit below 3:1 on the light surface, so every chart using them also
   ships direct labels and a table view (the relief rule). */

:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, .10);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #4a3aa7;
  --neutral-mark: #b9b8b1;
  --accent-soft: #cde2fb;
  --good: #0ca30c;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 1px 3px rgba(11, 11, 11, .04);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, .10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #9085e9;
    --neutral-mark: #55544f;
    --accent-soft: #184f95;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, .10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #9085e9;
  --neutral-mark: #55544f;
  --accent-soft: #184f95;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 3px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }

/* ---------- masthead ---------- */
header.site {
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}
header.site .wrap { padding-top: 22px; padding-bottom: 18px; }
.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.02em; font-weight: 640; }
.brand .tag {
  font-size: .75rem; color: var(--text-secondary); border: 1px solid var(--border);
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.lede { margin: 8px 0 0; color: var(--text-secondary); font-size: .92rem; max-width: 68ch; }

/* ---------- provenance strip ---------- */
.provenance {
  display: flex; flex-wrap: wrap; gap: 6px 22px; margin-top: 14px;
  font-size: .78rem; color: var(--text-muted);
}
.provenance b { font-weight: 600; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ---------- tabs ---------- */
nav.views { border-bottom: 1px solid var(--border); background: var(--surface-1); position: sticky; top: 0; z-index: 20; }
nav.views .wrap { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
nav.views .wrap::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-secondary); font: inherit; font-size: .88rem; padding: 12px 14px;
  cursor: pointer; white-space: nowrap; min-height: 44px;
}
.tab:hover { color: var(--text-primary); }
.tab[aria-selected="true"] { color: var(--text-primary); border-bottom-color: var(--series-1); font-weight: 600; }

/* ---------- filter row (one row, above everything it scopes) ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 14px 18px; align-items: flex-end;
  padding: 16px 0 18px;
}
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 600; }
select, input[type="search"] {
  appearance: none; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 7px; padding: 8px 11px;
  font: inherit; font-size: .88rem; min-height: 38px; max-width: 100%;
}
select { padding-right: 30px; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: right 13px center, right 8px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button {
  appearance: none; background: var(--surface-1); border: 0; border-right: 1px solid var(--border);
  color: var(--text-secondary); font: inherit; font-size: .84rem; padding: 8px 12px;
  cursor: pointer; min-height: 38px;
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--series-1); color: #fff; font-weight: 600; }

/* ---------- cards & grid ---------- */
main { padding-bottom: 56px; }
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 18px 14px; box-shadow: var(--shadow); min-width: 0;
}
.card + .card { margin-top: 18px; }
.card h2 { margin: 0; font-size: 1rem; font-weight: 640; letter-spacing: -.01em; }
.card .sub { margin: 5px 0 0; color: var(--text-secondary); font-size: .82rem; }
.grid2 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); }
.grid3 { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }

/* ---------- KPI / stat tiles ---------- */
.kpis { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); margin-bottom: 18px; }
.kpi { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 15px; box-shadow: var(--shadow); }
.kpi .label { font-size: .76rem; color: var(--text-muted); }
.kpi .value { font-size: 1.6rem; font-weight: 650; letter-spacing: -.02em; margin-top: 3px; }
.kpi .unit { font-size: .74rem; color: var(--text-muted); margin-top: 1px; }
.hero { font-size: 3rem; font-weight: 660; letter-spacing: -.03em; line-height: 1.05; }

/* ---------- chart chrome ---------- */
.chartwrap { margin-top: 12px; position: relative; }
svg.chart { display: block; width: 100%; height: auto; overflow: visible; }
svg.chart text { font: 11px system-ui, -apple-system, "Segoe UI", sans-serif; fill: var(--text-muted); }
svg.chart .tick line { stroke: var(--grid); stroke-width: 1; }
svg.chart .axisline { stroke: var(--axis); stroke-width: 1; }
svg.chart .axlabel { fill: var(--text-secondary); font-size: 11px; }
svg.chart .endlabel { fill: var(--text-secondary); font-size: 11px; font-weight: 600; }
svg.chart .crosshair { stroke: var(--axis); stroke-width: 1; pointer-events: none; }
svg.chart .hit { fill: transparent; cursor: pointer; }
.serieline { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot { stroke: var(--surface-1); stroke-width: 2; }

/* ---------- legend ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 12px; font-size: .82rem; color: var(--text-secondary); }
.legend .item { display: inline-flex; align-items: center; gap: 7px; }
.legend .key { width: 16px; height: 2px; border-radius: 1px; flex: none; }
.legend .key.rect { height: 10px; width: 10px; border-radius: 2px; }

/* ---------- tooltip ---------- */
.tip {
  position: absolute; pointer-events: none; z-index: 30; min-width: 150px; max-width: 280px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .14); padding: 9px 11px; font-size: .8rem;
  opacity: 0; transition: opacity .1s ease;
}
.tip[data-show="1"] { opacity: 1; }
.tip .tiphead { font-weight: 640; color: var(--text-primary); margin-bottom: 5px; font-size: .82rem; }
.tip .row { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.tip .row .key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.tip .row .nm { color: var(--text-secondary); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip .row .val { color: var(--text-primary); font-weight: 650; font-variant-numeric: tabular-nums; }
.tip .miss { color: var(--text-muted); font-style: italic; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: .84rem; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--text-muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .03em; position: sticky; top: 0; background: var(--surface-1); }
tbody td { font-variant-numeric: tabular-nums; color: var(--text-primary); }
tbody tr:hover td { background: color-mix(in srgb, var(--series-1) 6%, transparent); }
td.missing, .missing { color: var(--text-muted); font-style: italic; font-variant-numeric: normal; }
th[aria-sort] { cursor: pointer; }
th[aria-sort="ascending"]::after { content: " ▲"; }
th[aria-sort="descending"]::after { content: " ▼"; }

/* ---------- coverage / method notes ---------- */
.method {
  margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--border);
  font-size: .76rem; color: var(--text-muted); display: flex; flex-wrap: wrap; gap: 4px 16px;
}
.method .cov { font-variant-numeric: tabular-nums; }
.badge {
  display: inline-block; font-size: .7rem; padding: 1px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-secondary); vertical-align: middle;
}
.badge.warn { border-color: color-mix(in srgb, var(--critical) 40%, transparent); color: var(--critical); }

/* ---------- chips (selected entities) ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; font-size: .82rem;
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 7px 5px 10px;
  background: var(--surface-1);
}
.chip .sw { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.chip button {
  appearance: none; border: 0; background: none; color: var(--text-muted);
  cursor: pointer; font: inherit; line-height: 1; padding: 3px 4px; border-radius: 50%;
}
.chip button:hover { color: var(--text-primary); }

.muted { color: var(--text-muted); }
.empty { padding: 26px 0; text-align: center; color: var(--text-muted); font-size: .88rem; }
footer.site { border-top: 1px solid var(--border); background: var(--surface-1); padding: 22px 0; font-size: .8rem; color: var(--text-muted); }
footer.site a { color: var(--text-secondary); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 560px) {
  .hero { font-size: 2.2rem; }
  .card { padding: 15px 14px 12px; }
  .wrap { padding: 0 14px; }
}
