/* Singapore Data — SingStat official statistics portal
   Palette: dataviz reference instance (validated light + dark, 4 categorical slots). */

:root {
  color-scheme: light;
  --page:            #f9f9f7;
  --surface-1:       #fcfcfb;
  --surface-2:       #f2f1ed;
  --text-primary:    #0b0b0b;
  --text-secondary:  #52514e;
  --text-muted:      #898781;
  --grid:            #e1e0d9;
  --axis:            #c3c2b7;
  --border:          rgba(11, 11, 11, 0.10);
  --border-strong:   rgba(11, 11, 11, 0.18);
  --accent:          #2a78d6;
  --good:            #006300;
  --critical:        #d03b3b;

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;

  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, monospace;
  --radius: 10px;
  --maxw: 1240px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --surface-2:      #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.20);
    --accent:         #3987e5;
    --good:           #0ca30c;
    --critical:       #d03b3b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #0d0d0d;
  --surface-1:      #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255, 255, 255, 0.10);
  --border-strong:  rgba(255, 255, 255, 0.20);
  --accent:         #3987e5;
  --good:           #0ca30c;
  --critical:       #d03b3b;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar .wrap { display: flex; align-items: center; gap: 24px; height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -0.01em; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 5px; flex: none;
  background: linear-gradient(135deg, #ed2939 0%, #ed2939 50%, var(--surface-1) 50%);
  border: 1px solid var(--border-strong);
}
.navlinks { display: flex; gap: 20px; margin-left: auto; }
.navlinks a { color: var(--text-secondary); font-size: 14px; }
.navlinks a:hover { color: var(--text-primary); text-decoration: none; }
.theme-toggle {
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-secondary);
  border-radius: 8px; height: 32px; width: 32px; cursor: pointer; font-size: 14px;
  display: grid; place-items: center;
}
.theme-toggle:hover { color: var(--text-primary); border-color: var(--border-strong); }
@media (max-width: 820px) { .navlinks { display: none; } }

/* ---------- hero ---------- */
.hero { padding: 64px 0 40px; border-bottom: 1px solid var(--border); }
.eyebrow {
  font-size: 12px; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--text-muted); font-weight: 600; margin-bottom: 14px;
}
.hero h1 {
  font-size: clamp(32px, 5.2vw, 52px); line-height: 1.06; letter-spacing: -0.028em;
  margin: 0 0 16px; font-weight: 660; max-width: 17ch;
}
.hero p.lede { font-size: 17px; color: var(--text-secondary); max-width: 62ch; margin: 0 0 34px; }

