/* Lao Kip & Gold - app styles. Mobile first: base styles are for phones, wider screens at the bottom.
   Dark theme is the default; html[data-theme="light"] switches to light. */

/* ---------- Colours: dark (default) ---------- */
:root {
  color-scheme: dark;
  --page: #0f1115;
  --sidebar: #12151b;
  --surface: #171a21;
  --surface-2: #1f232c;
  --text: #f2f3f5;
  --text-2: #c3c6cf;
  --muted: #8b909c;
  --grid: #262a33;
  --axis: #3a3f4a;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --accent: #e0b43c; /* gold - brand + active menu only */
  --accent-soft: rgba(224, 180, 60, 0.12);
  /* One colour per KIND of number - same in cards and charts */
  --kind-official: #3987e5; /* blue   = BOL / official statistics */
  --kind-market: #d95926; /* orange = market */
  --kind-reference: var(--kind-market); /* a reference mid rate from a general API: not official, not a quote in Laos - same orange in every theme */
  --kind-estimated: #199e70; /* aqua   = our estimate */
  --kind-shop: #9085e9; /* violet = shop price typed in by owner */
  --kind-bank: #d85fae; /* pink   = commercial bank / bullion bank (LBB, BCEL) - validated for colour-blind separation */
  /* Categorical line colours for charts where every line is the same kind (Cost of living page) */
  --cat-1: #3987e5;
  --cat-2: #e0609a;
  --cat-3: #d95926;
  --cat-4: #1baf7a;
  --cat-5: #9085e9;
  --ok: #12ad12; /* 4.8:1 on its own tint (was 4.4) */
  --ok-bg: rgba(18, 173, 18, 0.14);
  --warn-text: #fab219;
  --warn-bg: rgba(250, 178, 25, 0.13);
  --bad-text: #ff7b72;
  --bad-bg: rgba(208, 59, 59, 0.18);
  --sidebar-w: 248px;
  /* Up / down / flat - numbers, arrows and % pills only (never series lines). Always shown WITH the arrow */
  --up: #22c55e;
  --up-bg: rgba(34, 197, 94, 0.14);
  --down: #f0616d;
  --down-bg: rgba(240, 97, 109, 0.14);
  --flat: #9398a4; /* 4.9:1 on its own tint (was 4.5) */
  --flat-bg: rgba(147, 152, 164, 0.14);
  /* Type scale, spacing and radius - one set for the whole site */
  --fs-sm: 0.8rem; /* the smallest size of a sentence: notes, sources, dates (audit P3-1). Only short labels - pills, chips, table heads, units - are smaller (the list: scripts/lint.js SMALL_OK) */
  --fs-lg: 1.05rem;
  --fs-xl: 1.35rem;
  --fs-2xl: 1.7rem;
  --radius-sm: 8px;
  --radius-md: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  --ease: 150ms ease;
  --nav-h: 0px; /* height of the phone bottom bar (set below on phones) */
  --on-accent: #0b0b0b; /* text on the gold accent button */
}

/* ---------- Colours: light ---------- */
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f6f6f4;
  --sidebar: #ffffff;
  --surface: #fcfcfb;
  --surface-2: #ffffff;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6b6964; /* 5.1:1 on the page, 5.3:1 on a card (the lighter grey before: 4.1 and 4.3 - audit P3-1) */
  --grid: #e8e7e1;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #9a6b00;
  --accent-soft: rgba(154, 107, 0, 0.1);
  --kind-official: #2a78d6;
  --kind-market: #eb6834;
  --kind-estimated: #1baf7a;
  --kind-shop: #4a3aa7;
  --kind-bank: #c2336f;
  --cat-1: #2a78d6;
  --cat-2: #c2336f;
  --cat-3: #eb6834;
  --cat-4: #13875c;
  --cat-5: #4a3aa7;
  --ok: #006300;
  --ok-bg: rgba(12, 163, 12, 0.12);
  --warn-text: #7a5200;
  --warn-bg: #fff1cc;
  --bad-text: #b42323;
  --bad-bg: #fde4e4;
  --up: #067a3b;
  --up-bg: rgba(6, 122, 59, 0.1);
  --down: #c9302c;
  --down-bg: rgba(201, 48, 44, 0.09);
  --flat: #6b6964;
  --flat-bg: rgba(107, 105, 100, 0.1);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.06);
  --on-accent: #ffffff;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  /* Inter for Latin letters and digits (finance standard), Noto for Thai / Lao script */
  font-family: "Inter", "Noto Sans Thai", "Noto Sans Lao", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
