/* ============================================================================
 * Green Hydrogen Cost Atlas — styles
 * Theme tokens follow the validated reference palette (light + dark selected
 * independently); charts reference these variables only.
 * ========================================================================= */

:root {
  --surface-1: #fcfcfb;
  --surface-2: #f9f9f7;
  --ink-1: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --series-1: #2a78d6;  /* blue    — Generation CAPEX */
  --series-2: #1baf7a;  /* aqua    — Generation O&M */
  --series-3: #eda100;  /* yellow  — Offshore transmission */
  --series-4: #008300;  /* green   — Electrolyzer CAPEX */
  --series-5: #4a3aa7;  /* violet  — Stack replacement */
  --series-6: #e34948;  /* red     — Electrolyzer O&M */
  --series-7: #e87ba4;  /* magenta — Water */
  --series-8: #eb6834;  /* orange  — Compression & storage */
}
@media (prefers-color-scheme: dark) {
  :root {
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --ink-1: #ffffff;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #199e70;
    --series-3: #c98500;
    --series-4: #008300;
    --series-5: #9085e9;
    --series-6: #e66767;
    --series-7: #d55181;
    --series-8: #d95926;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px; color: var(--ink-1); background: var(--surface-2);
  overflow: hidden;
}
a { color: var(--accent); }
h4 { margin: 0 0 8px; font-size: 13px; }
.h4-sub { color: var(--ink-3); font-weight: 400; }

#app { display: flex; height: 100vh; height: 100dvh; }
#map { flex: 1; min-width: 0; background: var(--surface-2); position: relative; }

/* Site title overlay — matches the CA Grid Map branding */
#site-title {
  position: absolute; top: 10px; left: 10px; z-index: 1000;
  font-family: 'Lora', serif; font-size: 1.5rem; font-weight: 600;
  color: var(--ink-1); text-decoration: none; pointer-events: auto;
}
#site-title:hover {
  background: linear-gradient(90deg, #ff0000, #ff8800, #ffdd00, #00cc44, #0088ff, #8800ff, #ff0000);
  background-size: 200% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: white; -webkit-text-stroke: 1.5px transparent;
  animation: rainbow-shift 2s linear infinite;
}
@keyframes rainbow-shift {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

/* ------------------------------ panel ------------------------------ */
#panel {
  width: 460px; max-width: 100%; display: flex; flex-direction: column;
  background: var(--surface-1); border-left: 1px solid var(--border);
  z-index: 1000;
}
#panel-header { padding: 14px 16px 10px; border-bottom: 1px solid var(--border); }
#panel-header h1 { margin: 0; font-size: 17px; letter-spacing: -0.01em; }
#panel-header .subtitle { color: var(--ink-2); font-size: 12px; margin-top: 3px; }
#panel-header .header-links { margin-top: 8px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
#panel-tabs { display: flex; border-bottom: 1px solid var(--border); }
#panel-tabs button {
  flex: 1; padding: 9px 0; border: none; background: none; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--ink-3);
  border-bottom: 2px solid transparent;
}
#panel-tabs button.active { color: var(--ink-1); border-bottom-color: var(--accent); font-weight: 600; }
#panel-body { flex: 1; overflow-y: auto; padding: 14px 16px 24px; }

#panel-toggle { display: none; }

@media (max-width: 800px) {
  #app { flex-direction: column; }
  #panel { width: 100%; height: 55%; border-left: none; border-top: 1px solid var(--border); }
  #panel.collapsed #panel-body, #panel.collapsed #panel-tabs { display: none; }
  #panel.collapsed { height: auto; }
  #panel-toggle {
    display: block; position: absolute; right: 12px; top: 10px;
    border: 1px solid var(--border); background: var(--surface-1); color: var(--ink-2);
    border-radius: 6px; padding: 2px 9px; cursor: pointer; font-size: 15px;
  }
  #panel-header { position: relative; }
}

/* ----------------------------- controls ----------------------------- */
.btn {
  font: inherit; font-size: 12.5px; padding: 5px 11px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface-1); color: var(--ink-1);
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.subtle { color: var(--ink-3); font-size: 12px; padding: 3px 9px; }
select, input[type="number"] {
  font: inherit; font-size: 12.5px; color: var(--ink-1);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 3px 6px;
}
input[type="number"] { width: 78px; text-align: right; }

.status-msg { padding: 20px 4px; color: var(--ink-2); line-height: 1.5; }
.status-msg.error { color: var(--series-6); }
.spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 8px;
  border: 2px solid var(--grid); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------- results ------------------------------ */
.loc-card { margin-bottom: 12px; }
.loc-title { font-weight: 600; font-size: 14px; }
.loc-sub { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }
.note-line { color: var(--ink-3); font-size: 12px; margin-top: 6px; line-height: 1.45; }

