/* Chrome tokens from the validated reference palette. Dark is the default;
   [data-theme="light"] swaps to the light column — both columns are the
   palette's own validated steps, never an automatic inversion. */
:root {
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --hairline: rgba(255, 255, 255, 0.10);
  --ghost-wash: rgba(255, 255, 255, 0.12);
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --smud-orange: #f58220;
  --line-color: #7d8a99;
}
:root[data-theme="light"] {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --hairline: rgba(11, 11, 11, 0.10);
  --ghost-wash: rgba(11, 11, 11, 0.08);
  --line-color: #6f7987;
}

html, body { height: 100%; margin: 0; }
body {
  background: var(--page);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text-primary);
}
#map { height: 100%; background: var(--page); }

.panel {
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 8px 12px;
  backdrop-filter: blur(4px);
}

/* Staleness badge — status is never color-alone: dot + word + timestamp. */
.badge {
  position: fixed; top: 12px; right: 12px; z-index: 1000;
  display: flex; align-items: center; gap: 8px;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
  font-size: 13px;
  color: var(--text-secondary);
}
.badge-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--text-muted); }
.badge[data-status="green"] .badge-dot { background: var(--status-good); }
.badge[data-status="amber"] .badge-dot { background: var(--status-warning); }
.badge[data-status="red"]   .badge-dot { background: var(--status-critical); }
.badge[data-status="red"] .badge-text { color: var(--status-critical); }
/* PAUSED is deliberate, not a failure — hollow dot, calm text, ⏸ word */
.badge[data-status="paused"] .badge-dot {
  background: transparent; border: 2px solid var(--text-muted);
  width: 7px; height: 7px;
}
.badge button {
  border: 0; background: transparent; color: var(--text-secondary);
  font-size: 13px; cursor: pointer; padding: 0 2px; line-height: 1;
}
.badge button:hover { color: var(--text-primary); }

/* small round quick-controls (theme) under the market toggle */
.quickctl {
  position: fixed; top: 92px; right: 12px; z-index: 1000; display: flex; gap: 6px;
}
.quickctl button {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  color: var(--text-secondary); font-size: 14px; cursor: pointer;
}
.quickctl button:hover { color: var(--text-primary); background: var(--ghost-wash); }

/* count badge on clustered person markers */
.haz-person { position: relative; overflow: visible; }
.person-count {
  position: absolute; top: -7px; right: -8px;
  min-width: 14px; height: 14px; border-radius: 7px;
  background: var(--status-critical); color: #fff;
  font: 700 10px/14px system-ui; text-align: center; padding: 0 3px;
}

.context {
  position: fixed; top: 12px; left: 12px; z-index: 1000;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 300px;
}
.context-title { font-size: 13px; font-weight: 600; color: var(--text-primary); margin-bottom: 6px; }
.chip {
  display: flex; justify-content: space-between; gap: 12px;
  font-size: 12.5px; color: var(--text-secondary); padding: 2px 0;
}
.chip .chip-price { color: var(--text-primary); font-variant-numeric: tabular-nums; }

