/* ── dashboard.css ──────────────────────────────────────────────────────────── */
/* All colours are driven by CSS custom properties so the whole tool (predictor bar,
   map chrome, cards, charts, calendar) switches cleanly between dark (default) and
   light themes. :root holds the dark palette; [data-theme="light"] overrides it.
   The existing visual language — navy/teal/orange/lime, Georgia serif, 12px card
   radius — is preserved; light mode keeps the same accents, desaturated for legibility. */

:root {
  --bg: #0a1628;
  --bg-2: #0e1d33;          /* panels / sections */
  --card: #0a1628;          /* inner cards / metric boxes */
  --card-2: #111f38;        /* nav + segmented buttons */
  --border: #1e2d45;
  --border-2: #25324a;
  --text: #e2e8f0;
  --heading: #f1f5f9;
  --muted: #64748b;
  --faint: #475569;
  --accent: #93c5fd;        /* brand / focus blue */
  --teal: #38bdf8;
  --orange: #f97316;
  --lime: #84cc16;
  --nav-active-bg: #1e3a5f;
  --nav-active-border: #60a5fa;
  --seg-active-bg: #0c3050;
  --tooltip-bg: #1e293b;
  --map-line: rgba(255,255,255,0.22);
  --map-label: rgba(255,255,255,0.6);
  --chart-belt: #84cc16;
  --chart-natl: #38bdf8;
  --shadow: rgba(0,0,0,0.35);
}

[data-theme="light"] {
  --bg: #eef1f5;
  --bg-2: #ffffff;
  --card: #f8fafc;
  --card-2: #ffffff;
  --border: #d6dee8;
  --border-2: #c3cedb;
  --text: #1e293b;
  --heading: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #1d4ed8;
  --teal: #0e7490;          /* desaturated teal, legible on white */
  --orange: #ea580c;
  --lime: #4d7c0f;
  --nav-active-bg: #dbeafe;
  --nav-active-border: #2563eb;
  --seg-active-bg: #e0f2fe;
  --tooltip-bg: #ffffff;
  --map-line: rgba(15,23,42,0.28);
  --map-label: rgba(15,23,42,0.62);
  --chart-belt: #4d7c0f;
  --chart-natl: #0e7490;
  --shadow: rgba(15,23,42,0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Georgia', serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px;
  transition: background 0.2s, color 0.2s;
}

/* ── Global period toggle ─────────────────────────────────────────────────── */
.period-seg { max-width: 1180px; margin: 0 auto 16px; }
.period-seg .seg-btn { font-size: 12px; padding: 6px 14px; }

/* ── Growing-conditions bar (selected country, between tabs and map) ────────── */
.growing-conditions {
  max-width: 1180px; margin: 0 auto 20px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-left: 3px solid var(--tile-accent, var(--border));
  border-radius: 12px; padding: 14px 18px; box-shadow: 0 1px 3px var(--shadow);
}
.gc-head { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); margin-bottom: 12px; }
.gc-head span { text-transform: none; letter-spacing: 0.03em; color: var(--faint); }
.gc-row { display: grid; grid-template-columns: 1.3fr 1.3fr 1.4fr 2fr; gap: 20px; align-items: center; }
/* .gc-row responsive collapse lives in the Responsive section near the end. */
.gc-loading { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }

.gc-id { display: flex; align-items: center; gap: 12px; }
.gc-flag { font-size: 28px; }
.gc-code { font-size: 15px; color: var(--heading); }
.gc-stage { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--teal); margin-top: 3px; }
.gc-rating-wrap { display: flex; align-items: center; gap: 10px; }
.gc-metrics { display: flex; gap: 18px; }
.gc-metric { display: flex; flex-direction: column; gap: 3px; }
.gc-m-lbl { font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.gc-m-val { font-size: 17px; color: var(--text); font-variant-numeric: tabular-nums; }
.gc-driver { font-size: 12.5px; line-height: 1.5; color: var(--text); }

.rating-pill {
  display: inline-block; font-size: 13px; font-weight: 700; color: #0a1628;
  padding: 3px 12px; border-radius: 20px; letter-spacing: 0.02em;
}
.rating-na { background: var(--border-2); color: var(--text); }
.rating-scale { display: inline-flex; gap: 3px; flex: 1; align-items: center; min-width: 70px; }
.rseg { flex: 1; height: 5px; border-radius: 3px; opacity: 0.35; transition: all 0.15s; }
.rseg.on { opacity: 1; height: 9px; box-shadow: 0 0 0 1.5px var(--bg-2), 0 0 6px currentColor; }

/* ── Top nav ──────────────────────────────────────────────────────────────── */
header.topbar { max-width: 1180px; margin: 0 auto 20px; position: relative; }
.brand {
  font-size: 18px; font-weight: 400; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 4px;
}
.brand small { display: block; font-size: 11px; color: var(--muted); letter-spacing: 0.04em;
  text-transform: none; margin-top: 4px; }

.topbar-actions { position: absolute; top: 0; right: 0; display: flex; gap: 8px; }
.tb-btn {
  background: var(--card-2); border: 1px solid var(--border-2); color: var(--text);
  font-family: 'Georgia', serif; font-size: 12px; letter-spacing: 0.04em;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; transition: all 0.15s;
}
.tb-btn:hover { border-color: var(--accent); color: var(--heading); }

#country-nav { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.nav-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--card-2); border: 1px solid var(--border-2); color: var(--text);
  font-family: 'Georgia', serif; font-size: 14px; letter-spacing: 0.03em;
  padding: 9px 18px; border-radius: 8px; cursor: pointer; transition: all 0.15s;
}
.nav-btn:hover { border-color: var(--accent); }
.nav-btn.active { background: var(--nav-active-bg); border-color: var(--nav-active-border);
  color: var(--heading); box-shadow: 0 0 0 1px var(--nav-active-border) inset; }
.nav-flag { font-size: 17px; }

/* Instant tap feedback: a subtle press, and a spinner that replaces the flag on the
   tab whose data is loading (so feedback appears right where the user tapped). */
.nav-btn:active { transform: scale(0.97); }
.nav-spin { display: none; width: 16px; height: 16px; flex-shrink: 0; border: 2px solid var(--border-2);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
.nav-btn.loading .nav-flag { display: none; }
.nav-btn.loading .nav-spin { display: inline-block; }
.nav-btn.loading { border-color: var(--accent); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.dash { max-width: 1180px; margin: 0 auto; display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 24px; align-items: start; }
/* .dash responsive tiers live in the Responsive section near the end. */

.map-col h1 { font-size: 17px; font-weight: 400; letter-spacing: 0.06em; color: var(--heading); }
.map-col .subtitle { font-size: 12px; color: var(--muted); letter-spacing: 0.03em; margin: 4px 0 14px; }

/* Segmented toggles (map rainfall + card windows) */
.seg { display: flex; align-items: center; gap: 6px; margin: 0 0 12px; flex-wrap: wrap; }
.seg-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); margin-right: 4px; }
.seg-btn { background: var(--card-2); border: 1px solid var(--border-2); color: var(--muted);
  font-family: 'Georgia', serif; font-size: 12px; padding: 5px 13px; border-radius: 7px;
  cursor: pointer; transition: all 0.15s; }
.seg-btn:hover { border-color: var(--accent); color: var(--text); }
.seg-btn.active { background: var(--seg-active-bg); border-color: var(--teal); color: var(--heading);
  box-shadow: 0 0 0 1px var(--teal) inset; }
.card-seg { margin-bottom: 12px; }
.card-seg .seg-btn { font-size: 11px; padding: 4px 9px; }

/* touch-action: pan-y lets a one-finger vertical swipe scroll the page; pinch (two
   fingers) and the ± buttons drive zoom, so the map never traps mobile scrolling. */
#map-container { position: relative; width: 100%; overflow: hidden; cursor: grab; border-radius: 8px;
  touch-action: pan-y; }
