/* ============================================================
   Solar + Battery Atlas — design tokens (dark Ember)
   Single source of truth. Tailwind mirrors these via its inline
   config in index.html so utility classes stay unchanged.
   ============================================================ */
:root {
    --bg-page: #0b0d0c;
    --card: #15181a;
    --elevated: #1f2325;
    --text: #ECEFF5;
    --muted: #9aa19f;
    --divider: #2a2f31;
    --input: #0f1213;
    --ember: #f59e0b;
    --ember-hover: #fbbf24;
    --solar: #f59e0b;
    --battery: #a855f7;
    /* SF Pro (Apple system font, à la Substack). Falls back gracefully on
       non-Apple platforms. Single source of truth — Tailwind's font-sans is
       set to the same stack in tailwind.config.js. */
    --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'SF Pro', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--card);
}

::-webkit-scrollbar-thumb {
    background: var(--elevated);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* Map Styles */
.leaflet-container {
    background: var(--bg-page);
    touch-action: none;
    font-family: var(--font-sans);
}

#map-shell {
    position: absolute;
    inset: 0;
    z-index: 0;
    display: block;
}

/* Population charts overlay should sit centered between demand/supply panels */
.population-charts-shell {
    padding-left: var(--charts-left-pad, 1.5rem);
    padding-right: var(--charts-right-pad, 1.5rem);
}

.population-charts-inner {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
}

.map-pane {
    width: 100%;
    height: 100%;
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    background: var(--bg-page);
}

/* Collapsible Panels */
.panel-collapsible {
    transition: width 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}

.panel-collapsible.is-collapsed {
    width: 3rem;
    padding: 0.75rem 0.5rem;
}

.panel-collapsible.is-collapsed .panel-body,
.panel-collapsible.is-collapsed .panel-title {
    display: none;
}

.panel-collapsible.is-collapsed .panel-header {
    justify-content: center;
}

.panel-collapse-btn .material-symbols-outlined {
    transition: transform 0.2s ease;
}

.panel-collapsible.is-collapsed .panel-collapse-btn .material-symbols-outlined {
    transform: rotate(180deg);
}

#map-supply {
    display: none;
}

body.split-maps #map-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

body.split-maps #map {
    width: 100%;
}

body.split-maps #map-supply {
    display: block;
    width: 100%;
}

#legend-stack {
    right: 1rem;
    left: auto;
}

body.split-maps #legend-stack {
    left: 1rem;
    right: auto;
    align-items: flex-start;
}

/* Marker clusters — ember accent */
.marker-cluster-small {
    background-color: rgba(245, 158, 11, 0.6);
}

.marker-cluster-small div {
    background-color: rgba(245, 158, 11, 0.6);
}

/* Chart Tooltip Customization */
#chartjs-tooltip {
    opacity: 1;
    position: absolute;
    background: rgba(21, 24, 26, 0.95);
    color: var(--text);
    border: 1px solid var(--divider);
    border-radius: 8px;
    pointer-events: none;
    transform: translate(-50%, 0);
    transition: all .1s ease;
    padding: 8px 12px;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.35), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

/* Leaflet Popup Customization */
.leaflet-popup-content-wrapper {
    background-color: rgba(21, 24, 26, 0.95);
    backdrop-filter: blur(8px);
    color: var(--text);
    border: 1px solid var(--divider);
    border-radius: 1rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.35), 0 10px 10px -5px rgba(0, 0, 0, 0.2);
    padding: 0;
}

.leaflet-popup-tip {
    background-color: rgba(21, 24, 26, 0.95);
    border: 1px solid var(--divider);
    border-top: none;
    border-left: none;
}

.leaflet-popup-content {
    margin: 0;
    line-height: 1.5;
}

