/* define palette and panel tokens */
:root {
  --so-night: #252C29;
  --so-day: #E8E7E1;
  --so-dusk: #81877C;
  --so-midday: #FFFFFF;
  --so-morning: #F8FEB9;
  --so-electric: #CBFB00;
  --so-hydro: #019CA1;
  --so-dear: #FF646D;
  --so-mint: #40C9A2;

  --accent: var(--so-electric);

  --panel-bg: rgba(31, 37, 34, 0.86);
  --panel-fg: var(--so-day);
  --panel-muted: #A7ACA2;
  --panel-border: rgba(232, 231, 225, 0.14);
  --panel-hover: rgba(232, 231, 225, 0.08);
  --radius: 16px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  font-family: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--so-night); }
#map { position: absolute; inset: 0; z-index: 0; background: var(--so-night); }
button { font-family: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ---- floating glass panels ---- */
.panel {
  position: absolute;
  z-index: 1000;
  background: var(--panel-bg);
  color: var(--panel-fg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

/* ---- thin dark scrollbars ---- */
.news-list, #controls {
  scrollbar-width: thin;
  scrollbar-color: rgba(232, 231, 225, 0.22) transparent;
}
.news-list::-webkit-scrollbar, #controls::-webkit-scrollbar { width: 8px; }
.news-list::-webkit-scrollbar-thumb, #controls::-webkit-scrollbar-thumb {
  background: rgba(232, 231, 225, 0.2);
  border: 2px solid transparent;
  border-radius: 6px;
  background-clip: padding-box;
}

/* ---- section headings ---- */
.section { padding: 12px 16px; border-top: 1px solid var(--panel-border); }
.section:first-child { border-top: none; }
h2 {
  margin: 0 0 8px;
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--panel-muted);
}

/* ---- alert badge ---- */
#alert { top: 18px; left: 18px; width: 320px; padding: 14px 18px 12px; }
#alert h1 {
  margin: 0 0 12px;
  font-size: 17px; font-weight: 700;
  letter-spacing: -0.01em; text-transform: lowercase;
}
.alert-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 7px 0;
}
.alert-row + .alert-row { border-top: 1px solid var(--panel-border); }
.alert-label { font-size: 13px; font-weight: 500; }
.alert-out { display: flex; align-items: center; gap: 8px; flex: none; }
.alert-pill {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 3px 9px; border-radius: 999px;
  background: var(--panel-hover); color: var(--panel-muted);
}
.alert-pill.low { background: rgba(64, 201, 162, 0.22); color: var(--so-mint); }
.alert-pill.medium { background: rgba(248, 254, 185, 0.2); color: var(--so-morning); }
.alert-pill.high { background: rgba(255, 100, 109, 0.22); color: var(--so-dear); }
.alert-pct {
  min-width: 40px; text-align: right;
  font-size: 17px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.outlook + .outlook {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--panel-border);
}
.outlook h2 { margin: 0 0 2px; }

