/* ═══════════════════════════════════════════════════════════════════
   style.css — Horizons Climate Explorer
   Aesthetic: cartographic elegance, warm amber on dark slate,
   Playfair Display for identity, DM Mono for data, DM Sans for UI
═══════════════════════════════════════════════════════════════════ */

:root {
  /* Core palette */
  --ink:        #0e0d0b;
  --slate:      #181612;
  --slate-mid:  #211f1a;
  --slate-high: #2d2a22;
  --border:     rgba(255, 220, 140, 0.10);
  --border-mid: rgba(255, 220, 140, 0.18);

  /* Accent: warm amber-gold */
  --amber:      #f5c842;
  --amber-dim:  rgba(245, 200, 66, 0.55);
  --amber-glow: rgba(245, 200, 66, 0.12);

  /* Text tiers */
  --text:       #f0ead8;
  --text-mid:   #b8ae96;
  --text-muted: #6e6650;

  /* Status colours */
  --hot:   #f07340;
  --cold:  #6ab3d8;
  --rain:  #5b9bd5;
  --wind:  #7dc87d;
  --sun:   #f5c842;

  /* Geometry */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --blur:      18px;

  /* Panel widths */
  --sidebar-w:  220px;
  --detail-w:   400px;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  background: var(--ink);
  color: var(--text);
  font-family: 'DM Sans', ui-sans-serif, sans-serif;
  font-weight: 400;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════
   MAP
═══════════════════════════════════════════════════════════════════ */
#map {
  position: absolute;
  inset: 0;
}

/* Override MapLibre attribution style */
.maplibregl-ctrl-attrib {
  background: rgba(14,13,11,0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.maplibregl-ctrl-attrib a { color: var(--text-muted) !important; }

.maplibregl-ctrl-group {
  background: var(--slate-mid) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4) !important;
}

.maplibregl-ctrl-group button {
  color: var(--text-mid) !important;
}

/* ═══════════════════════════════════════════════════════════════════
   SIDEBAR (top-left)
═══════════════════════════════════════════════════════════════════ */
#sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  width: var(--sidebar-w);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Wordmark */
#wordmark {
  padding: 14px 16px 12px;
  background: rgba(14,13,11,0.88);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  backdrop-filter: blur(var(--blur));
  margin-bottom: 2px;
}

.wm-h {
  display: block;
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--amber);
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.wm-sub {
  display: block;
  font-size: 0.64rem;
  font-weight: 300;
  color: var(--text-muted);
  letter-spacing: 0.10em;
  text-transform: uppercase;
  margin-top: 3px;
}

/* Panel label (small caps header) */
.panel-label {
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding: 0 4px;
  margin-top: 4px;
}

/* Layer selector */
#layerSelector {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: rgba(14,13,11,0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px;
  backdrop-filter: blur(var(--blur));
}

.layer-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-mid);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  font-weight: 400;
  text-align: left;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.layer-btn:hover {
  background: var(--amber-glow);
  color: var(--text);
  border-color: var(--border);
}

.layer-btn.active {
  background: var(--amber-glow);
  border-color: var(--amber-dim);
  color: var(--amber);
  font-weight: 500;
}

.layer-btn svg {
  width: 15px; height: 15px;
  flex-shrink: 0;
  opacity: 0.7;
}

.layer-btn.active svg { opacity: 1; }

/* ═══════════════════════════════════════════════════════════════════
   LEGEND (top-right)
═══════════════════════════════════════════════════════════════════ */
#legendPanel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 20;
  background: rgba(14,13,11,0.88);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 10px;
  backdrop-filter: blur(var(--blur));
  display: none;
  min-width: 56px;
}

#legendPanel.visible { display: block; }

.legend-title {
  font-size: 0.62rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--amber);
  margin-bottom: 8px;
  text-align: center;
}

.legend-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.legend-val {
  font-family: 'DM Mono', monospace;
  font-size: 0.68rem;
  color: var(--text-muted);
}

#legendCanvas {
  border-radius: 4px;
  border: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════
   MONTH BAR (bottom centre)
═══════════════════════════════════════════════════════════════════ */
#monthBar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 20;
  display: none; /* shown when a layer is active */
}

#monthBar.visible { display: block; }

#monthBarInner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(14,13,11,0.92);
  border: 1px solid var(--border-mid);
  border-radius: 999px;
  padding: 8px 14px;
  backdrop-filter: blur(var(--blur));
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.transport-btn {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-mid);
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  font-family: inherit;
}

.transport-btn:hover {
  border-color: var(--amber-dim);
  color: var(--amber);
  background: var(--amber-glow);
}