/* Legend Gradient */
.legend-gradient {
    background: linear-gradient(to right,
            #1e3a8a 0%,
            #1e3a8a 5%,
            #00c853 40%,
            #ff9800 70%,
            #d32f2f 100%);
}

.legend-gradient-cost {
    background: linear-gradient(to right,
            #0b1d3a 0%,
            #1d4ed8 15%,
            #16a34a 45%,
            #eab308 65%,
            #f59e0b 82.5%,
            #dc2626 100%);
    background-size: 100% 100%;
}

.legend-gradient-delta {
    background: linear-gradient(to right,
            #22c55e 0%,
            #22c55e 33%,
            #cbd5e1 50%,
            #ef4444 67%,
            #ef4444 100%);
    background-size: 100% 100%;
}

.legend-gradient-tx {
    background: linear-gradient(to right,
            #cbd5e1 0%,
            #86efac 50%,
            #22c55e 100%);
    background-size: 100% 100%;
}

/* Population legend — harmonized with dark Ember slate palette */
.legend-gradient-pop {
    background: linear-gradient(to right,
            #1f2325 0%,
            #626e88 30%,
            #9aa19f 60%,
            #d6dbe9 85%,
            #ECEFF5 100%);
}

/* Potential legend — darkened low end so it reads on the dark bg */
.legend-gradient-potential {
    background: linear-gradient(to right,
            #14532d 0%,
            #166534 20%,
            #16a34a 40%,
            #22c55e 60%,
            #4ade80 80%,
            #86efac 100%);
    background-size: 100% 100%;
}

.legend-gradient-potential-multiple {
    background: linear-gradient(to right,
            #f8b4b4 0%,
            #facc15 50%,
            #16a34a 100%);
    background-size: 100% 100%;
}

/* Map Transitions */
.transition-color {
    transition: fill 0.9s ease, stroke 0.9s ease;
}

/* During sample-week auto-play, suppress the per-cell fill cross-fade so each
   500ms recolor paints once instead of restarting an unfinishable 0.9s tween on
   thousands of SVG cells (a Chrome paint storm). !important beats both the
   .transition-color class above and the inline transition set in renderSampleVoronoi.
   The cross-fade is retained for scrubber drags and config changes (not .playing). */
.sample-voronoi.playing path {
    transition: none !important;
}

.voronoi-hover {
    stroke: #ffffff !important;
    stroke-width: 1.2 !important;
    stroke-opacity: 1 !important;
}

/* ============================================================
   Solar + Battery Atlas — shared component styles
   Used by markup in index.html and scrollytelling. Drives the
   "less finicky" input UX: bigger hit targets, consistent focus.
   ============================================================ */

/* Range sliders — 20px thumb, ember fill, better track contrast */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--divider);
    border-radius: 9999px;
    accent-color: var(--ember);
    cursor: pointer;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: var(--ember);
    border: 2px solid var(--text);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: transform 0.15s ease, background 0.15s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.08);
    background: var(--ember-hover);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 9999px;
    background: var(--ember);
    border: 2px solid var(--text);
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    transition: transform 0.15s ease, background 0.15s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.08);
    background: var(--ember-hover);
}

input[type="range"]::-moz-range-track {
    background: var(--divider);
    height: 6px;
    border-radius: 9999px;
}

/* Solar slider — amber thumb (semantic data category) */
input[type="range"].slider-solar {
    accent-color: var(--solar);
}
input[type="range"].slider-solar::-webkit-slider-thumb {
    background: var(--solar);
}
input[type="range"].slider-solar::-webkit-slider-thumb:hover {
    background: #fbbf24;
}
input[type="range"].slider-solar::-moz-range-thumb {
    background: var(--solar);
}
input[type="range"].slider-solar::-moz-range-thumb:hover {
    background: #fbbf24;
}

/* Battery slider — cyan thumb (semantic data category) */
input[type="range"].slider-battery {
    accent-color: var(--battery);
}
input[type="range"].slider-battery::-webkit-slider-thumb {
    background: var(--battery);
}
input[type="range"].slider-battery::-webkit-slider-thumb:hover {
    background: #22d3ee;
}
input[type="range"].slider-battery::-moz-range-thumb {
    background: var(--battery);
}
input[type="range"].slider-battery::-moz-range-thumb:hover {
    background: #22d3ee;
}

/* Number inputs — bigger, clearer, always-visible steppers */
.num-input {
    width: 100%;
    min-height: 36px;
    padding: 0.375rem 0.625rem;
    background: var(--input);
    border: 1px solid var(--divider);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.8125rem;
    font-family: var(--font-sans);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.num-input:hover {
    border-color: var(--muted);
}

.num-input:focus {
    outline: none;
    border-color: var(--ember);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

.num-input[type="number"] {
    -moz-appearance: textfield;
}

/* Text inputs that should share num-input styling */
.text-input {
    width: 100%;
    min-height: 36px;
    padding: 0.375rem 0.625rem;
    background: var(--input);
    border: 1px solid var(--divider);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.8125rem;
    font-family: var(--font-sans);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.text-input:focus {
    outline: none;
    border-color: var(--ember);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.18);
}

/* Toggle groups — segmented control pattern, bigger hit targets */
.toggle-group {
    display: inline-flex;
    align-items: stretch;
    min-height: 32px;
    padding: 3px;
    gap: 2px;
    background: var(--elevated);
    border-radius: 8px;
}

.toggle-group.toggle-group-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    width: 100%;
}

.toggle-group.toggle-group-col {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
}

.toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 26px;
    padding: 0 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--muted);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    font-family: var(--font-sans);
    line-height: 1;
    white-space: nowrap;
}

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

.toggle-btn.is-active {
    background: var(--ember);
    color: #0b0d0c;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Tiny variant (used inline in dense panels) */
.toggle-btn-sm {
    min-height: 22px;
    padding: 0 8px;
    font-size: 0.6875rem;
}

/* Checkbox / radio — ember-green when checked */
.check-ember {
    accent-color: var(--ember);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* Clickable label rows wrapping check/radio get a bigger hit target */
label.check-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 32px;
    cursor: pointer;
    transition: color 0.15s ease;
}

label.check-row:hover {
    color: var(--text);
}

/* Capsule CTA button */
.btn-capsule {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 40px;
    padding: 0 1.25rem;
    border-radius: 9999px;
    background: var(--ember);
    color: #0b0d0c;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    font-family: var(--font-sans);
}

.btn-capsule:hover {
    background: var(--ember-hover);
}

.btn-capsule:active {
    transform: translateY(1px);
}

/* Secondary capsule (outlined) */
.btn-capsule-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 40px;
    padding: 0 1.25rem;
    border-radius: 9999px;
    background: transparent;
    color: var(--text);
    border: 1px solid var(--divider);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
    font-family: var(--font-sans);
}

.btn-capsule-ghost:hover {
    background: var(--elevated);
    border-color: var(--muted);
}

/* Unified focus ring for keyboard users */
:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-page), 0 0 0 4px var(--ember);
}