.legend {
  position: fixed; bottom: 24px; left: 12px; z-index: 1000;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 11.5px; color: var(--text-secondary);
}
.legend-title { font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.legend-row { display: flex; align-items: center; gap: 7px; padding: 1.5px 0; }
.legend-swatch {
  width: 12px; height: 12px; border-radius: 50%;
  border: 1px solid var(--hairline);
}
.legend-lines { border-top: 1px solid var(--hairline); margin-top: 5px; padding-top: 4px; }
.legend-line { width: 16px; background: var(--line-color); opacity: 0.7; display: inline-block; }

/* Market toggle */
.market-toggle {
  position: fixed; top: 56px; right: 12px; z-index: 1000;
  display: flex; border: 1px solid var(--hairline); border-radius: 8px;
  overflow: hidden;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
}
.market-toggle button {
  border: 0; background: transparent; color: var(--text-secondary);
  font: 12.5px system-ui; padding: 6px 12px; cursor: pointer;
}
.market-toggle button.active {
  background: var(--ghost-wash); color: var(--text-primary);
  font-weight: 600;
}

/* Click-graph panel */
.graph-panel {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: 16px; z-index: 1100;
  background: color-mix(in srgb, var(--surface-1) 96%, transparent);
  border: 1px solid var(--hairline); border-radius: 10px;
  padding: 10px 14px 8px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.graph-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.graph-title { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.graph-sub { font-size: 11.5px; color: var(--text-muted); margin-left: 8px; }
.graph-close {
  border: 0; background: transparent; color: var(--text-muted);
  font-size: 18px; cursor: pointer; line-height: 1;
}
.graph-close:hover { color: var(--text-primary); }
.graph-note { font-size: 11px; color: var(--text-muted); margin-top: 4px; max-width: 720px; }
.u-legend { font-size: 11px; color: var(--text-secondary) !important; }

/* Hazard markers & layer control */
.haz {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%;
  border-radius: 50%;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.9);
  filter: drop-shadow(0 0 3px rgba(0, 0, 0, 0.8));
}
.haz-outage {
  background: rgba(245, 130, 32, 0.20);
  border: 1.5px solid var(--smud-orange); /* SMUD brand orange */
  font-size: 13px;
}
.haz-fire { line-height: 1; }
.haz-person { background: transparent; border: 0; }

.graph-actions { display: flex; align-items: center; gap: 8px; }
.graph-notebtn {
  border: 1px solid var(--status-critical); border-radius: 6px;
  background: rgba(208, 59, 59, 0.30); color: var(--text-primary);
  font-size: 13px; font-weight: 600; padding: 6px 14px; cursor: pointer;
}
.graph-notebtn:hover { background: var(--status-critical); color: #ffffff; }
.note-row { padding: 2px 0; }
.note-move-row { display: flex; gap: 6px; margin-top: 6px; }
.note-coord {
  flex: 1; min-width: 0; border: 1px solid var(--hairline); border-radius: 6px;
  background: transparent; color: var(--text-primary);
  font-size: 11.5px; padding: 3px 8px;
}
.note-move-btn { margin-top: 0; }
.note-sep { border: 0; border-top: 1px solid var(--hairline); margin: 6px 0; }
.note-clear {
  margin-top: 6px; border: 1px solid var(--hairline); border-radius: 6px;
  background: transparent; color: var(--text-secondary);
  font-size: 11.5px; padding: 3px 8px; cursor: pointer;
}
.note-clear:hover { color: var(--text-primary); background: var(--ghost-wash); }

/* About / disclaimer modal */
.about-backdrop {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
}
/* display:flex above beats the UA's [hidden]{display:none} — restate it
   with higher specificity or the modal can never close */
.about-backdrop[hidden] { display: none; }
.about-panel {
  max-width: 560px; max-height: 80vh; overflow-y: auto;
  margin: 16px;
  background: var(--surface-1);
  border: 1px solid var(--hairline); border-radius: 10px;
  padding: 14px 18px 16px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
}
.about-head { display: flex; justify-content: space-between; align-items: baseline; }
.about-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.about-body { font-size: 12.5px; line-height: 1.55; color: var(--text-secondary); }
.about-heading {
  font-weight: 600; color: var(--text-primary);
  margin: 12px 0 2px; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.about-body a { color: var(--text-primary); }

.layerctl {
  position: fixed; bottom: 24px; right: 12px; z-index: 1000;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px solid var(--hairline); border-radius: 8px;
  padding: 8px 12px; font-size: 12.5px; color: var(--text-secondary);
}
.layerctl-title { font-weight: 600; color: var(--text-muted); font-size: 11.5px; margin-bottom: 4px; }
.layerctl-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.layerctl-count { margin-left: auto; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.layerctl-action {
  border: 0; background: transparent; color: var(--text-muted);
  font-size: 12px; cursor: pointer; padding: 0 0 0 6px; line-height: 1;
}
.layerctl-action:hover { color: var(--status-critical); }

/* right-edge drag source for freeform field notes */
.note-dropbox {
  position: fixed; right: 12px; top: 45%; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  width: 86px; padding: 10px 6px;
  background: color-mix(in srgb, var(--surface-1) 92%, transparent);
  border: 1px dashed var(--status-critical); border-radius: 10px;
  color: var(--text-secondary); font-size: 10.5px; text-align: center;
  cursor: grab; user-select: none;
}
.note-dropbox:active { cursor: grabbing; }
.note-dropbox:hover { background: var(--ghost-wash); color: var(--text-primary); }
.note-dropbox.armed {
  border-color: var(--status-warning);
  background: rgba(245, 179, 1, 0.18);
  color: var(--text-primary);
}

/* Leaflet dark-theme adjustments */
.leaflet-container { background: var(--page); font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface-1); color: var(--text-secondary);
  border: 1px solid var(--hairline);
}
.leaflet-popup-content { font-size: 12.5px; line-height: 1.45; }
.popup-name { font-weight: 600; color: var(--text-primary); font-size: 13.5px; }
.popup-lmp { font-size: 18px; font-weight: 600; color: var(--text-primary); }
.popup-meta { color: var(--text-muted); font-size: 11.5px; }
.leaflet-tooltip {
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--hairline); box-shadow: none;
  font-size: 12px;
}
.leaflet-control-attribution {
  background: rgba(13, 13, 13, 0.7) !important;
  color: var(--text-muted) !important;
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }
