/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg-base:    #0d0f18;
  --bg-panel:   #111420;
  --bg-surface: #181c2c;
  --bg-hover:   #1f2438;
  --border:     #272d44;
  --border-mid: #333c58;

  --text-hi:    #ffffff;
  --text-mid:   #ffffff;
  --text-lo:    #ffffff;

  --solar:      #ff8c00;
  --solar-glow: rgba(255, 140, 0, 0.35);
  --solar-dim:  rgba(255, 140, 0, 0.15);
  --solar-ring: rgba(255, 140, 0, 0.35);

  --wind:       #4db8ff;
  --wind-glow:  rgba(77, 184, 255, 0.35);
  --wind-dim:   rgba(77, 184, 255, 0.15);
  --wind-ring:  rgba(77, 184, 255, 0.35);

  --radius-sm:  5px;
  --radius-md:  8px;
  --radius-lg:  10px;
}

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

body {
  background: var(--bg-base);
  color: var(--text-hi);
  font-family: 'Lora', Georgia, 'Times New Roman', serif;
  font-size: 13px;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Top bar ────────────────────────────────────────────────────────────────── */
#top-bar {
  width: 100%;
  flex-shrink: 0;
  height: 48px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 12px;
}

#top-bar-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--text-hi);
  flex: 1;
}

#sources-btn {
  background: transparent;
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  color: var(--text-hi);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 12px;
  transition: background 0.13s, border-color 0.13s;
}

#sources-btn:hover,
#sources-btn.active {
  background: var(--bg-surface);
  border-color: var(--text-mid);
}

#rey-btn {
  background: transparent;
  border: 1px solid rgba(245,158,11,0.5);
  border-radius: var(--radius-sm);
  color: rgb(245,158,11);
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 12px;
  text-decoration: none;
  transition: background 0.13s, border-color 0.13s;
}
#rey-btn:hover {
  background: rgba(245,158,11,0.08);
  border-color: rgb(245,158,11);
}

/* ── Layout ─────────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── Map pane ───────────────────────────────────────────────────────────────── */
#map-pane {
  flex: 0 0 60%;
  position: relative;
  background: #0d0f18;
  min-height: 0;
}

#map {
  width: 100%;
  height: 100%;
}

#panel-toggle {
  position: absolute;
  right: -13px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1000;
  width: 26px;
  height: 52px;
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-left: none;
  border-radius: 0 6px 6px 0;
  color: var(--text-mid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

#panel-toggle:hover {
  background: var(--bg-hover);
  color: var(--text-hi);
}

/* Collapsed state */
#app.panel-collapsed #side-panel  { display: none; }
#app.panel-collapsed #map-pane    { flex: 0 0 100%; }
#app.panel-collapsed #panel-toggle {
  right: 0;
  border-left: 1px solid var(--border-mid);
  border-radius: 0 6px 6px 0;
}

#map-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(13, 15, 24, 0.88);
  backdrop-filter: blur(2px);
  gap: 10px;
  text-align: center;
  padding: 24px;
  z-index: 500;
}

#map-empty .empty-icon {
  font-size: 36px;
  margin-bottom: 4px;
  opacity: 0.6;
}

#map-empty h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-mid);
}

#map-empty p {
  font-size: 12px;
  color: var(--text-lo);
  line-height: 1.6;
}

.hidden { display: none !important; }

/* ── Side panel ─────────────────────────────────────────────────────────────── */
#side-panel {
  flex: 0 0 40%;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
  min-width: 320px;
}

.section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-lo);
  margin-bottom: 12px;
}

/* ── Mode selector ──────────────────────────────────────────────────────────── */
#mode-selector {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
}

.mode-btn {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-hi);
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 10px 8px;
  text-align: center;
  transition: background 0.13s, border-color 0.13s;
}

.mode-btn:hover { background: var(--bg-hover); border-color: var(--border-mid); }

.mode-btn.active {
  background: var(--bg-hover);
  border-color: var(--text-hi);
}

/* ── Metrics ────────────────────────────────────────────────────────────────── */
#metrics-section {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.metric-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.metric-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-lo);
  margin-bottom: 5px;
}

.metric-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-hi);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.metric-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-mid);
  margin-left: 2px;
}