/* View tabs — active state driven by .is-active; bg-primary still works
   because tailwind's `primary` token is re-pointed to ember green */
.view-tab {
    font-family: var(--font-sans);
}

/* ============================================================
   Guided Tour — "Take a Tour" callouts, glowing ring, chooser
   ============================================================ */

/* Glowing accent ring drawn around the highlighted element. No screen
   dimming — the tool stays fully visible behind it. */
.tour-ring {
    position: fixed;
    z-index: 10000;
    border: 2px solid var(--ember);
    border-radius: 14px;
    pointer-events: none;
    box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.22),
                0 0 18px 2px rgba(245, 158, 11, 0.45);
    transition: left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease;
    animation: tour-ring-pulse 1.8s ease-in-out infinite;
}

@keyframes tour-ring-pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.20), 0 0 16px 1px rgba(245, 158, 11, 0.40); }
    50%      { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0.30), 0 0 26px 4px rgba(245, 158, 11, 0.60); }
}

/* Callout box */
.tour-callout {
    position: fixed;
    z-index: 10001;
    width: 320px;
    max-width: calc(100vw - 16px);
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 16px;
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.7);
    padding: 18px 18px 14px;
    color: var(--text);
    font-family: var(--font-sans);
    transition: left 0.25s ease, top 0.25s ease;
}

.tour-callout__close {
    position: absolute;
    top: 10px;
    right: 10px;
    color: var(--muted);
    line-height: 0;
    transition: color 0.2s ease;
}
.tour-callout__close:hover { color: var(--text); }
.tour-callout__close .material-symbols-outlined { font-size: 20px; }

.tour-callout__title {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    margin: 0 24px 8px 0;
    line-height: 1.3;
}

.tour-callout__body {
    font-size: 13px;
    line-height: 1.55;
    color: #cdd3d1;
}
.tour-callout__body b { color: #fff; font-weight: 600; }

.tour-callout__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 16px;
}

.tour-callout__counter {
    font-size: 11px;
    color: var(--muted);
    letter-spacing: 0.02em;
}

.tour-callout__nav { display: flex; gap: 8px; }

.tour-callout__btn {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 9999px;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}
.tour-callout__back {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--divider);
}
.tour-callout__back:hover:not(:disabled) { color: var(--text); border-color: var(--muted); }
.tour-callout__back:disabled { opacity: 0.35; cursor: default; }
.tour-callout__next {
    background: var(--ember);
    color: #06140d;
    border: 1px solid var(--ember);
}
.tour-callout__next:hover { background: var(--ember-hover); border-color: var(--ember-hover); }

/* Arrow pointing toward the target */
.tour-callout__arrow {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.12);
    transform: rotate(45deg);
}
.tour-callout__arrow--right { left: -7px; border-right: none; border-top: none; }
.tour-callout__arrow--left  { right: -7px; border-left: none; border-bottom: none; }
.tour-callout__arrow--bottom { top: -7px; border-bottom: none; border-right: none; }
.tour-callout__arrow--top    { bottom: -7px; border-top: none; border-left: none; }

/* Centered welcome / fallback callout */
.tour-callout--centered {
    width: 380px;
    text-align: center;
}
.tour-callout--centered .tour-callout__title { margin-right: 0; }
.tour-callout--centered .tour-callout__footer { justify-content: space-between; }

/* ---- Tour chooser modal ---- */
.tour-chooser {
    position: fixed;
    inset: 0;
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    font-family: var(--font-sans);
}
.tour-chooser.hidden { display: none; }