#map-container:active { cursor: grabbing; }
/* Plain positioning wrapper. The heatmap canvas and the SVG's .zoom-layer group are
   transformed individually on zoom (see map.js) — the SVG geometrically (crisp
   vectors), the canvas via CSS (raster). */
#map-zoom { position: relative; width: 100%; }
#map-container canvas {
  position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none;
  border-radius: 8px; transform-origin: 0 0; will-change: transform;
}
/* Constant, sharp border weight at every zoom level — the stroke width ignores the
   group's zoom scale, so admin + cocoa-belt outlines never go fuzzy or thick. */
#svg .zoom-layer path, #svg .zoom-layer line,
#svg .zoom-layer circle, #svg .zoom-layer rect { vector-effect: non-scaling-stroke; }

/* Zoom controls (overlay, top-right of the map; theme-aware). */
.map-zoom-controls { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column;
  gap: 6px; z-index: 5; }
.mz-btn {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: var(--card-2); border: 1px solid var(--border-2); color: var(--text);
  font-family: 'Georgia', serif; font-size: 17px; line-height: 1; border-radius: 8px;
  cursor: pointer; transition: all 0.15s; box-shadow: 0 1px 3px var(--shadow);
}
.mz-btn:hover { border-color: var(--accent); color: var(--heading); }

/* ── Loading indicators ─────────────────────────────────────────────────────── */
/* Fixed indeterminate top progress bar (shown on tab switch; visible at any scroll). */
.load-bar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 200;
  pointer-events: none; opacity: 0; transition: opacity 0.25s; }
