:root {
  --bg: #f7f6f1;
  --surface: #fffdf6;
  --ink: #1f2a2e;
  --accent: #0b6e4f;
  --line: #d7d3c7;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 0% 0%, #e7efe8 0%, rgba(231,239,232,0) 50%),
    radial-gradient(circle at 100% 100%, #f3ead3 0%, rgba(243,234,211,0) 45%),
    var(--bg);
}

/* ── Hero ─────────────────────────────────────────── */
.hero {
  padding: 1.75rem 1.25rem 1.4rem;
  background: linear-gradient(120deg, #0e5a44, #0b6e4f);
  color: #fff;
}
.hero h1 { margin: 0; font-size: clamp(1.55rem, 2.8vw, 2.2rem); }
.hero p  { margin: .4rem 0 .75rem; max-width: 80ch; font-size: .95rem; }

.nav { display: flex; flex-wrap: wrap; gap: .4rem; }
.nav a {
  color: #fff; text-decoration: none;
  border: 1px solid rgba(255,255,255,.35);
  border-radius: 999px; padding: .3rem .7rem; font-size: .88rem;
}
.nav a[aria-current="page"] { background: rgba(255,255,255,.22); }

/* ── Layout ───────────────────────────────────────── */
main {
  width: min(1240px, 95vw);
  margin: -1rem auto 2.5rem;
  display: grid; gap: .85rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  box-shadow: 0 5px 16px rgba(0,0,0,.04);
}
.card h2 { margin: 0 0 .65rem; font-size: 1.05rem; }
.card h3 { margin: 0 0 .55rem; font-size: .93rem; color: #333; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }

/* ── Snapshot bar ─────────────────────────────────── */
.snapshot-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; flex-wrap: wrap;
  padding: .6rem 1.15rem; font-size: .85rem; color: #444;
}

/* ── Classification tab bar ──────────────────────── */
.cls-tab-bar {
  display: flex; flex-wrap: wrap; gap: .4rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .6rem .75rem;
  box-shadow: 0 5px 16px rgba(0,0,0,.04);
}

.cls-tab {
  display: flex; flex-direction: column; align-items: flex-start;
  background: #f0f0eb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .55rem .85rem;
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, border-color .15s;
  flex: 1; min-width: 140px;
}
.cls-tab:hover { background: #e5f3ed; border-color: #aacfc0; }
.cls-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.cls-tab-label { font-size: .88rem; font-weight: 600; }
.cls-tab-count {
  font-size: .76rem; margin-top: .15rem;
  opacity: .75;
}
.cls-tab.active .cls-tab-count { opacity: .9; }

/* ── Tab content ──────────────────────────────────── */
.tab-content { display: contents; }
.tab-content.hidden { display: none; }

/* ── Classification info card ────────────────────── */
.cls-info-card {
  display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap;
  border-left: 4px solid var(--accent);
}
.cls-info-main { flex: 1; min-width: 280px; }
.cls-info-main h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
.cls-info-main p  { font-size: .88rem; margin: 0 0 .4rem; line-height: 1.55; }
.cls-info-stats {
  display: flex; gap: .6rem; flex-wrap: wrap;
  align-items: flex-start;
}
.mini-stat {
  background: #f0f7f4;
  border: 1px solid #cde4d8;
  border-radius: 8px;
  padding: .55rem .75rem;
  text-align: center; min-width: 80px;
}
.mini-num   { font-size: 1.6rem; font-weight: 700; color: var(--accent); line-height: 1; }
.mini-lbl   { font-size: .72rem; color: #555; margin-top: .2rem; }

.cls-warning {
  background: #fff8e5; border: 1px solid #f4c342;
  border-radius: 6px; padding: .6rem .85rem;
  font-size: .85rem; margin-top: .5rem;
}

/* ── Filters ──────────────────────────────────────── */
.cls-filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: .65rem;
}
label { display: block; margin-bottom: .3rem; font-size: .83rem; font-weight: 500; color: #333; }
input, select, .stat-box {
  width: 100%; padding: .5rem .6rem;
  border: 1px solid var(--line); border-radius: 7px;
  font-family: inherit; font-size: .88rem; background: #fff;
}
.stat-box { min-height: 36px; line-height: 1.4; font-weight: 600; }

/* ── Charts ───────────────────────────────────────── */
.chart-wrap  { position: relative; height: 240px; }
.chart-note  { font-size: .79rem; color: #666; margin: -.2rem 0 .5rem; }

/* ── Table ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: .42rem .5rem; text-align: left; font-size: .86rem;
}
th { background: #edf6f2; font-weight: 600; white-space: nowrap; }
td code {
  font-size: .81rem; background: #f0f0f0;
  padding: .08rem .28rem; border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, monospace;
}

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-block; background: var(--accent); color: #fff;
  text-decoration: none; border-radius: 7px;
  padding: .5rem .85rem; border: 1px solid var(--accent);
  cursor: pointer; font-family: inherit; font-size: .88rem; font-weight: 500;
}
.btn-sm  { padding: .28rem .6rem; font-size: .8rem; }
.btn-outline { background: transparent; color: var(--accent); }
.btn-outline:hover { background: var(--accent); color: #fff; }
.link-btn {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-family: inherit; font-size: inherit;
  text-decoration: underline; padding: 0;
}
.cta-row { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .75rem; }

/* ── Pills ────────────────────────────────────────── */
.pill {
  display: inline-block; min-width: 1.8rem; text-align: center;
  padding: .1rem .42rem; border-radius: 999px;
  background: #edf0ee; font-size: .78rem;
}
.pill-yes  { background: #d4edda; color: #155724; }
.pill-warn { background: #ffe0dd; color: #7a1010; font-size: .74rem; }
.pill-sids { background: #dce8ff; color: #1a3a6e; }
.pill-oda  { background: #e8f0fe; color: #1a3a6e; }
.pill-sdg  {
  background: #f0faf7; color: var(--accent);
  border: 1px solid #b8ddd2; font-size: .74rem; margin: .1rem .1rem;
}
.income-pill {
  display: inline-block; padding: .12rem .45rem;
  border-radius: 999px; font-size: .8rem; font-weight: 500;
}

/* Source pills in detail panel */
.src-pill { font-size: .74rem; }
.src-un-m49       { background: #e8f4f0; color: #0b5e42; }
.src-world-bank   { background: #e8f0fe; color: #1a3a6e; }
.src-world-bank-fcs { background: #ffe0dd; color: #7a1010; }
.src-oecd-dac     { background: #fff3e0; color: #7a4100; }
.src-un-sdg       { background: #f3e8ff; color: #5b1a7e; }

/* ── Error ────────────────────────────────────────── */
.error-card { border-color: #cc3d3d; color: #7a1010; background: #fff3f3; }
.hidden { display: none !important; }

/* ── Downloads page ───────────────────────────────── */
.dataset-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.dataset-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 1rem 1.1rem;
}
.dataset-card h3 { margin: 0 0 .35rem; font-size: .97rem; }
.dataset-card .file-meta { font-size: .79rem; color: #555; margin-bottom: .45rem; }
.dataset-card ul { margin: .35rem 0 0; padding-left: 1.15rem; font-size: .84rem; }
.dl-links { display: flex; gap: .45rem; flex-wrap: wrap; margin-top: .7rem; }
.dl-links a { font-size: .81rem; }

code, pre { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
pre {
  background: #1e2930; color: #e8f4f1;
  padding: .9rem 1rem; border-radius: 8px;
  overflow-x: auto; font-size: .8rem; line-height: 1.55; margin: .45rem 0 0;
}

.tab-bar  { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .4rem; }
.tab-btn  {
  background: #eee; border: 1px solid var(--line);
  border-radius: 6px 6px 0 0; padding: .28rem .7rem;
  font-size: .81rem; cursor: pointer; font-family: inherit;
}
.tab-btn.active  { background: #1e2930; color: #e8f4f1; border-color: #1e2930; }
.tab-pane        { display: none; }
.tab-pane.active { display: block; }

/* ── About page ───────────────────────────────────── */
.step-list { counter-reset: steps; list-style: none; padding: 0; }
.step-list li {
  counter-increment: steps;
  padding: .55rem .7rem .55rem 2.8rem; position: relative;
  border-left: 3px solid var(--accent); margin-bottom: .5rem;
  background: #f5faf8; border-radius: 0 6px 6px 0; font-size: .87rem;
}
.step-list li::before {
  content: counter(steps); position: absolute; left: .7rem;
  font-weight: 700; color: var(--accent);
}
.source-table td, .source-table th { font-size: .82rem; }
.source-table th { white-space: nowrap; }

/* ── Cross-system filters card ────────────────────── */
.cross-filters-card {
  background: #f0f7f4;
  border: 1px solid #b8ddd2;
  border-radius: 12px;
  padding: .75rem 1.15rem;
  box-shadow: 0 5px 16px rgba(0,0,0,.04);
}
.cross-filter-header {
  display: flex; align-items: center; gap: .6rem;
  margin-bottom: .55rem; flex-wrap: wrap;
}
.cross-filter-note { font-size: .79rem; color: #556; }
.cross-filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .65rem;
}

/* ── Export guide ─────────────────────────────────── */
details.export-guide {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .65rem 1.15rem;
  box-shadow: 0 5px 16px rgba(0,0,0,.04);
}
details.export-guide summary {
  cursor: pointer;
  font-weight: 600; font-size: .93rem;
  list-style: none;
  display: flex; align-items: center; gap: .5rem;
  user-select: none;
}
details.export-guide summary::before {
  content: '▶'; font-size: .7rem;
  transition: transform .15s; color: var(--accent);
}
details.export-guide[open] summary::before { transform: rotate(90deg); }
details.export-guide summary::-webkit-details-marker { display: none; }

.export-guide-body { padding-top: .75rem; }
.export-guide-body > p { font-size: .88rem; margin: 0 0 .6rem; line-height: 1.55; }
.export-guide-body h3 { font-size: .9rem; margin: .8rem 0 .3rem; color: var(--accent); }
.export-guide-example {
  background: #f5faf8; border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0; padding: .5rem .75rem;
  margin: .3rem 0; font-size: .84rem; line-height: 1.5;
}
.export-guide-example code {
  background: #e0f0ea; padding: .05rem .28rem;
  border-radius: 3px; font-size: .79rem;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.export-row {
  display: flex; align-items: center;
  justify-content: flex-end; gap: .75rem;
  grid-column: 1 / -1;
  padding-top: .5rem;
  border-top: 1px solid var(--line);
  margin-top: .1rem;
}
.export-note { font-size: .8rem; color: #666; }

/* ── SDG Analytics Lab ───────────────────────────── */
.hero-lab {
  background:
    radial-gradient(circle at 12% 15%, rgba(255,255,255,.18), rgba(255,255,255,0) 38%),
    radial-gradient(circle at 80% 10%, rgba(249,198,124,.24), rgba(249,198,124,0) 34%),
    linear-gradient(128deg, #094c57, #0a5f4f 48%, #1c6d3e);
}

.lab-main { gap: 1rem; }
.lab-main h2, .lab-main h3 { font-family: "Sora", "Space Grotesk", sans-serif; }
.lab-intro p { font-size: .9rem; line-height: 1.6; margin-top: .35rem; }

.source-ribbon {
  display: flex; flex-wrap: wrap; gap: .5rem;
  margin-top: .75rem;
}
.src-link {
  text-decoration: none;
  border: 1px solid #bdd8ce;
  background: #f1faf6;
  color: #0f5b46;
  border-radius: 999px;
  padding: .27rem .68rem;
  font-size: .78rem;
}
.src-link:hover { background: #e5f3ec; }

.source-meta-table {
  width: 100%; border-collapse: collapse;
  font-size: .82rem; margin: .85rem 0;
}
.source-meta-table th, .source-meta-table td {
  padding: .38rem .6rem;
  border: 1px solid #d4e8e0;
  vertical-align: top;
  text-align: left;
}
.source-meta-table th {
  background: #f1faf6; color: #0f5b46;
  font-weight: 600; width: 10rem; white-space: nowrap;
}
.source-meta-table td code {
  font-family: monospace; font-size: .8rem;
  background: #e8f5ef; padding: .1rem .35rem;
  border-radius: 3px;
}
.source-note {
  font-size: .82rem; line-height: 1.55;
  background: #f7fcf9; border-left: 3px solid #0b6e4f;
  padding: .55rem .85rem; margin: .75rem 0 .25rem;
  border-radius: 0 4px 4px 0;
}

.lab-filters {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: .7rem;
  align-items: end;
}
.lab-filter-actions {
  display: flex;
  justify-content: flex-end;
  align-items: end;
  min-height: 100%;
}
.lab-metric-card h3 { margin-bottom: .45rem; }
.lab-metric-explainer {
  font-size: .84rem;
  line-height: 1.52;
  color: #2d3b39;
}
.lab-metric-explainer p { margin: .22rem 0; }
.lab-metric-explainer .meta {
  color: #52625f;
  font-size: .79rem;
}

.lab-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: .75rem;
}
.kpi-card {
  background: linear-gradient(155deg, #fffef8, #f4fbf8);
  border: 1px solid #cfe0d8;
}
.kpi-label {
  font-size: .77rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #516462;
}
.kpi-value {
  margin-top: .3rem;
  font-size: 1.36rem;
  font-weight: 700;
  color: #0f5b46;
}
.kpi-sub { font-size: .77rem; color: #556; margin-top: .15rem; }

.lab-subnav-wrap { padding: .65rem .8rem; }
.lab-subnav { display: flex; flex-wrap: wrap; gap: .5rem; }
.lab-tab-link {
  border: 1px solid #c6d8d0;
  background: #f0f6f3;
  border-radius: 9px;
  padding: .42rem .75rem;
  text-decoration: none;
  color: inherit;
  font-size: .86rem;
}
.lab-tab-link.active {
  background: #0b6e4f;
  color: #fff;
  border-color: #0b6e4f;
}
.lab-tab {
  border: 1px solid #c6d8d0;
  background: #f0f6f3;
  border-radius: 9px;
  padding: .42rem .75rem;
  cursor: pointer;
  font-family: inherit;
  font-size: .86rem;
}
.lab-tab.active {
  background: #0b6e4f;
  color: #fff;
  border-color: #0b6e4f;
}

.lab-grid-2 { grid-template-columns: 1.05fr .95fr; }
.plot { width: 100%; min-height: 340px; }
#lab-map, #ai-map, #edb-map {
  width: 100%;
  height: 420px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #d4ddd8;
}
.chart-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .55rem;
}
.lab-notes p { font-size: .87rem; line-height: 1.55; margin: .45rem 0; }
.lab-country-meta {
  margin-top: .65rem;
  background: #f4faf7;
  border: 1px solid #d4e4dd;
  border-radius: 8px;
  padding: .65rem .75rem;
  font-size: .86rem;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 900px) {
  .grid, .dataset-grid { grid-template-columns: 1fr; }
  .cls-info-card { flex-direction: column; }
  .lab-grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .cls-tab { min-width: 120px; flex: 1 1 40%; }
  .plot { min-height: 300px; }
  #lab-map, #ai-map, #edb-map { height: 360px; }
}
@media (max-width: 480px) {
  .cls-tab { min-width: 100%; }
  .lab-filters { grid-template-columns: 1fr; }
}