.tour-chooser__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.tour-chooser__card {
    position: relative;
    width: 100%;
    max-width: 420px;
    background: var(--card);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    box-shadow: 0 24px 48px -12px rgba(0, 0, 0, 0.75);
    padding: 32px 28px;
    color: var(--text);
}
.tour-chooser__card--single { text-align: center; }

.tour-chooser__close {
    position: absolute;
    top: 16px;
    right: 16px;
    color: var(--muted);
    line-height: 0;
    transition: color 0.2s ease;
}
.tour-chooser__close:hover { color: var(--text); }

.tour-chooser__icon {
    color: var(--ember);
    font-size: 34px;
    margin-bottom: 10px;
}

.tour-chooser__heading {
    font-size: 20px;
    font-weight: 600;
    color: #fff;
    margin: 0 0 8px;
}
.tour-chooser__sub {
    font-size: 13px;
    color: var(--muted);
    margin: 0 0 22px;
    line-height: 1.55;
}

.tour-chooser__start {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    background: var(--ember);
    color: #06140d;
    border: 1px solid var(--ember);
    border-radius: 9999px;
    padding: 10px 28px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease;
}
.tour-chooser__start:hover { background: var(--ember-hover); border-color: var(--ember-hover); }

/* ---- First-visit nudge tooltip ---- */
.tour-nudge {
    position: fixed;
    z-index: 10001;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 400px;
    background:
        linear-gradient(180deg, rgba(245, 158, 11, 0.18), rgba(245, 158, 11, 0.06)),
        var(--card);
    border: 3px solid var(--ember);
    border-radius: 16px;
    padding: 18px 18px 18px 20px;
    color: var(--text);
    font-family: var(--font-sans);
    cursor: pointer;
    animation:
        tour-nudge-in 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
        tour-nudge-breathe 1.6s ease-in-out 0.4s infinite,
        tour-nudge-radiate 1.8s ease-out 0.4s infinite;
}
/* Second, staggered ring wave so pulses keep radiating outward. */
.tour-nudge::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    animation: tour-nudge-radiate2 1.8s ease-out 1.3s infinite;
}
.tour-nudge:hover { border-color: var(--ember-hover); }

.tour-nudge__arrow {
    position: absolute;
    top: -9px;
    width: 16px;
    height: 16px;
    background: rgba(61, 48, 23, 1);
    border-left: 3px solid var(--ember);
    border-top: 3px solid var(--ember);
    transform: rotate(45deg);
}
.tour-nudge__icon {
    color: var(--ember);
    font-size: 32px;
    flex-shrink: 0;
    transform-origin: 50% 80%;
    animation: tour-nudge-wave 1.6s ease-in-out 0.4s infinite;
    filter: drop-shadow(0 0 6px rgba(245, 158, 11, 0.7));
}
.tour-nudge__text {
    font-size: 17px;
    font-weight: 700;
    line-height: 1.3;
    letter-spacing: 0.2px;
    text-shadow: 0 0 10px rgba(245, 158, 11, 0.35);
}
.tour-nudge__close {
    flex-shrink: 0;
    color: var(--muted);
    line-height: 0;
    transition: color 0.2s ease;
}
.tour-nudge__close:hover { color: var(--text); }
.tour-nudge__close .material-symbols-outlined { font-size: 22px; }

@keyframes tour-nudge-in {
    from { opacity: 0; transform: translateY(-10px) scale(0.85); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
/* Whole-callout breathing pulse so it visibly grows and shrinks. */
@keyframes tour-nudge-breathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.06); }
}
/* Icon wave to add lively motion that catches the eye. */
@keyframes tour-nudge-wave {
    0%, 100%      { transform: rotate(0deg); }
    20%           { transform: rotate(-12deg); }
    40%           { transform: rotate(12deg); }
    60%           { transform: rotate(-8deg); }
    80%           { transform: rotate(6deg); }
}
/* Primary expanding ring + constant glow (drop shadow stays underneath). */
@keyframes tour-nudge-radiate {
    0%        { box-shadow: 0 16px 34px -10px rgba(0, 0, 0, 0.7), 0 0 22px 2px rgba(245, 158, 11, 0.45), 0 0 0 0 rgba(245, 158, 11, 0.75); }
    70%, 100% { box-shadow: 0 16px 34px -10px rgba(0, 0, 0, 0.7), 0 0 22px 2px rgba(245, 158, 11, 0.45), 0 0 0 32px rgba(245, 158, 11, 0); }
}
/* Secondary expanding ring, offset in time for a continuous radar pulse. */
@keyframes tour-nudge-radiate2 {
    0%        { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.6); }
    70%, 100% { box-shadow: 0 0 0 48px rgba(245, 158, 11, 0); }
}