.transport-btn.playing {
  border-color: var(--amber);
  color: var(--amber);
  background: var(--amber-glow);
}

/* Month track pills */
#monthTracks {
  display: flex;
  align-items: center;
  gap: 3px;
}

.month-pill {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem;
  font-weight: 400;
  transition: all 0.15s;
  white-space: nowrap;
}

.month-pill:hover {
  color: var(--text);
  background: rgba(255,255,255,0.05);
}

.month-pill.active {
  background: var(--amber);
  color: var(--ink);
  font-weight: 500;
  border-color: var(--amber);
}

#currentMonthDisplay {
  padding-left: 6px;
  border-left: 1px solid var(--border);
  min-width: 72px;
}

#currentMonthName {
  font-family: 'Playfair Display', serif;
  font-size: 0.95rem;
  color: var(--amber);
  font-style: italic;
}

/* ═══════════════════════════════════════════════════════════════════
   STATUS PILL
═══════════════════════════════════════════════════════════════════ */
#statusPill {
  position: absolute;
  bottom: 20px;
  left: 16px;
  z-index: 15;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(14,13,11,0.80);
  border: 1px solid var(--border);
  backdrop-filter: blur(var(--blur));
  font-size: 0.75rem;
  color: var(--text-muted);
  pointer-events: none;
}

/* ═══════════════════════════════════════════════════════════════════
   DETAIL PANEL (right slide-in)
═══════════════════════════════════════════════════════════════════ */
#detailPanel {
  position: fixed;
  top: 0;
  right: calc(-1 * var(--detail-w) - 20px);
  bottom: 0;
  width: var(--detail-w);
  z-index: 50;
  background: var(--slate);
  border-left: 1px solid var(--border-mid);
  overflow-y: auto;
  overflow-x: hidden;
  transition: right 0.38s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: -12px 0 48px rgba(0,0,0,0.6);

  /* Custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: var(--slate-high) transparent;
}

#detailPanel::-webkit-scrollbar { width: 4px; }
#detailPanel::-webkit-scrollbar-track { background: transparent; }
#detailPanel::-webkit-scrollbar-thumb { background: var(--slate-high); border-radius: 2px; }

#detailPanel.open { right: 0; }

/* Header */
#detailHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--slate);
  z-index: 5;
}

.detail-coords {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.detail-name {
  font-family: 'Playfair Display', serif;
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
}

#detailClose {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 8px;
  margin-top: 2px;
  transition: all 0.15s;
}

#detailClose:hover { color: var(--hot); border-color: var(--hot); }

/* Loader */
#detailLoader {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px;
  gap: 14px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

#detailLoader.active { display: flex; }

.loader-ring {
  width: 32px; height: 32px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Panel month nav */
#panelMonthNav {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 12px 20px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.panel-section-label {
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
}

.panel-month-name {
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--amber);
}

/* Sections */
.detail-section {
  padding: 0;
  border-bottom: 1px solid var(--border);
}

.detail-section.primary-section {
  padding: 16px 20px;
  border-bottom: 2px solid var(--border-mid);
  background: rgba(245, 200, 66, 0.02);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.10em;
  color: var(--text-muted);
  margin-bottom: 0;
}

.section-header svg { opacity: 0.6; flex-shrink: 0; }

/* Collapsible section toggle */
.section-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
  font-family: inherit;
  font-size: inherit;
}

.section-toggle:hover {
  background: var(--slate-high);
  color: var(--amber);
}

.section-toggle svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.section-toggle.expanded svg {
  transform: rotate(180deg);
  color: var(--amber);
}

.section-content {
  max-height: 2000px;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 0 12px 0;
}

.section-content.hidden {
  max-height: 0;
  padding: 0;
}

/* Mini stat groups within Quick Summary */
.mini-stat-group {
  padding: 12px 0;
}

.mini-stat-header {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
  padding: 0 20px;
}

/* Chart sections */
.chart-section {
  padding: 12px 20px 20px;
}

.chart-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 10px;
  font-weight: 600;
}

/* Stat rows */
.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
  padding: 0 20px;
}

.detail-section.primary-section .stat-row {
  padding: 0;
  margin: 0;
}

.mini-stat-group .stat-row {
  padding: 0 20px;
}

.stat-card {
  background: var(--slate-mid);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 8px 8px;
  text-align: center;
  transition: border-color 0.2s;
}

.stat-card:hover { border-color: var(--border-mid); }

.stat-value {
  font-family: 'DM Mono', monospace;
  font-size: 1.3rem;
  font-weight: 500;
  color: var(--text);
  line-height: 1.1;
}