p { margin: 0; }
.muted { color: var(--muted); }
button {
  font: inherit; font-size: 0.88rem; padding: 6px 12px; min-height: 36px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text); cursor: pointer; white-space: nowrap;
  transition: border-color var(--ease), background-color var(--ease), color var(--ease);
}
button:hover { border-color: var(--muted); }
button:focus-visible, a:focus-visible, summary:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { display: inline-flex; flex: none; }

/* ---------- App layout ---------- */
.app { min-height: 100vh; }
.main { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; }

/* Sidebar: off-canvas on phones */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(288px, 84vw); /* wide screens: var(--sidebar-w), see below */
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px;
  transform: translateX(-100%); transition: transform 0.2s ease; overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.backdrop { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.backdrop.show { opacity: 1; pointer-events: auto; }
@media (prefers-reduced-motion: reduce) { .sidebar, .backdrop { transition: none; } }

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; font-weight: 600; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 1.1rem; font-weight: 700;
}
.brand-text { font-size: 0.95rem; line-height: 1.2; flex: 1 1 auto; min-width: 0; }
.menu-close { flex: none; margin: -4px -4px -4px 0; } /* phones only: closes the slide-in menu */
.nav-group { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 14px 10px 6px; }
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-link {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin: 2px 0;
  border-radius: 8px; text-decoration: none; color: var(--text-2); font-size: 0.92rem;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.nav-link[aria-current="page"]::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav-link[aria-current="page"] .icon { color: var(--accent); }
.sidebar-foot { margin-top: auto; padding: 16px 4px 0; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.1rem; flex: 1 1 auto; min-width: 0; }
.topbar-updated { font-size: var(--fs-sm); color: var(--muted); text-align: right; }
/* "offline": the numbers are the copy saved on this device (sw.js). On its own line above the time, so the
   page title keeps its room on a phone. */
.offline-chip {
  display: block; width: max-content; margin: 0 0 2px auto; padding: 0 7px; border-radius: 999px; font-weight: 600;
  white-space: nowrap; line-height: 1.45; background: var(--warn-bg); color: var(--warn-text);
}
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0; }

.view { width: 100%; max-width: 1280px; margin: 0 auto; padding: 16px; outline: none; flex: 1 0 auto; }
/* Page change: short fade-in (switched off for people who ask for reduced motion) */
.view.enter { animation: view-in 180ms ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .view.enter { animation: none; } }
.site-footer { max-width: 1280px; width: 100%; margin: 0 auto; padding: 12px 16px calc(24px + var(--nav-h)); font-size: var(--fs-sm); color: var(--muted); }

/* ---------- Common pieces ---------- */
.section-title { font-size: 1rem; font-weight: 600; margin: 24px 0 10px; }
.section-title:first-child { margin-top: 0; }
.lead { color: var(--text-2); font-size: 0.9rem; margin-bottom: 12px; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.filters label { font-size: 0.82rem; color: var(--text-2); }
.stack > .filters { margin-bottom: 0; } /* inside a column the gap of the stack is the space above the chart */
select {
  font: inherit; font-size: 0.88rem; min-height: 36px; padding: 4px 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
}
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; background: transparent; min-width: 58px; }
.segmented button + button { border-left: 1px solid var(--border-strong); }
.segmented button[aria-pressed="true"] { background: var(--text); color: var(--page); font-weight: 600; }
.segmented.small button { min-height: 32px; font-size: 0.82rem; min-width: 0; flex: 1; }
.segmented.small { display: flex; }

.grid { display: grid; grid-template-columns: 1fr; gap: 12px; align-items: start; } /* start = cards keep their own height */
.stack { display: grid; gap: 12px; align-content: start; min-width: 0; } /* cards stacked inside one grid column */

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 14px 16px; min-width: 0; position: relative; box-shadow: var(--shadow);
  transition: border-color var(--ease);
}
.card:hover { border-color: var(--border-strong); }
.card[data-kind]::before {
  content: ""; position: absolute; left: 14px; right: 14px; top: 0; height: 2px; border-radius: 0 0 2px 2px; background: var(--kind-color);
}
[data-kind="official"] { --kind-color: var(--kind-official); }
[data-kind="market"] { --kind-color: var(--kind-market); }
[data-kind="reference"] { --kind-color: var(--kind-reference); }
[data-kind="estimated"] { --kind-color: var(--kind-estimated); }
[data-kind="shop"] { --kind-color: var(--kind-shop); }
[data-kind="own"] { --kind-color: var(--kind-shop); } /* typed in by the owner about his own sales (same violet as shop prices) */
[data-kind="bank"] { --kind-color: var(--kind-bank); }

