:root {
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--ink);
  background: var(--page);
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
#topbar {
  display: grid; grid-template-columns: minmax(410px, 1fr) minmax(360px, 620px) minmax(410px, 1fr);
  align-items: center; justify-content: space-between; gap: 10px 16px;
  overflow: hidden;
  padding: 8px 16px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--grid);
  flex: 0 0 auto;
}
.brand { display: flex; flex: 0 1 auto; align-items: center; gap: 10px; min-width: 0; white-space: nowrap; }
.site-home-link {
  flex: 0 0 auto; color: var(--ink); font-family: 'Lora', Georgia, serif;
  font-size: 21px; font-weight: 600; text-decoration: none; white-space: nowrap;
  transition-property: color; transition-duration: 0.2s;
}
.site-home-link:hover { color: var(--accent); }
.site-home-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 2px; }
.brand-divider { width: 1px; height: 24px; flex: 0 0 auto; background: var(--grid); }
.app-identity { display: flex; min-width: 0; align-items: baseline; }
.brand-title {
  overflow: hidden; font-size: 15px; font-weight: 650;
  text-overflow: ellipsis; white-space: nowrap;
}
.controls {
  display: flex; min-width: 0; justify-self: end; justify-content: flex-end;
  gap: 8px 10px; align-items: center; flex-wrap: nowrap; white-space: nowrap;
}
.seg { display: inline-flex; border: 1px solid var(--baseline); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; padding: 5px 14px; cursor: pointer;
  font: inherit; color: var(--ink-2); border-right: 1px solid var(--grid);
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: #fff; font-weight: 600; }

/* ---------- layout ---------- */
#layout { flex: 1 1 auto; display: flex; min-height: 0; }
#sidebar {
  width: 320px; flex: 0 0 auto; overflow-y: auto;
  background: var(--surface-1); border-right: 1px solid var(--grid);
  padding: 12px 14px 20px;
}
#sidebar section { margin-bottom: 16px; }
.sec-label {
  font-size: 11px; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 6px; display: block;
}
.hint { font-weight: 400; text-transform: none; letter-spacing: 0; }
select, input {
  width: 100%; padding: 5px 8px; font: inherit; color: var(--ink);
  border: 1px solid var(--baseline); border-radius: 6px; background: #fff;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.oos-toggle { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.oos-toggle input { width: auto; margin: 0; }
/* stats */
.stat-row { display: flex; gap: 10px; }
.stat {
  flex: 1; background: var(--page); border: 1px solid var(--grid);
  border-radius: 8px; padding: 8px 10px;
}
.stat-v { font-size: 20px; font-weight: 650; }
.stat-l { font-size: 11px; color: var(--muted); }

/* area chart */
#areaChart .bar-row { margin-bottom: 7px; cursor: pointer; }
#areaChart .bar-row:hover .bar-name { color: var(--ink); }
#areaChart .bar-row.sel .bar-name { color: var(--ink); font-weight: 650; }
.bar-head { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 2px; }
.bar-name { color: var(--ink-2); }
.bar-val { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-track { display: flex; height: 12px; border-radius: 3px; overflow: hidden; background: var(--page); }
.bar-track .segm { height: 100%; margin-right: 2px; }
.bar-track .segm:last-child { margin-right: 0; }

.seg-sm { margin-top: 8px; }
.seg-sm button { padding: 2px 10px; font-size: 11px; }

#timeCtl { width: 100%; min-width: 360px; max-width: 620px; justify-self: center; padding-inline: 8px; }
#timeLabel {
  text-align: center; font-size: 13px; font-weight: 700; color: var(--ink);
  white-space: nowrap; margin-bottom: 3px; font-variant-numeric: tabular-nums;
}

/* custom track so the left fill can express the mode:
   cumulative = filled through the thumb (a range of years),
   incremental = no fill (a single point in time) */
#timeSlider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 18px; padding: 0; margin: 0;
  border: 0; border-radius: 0; background: transparent; box-shadow: none; cursor: pointer;
  --fill: 0%;
}
#timeSlider::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(to right,
    var(--ink) 0%, var(--ink) var(--fill),
    var(--grid) var(--fill), var(--grid) 100%);
}
#timeSlider.inc::-webkit-slider-runnable-track { background: var(--grid); }
#timeSlider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%; margin-top: -6px;
  background: var(--ink); border: 2.5px solid var(--surface-1);
  box-shadow: 0 0 0 1px var(--baseline), 0 1px 3px rgba(0,0,0,0.25);
}
#timeSlider::-moz-range-track {
  height: 6px; border-radius: 3px; background: var(--grid);
}
#timeSlider::-moz-range-progress {
  height: 6px; border-radius: 3px; background: var(--ink);
}
#timeSlider.inc::-moz-range-progress { background: transparent; }
#timeSlider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--ink); border: 2.5px solid var(--surface-1);
  box-shadow: 0 0 0 1px var(--baseline), 0 1px 3px rgba(0,0,0,0.25);
}
#timeSlider:focus { outline: none; }
#timeSlider:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 1px var(--baseline), 0 1px 3px rgba(0,0,0,0.25), 0 0 0 4px rgba(42,120,214,0.24);
}
#timeSlider:focus-visible::-moz-range-thumb {
  box-shadow: 0 0 0 1px var(--baseline), 0 1px 3px rgba(0,0,0,0.25), 0 0 0 4px rgba(42,120,214,0.24);
}