.stat-unit {
  font-size: 0.58rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 1px;
}

.stat-label {
  font-size: 0.64rem;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-top: 4px;
  line-height: 1.3;
}

/* Coloured stat variants */
.stat-hot  .stat-value { color: var(--hot); }
.stat-cold .stat-value { color: var(--cold); }
.stat-rain .stat-value { color: var(--rain); }
.stat-wind .stat-value { color: var(--wind); }
.stat-sun  .stat-value { color: var(--sun); }

/* Charts */
.chart-wrap {
  height: 140px;
  position: relative;
}

.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Best time */
.best-time-placeholder {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  background: var(--slate-mid);
  border-radius: var(--radius-md);
  border: 1px dashed var(--border-mid);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.muted-note {
  font-size: 0.68rem;
  opacity: 0.6;
  font-style: italic;
}

/* ── Holiday Comfort Index (HCI) styling – PRIMARY FOCUS ── */

.hci-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.hci-best-month,
.hci-top-three {
  padding: 16px;
  background: linear-gradient(135deg, rgba(245, 200, 66, 0.08), rgba(245, 200, 66, 0.02));
  border-radius: var(--radius-md);
  border: 1px solid var(--border-mid);
}

.hci-best-month {
  background: linear-gradient(135deg, rgba(245, 200, 66, 0.12), rgba(245, 200, 66, 0.04));
}

.hci-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
}

.hci-best-month .hci-value {
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
  font-family: 'Playfair Display', serif;
}

.hci-score-display {
  font-family: 'DM Mono', monospace;
  font-size: 0.9rem;
  color: var(--sun);
  font-weight: 600;
}

.hci-top-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hci-item {
  font-size: 0.8rem;
  color: var(--text-mid);
  font-family: 'DM Mono', monospace;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hci-item strong {
  color: var(--text);
  font-size: 0.9rem;
}

/* HCI Month Grid - Fixed width constraint */
.hci-months-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 20px;
  width: 100%;
  overflow: visible;
}

.hci-month-pill {
  padding: 12px 8px;
  background: var(--slate-mid);
  border-radius: var(--radius-md);
  border: 2px solid var(--hci-color, var(--amber));
  text-align: center;
  cursor: default;
  transition: all 0.2s ease;
  min-width: 0;
}

.hci-month-pill.current {
  transform: scale(1.12);
  background: var(--slate-high);
  box-shadow: 0 4px 16px rgba(245, 200, 66, 0.2);
}

.hci-month-pill:hover {
  background: var(--slate-high);
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.hci-month-pill.current:hover {
  transform: scale(1.15);
}

.hci-month-name {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 5px;
  line-height: 1.2;
}

.hci-score {
  font-family: 'DM Mono', monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hci-color, var(--amber));
}

.hci-legend {
  padding: 12px;
  background: rgba(245, 200, 66, 0.05);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-mid);
  font-size: 0.7rem;
  margin-top: 8px;
}

.hci-formula {
  font-family: 'DM Mono', monospace;
  font-size: 0.62rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.5;
}

/* Debug accordion */
.debug-accordion {
  margin: 12px 20px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.debug-accordion summary {
  padding: 8px 12px;
  font-size: 0.72rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  background: var(--slate-mid);
  letter-spacing: 0.05em;
}

.debug-accordion summary:hover { color: var(--text); }

#debugDump {
  padding: 12px;
  font-family: 'DM Mono', monospace;
  font-size: 0.65rem;
  color: var(--text-muted);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--slate);
  max-height: 400px;
  overflow-y: auto;
  user-select: all;
}

/* ═══════════════════════════════════════════════════════════════════
   UTILITIES
═══════════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

/* ═══════════════════════════════════════════════════════════════════
   RESPONSIVE
═══════════════════════════════════════════════════════════════════ */
@media (max-width: 700px) {
  #sidebar {
    top: auto;
    bottom: 90px;
    left: 8px;
    width: auto;
  }

  .wm-sub { display: none; }
  .layer-label { display: none; }
  .layer-btn { padding: 9px; }

  #layerSelector { flex-direction: row; flex-wrap: wrap; padding: 4px; }

  #legendPanel {
    right: 8px;
    top: auto;
    bottom: 90px;
  }

  #monthBar {
    bottom: 10px;
    left: 8px;
    right: 8px;
    transform: none;
  }

  #monthBarInner {
    border-radius: var(--radius-md);
    flex-wrap: wrap;
  }

  #detailPanel {
    width: 100%;
    right: -110%;
  }
}