/* ---- news panel ---- */
#news {
  top: 276px; left: 18px; width: 320px; height: 190px;
  padding: 0; overflow: hidden; display: flex; flex-direction: column;
}
.news-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px;
}
.news-head h2 { margin: 0; }
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--so-dear); animation: ping 2s infinite;
}
@keyframes ping {
  0% { box-shadow: 0 0 0 0 rgba(255, 100, 109, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(255, 100, 109, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 100, 109, 0); }
}
.news-list { flex: 1 1 auto; overflow-y: auto; padding: 0 8px 10px; }
.news-item { display: block; padding: 8px; border-radius: 10px; text-decoration: none; color: var(--panel-fg); }
.news-item:hover { background: var(--panel-hover); }
.news-item + .news-item { border-top: 1px solid var(--panel-border); }
.news-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.news-chip {
  font-size: 9px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; padding: 2px 6px; border-radius: 5px;
}
.news-chip.heatwave { background: rgba(255, 100, 109, 0.18); color: var(--so-dear); }
.news-chip.el_nino { background: rgba(1, 156, 161, 0.2); color: var(--so-hydro); }
.news-src { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--panel-muted); }
.news-item.primary .news-src { color: var(--so-morning); }
.news-title { font-size: 12px; line-height: 1.35; }
.news-time { font-size: 10px; color: var(--panel-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.news-empty { padding: 10px; font-size: 12px; color: var(--panel-muted); }

/* ---- controls ---- */
#controls { top: 18px; right: 18px; width: 230px; padding: 4px 0 6px; }
.segmented { display: flex; gap: 6px; }
.segmented button {
  flex: 1; padding: 8px 6px;
  font-size: 12px; font-weight: 600;
  color: var(--panel-fg); background: var(--panel-hover);
  border: 1px solid transparent; border-radius: 10px;
}
.segmented button[aria-pressed="true"] { background: var(--accent); color: var(--so-night); }
.segmented.small button { padding: 5px 8px; font-size: 11px; }
.run-note { padding: 4px 16px 8px; font-size: 10px; line-height: 1.4; color: var(--panel-muted); }

/* ---- imbalance panel ---- */
#imbalance { top: 476px; left: 18px; width: 320px; padding: 12px 14px 10px; }
.imb-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.imb-head h2 { margin: 0; }
.imb-chart { width: 100%; height: 168px; }
.imb-chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.imb-axis { stroke: rgba(232, 231, 225, 0.55); stroke-width: 1; }
.imb-grid { stroke: rgba(232, 231, 225, 0.1); stroke-width: 1; }
.imb-tick { fill: var(--panel-muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.imb-line { fill: none; stroke-width: 1.5; }
.imb-line.current { stroke: var(--so-midday); stroke-width: 2.4; }
.imb-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 8px; }
.imb-key { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--panel-muted); }
.imb-key i { width: 14px; height: 0; border-top: 3px solid; border-radius: 2px; }
.imb-key.current b { color: var(--so-day); font-weight: 600; }
.imb-empty { padding: 16px 4px; font-size: 12px; color: var(--panel-muted); text-align: center; }

/* ---- colour scale legend (inside controls) ---- */
.legend-title {
  font-size: 11px; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--panel-muted);
  margin: 0 0 8px;
}
.legend-bar { height: 14px; border-radius: 7px; border: 1px solid var(--panel-border); }
.legend-ticks {
  display: flex; justify-content: space-between; margin-top: 5px;
  font-size: 10px; color: var(--panel-muted); font-variant-numeric: tabular-nums;
}

/* ---- day slider ---- */
#timebar {
  bottom: 22px; left: 50%; transform: translateX(-50%);
  width: min(720px, calc(100vw - 36px)); padding: 14px 20px 14px;
}
#timebar .row { display: flex; align-items: center; gap: 14px; }
.tt-btn {
  flex: none; width: 38px; height: 38px; display: grid; place-items: center;
  font-size: 14px; color: var(--panel-fg);
  background: var(--panel-hover); border: 1px solid var(--panel-border); border-radius: 10px;
}
.tt-btn:hover { background: rgba(232, 231, 225, 0.16); }
#todayBtn {
  flex: none; padding: 0 16px; height: 38px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  color: var(--so-night); background: var(--so-mint); border: none; border-radius: 10px;
}
#todayBtn[data-active="false"] { background: var(--panel-hover); color: var(--panel-fg); }
#dayStamp {
  flex: none; min-width: 150px; text-align: right;
  font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums;
}
#dayRange {
  flex: 1; -webkit-appearance: none; appearance: none;
  height: 6px; border-radius: 6px;
  background: linear-gradient(90deg, var(--so-hydro) 0%, var(--accent) 100%);
  opacity: 0.9;
}
#dayRange::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--so-night); border: 3px solid var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
#dayRange::-moz-range-thumb {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--so-night); border: 3px solid var(--accent);
}
#dayCaption { margin-top: 8px; font-size: 11px; color: var(--panel-muted); text-align: center; }

/* ---- sources tray ---- */
#sources { bottom: 22px; right: 18px; width: 262px; padding: 0; overflow: hidden; }
.src-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 12px 16px; background: none; border: none;
  color: var(--panel-fg); font-size: 11px; font-weight: 600;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.src-chev { color: var(--panel-muted); transition: transform 0.2s; }
#sources.collapsed .src-chev { transform: rotate(180deg); }
#sources.collapsed .src-body { display: none; }
.src-body { padding: 0 16px 14px; }
.src-group { padding: 8px 0; border-top: 1px solid var(--panel-border); }
.src-label {
  display: block; margin-bottom: 4px;
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--panel-muted);
}
.src-group a { font-size: 12px; color: var(--so-hydro); text-decoration: none; margin-right: 10px; }
.src-group a:hover { text-decoration: underline; }
.src-note { display: block; margin-top: 4px; font-size: 10px; line-height: 1.4; color: var(--panel-muted); }

/* ---- cursor value readout ---- */
.readout {
  position: absolute; z-index: 1200; pointer-events: none;
  padding: 4px 9px; border-radius: 8px;
  background: rgba(31, 37, 34, 0.92); color: var(--so-day);
  border: 1px solid var(--panel-border);
  font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}

/* ---- zoom controls inside the panel ---- */
.zoom-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.zoom-row:last-child { margin-bottom: 0; }
.zoom-label { font-size: 12px; font-weight: 500; color: var(--panel-fg); }
.zoom-btns { display: flex; gap: 6px; }
.zbtn {
  width: 30px; height: 30px; line-height: 1;
  font-size: 16px; font-weight: 400;
  color: var(--panel-fg); background: var(--panel-hover);
  border: 1px solid var(--panel-border); border-radius: 8px;
}
.zbtn:hover { background: rgba(232, 231, 225, 0.16); color: var(--accent); }
.leaflet-bottom.leaflet-right { display: none; }

@media (max-width: 880px) {
  #imbalance { display: none; }
  #news { display: none; }
}