.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 6px; }
.card-head h3 { font-size: 0.93rem; font-weight: 600; flex: 1 1 auto; min-width: 0; }

/* Kind chip: coloured dot + text in normal ink (text never wears the data colour) */
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 0.7rem; font-weight: 600;
  padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-2); white-space: nowrap;
}
.chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--kind-color); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; font-weight: 600; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-bad { background: var(--bad-bg); color: var(--bad-text); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 7px 0; border-top: 1px solid var(--grid); }
.card-head + .row { border-top: 0; }
.row-label { color: var(--text-2); font-size: 0.86rem; }
.row-right { text-align: right; min-width: 0; }
.value { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -0.01em; white-space: nowrap; }
.value .unit { font-size: 0.72rem; font-weight: 400; color: var(--muted); margin-left: 3px; }
.change { font-size: var(--fs-sm); color: var(--text-2); white-space: nowrap; display: flex; align-items: center; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.change .vs { color: var(--muted); }
/* Up / down pill: green = up, red = down, grey = flat - the arrow always goes with the colour */
.delta {
  display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.5;
}
.delta.up { color: var(--up); background: var(--up-bg); }
.delta.down { color: var(--down); background: var(--down-bg); }
.delta.flat { color: var(--flat); background: var(--flat-bg); }
.delta.plain { background: transparent; padding: 0; }
.change.wrap { white-space: normal; }
.note { font-size: var(--fs-sm); color: var(--muted); margin-top: 6px; }
.card-foot { font-size: var(--fs-sm); color: var(--muted); margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--grid); }
.card-link { display: inline-block; margin-top: 8px; font-size: 0.82rem; color: var(--text-2); }

/* Stat tiles */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 14px 16px; min-width: 0; box-shadow: var(--shadow); }
.stat[data-kind] { border-left: 3px solid var(--kind-color); }
.stat-label { font-size: var(--fs-sm); color: var(--text-2); }
.stat-value { font-size: var(--fs-2xl); font-weight: 650; letter-spacing: -0.02em; line-height: 1.2; margin-top: 2px; }
.stat-unit { font-size: var(--fs-sm); font-weight: 500; letter-spacing: 0; color: var(--text-2); margin-left: 5px; white-space: nowrap; }
.stat-sub { font-size: var(--fs-sm); color: var(--muted); margin-top: 2px; }
.stat-sub .delta { white-space: normal; } /* a pill with words ("+96% from 2024") may wrap inside a narrow tile */

/* Direction hint */
.hint-card { display: grid; gap: 10px; align-content: start; }
.hint-row { display: flex; align-items: center; gap: 12px; }
.hint-arrow {
  width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; flex: none;
  font-size: 1.3rem; background: var(--surface-2); border: 1px solid var(--border-strong);
}
.hint-arrow.up, .dir-up { color: var(--up); }
.hint-arrow.down, .dir-down { color: var(--down); }
.hint-arrow.flat, .dir-flat { color: var(--flat); }
.hint-text strong { display: block; font-size: 0.95rem; }
.hint-text span { font-size: var(--fs-sm); color: var(--text-2); }