.hero-figure { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.hero-figure .num {
  font-size: clamp(46px, 7vw, 68px); font-weight: 660; letter-spacing: -0.035em; line-height: 1;
}
.hero-figure .cap { color: var(--text-secondary); font-size: 15px; }

.countrow { display: flex; flex-wrap: wrap; gap: 10px 34px; margin-top: 26px; }
.countrow div { display: flex; flex-direction: column; }
.countrow b { font-size: 20px; font-weight: 640; letter-spacing: -0.015em; }
.countrow span { font-size: 12.5px; color: var(--text-muted); }

/* ---------- sections ---------- */
section { padding: 54px 0; border-bottom: 1px solid var(--border); }
section > .wrap > header { margin-bottom: 26px; max-width: 72ch; }
section h2 {
  font-size: 25px; letter-spacing: -0.02em; margin: 0 0 8px; font-weight: 640;
}
section header p { color: var(--text-secondary); margin: 0; font-size: 14.5px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 16px 14px;
}
.tile .label { font-size: 12.5px; color: var(--text-secondary); margin-bottom: 8px; min-height: 2.6em; }
.tile .value { font-size: 30px; font-weight: 650; letter-spacing: -0.028em; line-height: 1.05; }
.tile .unit { font-size: 14px; color: var(--text-muted); font-weight: 500; margin-left: 3px; }
.tile .meta { display: flex; align-items: center; gap: 8px; margin-top: 9px; font-size: 12px; color: var(--text-muted); flex-wrap: wrap; }
.tile .delta { font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.tile .delta.up { color: var(--good); }
.tile .delta.down { color: var(--critical); }
.tile .delta.flat { color: var(--text-muted); }
.tile .spark { margin-top: 10px; display: block; }

/* ---------- chart cards ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(430px, 1fr)); gap: 16px; }
@media (max-width: 720px) { .charts { grid-template-columns: 1fr; } }
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 18px 14px; display: flex; flex-direction: column;
}
.card h3 { margin: 0 0 5px; font-size: 15.5px; font-weight: 620; letter-spacing: -0.012em; }
.card .sub { font-size: 12px; color: var(--text-muted); margin-bottom: 14px; }
.card .sub code { font-family: var(--mono); font-size: 11px; }
.chart-host { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 12px; }
.legend .item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend .key { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.card-foot { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--border); }
.linkbtn {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-size: 12px;
  color: var(--text-secondary); text-decoration: underline; text-underline-offset: 2px;
}
.linkbtn:hover { color: var(--text-primary); }
.card-foot .src { margin-left: auto; font-size: 11.5px; color: var(--text-muted); }

.tableview { display: none; margin-top: 12px; max-height: 300px; overflow: auto; }
.tableview.on { display: block; }
.tableview table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.tableview th, .tableview td { padding: 5px 9px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--border); }
.tableview th:first-child, .tableview td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface-1); }
.tableview thead th { position: sticky; top: 0; background: var(--surface-1); color: var(--text-secondary); font-weight: 600; }

/* tooltip */
.tip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity .09s;
  background: var(--surface-1); border: 1px solid var(--border-strong);
  border-radius: 8px; padding: 9px 11px; font-size: 12px; min-width: 150px;
  box-shadow: 0 6px 22px rgba(0,0,0,.16); z-index: 5;
}
.tip .tt { font-weight: 640; margin-bottom: 6px; font-size: 12px; }
.tip .tr { display: flex; align-items: center; gap: 7px; margin-top: 3px; }
.tip .tr .key { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.tip .tr .nm { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tip .tr .vl { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- explorer ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 14px; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 14px;
}
.filters input[type="search"], .filters select {
  font: inherit; font-size: 13.5px; color: var(--text-primary);
  background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 11px; height: 36px;
}
.filters input[type="search"] { flex: 1 1 260px; min-width: 200px; }
.filters select { max-width: 230px; }
.filters input:focus, .filters select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.filters .count { margin-left: auto; font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.results { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.results table { width: 100%; border-collapse: collapse; font-size: 13px; }
.results thead th {
  text-align: left; font-weight: 600; font-size: 11.5px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-muted); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.results td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.results tbody tr { cursor: pointer; }
.results tbody tr:hover { background: var(--surface-2); }
.results tbody tr:last-child td { border-bottom: 0; }
.results .rid { font-family: var(--mono); font-size: 11.5px; color: var(--text-secondary); white-space: nowrap; }
.results .ttl { font-weight: 520; }
.results .crumb { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.results .num { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text-secondary); }
.pager { display: flex; justify-content: center; padding: 14px; }
.btn {
  font: inherit; font-size: 13px; padding: 8px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-primary);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .5; cursor: default; }

.chip { display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-secondary); border: 1px solid var(--border); white-space: nowrap; }

/* ---------- drawer ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.42); opacity: 0; pointer-events: none; transition: opacity .16s; z-index: 90; }
.scrim.on { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100dvh; width: min(760px, 100vw);
  background: var(--page); border-left: 1px solid var(--border); z-index: 100;
  transform: translateX(100%); transition: transform .2s cubic-bezier(.4,0,.2,1);
  display: flex; flex-direction: column;
}
.drawer.on { transform: none; }
.drawer header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; gap: 14px; align-items: flex-start; }
.drawer header h3 { margin: 0 0 4px; font-size: 17px; letter-spacing: -0.015em; font-weight: 630; }
.drawer header .crumb { font-size: 12px; color: var(--text-muted); }
.drawer .close { margin-left: auto; flex: none; }
.drawer .body { overflow: auto; padding: 20px 22px 40px; }
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: 7px 18px; font-size: 13px; margin-bottom: 20px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.drawer h4 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 22px 0 10px; font-weight: 600; }
.serieslist { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-1); }
.serieslist table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.serieslist td { padding: 6px 12px; border-bottom: 1px solid var(--border); }
.serieslist tr:last-child td { border-bottom: 0; }
.serieslist .sn { font-family: var(--mono); font-size: 11px; color: var(--text-muted); white-space: nowrap; width: 1%; }
.serieslist .uom { color: var(--text-muted); text-align: right; white-space: nowrap; font-size: 11.5px; }
.note { font-size: 12.5px; color: var(--text-muted); background: var(--surface-1); border: 1px solid var(--border); border-left: 3px solid var(--axis); border-radius: 8px; padding: 11px 13px; }
.actions { display: flex; gap: 9px; flex-wrap: wrap; margin: 8px 0 4px; }
.livewrap { margin-top: 12px; }
.livewrap table { width: 100%; border-collapse: collapse; font-size: 12px; font-variant-numeric: tabular-nums; }
.livewrap th, .livewrap td { padding: 5px 9px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
.livewrap th:first-child, .livewrap td:first-child { text-align: left; }
.livewrap thead th { color: var(--text-secondary); font-weight: 600; }
.scrollx { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-1); }

/* ---------- tree / agencies ---------- */
.themegrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
.themecard { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.themecard h3 { margin: 0 0 3px; font-size: 15.5px; font-weight: 620; }
.themecard .n { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.themecard details { border-top: 1px solid var(--border); padding: 7px 0 3px; }
.themecard summary { cursor: pointer; font-size: 13px; display: flex; gap: 8px; align-items: baseline; list-style: none; }
.themecard summary::-webkit-details-marker { display: none; }
.themecard summary::before { content: "▸"; color: var(--text-muted); font-size: 10px; transition: transform .12s; display: inline-block; }
.themecard details[open] summary::before { transform: rotate(90deg); }
.themecard summary .c { margin-left: auto; color: var(--text-muted); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.themecard .topics { padding: 6px 0 8px 18px; display: flex; flex-direction: column; gap: 4px; }
.themecard .topics button {
  background: none; border: 0; padding: 2px 0; text-align: left; font: inherit; font-size: 12.5px;
  color: var(--text-secondary); cursor: pointer; display: flex; gap: 8px;
}
.themecard .topics button:hover { color: var(--accent); }
.themecard .topics .c { margin-left: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.agencies { display: flex; flex-wrap: wrap; gap: 7px; }
.agency {
  font-size: 12px; padding: 5px 11px; border-radius: 999px; cursor: pointer;
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-secondary);
}
.agency:hover { border-color: var(--border-strong); color: var(--text-primary); }
.agency b { color: var(--text-primary); font-variant-numeric: tabular-nums; margin-left: 5px; font-weight: 600; }

/* ---------- docs ---------- */
.doccols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
pre.code {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 8px;
  padding: 13px 15px; overflow-x: auto; font-family: var(--mono); font-size: 12px;
  line-height: 1.65; margin: 0 0 12px; color: var(--text-primary);
}
pre.code .c { color: var(--text-muted); }
pre.code .k { color: var(--accent); }
.toolcard { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.toolcard h4 { margin: 0 0 6px; font-family: var(--mono); font-size: 13px; color: var(--text-primary); text-transform: none; letter-spacing: 0; }
.toolcard p { margin: 0 0 12px; font-size: 13px; color: var(--text-secondary); }
.toolcard table { width: 100%; border-collapse: collapse; font-size: 12px; }
.toolcard th { text-align: left; color: var(--text-muted); font-weight: 600; padding: 4px 8px 4px 0; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.toolcard td { padding: 4px 8px 4px 0; border-top: 1px solid var(--border); vertical-align: top; }
.toolcard td:first-child { font-family: var(--mono); font-size: 11.5px; white-space: nowrap; }
.stepnum {
  display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 11px; font-weight: 640; flex: none;
}

footer.site { padding: 34px 0 56px; color: var(--text-muted); font-size: 12.5px; }
footer.site p { margin: 0 0 8px; max-width: 78ch; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
