/* ============================================================
   ISOTHERM — 2026 Global Temperature Dashboard
   Design tokens + component styles
   ============================================================ */

:root {
  /* Type scale — fluid clamp() */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.8125rem, 0.78rem + 0.2vw, 0.9375rem);
  --text-base: clamp(0.9375rem, 0.9rem + 0.2vw, 1rem);
  --text-lg: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem);
  --text-xl: clamp(1.375rem, 1.15rem + 1vw, 1.875rem);

  /* 4px spacing system */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-full: 9999px;

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);
  --ease-golden: cubic-bezier(0.16, 1, 0.3, 1);

  --content-wide: 1280px;

  --font-display: 'Geist Mono', 'JetBrains Mono', ui-monospace, monospace;
  --font-body: 'Geist', 'Inter', -apple-system, sans-serif;
  --font-mono: 'Geist Mono', 'JetBrains Mono', ui-monospace, monospace;
}

/* ---------------- LIGHT MODE (default) ---------------- */
:root,
[data-theme='light'] {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-surface-2: #fbfbfc;
  --color-surface-offset: #ecedf1;
  --color-divider: #dfe1e6;
  --color-border: #d3d6dd;

  --color-text: #12161d;
  --color-text-muted: #5b6270;
  --color-text-faint: #9aa0ab;
  --color-text-inverse: #f7f8fa;

  /* Primary accent — thermal amber (warming) */
  --color-primary: #c05621;
  --color-primary-hover: #9c4419;
  --color-primary-active: #7a3513;
  --color-primary-highlight: #f3ddc9;

  /* Baseline blue — pre-industrial reference */
  --color-baseline: #2563a8;
  --color-baseline-highlight: #d3e4f4;

  /* Alert red — threshold exceedance */
  --color-alert: #c0272d;
  --color-alert-hover: #9e1f24;
  --color-alert-highlight: #f5d6d7;

  /* Success green — below benchmark */
  --color-success: #3a7d44;
  --color-success-highlight: #d7e8da;

  /* Gold — 1.5C threshold line */
  --color-gold: #b8860b;
  --color-gold-highlight: #f0e2bd;

  --shadow-sm: 0 1px 2px rgb(20 22 28 / 0.06);
  --shadow-md: 0 4px 14px rgb(20 22 28 / 0.08);
  --shadow-lg: 0 16px 40px rgb(20 22 28 / 0.12);
}

/* ---------------- DARK MODE ---------------- */
[data-theme='dark'] {
  --color-bg: #0b0e13;
  --color-surface: #12161d;
  --color-surface-2: #161b23;
  --color-surface-offset: #1a2029;
  --color-divider: #232a35;
  --color-border: #2b333f;

  --color-text: #e7e9ed;
  --color-text-muted: #9199a6;
  --color-text-faint: #656d7a;
  --color-text-inverse: #12161d;

  --color-primary: #e8974a;
  --color-primary-hover: #f0ab6a;
  --color-primary-active: #f5bd8b;
  --color-primary-highlight: #3a2c1c;

  --color-baseline: #6fa8e8;
  --color-baseline-highlight: #1c2c3d;

  --color-alert: #f2555f;
  --color-alert-hover: #f57880;
  --color-alert-highlight: #3a1f22;

  --color-success: #6cbf7a;
  --color-success-highlight: #1e2f21;

  --color-gold: #e0b84a;
  --color-gold-highlight: #362c15;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 14px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 16px 40px rgb(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #0b0e13;
    --color-surface: #12161d;
    --color-surface-2: #161b23;
    --color-surface-offset: #1a2029;
    --color-divider: #232a35;
    --color-border: #2b333f;
    --color-text: #e7e9ed;
    --color-text-muted: #9199a6;
    --color-text-faint: #656d7a;
    --color-text-inverse: #12161d;
    --color-primary: #e8974a;
    --color-primary-hover: #f0ab6a;
    --color-primary-active: #f5bd8b;
    --color-primary-highlight: #3a2c1c;
    --color-baseline: #6fa8e8;
    --color-baseline-highlight: #1c2c3d;
    --color-alert: #f2555f;
    --color-alert-hover: #f57880;
    --color-alert-highlight: #3a1f22;
    --color-success: #6cbf7a;
    --color-success-highlight: #1e2f21;
    --color-gold: #e0b84a;
    --color-gold-highlight: #362c15;
  }
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
}

.tabular {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums;
}

/* ============================================================
   LAYOUT
   ============================================================ */

.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.top-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-6);
  background: color-mix(in oklab, var(--color-surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-divider);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-logo {
  width: 32px;
  height: 32px;
  color: var(--color-primary);
  flex-shrink: 0;
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.brand-text p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  border: 1px solid var(--color-border);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-success);
  box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-success) 60%, transparent);
  animation: pulse-dot 2.4s var(--ease-golden) infinite;
}

@keyframes pulse-dot {
  0% {
    box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-success) 45%, transparent);
  }
  70% {
    box-shadow: 0 0 0 7px color-mix(in oklab, var(--color-success) 0%, transparent);
  }
  100% {
    box-shadow: 0 0 0 0 color-mix(in oklab, var(--color-success) 0%, transparent);
  }
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
}
.theme-toggle:hover {
  background: var(--color-surface-offset);
  color: var(--color-text);
}