/* clickable year ticks under the track, placed at their true (non-linear) positions */
#timeTicks { position: relative; height: 13px; }
#timeTicks span {
  position: absolute; transform: translateX(-50%);
  font-size: 9.5px; color: var(--muted); cursor: pointer; user-select: none;
  padding: 0 3px; line-height: 13px; font-variant-numeric: tabular-nums;
}
#timeTicks span:hover { color: var(--ink); }
#timeTicks span.cur { color: var(--ink); font-weight: 650; }
#timeTicks span:first-child { transform: none; }
#timeTicks span:nth-last-child(2) { transform: translateX(-100%); }
#timeTicks span:last-child { transform: translateX(-100%); }

.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Keep header geometry stable while making plan-only controls clearly unavailable. */
.inactive { opacity: 0.38; pointer-events: none; }
.view-hidden { display: none !important; }

.built-chart { margin-top: 8px; }
.built-chart .bc-title {
  font-size: 11px; font-weight: 650; color: var(--ink-2); margin-bottom: 5px;
}
.built-chart .bar-row {
  display: block; width: 100%; min-height: 40px; margin: 0 0 3px; padding: 5px 6px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
  color: inherit; font: inherit; text-align: left; opacity: 0.56;
  transition-property: opacity, background-color, box-shadow;
  transition-duration: 0.16s;
}
.built-chart .bar-row:hover { opacity: 0.82; background: rgba(42, 120, 214, 0.05); }
.built-chart .bar-row.current {
  opacity: 1; background: rgba(42, 120, 214, 0.09);
  box-shadow: inset 3px 0 0 var(--accent);
}
.built-chart .bar-row.current .bar-name { color: var(--ink); font-weight: 650; }
.built-chart .bar-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; opacity: 1; }

.foot-note { font-size: 11px; color: var(--muted); border-top: 1px solid var(--grid); padding-top: 10px; }
.foot-note em { font-style: italic; }

/* ---------- map ---------- */
#mapwrap { flex: 1 1 auto; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

#legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 800;
  display: flex; flex-direction: column;
  background: rgba(252, 252, 251, 0.94); border: 1px solid var(--grid); border-radius: 8px;
  padding: 9px 12px; font-size: 11.5px; color: var(--ink-2); width: min(280px, calc(100% - 24px));
  min-height: 552px; height: auto; overflow: visible; box-sizing: border-box;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