/* type breakdown chips */
.type-breakdown {
  display: flex;
  gap: 8px;
}

.type-chip {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
}

.type-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.type-dot.solar {
  background: var(--solar);
  box-shadow: 0 0 6px var(--solar-glow);
}

.type-dot.wind {
  background: var(--wind);
  box-shadow: 0 0 6px var(--wind-glow);
}

.type-info { min-width: 0; }

.type-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-lo);
}

.type-count {
  font-size: 19px;
  font-weight: 700;
  color: var(--text-hi);
  font-variant-numeric: tabular-nums;
}

.type-cap {
  font-size: 13px;
  color: var(--text-mid);
  font-variant-numeric: tabular-nums;
}

/* ── Controls ───────────────────────────────────────────────────────────────── */
#controls-section {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-lo);
  white-space: nowrap;
  min-width: 76px;
}

.toggle-group {
  display: flex;
  gap: 3px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.toggle-btn {
  background: transparent;
  border: none;
  border-radius: 3px;
  color: var(--text-mid);
  cursor: pointer;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 11px;
  transition: background 0.13s, color 0.13s;
  white-space: nowrap;
  line-height: 1;
}

.toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--text-hi);
}

.toggle-btn.solar-active.active {
  background: var(--solar);
  color: #fff;
}

.toggle-btn.wind-active.active {
  background: var(--wind);
  color: #fff;
}

.toggle-btn.curtail-btn.active {
  background: #cc0000;
  color: #fff;
}

.curtail-hint {
  font-size: 9px;
  color: var(--text-lo);
  white-space: nowrap;
  margin-left: 2px;
}

.curtail-legend {
  display: flex;
  gap: 14px;
  align-items: center;
}

.curtail-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-hi);
}

.curtail-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

/* Popup curtailment badge */
.popup-divider {
  border-top: 1px solid var(--border);
  margin-top: 5px;
  padding-top: 5px;
}

.curtail-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.curtail-none  { background: rgba(255,140,0,0.15); color: #ff8c00; border: 1px solid rgba(255,140,0,0.4); }
.curtail-low   { background: rgba(255,215,0,0.2);  color: #c8a800; border: 1px solid rgba(255,215,0,0.5); }
.curtail-mid   { background: rgba(255,85,0,0.2);   color: #ff5500; border: 1px solid rgba(255,85,0,0.5); }
.curtail-high  { background: rgba(204,0,0,0.2);    color: #cc0000; border: 1px solid rgba(204,0,0,0.5); }

/* ── Table ──────────────────────────────────────────────────────────────────── */
#table-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

#table-toolbar {
  padding: 8px 20px 7px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.table-count-text {
  font-size: 10px;
  color: var(--text-lo);
  letter-spacing: 0.04em;
}

#table-scroll {
  overflow-y: auto;
  flex: 1;
}

#table-scroll::-webkit-scrollbar { width: 4px; }
#table-scroll::-webkit-scrollbar-track { background: transparent; }
#table-scroll::-webkit-scrollbar-thumb {
  background: var(--border-mid);
  border-radius: 2px;
}

#plants-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

#plants-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-panel);
  z-index: 2;
}

#plants-table th {
  text-align: left;
  padding: 7px 10px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-lo);
  cursor: pointer;
  border-bottom: 1px solid var(--border-mid);
  white-space: nowrap;
  user-select: none;
  transition: color 0.12s;
}

#plants-table th:hover { color: var(--text-mid); }

.sort-icon::before { content: '↕'; color: var(--text-lo); }
th.sorted-asc  .sort-icon::before { content: '↑'; color: var(--text-mid); }
th.sorted-desc .sort-icon::before { content: '↓'; color: var(--text-mid); }

#plants-table td {
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.035);
  color: var(--text-mid);
  vertical-align: middle;
}

td.cell-name {
  color: var(--text-hi);
  font-weight: 500;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.cell-cap {
  color: var(--text-hi);
  font-variant-numeric: tabular-nums;
}

td.cell-utility {
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.type-badge.solar {
  background: var(--solar-dim);
  color: var(--solar);
  border: 1px solid var(--solar-ring);
}

.type-badge.wind {
  background: var(--wind-dim);
  color: var(--wind);
  border: 1px solid var(--wind-ring);
}

#plants-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

#plants-table tbody tr:hover,
#plants-table tbody tr.row-hl {
  background: var(--bg-hover);
}

.loading-row, .empty-row {
  text-align: center;
  color: var(--text-lo);
  font-size: 12px;
  padding: 32px 10px !important;
}

/* ── Leaflet overrides ──────────────────────────────────────────────────────── */
.leaflet-control-zoom a {
  background: var(--bg-surface) !important;
  color: var(--text-mid) !important;
  border-color: var(--border-mid) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-hover) !important;
  color: var(--text-hi) !important;
}

.leaflet-control-attribution {
  background: rgba(13, 15, 24, 0.75) !important;
  color: var(--text-lo) !important;
  font-size: 9px !important;
}

.leaflet-control-attribution a { color: var(--text-lo) !important; }

/* ── Popups ─────────────────────────────────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--bg-surface) !important;
  border: 1px solid var(--border-mid) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.7) !important;
  color: var(--text-hi) !important;
  padding: 0 !important;
}

.leaflet-popup-tip-container { display: none; }

.leaflet-popup-content {
  margin: 0 !important;
  padding: 12px 14px !important;
  font-family: inherit;
}

.popup-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-hi);
  margin-bottom: 7px;
  line-height: 1.3;
}

.popup-row {
  font-size: 11px;
  color: var(--text-mid);
  margin-bottom: 2px;
  display: flex;
  gap: 6px;
}

.popup-row .val {
  color: var(--text-hi);
  font-weight: 500;
}

/* ── Individual marker glow ─────────────────────────────────────────────────── */
.marker-solar path { filter: drop-shadow(0 0 4px var(--solar)); }
.marker-wind  path { filter: drop-shadow(0 0 4px var(--wind));  }

body.sat .marker-solar path,
body.sat .marker-wind  path {
  stroke: #fff !important;
  stroke-width: 1.5px !important;
  filter: drop-shadow(0 0 3px rgba(0,0,0,0.8));
}

/* ── Marker cluster overrides ───────────────────────────────────────────────── */
.leaflet-cluster-anim .leaflet-marker-icon,
.leaflet-cluster-anim .leaflet-marker-shadow {
  transition: transform 0.2s ease-out, opacity 0.2s ease-in-out;
}

.leaflet-cluster-spider-leg { stroke: var(--border-mid) !important; }

/* ── Sources panel ──────────────────────────────────────────────────────────── */
#sources-panel {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#sources-scroll {
  overflow-y: auto;
  flex: 1;
  padding: 16px 20px 24px;
}

#sources-scroll::-webkit-scrollbar { width: 4px; }
#sources-scroll::-webkit-scrollbar-track { background: transparent; }
#sources-scroll::-webkit-scrollbar-thumb { background: var(--border-mid); border-radius: 2px; }

.src-block {
  margin-bottom: 24px;
}

.src-heading {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-lo);
  margin-bottom: 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.src-row {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  align-items: flex-start;
}

.src-flag {
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}

.src-body { min-width: 0; }

.src-name {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-hi);
  text-decoration: none;
  margin-bottom: 3px;
}

.src-name:hover { text-decoration: underline; }

.src-desc {
  font-size: 11px;
  color: var(--text-hi);
  line-height: 1.55;
  margin-bottom: 8px;
}

.src-desc a { color: var(--text-hi); }
.src-desc a:hover { text-decoration: underline; }

.src-muted { opacity: 0.55; margin-bottom: 0; }

.src-math {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin: 10px 0 10px;
}

.src-math-row {
  font-size: 11px;
  color: var(--text-hi);
  margin-bottom: 4px;
  display: flex;
  gap: 8px;
}

.src-math-label {
  font-weight: 600;
  min-width: 76px;
  flex-shrink: 0;
}

.src-math-val { opacity: 0.8; }

.src-math-tier {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 6px;
  margin-bottom: 2px;
  display: block;
}

.src-math-tier.low  { color: #ffd700; }
.src-math-tier.mid  { color: #ff5500; }
.src-math-tier.high { color: #cc0000; }

.src-math-detail {
  font-size: 10.5px;
  opacity: 0.75;
  margin-bottom: 2px;
  display: block;
}