.hero {
  padding: 14px 16px; margin-bottom: 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
.hero-label { font-size: 12px; color: var(--ink-2); }
.hero-value { font-size: 42px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.hero-unit { font-size: 17px; font-weight: 500; color: var(--ink-2); margin-left: 3px; }
.hero-sub { font-size: 12.5px; color: var(--ink-2); }

.chart-block { margin-bottom: 14px; }
.chart-svg { width: 100%; height: auto; display: block; }

.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--baseline); stroke-width: 1; }
.axis-label { fill: var(--ink-3); font-size: 9px; }
.row-label { fill: var(--ink-2); font-size: 10.5px; font-weight: 600; }
.value-label { fill: var(--ink-1); font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.line-series { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dot-series { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }

.seg { cursor: default; }
.seg-1 { fill: var(--series-1); } .seg-2 { fill: var(--series-2); }
.seg-3 { fill: var(--series-3); } .seg-4 { fill: var(--series-4); }
.seg-5 { fill: var(--series-5); } .seg-6 { fill: var(--series-6); }
.seg-7 { fill: var(--series-7); } .seg-8 { fill: var(--series-8); }

.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.legend-item { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--ink-2); }
.legend-swatch { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
span.legend-swatch.seg-1 { background: var(--series-1); } span.legend-swatch.seg-2 { background: var(--series-2); }
span.legend-swatch.seg-3 { background: var(--series-3); } span.legend-swatch.seg-4 { background: var(--series-4); }
span.legend-swatch.seg-5 { background: var(--series-5); } span.legend-swatch.seg-6 { background: var(--series-6); }
span.legend-swatch.seg-7 { background: var(--series-7); } span.legend-swatch.seg-8 { background: var(--series-8); }

.tech-cards { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.tech-card { border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; }
.tech-card-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.tech-lcoh { font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 5px 14px; }
.stat-grid > div { display: flex; justify-content: space-between; font-size: 12px; gap: 8px; }
.stat-grid span { color: var(--ink-3); }
.stat-grid b { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.tech-actions { margin-top: 9px; display: flex; align-items: center; gap: 10px; }
.ratio-note { color: var(--ink-3); font-size: 12px; }
.ratio-chart { margin-top: 8px; }

.mini-charts { display: flex; gap: 12px; margin-bottom: 12px; }
.mini-chart { flex: 1; min-width: 0; }
.mini-title { font-size: 11px; color: var(--ink-2); margin-bottom: 3px; }

.table-block { margin: 10px 0; }
.table-block summary { cursor: pointer; color: var(--ink-2); font-size: 12.5px; }
.num-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12px; }
.num-table td { padding: 3.5px 4px; border-bottom: 1px solid var(--grid); }
.num-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }

.footnote { color: var(--ink-3); font-size: 11.5px; line-height: 1.5; margin-top: 12px; }

/* --------------------------- assumptions ---------------------------- */
.assump-intro { color: var(--ink-2); font-size: 12.5px; line-height: 1.5; margin-bottom: 12px; }
.assump-intro .btn { margin-top: 8px; display: inline-block; }
.assump-group { border: 1px solid var(--border); border-radius: 9px; margin-bottom: 8px; }
.assump-group summary {
  cursor: pointer; padding: 9px 12px; font-weight: 600; font-size: 13px;
  list-style: none;
}
.assump-group summary::-webkit-details-marker { display: none; }
.assump-group[open] summary { border-bottom: 1px solid var(--border); }
.badge {
  font-size: 10px; font-weight: 600; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 99px; padding: 1px 7px; margin-left: 6px;
  vertical-align: 1px;
}
.assump-body { padding: 6px 12px 10px; }
.assump-row {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 4px 0;
}
.assump-row label { font-size: 12px; color: var(--ink-2); flex: 1; }
.assump-row.modified label { color: var(--ink-1); font-weight: 600; }
.assump-row.modified input, .assump-row.modified select { border-color: var(--accent); }
.assump-ctrl { display: flex; align-items: center; gap: 6px; }
.unit { color: var(--ink-3); font-size: 11px; min-width: 34px; }
.info-dot {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; flex: none;
  border: 1px solid var(--baseline); color: var(--ink-3);
  font-size: 10px; font-style: italic; font-family: Georgia, serif;
  cursor: help; user-select: none;
}
.reset-one {
  border: none; background: none; cursor: pointer; color: var(--accent);
  font-size: 13px; padding: 0 2px;
}

/* ------------------------------ tooltip ----------------------------- */
#viz-tooltip {
  position: fixed; display: none; z-index: 5000; pointer-events: none;
  max-width: 300px; padding: 8px 10px; font-size: 12px; line-height: 1.45;
  background: var(--surface-1); color: var(--ink-1);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}

/* ---------------------------- scan legend ---------------------------- */
#scan-legend {
  position: absolute; left: 12px; bottom: 24px; z-index: 1200;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 12px; width: 190px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
#scan-legend .legend-title { font-size: 11.5px; font-weight: 600; margin-bottom: 5px; }
#scan-legend .legend-bar { height: 9px; border-radius: 4px; }
#scan-legend .legend-ends { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-3); margin: 3px 0 6px; font-variant-numeric: tabular-nums; }

#scan-status { color: var(--ink-3); font-size: 11.5px; }

/* Leaflet chrome harmonized with theme */
.leaflet-container { font: inherit; }
.leaflet-control-layers, .leaflet-bar a {
  background: var(--surface-1); color: var(--ink-1);
}
.leaflet-bar a { border-bottom-color: var(--border); }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface-1) 80%, transparent); color: var(--ink-3); }
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-tooltip {
  background: var(--surface-1); color: var(--ink-1);
  border: 1px solid var(--border); border-radius: 6px;
  font-variant-numeric: tabular-nums;
}