#legend .lg-title { font-weight: 650; color: var(--ink); margin-bottom: 4px; font-size: 11px; }
#legend .lg-row { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
#legend .lg-dot { border-radius: 50%; flex: 0 0 auto; }
#legend .lg-section + .lg-section { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--grid); }
#legend .lg-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#legend .lg-title-row .lg-title { margin-bottom: 0; }
#legend .lg-hint { margin: 2px 0 6px; color: var(--muted); font-size: 10.5px; line-height: 1.35; }
#legend .lg-criteria-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px 8px; }
#legend .lg-criteria-grid .lg-row { min-width: 0; margin: 0; white-space: nowrap; }
#legend .lg-resource-section { flex: 0 0 auto; }
#legend .lg-filter-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  min-height: 212px; align-content: start; gap: 3px;
}
#legend .lg-filter {
  display: flex; min-width: 0; min-height: 40px; align-items: center; gap: 6px;
  padding: 5px 6px; border: 0; border-radius: 6px; background: transparent;
  color: var(--ink-2); cursor: pointer; font: 11px/1.2 system-ui, sans-serif; text-align: left;
  transition-property: opacity, background-color, transform;
  transition-duration: 0.16s;
}
#legend .lg-filter:hover { background: rgba(42, 120, 214, 0.08); }
#legend .lg-filter:active { transform: scale(0.96); }
#legend .lg-filter:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#legend .lg-filter.excluded { opacity: 0.34; }
#legend .lg-filter.selected { background: rgba(42, 120, 214, 0.10); color: var(--ink); font-weight: 600; }
#legend .lg-reset {
  min-height: 28px; padding: 3px 7px; border: 1px solid var(--grid); border-radius: 5px;
  background: var(--surface-1); color: var(--accent); cursor: pointer; font: 10.5px system-ui, sans-serif;
  transition-property: background-color, transform; transition-duration: 0.16s;
}
#legend .lg-reset:hover { background: rgba(42, 120, 214, 0.08); }
#legend .lg-reset:active { transform: scale(0.96); }
#legend .lg-reset:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#legend .lg-transmission-section { position: relative; flex: 0 0 auto; }
#legend .lg-transmission-toggle {
  display: flex; width: 100%; min-height: 40px; align-items: center; gap: 8px;
  padding: 5px 6px; border: 0; border-radius: 6px; background: transparent;
  color: var(--ink-2); cursor: pointer; font: 11px/1.2 system-ui, sans-serif; text-align: left;
  transition-property: opacity, background-color, transform; transition-duration: 0.16s;
}
#legend .lg-transmission-toggle:hover { background: rgba(42, 120, 214, 0.08); }
#legend .lg-transmission-toggle:active { transform: scale(0.96); }
#legend .lg-transmission-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#legend .lg-transmission-toggle.off { opacity: 0.48; }
#legend .lg-transmission-toggle.error { cursor: not-allowed; opacity: 0.38; }
#legend .tx-gradient {
  width: 28px; height: 5px; flex: 0 0 auto; border-radius: 3px;
  background: linear-gradient(90deg, #747d8c, #2e86de, #00d2d3, #ffa502, #ff9f43, #ff2e63);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
#legend .tx-label { min-width: 0; flex: 1 1 auto; }
#legend .tx-label strong { display: block; color: var(--ink); font-size: 11px; font-weight: 650; }
#legend .tx-label small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; }
#legend .tx-switch {
  position: relative; width: 28px; height: 16px; flex: 0 0 auto; border-radius: 9px;
  background: var(--grid); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
  transition-property: background-color; transition-duration: 0.16s;
}
#legend .tx-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
  transition-property: transform; transition-duration: 0.16s;
}
#legend .lg-transmission-toggle[aria-pressed="true"] .tx-switch { background: var(--accent); }
#legend .lg-transmission-toggle[aria-pressed="true"] .tx-switch::after { transform: translateX(12px); }
#txVoltageKey {
  position: absolute; z-index: 950; visibility: hidden; opacity: 0; pointer-events: none;
  min-width: 166px; padding: 9px 11px; border-radius: 8px; background: rgba(252, 252, 251, 0.98);
  color: var(--ink-2); font-size: 11px; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.16);
  transform: translateX(-4px); transition-property: opacity, transform, visibility; transition-duration: 0.16s;
}
#txVoltageKey.show { visibility: visible; opacity: 1; transform: translateX(0); }
#txVoltageKey .tx-key-title { margin-bottom: 6px; color: var(--ink); font-weight: 650; }
#txVoltageKey .tx-key-row { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
#txVoltageKey .tx-key-line { width: 24px; height: 4px; flex: 0 0 auto; border-radius: 2px; }
#legend .lg-symbol-section { flex: 0 0 66px; min-height: 66px; }
#legend .lg-size-section { flex: 0 0 113px; min-height: 113px; margin-top: auto; }
#legend .size-row { display: flex; align-items: flex-end; gap: 12px; margin-top: 6px; }
#legend .size-item { display: flex; flex-direction: column; align-items: center; gap: 2px; }
#legend .size-circ { border-radius: 50%; border: 1.5px solid var(--muted); background: transparent; }
#legend .size-square { border-radius: 2px; }