.load-bar.active { opacity: 1; }
.load-bar::before { content: ''; position: absolute; top: 0; left: -35%; height: 100%; width: 35%;
  border-radius: 0 3px 3px 0; background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.load-bar.active::before { animation: loadbar 1.05s ease-in-out infinite; }
@keyframes loadbar {
  0%   { left: -35%; width: 35%; }
  50%  { width: 55%; }
  100% { left: 100%;  width: 35%; }
}

/* Map overlay — dims/blurs the stale map while the next origin loads. Fades via
   opacity/visibility (kept in flow) so it transitions smoothly instead of popping. */
.map-loading { position: absolute; inset: 0; z-index: 6; border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: color-mix(in srgb, var(--bg-2) 72%, transparent);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  color: var(--muted); font-size: 13px; letter-spacing: 0.03em;
  opacity: 0; visibility: hidden; transition: opacity 0.18s ease, visibility 0.18s ease; }
.map-loading.active { opacity: 1; visibility: visible; }
.map-loading .spinner-lg { margin: 0; }
/* width:100% + the 660×660 viewBox makes the map scale to its container while the
   viewBox aspect ratio fixes height (height:auto is explicit for that intent). The
   canvas overlay tracks the SVG box via top/left/width/height:100% above. */
#map-container svg { position: relative; display: block; width: 100%; height: auto; }

#status { color: var(--muted); font-size: 12px; padding: 0.8rem 0; text-align: center; min-height: 20px; }

#tooltip {
  position: fixed; pointer-events: none; display: none;
  background: var(--tooltip-bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; font-size: 13px; color: var(--text); z-index: 100;
  max-width: 250px; line-height: 1.55; box-shadow: 0 4px 14px var(--shadow);
}
.tt-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.tt-sub { font-size: 12px; color: var(--muted); }
.tt-badge { display: inline-block; background: rgba(14,165,233,0.25); border: 1px solid #0ea5e9;
  color: #7dd3fc; font-size: 11px; padding: 2px 9px; border-radius: 3px; margin-bottom: 6px; }

/* ── Risk panel + cards ───────────────────────────────────────────────────── */
#risk-panel { display: flex; flex-direction: column; gap: 14px; }
.panel-loading { color: var(--muted); font-size: 13px; text-align: center; padding: 40px 0;
  background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; }

.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: 12px; padding: 16px;
  box-shadow: 0 1px 3px var(--shadow); }
.card-head { font-size: 13px; color: var(--heading); margin-bottom: 12px; }
.card-sub { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.card-foot { font-size: 9.5px; color: var(--faint); margin-top: 8px; }

/* Rainfall value boxes */
.rain-values { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.rv { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.rv.belt { border-color: #3f6212; background: color-mix(in srgb, var(--lime) 8%, var(--card)); }
.rv-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 5px; }
.rv-val { font-size: 22px; color: var(--text); }
.rv.belt .rv-val { color: var(--lime); }
.rv-val span { font-size: 12px; color: var(--muted); }
.rv-meta { font-size: 10.5px; margin-top: 4px; min-height: 13px; }
.fc-pill { display: inline-block; font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--teal); border: 1px solid var(--teal); border-radius: 10px; padding: 1px 7px; }
.meta-pending { color: var(--faint); }

/* Charts */
.chart { width: 100%; min-height: 110px; }
.chart-svg { display: block; }
.chart-legend { display: flex; gap: 16px; font-size: 10.5px; color: var(--muted); margin-bottom: 6px; }
.chart-legend span { display: flex; align-items: center; gap: 5px; }
.lswatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.chart-empty { font-size: 11.5px; color: var(--faint); padding: 16px 0; text-align: center; }
.chart-readouts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.readout { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
.rdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.rlbl { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.rval { display: block; font-size: 22px; color: var(--text); margin-top: 4px; }
.runit { font-size: 12px; color: var(--muted); }

/* Loading spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--teal);
  border-radius: 50%; animation: spin 0.8s linear infinite; }
.spinner-lg { width: 28px; height: 28px; border-width: 3px; margin: 0 auto 12px; }

/* ENSO */
.enso-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); margin-bottom: 10px; }
.enso-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.enso-dot { width: 13px; height: 13px; border-radius: 50%; flex-shrink: 0; }
.enso-phase { font-size: 16px; color: var(--heading); }
.enso-oni { font-size: 12px; color: var(--muted); margin-left: auto; }
.enso-trend { font-size: 12px; color: var(--text); margin-bottom: 8px; }
.enso-impact { font-size: 12px; color: var(--muted); line-height: 1.5; border-left: 2px solid var(--border-2); padding-left: 10px; }
.enso-src { font-size: 9.5px; color: var(--faint); margin-top: 8px; }
.enso-live { font-size: 9px; color: #4ade80; letter-spacing: 0.04em; margin-left: 6px; }
.enso-static { font-size: 9px; color: var(--muted); letter-spacing: 0.04em; margin-left: 6px; }
.enso-approx { font-size: 9px; color: #fbbf24; letter-spacing: 0.04em; }

/* Seasonal outlook */
.seasonal-note { font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.seasonal-item { display: block; text-decoration: none; padding: 8px 0; border-bottom: 1px solid var(--border); }
.seasonal-item:last-child { border-bottom: none; }
.seasonal-title { font-size: 12.5px; color: var(--text); line-height: 1.4; }
.seasonal-item:hover .seasonal-title { color: var(--accent); }
.seasonal-date { font-size: 10px; color: var(--faint); margin-top: 3px; }

/* ── Phenology calendar ───────────────────────────────────────────────────── */
.phenology { max-width: 1180px; margin: 26px auto 0; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 12px; padding: 6px 18px 18px; box-shadow: 0 1px 3px var(--shadow); }
.phenology-summary { cursor: pointer; font-size: 15px; letter-spacing: 0.04em; color: var(--heading);
  padding: 14px 0 6px; list-style: none; }
.phenology-summary::-webkit-details-marker { display: none; }
.phenology-summary::before { content: '▾'; color: var(--muted); margin-right: 8px; font-size: 12px; }
details:not([open]) .phenology-summary::before { content: '▸'; }
.phenology-summary span { font-size: 11px; color: var(--faint); letter-spacing: 0.02em; }
.phenology-body { padding-top: 12px; }
.phenology-legend { display: flex; flex-wrap: wrap; gap: 12px 26px; margin-bottom: 12px; }
.gl-group { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.gl-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.gl-swatch { display: inline-block; width: 16px; height: 11px; border-radius: 3px; }
.gl-solid { background: var(--muted); opacity: 0.85; }
.gl-hatch { background-image: repeating-linear-gradient(45deg, var(--muted) 0 2px, transparent 2px 5px);
  border: 1px solid var(--border-2); }

/* Phenology grid table — month columns × stage rows, with frozen header row and
   frozen stage-label column (position: sticky) so scrolling keeps both visible. */
#phenology-chart { overflow: auto; -webkit-overflow-scrolling: touch; }
.phen-table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 660px;
  table-layout: fixed; font-size: 11px; }
.phen-table th, .phen-table td { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.phen-table thead th { position: sticky; top: 0; z-index: 2; background: var(--bg-2);
  color: var(--muted); font-weight: 400; font-size: 10px; padding: 5px 2px; text-align: center;
  border-top: 1px solid var(--border); }
.phen-table tbody th.rowlbl { position: sticky; left: 0; z-index: 1; background: var(--bg-2);
  color: var(--muted); font-weight: 400; font-size: 10px; text-align: right; white-space: nowrap;
  padding: 2px 10px 2px 8px; }
.phen-table thead th.corner { left: 0; top: 0; z-index: 3; width: 132px; text-align: left;
  color: var(--heading); font-size: 12px; font-weight: 600; }
.phen-table tbody th.rowlbl { width: 132px; }
.phen-table td.cell { height: 22px; }
.phen-table thead th.mcol.now { color: var(--orange); border-bottom: 2px solid var(--orange); }
.phen-table td.cell.now { box-shadow: inset 1px 0 0 var(--orange), inset -1px 0 0 var(--orange); }

/* ── Map legend (directly below the map, theme-aware so it prints cleanly) ───── */
.map-legend {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 22px;
  margin: 10px 0 2px; font-size: 11px; color: var(--muted);
}
.ml-group { display: flex; align-items: center; gap: 7px; }
.ml-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ml-end { font-size: 9px; color: var(--faint); }
.ml-ramp { display: inline-block; width: 96px; height: 9px; border-radius: 3px;
  background: linear-gradient(to right, #0a1628, #03396c, #0369a1, #0ea5e9, #7dd3fc, #e0f2fe); }
.ml-sw { display: inline-block; flex-shrink: 0; }
.ml-cocoa { width: 14px; height: 9px; border-radius: 2px; background: rgba(132,204,22,0.18); border: 1.4px dashed #84cc16; }
.ml-capital { width: 9px; height: 9px; border-radius: 50%; background: #ef4444; border: 1px solid #fff; }

/* ── Hydro table ──────────────────────────────────────────────────────────── */
#hydro-table-wrap { max-width: 1180px; margin: 26px auto 0; }
.table-title { font-size: 15px; font-weight: 400; letter-spacing: 0.05em; color: var(--orange); margin-bottom: 4px; }
.table-sub { font-size: 11px; color: var(--muted); margin-bottom: 12px; }
.hydro-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.hydro-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border-2); font-weight: 400; }
.hydro-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); color: var(--text); }
.hydro-table td.num, .hydro-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.risk-pill { display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 10px; border: 1px solid; }

.source-note { max-width: 1180px; margin: 18px auto 0; font-size: 10px; color: var(--faint); line-height: 1.6; }

/* ── Data freshness indicator (KV cache last-refresh) ───────────────────────── */
.data-asof {
  font-size: 10px; color: var(--faint); letter-spacing: 0.04em;
  margin: 8px 0 0; text-align: right;
}

/* ── Global composite view (production-weighted across origins) ──────────────── */
.global-view { max-width: 1180px; margin: 0 auto; }
.nav-btn.nav-global.active { background: var(--nav-active-bg); border-color: var(--nav-active-border); }

.gv-head {
  border-left: 3px solid var(--tile-accent, var(--border));
  margin-bottom: 16px;
}
.gv-head-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gv-head-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); }
.gv-head-label span { text-transform: none; letter-spacing: 0.03em; color: var(--faint); }
.gv-asof { font-size: 10px; color: var(--faint); letter-spacing: 0.04em; }
.gv-head-main { display: flex; align-items: center; gap: 16px; margin: 14px 0 12px; flex-wrap: wrap; }
.gv-big-pill { font-size: 15px; padding: 5px 16px; }
.gv-big-score { font-size: 30px; color: var(--heading); font-variant-numeric: tabular-nums; }
.gv-big-score span { font-size: 13px; color: var(--muted); }
.gv-pending { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.gv-method { font-size: 12px; line-height: 1.55; color: var(--muted); }

.gv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.gv-origin {
  background: var(--bg-2); border: 1px solid var(--border);
  border-left: 3px solid var(--tile-accent, var(--border));
  border-radius: 12px; padding: 14px 16px; box-shadow: 0 1px 3px var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.gv-origin-loading { min-height: 120px; }
.gv-id { display: flex; align-items: center; gap: 12px; }
.gv-flag { font-size: 26px; }
.gv-name { font-size: 15px; color: var(--heading); }
.gv-stage { font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--teal); margin-top: 3px; }
.gv-weight {
  margin-left: auto; font-size: 10px; color: var(--muted);
  border: 1px solid var(--border-2); border-radius: 10px; padding: 2px 9px; white-space: nowrap;
}
.gv-spinner { display: flex; align-items: center; justify-content: center; flex: 1; padding: 12px 0; }
.gv-rating { display: flex; align-items: center; gap: 10px; }
.gv-score { font-size: 20px; color: var(--text); font-variant-numeric: tabular-nums; }
.gv-score span { font-size: 11px; color: var(--muted); }
.gv-metrics { display: flex; gap: 22px; }
.gv-metric { display: flex; flex-direction: column; gap: 3px; }
.gv-m-lbl { font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.gv-m-val { font-size: 16px; color: var(--text); font-variant-numeric: tabular-nums; }

@media screen and (max-width: 767.98px) { .gv-grid { grid-template-columns: 1fr; } }

/* ── Responsive: tablet (768–1024px) + mobile (<768px) ────────────────────────────
   CSS media queries only — no JS device detection. Three tiers:
     • desktop  > 1024px  → the default rules above (1.6fr / 1fr two-column dash)
     • tablet   768–1024  → a narrower two-column dash
     • mobile   < 768px   → single column; the map renders first (DOM order is
                            .map-col then #risk-panel) with the risk panel below.
   Every rule is scoped to `screen` so the print block (below, last in the file) is
   untouched. Layout only — no colours, fonts or theme tokens are changed here. */

/* Growing-conditions metric grid follows the same tiers. */
@media screen and (min-width: 768px) and (max-width: 1024px) { .gc-row { grid-template-columns: 1fr 1fr; } }
@media screen and (max-width: 767.98px)                      { .gc-row { grid-template-columns: 1fr; } }

/* Tablet: keep two columns but tighten the panel min-width and the gap. */
@media screen and (min-width: 768px) and (max-width: 1024px) {
  .dash { grid-template-columns: minmax(0, 1.4fr) minmax(220px, 0.95fr); gap: 16px; }
}

/* Mobile: single column. Map first, risk panel stacked below (natural DOM order). */
@media screen and (max-width: 767.98px) {
  .dash { grid-template-columns: 1fr; gap: 18px; }
  body { padding: 14px; }
}

/* Touch tap targets ≥44px tall on the period toggle and country nav (tablet + mobile). */
@media screen and (max-width: 1024px) {
  .period-seg .seg-btn { min-height: 44px; padding: 8px 16px; }
  .nav-btn { min-height: 44px; }
  .mz-btn { width: 40px; height: 40px; font-size: 19px; }
}

/* Mobile chrome: topbar, calendar, legend. */
@media screen and (max-width: 767.98px) {
  /* Actions drop into normal flow (top-right) so the long brand title can't sit
     under them; the brand title then truncates with an ellipsis, sub-line wraps. */
  .topbar-actions { position: static; justify-content: flex-end; margin-bottom: 12px; }
  .brand-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand small { white-space: normal; }

  /* Country tabs already wrap (flex-wrap above); keep them tidy on small screens. */
  #country-nav { gap: 8px; }

  /* Phenology calendar: the header row + stage-label column stay frozen (sticky)
     while the grid scrolls horizontally. Show only quarter-month labels (Mar/Jun/
     Sep/Dec) so the header isn't cramped — but always keep the current month's. */
  .phen-table thead th.mcol:not(.qtr):not(.now) .mlabel { display: none; }
  .phen-table { font-size: 10px; }
  .phen-table thead th.corner, .phen-table tbody th.rowlbl { width: 116px; }

  /* Map legend stacks vertically when horizontal space is tight. */
  .map-legend { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ── Print: one-page, light, colour-accurate report ───────────────────────────── */
/* theme.js also flips the live theme to light on beforeprint so the canvas/SVG bake
   light colours; this block forces the page palette + scales the report to one page.
   Redefining the palette on :root here (last rule in the file) overrides whichever
   data-theme is active during printing. */
@media print {
  @page { size: A4 portrait; margin: 8mm; }

  :root {
    --bg: #ffffff; --bg-2: #ffffff; --card: #f4f6f9; --card-2: #ffffff;
    --border: #c3cedb; --border-2: #aebccd; --text: #0f172a; --heading: #0f172a;
    --muted: #475569; --faint: #64748b; --accent: #1d4ed8;
    --teal: #0e7490; --orange: #c2410c; --lime: #3f6212;
    --nav-active-bg: #dbeafe; --nav-active-border: #1d4ed8; --seg-active-bg: #e0f2fe;
    --tooltip-bg: #ffffff; --map-line: rgba(15,23,42,0.30); --map-label: rgba(15,23,42,0.65);
    --chart-belt: #3f6212; --chart-natl: #0e7490; --shadow: transparent;
  }

  /* Make every colour (gradients, pills, bars, map) actually render on paper. */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; box-shadow: none !important; }
  html, body { background: #ffffff !important; }
  body { padding: 0 !important; zoom: 0.7; }

  /* Keep the desktop layout when printing — the print page is narrower than the
     880px phone breakpoint, which would otherwise stack the two columns. Force the
     map+cards two-column grid and the growing-conditions row back to desktop. */
  .dash { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) !important; }
  .gc-row { grid-template-columns: 1.3fr 1.3fr 1.4fr 2fr !important; }

  /* Hide screen-only chrome and the flag glyphs (Windows renders them as bare
     letters that duplicate the ISO code — the code + name carry the identity). */
  .topbar-actions, #tooltip, .map-zoom-controls, .load-bar, .map-loading { display: none !important; }
  .gc-flag, .nav-flag { display: none !important; }

  /* Tighten vertical rhythm so the whole report packs onto a single page. */
  header.topbar { margin-bottom: 6px; }
  #country-nav { margin-top: 8px; gap: 6px; }
  .nav-btn { padding: 5px 12px; }
  #period-toggle, .growing-conditions { margin-bottom: 8px; }
  .growing-conditions { padding: 10px 14px; }
  .gc-head { margin-bottom: 8px; }
  .map-col h1 { margin-bottom: 0; }
  .map-col .subtitle { margin: 2px 0 6px; }
  .dash { gap: 14px; }
  #risk-panel { gap: 8px; }
  .card { padding: 11px; }
  .card-head { margin-bottom: 8px; }
  .map-legend { margin: 6px 0 0; }
  .phenology { margin-top: 10px; padding: 4px 14px 10px; }
  .source-note { margin-top: 8px; font-size: 8.5px; line-height: 1.45; }

  /* The map fills its column as on screen; the two-column layout keeps the page
     short enough that the whole report still fits one portrait page via `zoom`. */
  #map-container { max-width: 100%; }
}