/* Alerts & empty states */
.alert { display: flex; gap: 8px; align-items: flex-start; background: var(--warn-bg); color: var(--warn-text); border-radius: 10px; padding: 10px 12px; font-size: 0.85rem; margin-bottom: 12px; }
.alert a { color: inherit; font-weight: 600; }
.empty { border: 1px dashed var(--border-strong); border-radius: 12px; padding: 16px; color: var(--text-2); font-size: 0.86rem; }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }
.empty p + p { margin-top: 6px; }
ol.steps { margin: 8px 0 0; padding-left: 20px; font-size: 0.86rem; color: var(--text-2); }
ol.steps li { margin: 3px 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 6px; text-align: right; border-top: 1px solid var(--grid); white-space: nowrap; }
th { font-weight: 600; color: var(--muted); font-size: 0.72rem; letter-spacing: 0.02em; border-top: 0; border-bottom: 1px solid var(--grid); }
/* Long tables: fixed height with the header row staying visible */
.table-wrap.scroll-y { max-height: 420px; overflow-y: auto; }
.table-wrap.scroll-y.tall { max-height: 620px; } /* a table of a dozen years is shown whole, without a second scroll bar */
@media (min-width: 421px) { .table-wrap.scroll-y { padding-right: 8px; } } /* room next to the scroll bar (a phone needs the full width for 5 columns, and its scroll bar hides itself) */
.table-wrap.scroll-y thead { position: sticky; top: 0; z-index: 1; }
.table-wrap.scroll-y thead th { background: var(--surface); white-space: normal; vertical-align: bottom; } /* long series names wrap instead of widening the table */
/* First header line of a chart's table: what the numbers are + their unit (stays visible while scrolling) */
th.table-cap { text-align: left; border-bottom: 0; padding-bottom: 2px; font-size: var(--fs-sm); letter-spacing: 0; line-height: 1.35; }
th.table-cap strong { display: block; color: var(--text); font-weight: 600; }
th.table-cap span { display: block; color: var(--text-2); font-weight: 500; }
td.soft { color: var(--text-2); } /* forecast / target: not a measured number */
th:first-child, td:first-child { text-align: left; }
td .sub { color: var(--muted); font-size: 0.74rem; margin-left: 4px; }
tr.clickable { cursor: pointer; }
tbody tr td { transition: background-color var(--ease); }
tbody tr:hover td { background: var(--surface-2); }
tr.clickable:hover td { background: var(--surface-2); }
tr[aria-selected="true"] td { background: var(--accent-soft); }
tr[aria-selected="true"] td .sub, tr[aria-selected="true"] td .sub-line { color: var(--text-2); } /* the grey is too weak on the tint (4.3:1) */
/* Horizontal bar inside a table cell (inflation by category). Length is measured from 0. */
.bar-cell { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.bar-track { width: 90px; height: 8px; border-radius: 4px; background: var(--grid); flex: none; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--kind-official); }
.neg-text { color: var(--bad-text); }
/* Tables with long first-column names (Cost of living page): let the name wrap so the numbers fit a phone */
.wrap-first td:first-child { white-space: normal; min-width: 6.5em; }
.wrap-first th { white-space: normal; vertical-align: bottom; }
.wrap-all th, .wrap-all td { white-space: normal; }
.wrap-first td .sub-line { display: block; color: var(--muted); font-size: var(--fs-sm); }
@media (max-width: 480px) {
  .bar-track { width: 44px; }
  .wrap-first th, .wrap-first td { padding-left: 4px; padding-right: 4px; }
  .wrap-first table { font-size: 0.8rem; }
  /* Phones: headers may wrap and pills inside tables get slimmer (Lao words are long) */
  th { white-space: normal; vertical-align: bottom; }
  td .delta { padding: 0 4px; font-size: 0.7rem; }
  .table-wrap td, .table-wrap th { padding-left: 4px; padding-right: 4px; }
}
.ok-text { color: var(--ok); font-weight: 600; }
.bad-text { color: var(--bad-text); font-weight: 600; }

/* ---------- Charts ---------- */
.chart-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.chart-card h3 { font-size: 0.92rem; font-weight: 600; flex: 1 1 auto; min-width: 0; }
.chart-head .delta, .card-head .delta { flex: none; } /* the pill never shrinks: it moves to the next line instead */
.chart-sub { font-size: var(--fs-sm); color: var(--muted); margin-top: 2px; }
.chart-box { position: relative; height: 230px; margin-top: 6px; } /* includes the axis labels */
.chart-box canvas { touch-action: pan-y; } /* a finger moving sideways reads the chart; up / down still scrolls the page */
/* Read-out above the plot: latest values, or the values of the touched point. It is also the legend. */
.readout { margin-top: 8px; font-size: var(--fs-sm); }
.readout-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 10px; font-size: var(--fs-sm); color: var(--muted); padding-bottom: 2px; border-bottom: 1px solid var(--grid); margin-bottom: 2px; }
.readout-when { color: var(--text); font-weight: 600; }
.readout-row {
  display: flex; align-items: baseline; gap: 8px; width: 100%; min-height: 0; padding: 4px 0; border: 0; border-radius: 0;
  background: none; color: inherit; font: inherit; text-align: left; white-space: normal;
}
button.readout-row { cursor: pointer; }
button.readout-row:hover .readout-label { color: var(--text); }
.readout-key { flex: none; width: 16px; height: 0; border-top: 2px solid; align-self: center; }
.readout-key.dashed { border-top-style: dashed; }
.readout-label { flex: 1 1 auto; min-width: 0; color: var(--text-2); }
.readout-at { color: var(--muted); white-space: nowrap; }
.readout-value { flex: none; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--text); }
.readout-since { flex: none; min-width: 6.2em; text-align: right; font-size: 0.74rem; }
.readout-peak { font-size: var(--fs-sm); color: var(--muted); padding-top: 3px; margin-top: 2px; border-top: 1px dashed var(--grid); }
.readout-row[aria-pressed="false"] { opacity: 0.45; }
.readout-row[aria-pressed="false"] .readout-label { text-decoration: line-through; }
@media (min-width: 900px) { .chart-box { height: 280px; } }
.chart-empty { display: flex; align-items: center; justify-content: center; text-align: center; height: 100%; padding: 0 16px; color: var(--muted); font-size: 0.84rem; }
details { margin-top: 8px; font-size: 0.8rem; }
summary { cursor: pointer; color: var(--text-2); }
details table { margin-top: 6px; }

/* Settings */
.setting-row { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; border-top: 1px solid var(--grid); }
.card-head + .setting-row { border-top: 0; }
.setting-row span { color: var(--text-2); font-size: 0.9rem; }
.status-list { list-style: none; margin: 0; padding: 0; }
.status-item { padding: 10px 0; border-top: 1px solid var(--grid); }
.status-item:first-child { border-top: 0; padding-top: 0; }
.status-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; font-size: 0.88rem; }
.status-top > div, .status-top > strong { min-width: 0; overflow-wrap: anywhere; }
.status-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin-top: 4px; font-size: var(--fs-sm); color: var(--muted); }
.card > h3 { font-size: 0.92rem; font-weight: 600; margin-bottom: 8px; }
.error-text { color: var(--bad-text); font-size: var(--fs-sm); white-space: normal; overflow-wrap: anywhere; } /* a failed download names its address: one long word */
/* Settings: the full list of sources - one group per data file, opened by a tap; its state shows without opening */
.src-summary { margin: 0 0 6px; font-size: 0.86rem; color: var(--text-2); }
.src-group { margin-top: 0; border-top: 1px solid var(--grid); font-size: 0.86rem; }
.src-group > summary { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 0; color: var(--text); list-style: none; }
.src-group > summary::-webkit-details-marker { display: none; }
.src-group > summary::before { content: "▸"; color: var(--muted); flex: none; }
.src-group[open] > summary::before { content: "▾"; }
.src-group > summary .badge { flex: none; }
.src-group-title { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.src-group-count { display: block; font-size: var(--fs-sm); color: var(--muted); }
.src-list { list-style: none; margin: 0 0 10px; padding: 0 0 0 18px; }
.src-item { padding: 6px 0; border-top: 1px dashed var(--grid); }
.src-item:first-child { border-top: 0; }
.src-name, .src-meta { overflow-wrap: anywhere; }
.src-meta { font-size: var(--fs-sm); color: var(--muted); }
.status-route { color: var(--text-2); font-size: var(--fs-sm); font-weight: 400; margin-top: 2px; }

/* Link or label that looks like a button */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 0.88rem; padding: 6px 14px; min-height: 40px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text);
  text-decoration: none; cursor: pointer; white-space: nowrap; transition: border-color var(--ease), background-color var(--ease);
}
.btn:hover { border-color: var(--muted); }
.btn-primary, button.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; min-height: 40px; }
button.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- Gold page: save a shop price from a picture ---------- */
.upload-card { margin-bottom: 12px; }
.install-card { margin-top: 12px; } /* Settings: the card under the two-column grid */
.up-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.up-panel { display: grid; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--grid); }
.up-progress { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.up-progress > span { display: block; height: 100%; background: var(--accent); transition: width 0.2s; }
.up-progress-label { font-size: var(--fs-sm); color: var(--text-2); }
.up-preview { max-width: 100%; max-height: 300px; object-fit: contain; border-radius: var(--radius-sm); border: 1px solid var(--border); justify-self: center; }
.up-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.up-field { display: grid; gap: 4px; font-size: var(--fs-sm); color: var(--text-2); min-width: 0; }
.up-field select { min-height: 44px; width: 100%; min-width: 0; font-size: 0.95rem; font-weight: 600; }
.up-field input {
  font: inherit; font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; min-height: 44px; padding: 6px 10px; width: 100%; min-width: 0;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); color-scheme: inherit;
}
.up-field input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.up-actions [hidden] { display: none; }
.up-key { margin-top: 12px; }
.up-key .up-field { max-width: 340px; }
.up-key-forget { min-height: 32px; padding: 2px 10px; font-size: var(--fs-sm); }
.up-date { grid-column: 1 / -1; }
.up-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; font-size: var(--fs-sm); }
.up-check.ok { color: var(--up); }
.up-check.warn { color: var(--warn-text); }
.up-check.bad { color: var(--down); }
.up-subtitle { font-size: 0.88rem; font-weight: 600; }
.up-analysis .row:first-child { border-top: 0; }
.up-save-status { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.up-save-status.ok { color: var(--up); }
.up-save-status.warn { color: var(--warn-text); }

/* ---------- Cost of living v2: facts, budget ---------- */
.facts-card { margin-bottom: 12px; }
.facts { list-style: none; margin: 0; padding: 0; }
.facts li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0;
  border-top: 1px solid var(--grid); font-size: 0.86rem; color: var(--text);
}
.facts li:first-child { border-top: 0; }
.facts li > span:first-child { min-width: 0; }
.facts li .delta { flex: none; }
.budget-card { margin-top: 2px; }
.budget-inputs { margin: 10px 0 6px; }
.segmented.small-seg { display: flex; }
.segmented.small-seg button { flex: 1; min-width: 0; min-height: 44px; }
.budget-table th, .budget-table td { padding: 6px 3px; vertical-align: middle; }
.budget-table td:first-child { min-width: 5.4em; }
.budget-table td .sub-line { display: block; color: var(--muted); font-size: var(--fs-sm); }
/* 16px text: phones do not zoom in when the box is tapped */
.qty-input {
  font: inherit; font-size: 16px; font-variant-numeric: tabular-nums; width: 3.1em; min-height: 34px; padding: 4px 5px; text-align: right;
  border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); color-scheme: inherit;
}
.qty-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* no up/down arrows inside the small box (they hide the number on computers) */
.qty-input { -moz-appearance: textfield; appearance: textfield; }
.qty-input::-webkit-outer-spin-button, .qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.budget-body { display: grid; gap: 4px; }
@media (min-width: 1100px) {
  .budget-body { grid-template-columns: minmax(0, 3fr) minmax(260px, 2fr); gap: 28px; align-items: start; }
  .budget-side .budget-summary { margin-top: 0; }
}
.total-row td { font-weight: 650; border-top: 2px solid var(--border-strong); white-space: normal; }
.budget-summary { margin-top: 8px; }
.value.small-value { font-size: var(--fs-lg); }
@media (max-width: 420px) {
  .budget-table table { font-size: 0.8rem; }
  /* "show as table" under charts: smaller, and the date column may wrap, so 4-5 columns fit a phone */
  .table-wrap.scroll-y table { font-size: 0.76rem; }
  .table-wrap.scroll-y th, .table-wrap.scroll-y td { padding: 6px 3px; }
  .table-wrap.scroll-y td:first-child { white-space: normal; }
  .table-wrap.scroll-y table.few-cols td:first-child { white-space: nowrap; }
}
@media (min-width: 640px) { .budget-inputs { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ---------- Economy page: tabs, "latest or old", target status ---------- */
.tabbar {
  display: flex; gap: 6px; overflow-x: auto; margin: 2px 0 14px; padding: 2px 0 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
}
.tabbar::-webkit-scrollbar { display: none; }
.tabbar button {
  flex: none; scroll-snap-align: start; border-radius: 999px; padding: 6px 14px; min-height: 36px; font-size: 0.86rem;
  background: var(--surface); color: var(--text-2);
}
.tabbar button[aria-selected="true"] { background: var(--text); border-color: var(--text); color: var(--page); font-weight: 600; }
.tabpanel { display: grid; gap: 12px; }
/* Above the tab bar: a search box over the names of tabs, cards and tiles, and the index of all tabs (audit P3-2).
   16px text in the box: phones do not zoom in when it is tapped. */
.tab-find { display: flex; gap: 8px; margin: 2px 0 8px; }
.tab-search {
  flex: 1 1 auto; min-width: 0; font: inherit; font-size: 16px; min-height: 40px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); color-scheme: inherit;
}
.tab-search::placeholder { color: var(--muted); opacity: 1; }
.tab-search:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tab-index-btn { flex: none; border-radius: 999px; min-height: 40px; }
.tab-index-btn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent); font-weight: 600; }
.tab-index { margin: 0 0 10px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.tab-index[hidden] { display: none; }
.tab-index-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.tab-index-item {
  display: block; width: 100%; min-height: 44px; padding: 8px 10px; border: 0; border-radius: var(--radius-sm);
  background: none; text-align: left; white-space: normal;
}
.tab-index-item:hover { background: var(--surface-2); }
.tab-index-item[aria-current="true"] { background: var(--accent-soft); }
.tab-index-item[aria-current="true"] .tab-index-sub { color: var(--text-2); } /* the grey is too weak on the tint */
.tab-index-item strong { display: block; font-size: 0.9rem; font-weight: 600; overflow-wrap: anywhere; }
.tab-index-sub { display: block; font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.tab-index-count { padding: 4px 10px 6px; font-size: var(--fs-sm); color: var(--text-2); }
.found { outline: 2px solid var(--accent); outline-offset: 2px; } /* the card the search led to, for a moment */
@media (min-width: 640px) { .tab-index-list.as-index { grid-template-columns: 1fr 1fr; } }
/* Choices inside a tab (view, year, form of rubber, road class): pills that wrap; the main one scrolls sideways */
.choice { display: flex; flex-wrap: wrap; gap: 6px; }
.choice button { border-radius: 999px; padding: 4px 12px; min-height: 34px; font-size: 0.8rem; background: var(--surface-2); color: var(--text-2); white-space: normal; text-align: left; }
.choice button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600; }
.choice-main { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.choice-main::-webkit-scrollbar { display: none; }
.choice-main button { flex: none; white-space: nowrap; min-height: 38px; font-size: 0.84rem; }
.choices { display: grid; gap: 8px; margin: 8px 0 4px; }
.choice-row { display: grid; gap: 4px; }
.choice-label { font-size: 0.72rem; color: var(--muted); }
.card > .choice { margin: 8px 0 4px; }
/* The last row of these tables is a total */
.total-last tbody tr:last-child td { font-weight: 650; border-top: 2px solid var(--border-strong); }
.bar-track.no-bar { background: transparent; }
.focus-name { font-weight: 650; }
.tabpanel > .section-title { margin: 12px 0 0; }
.tabpanel > .facts-card { margin-bottom: 0; }
.tab-intro { font-size: 0.84rem; }
.cmp-year { white-space: nowrap; }
.cmp-year-off { color: var(--warn-text); font-weight: 600; } /* a number from another year than the card's: marked, never silent */
.stats-foot { margin: 8px 2px 0; } /* note + sources under a row of tiles that is not inside a card */
.stats-foot .card-foot { border-top: 0; margin-top: 2px; padding-top: 0; }
.fresh { display: inline-flex; flex-wrap: wrap; gap: 2px 6px; font-size: var(--fs-sm); color: var(--muted); margin-top: 4px; }
.stat .fresh { display: flex; }
td:not(:first-child) .fresh { justify-content: flex-end; } /* the numbers of a table stand at the right: a date that wraps does too */
.fresh-ok { color: var(--text-2); }
.fresh-old { color: var(--warn-text); font-weight: 600; }
.fresh-behind { color: var(--warn-text); } /* the newest the source has, but months behind today */
.differ-topic { margin: 14px 0 6px; font-size: 0.88rem; font-weight: 650; color: var(--text); }
.differ-card .watch-list { font-size: 0.82rem; }
.fresh-stale { color: var(--bad-text); font-weight: 600; }
.status { display: inline-block; font-size: 0.72rem; font-weight: 600; border-radius: 999px; padding: 1px 8px; margin-top: 4px; white-space: nowrap; }
.status-met { color: var(--up); background: var(--up-bg); }
.status-near { color: var(--warn-text); background: var(--warn-bg); }
.status-far { color: var(--bad-text); background: var(--bad-bg); }
.status-none, .status-baseline, .status-old, .status-split { color: var(--flat); background: var(--flat-bg); } /* no judgement: neutral */
.plan-actual .status + .plan-value { margin-top: 8px; } /* the same thing counted a second way, in the same cell */
.facts li .status { flex: none; margin-top: 0; }
.plan-table td { vertical-align: top; }
/* Land tab: province | date of the newest decision (+ "older than 3 years") | link. The middle column may wrap. */
.land-table td:nth-child(2), .land-table th:nth-child(2) { white-space: normal; overflow-wrap: anywhere; }
.land-table td:nth-child(2) .fresh-old { white-space: nowrap; }
/* Rubber prices of every country (country + kind | local price | USD | date): on a phone the local price may wrap
   between the number and its unit ("19,710 / yuan a tonne"); a date stays in one piece. */
.prices-table td:nth-child(2) { white-space: normal; }
.nobr { white-space: nowrap; } /* a number, or a unit: never cut in two */
.plan-table td .sub-line { display: block; color: var(--muted); font-size: var(--fs-sm); margin-top: 2px; }
.plan-actual .fresh { margin-top: 0; }
.plan-table td:nth-child(2) { min-width: 4.6em; }
.plan-actual { text-align: right; }
.plan-value { font-weight: 650; }
.plan-actual .sub-line { display: block; color: var(--muted); font-size: var(--fs-sm); }
.watch-list { margin: 0; padding-left: 1.1em; display: grid; gap: 6px; font-size: 0.86rem; color: var(--text); }
.watch-links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.watch-links .btn { min-height: 36px; font-size: 0.82rem; }
.disclaimer { margin-top: 16px; }

/* Population tab - age pyramid: men to the left, women to the right, bars grow from the middle.
   Bar length = people, measured from 0, the same scale on both sides. */
.pyramid { display: grid; gap: 3px; margin-top: 8px; font-size: 0.74rem; }
.pyr-row { display: grid; grid-template-columns: minmax(0, 1fr) 3.6em minmax(0, 1fr); align-items: center; gap: 6px; }
.pyr-side { display: flex; align-items: center; gap: 6px; min-width: 0; }
.pyr-left { justify-content: flex-end; }
.pyr-track { flex: 1 1 auto; min-width: 0; display: flex; }
.pyr-left .pyr-track { justify-content: flex-end; }
.pyr-bar { height: 12px; min-width: 1px; }
.pyr-men { background: var(--cat-1); border-radius: 4px 0 0 4px; }
.pyr-women { background: var(--cat-2); border-radius: 0 4px 4px 0; }
.pyr-num { flex: none; width: 2.4em; color: var(--text-2); font-variant-numeric: tabular-nums; }
.pyr-left .pyr-num { text-align: right; }
.pyr-age { text-align: center; color: var(--text-2); white-space: nowrap; font-variant-numeric: tabular-nums; }
.pyr-head { color: var(--muted); padding-bottom: 2px; }
.pyr-head .pyr-age { color: var(--muted); }
.pyr-key { flex: none; width: 10px; height: 10px; border-radius: 2px; }

/* Policy tab */
.policy-affects { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 2px 0 10px; font-size: 0.74rem; }
.policy-affects-label { color: var(--muted); }
.tag { padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border-strong); color: var(--text-2); white-space: nowrap; }
/* a sentence that comes from a file which updates itself (not typed in by hand) */
.tag-auto { font-size: 0.68rem; padding: 0 7px; border-color: var(--kind-official); }
.policy-read { margin-bottom: 14px; }
.policy-card { display: flex; flex-direction: column; }
.policy-card .watch-links { margin-top: auto; padding-top: 12px; }
.policy-list li { line-height: 1.5; overflow-wrap: anywhere; }
.calendar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; font-size: 0.86rem; }
.calendar-list li { display: grid; grid-template-columns: 6.4em minmax(0, 1fr); gap: 10px; align-items: baseline; }
.cal-when { font-weight: 650; font-variant-numeric: tabular-nums; }
.cal-what { overflow-wrap: anywhere; }
.calendar-list li.past { color: var(--muted); }