/* ---------- detail panel ---------- */
#detail {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: 420px; z-index: 900;
  background: var(--surface-1); border: 1px solid var(--grid); border-radius: 10px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.14); overflow-y: auto; padding: 14px 16px;
}
#detail.hidden { display: none; }
#detailClose {
  position: absolute; top: 8px; right: 10px; border: 0; background: none;
  font-size: 20px; color: var(--muted); cursor: pointer; line-height: 1;
}
#detailClose:hover { color: var(--ink); }
.d-title { font-size: 16px; font-weight: 650; margin: 0 40px 2px 0; }
.d-meta { color: var(--ink-2); font-size: 12px; margin-bottom: 4px; }
.d-badge {
  display: inline-block; font-size: 10.5px; padding: 1px 7px; border-radius: 10px;
  background: var(--page); border: 1px solid var(--baseline); color: var(--ink-2); margin-right: 4px;
}
.d-badge.warn { background: #fdf3e0; border-color: #eda100; color: #7a5200; }
.d-sec { margin-top: 14px; }
.d-sec h4 {
  margin: 0 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 650;
}
table.mwt { width: 100%; border-collapse: collapse; font-size: 12px; }
table.mwt th, table.mwt td { padding: 3px 6px; text-align: right; font-variant-numeric: tabular-nums; }
table.mwt th { color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--grid); }
table.mwt td:first-child, table.mwt th:first-child { text-align: left; }
table.mwt tr.tot td { border-top: 1px solid var(--baseline); font-weight: 650; }
.t-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }

/* criteria grid */
table.crit { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.crit th, table.crit td { padding: 2px 4px; }
table.crit th { color: var(--muted); font-weight: 600; text-align: center; font-size: 10.5px; }
table.crit td.cname { color: var(--ink-2); text-align: left; max-width: 170px; }
table.crit td.grp {
  padding-top: 8px; font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--muted); font-weight: 650;
}
.lvl {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 17px; border-radius: 4px; color: #fff; font-weight: 650; font-size: 10.5px;
}
.lvl.na { background: var(--page); color: var(--baseline); border: 1px solid var(--grid); }
.d-note { font-size: 12px; color: var(--ink-2); background: var(--page); border-left: 3px solid var(--baseline); padding: 6px 9px; border-radius: 0 6px 6px 0; margin-top: 6px; }

/* actual-buildout markers (EIA-860M) */
.built-icon { background: none; border: none; }
.built-icon .bmk {
  display: block; width: 100%; height: 100%; box-sizing: border-box;
  border: 1.4px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 0.6px rgba(11, 11, 11, 0.35);
  opacity: 0.88;
}
.built-icon .bmk.planned {
  transform: rotate(45deg);
  border-width: 2px;
  border-style: dashed;
}

/* leaflet tooltip */
.leaflet-tooltip.sub-tip {
  background: var(--surface-1); border: 1px solid var(--grid); border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12); color: var(--ink); padding: 7px 10px;
}
.tip-name { font-weight: 650; font-size: 12.5px; }
.tip-meta { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.tip-row { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); }
.tip-row b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; color: var(--ink); }

@media (max-width: 1248px) {
  #topbar { grid-template-columns: auto minmax(260px, 1fr) auto; }
  .seg button { padding-inline: 10px; }
}

@media (max-width: 900px) {
  #topbar { padding-inline: 10px; }
  .app-identity, .brand-divider { display: none; }
  .site-home-link { font-size: 18px; }
  .controls { gap: 6px; }
  #timeCtl { min-width: 150px; padding-inline: 2px; }
  .seg button { padding-inline: 7px; }
  #layout { flex-direction: column; }
  #sidebar { width: auto; max-height: 45%; border-right: 0; border-bottom: 1px solid var(--grid); }
  #detail { width: auto; left: 12px; }
}