main {
  flex: 1;
  max-width: var(--content-wide);
  width: 100%;
  margin-inline: auto;
  padding: var(--space-8) var(--space-6) var(--space-24);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

section {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.section-head h2 {
  font-size: var(--text-lg);
  font-weight: 600;
}

.section-head .subtitle {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 60ch;
}

.section-tag {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ============================================================
   HERO / INTRO
   ============================================================ */

.hero {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-4);
}

.hero h1 {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  letter-spacing: -0.01em;
}

.hero p {
  color: var(--color-text-muted);
  font-size: var(--text-base);
  max-width: 68ch;
}

/* ============================================================
   KPI CARDS
   ============================================================ */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
}

.kpi-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  content-visibility: auto;
  contain-intrinsic-size: 0 140px;
}

.kpi-label {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi-value {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 600;
  line-height: 1.1;
}

.kpi-value .unit {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 400;
  margin-left: var(--space-1);
}

.kpi-delta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-family: var(--font-mono);
}

.kpi-delta.hot { color: var(--color-alert); }
.kpi-delta.warm { color: var(--color-primary); }
.kpi-delta.cool { color: var(--color-success); }
.kpi-delta.neutral { color: var(--color-text-muted); }

.kpi-foot {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ============================================================
   PANELS / CARDS
   ============================================================ */

.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}

.panel-grid-2 {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: var(--space-5);
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 340px;
}

.chart-wrap.short { height: 260px; }

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.legend-swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.legend-line {
  width: 14px;
  height: 2px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ============================================================
   1.5C MONITOR
   ============================================================ */

.monitor-panel {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: var(--space-8);
  align-items: center;
}

.gauge-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}

.gauge-wrap {
  position: relative;
  width: 220px;
  height: 220px;
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.gauge-value {
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.5rem);
  font-weight: 700;
  line-height: 1;
}

.gauge-caption {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  margin-top: var(--space-1);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.status-badge.alert {
  background: var(--color-alert-highlight);
  color: var(--color-alert);
}

.status-badge.warn {
  background: var(--color-gold-highlight);
  color: var(--color-gold);
}

.monitor-detail {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.monitor-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
  padding-block: var(--space-2);
  border-bottom: 1px solid var(--color-divider);
}
.monitor-row:last-child { border-bottom: none; }

.monitor-row .label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.monitor-row .value {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  font-weight: 600;
}

.threshold-track {
  position: relative;
  height: 10px;
  border-radius: var(--radius-full);
  background: linear-gradient(
    to right,
    var(--color-success) 0%,
    var(--color-gold) 65%,
    var(--color-alert) 100%
  );
  margin-top: var(--space-2);
}

.threshold-marker {
  position: absolute;
  top: -5px;
  width: 3px;
  height: 20px;
  background: var(--color-text);
  border-radius: 2px;
}

.threshold-marker::after {
  content: attr(data-label);
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  white-space: nowrap;
  font-family: var(--font-mono);
}

/* ============================================================
   ALERT TABLE
   ============================================================ */

.alert-summary {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  background: var(--color-alert-highlight);
  border: 1px solid color-mix(in oklab, var(--color-alert) 35%, transparent);
  margin-bottom: var(--space-2);
}

.alert-summary-icon {
  width: 22px;
  height: 22px;
  color: var(--color-alert);
  flex-shrink: 0;
}

.alert-summary-text {
  font-size: var(--text-sm);
  color: var(--color-text);
}
.alert-summary-text strong {
  color: var(--color-alert);
}

.data-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
}

table.data-table {
  min-width: 640px;
}

table.data-table th,
table.data-table td {
  text-align: right;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--color-divider);
  white-space: nowrap;
}

table.data-table th:first-child,
table.data-table td:first-child {
  text-align: left;
}

table.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface-2);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

table.data-table tbody tr:last-child td {
  border-bottom: none;
}

table.data-table tbody tr:hover {
  background: var(--color-surface-offset);
}

.flag-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-mono);
}

.flag-pill.exceed {
  background: var(--color-alert-highlight);
  color: var(--color-alert);
}
.flag-pill.ok {
  background: var(--color-success-highlight);
  color: var(--color-success);
}

.value-cell {
  font-family: var(--font-mono);
}

/* ============================================================
   FORECAST PANEL
   ============================================================ */

.forecast-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
}

.forecast-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  background: var(--color-surface-2);
}

.forecast-card h3 {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.forecast-card p {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.forecast-stat {
  font-family: var(--font-mono);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-primary);
  margin: var(--space-1) 0;
}

/* ============================================================
   SOURCES / FOOTER
   ============================================================ */

.sources-panel ul {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sources-panel li {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.sources-panel a {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-color: color-mix(in oklab, var(--color-primary) 40%, transparent);
}
.sources-panel a:hover {
  color: var(--color-primary-hover);
}

footer.site-footer {
  border-top: 1px solid var(--color-divider);
  padding: var(--space-6);
  text-align: center;
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-grid-2 { grid-template-columns: 1fr; }
  .monitor-panel { grid-template-columns: 1fr; }
  .forecast-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .top-header { padding: var(--space-3) var(--space-4); }
  main { padding: var(--space-6) var(--space-4) var(--space-16); }
  .brand-text p { display: none; }
  .live-pill span.long { display: none; }
}