/* Official fuel prices (cost-of-living page) and the wages tab */
.fuel-notice { margin: 0 0 8px; overflow-wrap: anywhere; }
.fuel-notice a { color: inherit; font-weight: 600; }
.fuel-provinces { margin: 10px 0 2px; }
.source-list { margin: 6px 0 0; padding-left: 1.1em; display: grid; gap: 4px; font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.wage-table td .sub-line { overflow-wrap: anywhere; }
.wage-table th:last-child { white-space: nowrap; }

/* Loading placeholder (instead of an empty page) */
.skeleton { display: grid; gap: 12px; }
.skeleton div {
  height: 96px; border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton div { animation: none; } }

/* Phone bottom tab bar (like finance apps). Hidden on wide screens, where the sidebar is always visible */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--sidebar) 92%, transparent); backdrop-filter: blur(10px);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; min-width: 0;
  font-size: 0.66rem; color: var(--muted); text-decoration: none; transition: color var(--ease);
}
.bottom-nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.bottom-nav a > span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
@media (max-width: 899px) { :root { --nav-h: 60px; } .app { padding-bottom: var(--nav-h); } }
@media (min-width: 900px) { .bottom-nav { display: none; } }

/* ---------- Wider screens ---------- */
@media (min-width: 640px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .view { padding: 20px 24px; }
}
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .sidebar { position: sticky; top: 0; height: 100vh; transform: none; width: var(--sidebar-w); }
  .backdrop, .menu-close { display: none; }
  .topbar { padding: 12px 24px; }
}
@media (min-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr 1fr; }
}
