/* ═══════════════════════════════════════════════════
   styles.css -- Project-specific layout, hex tiles,
   sidebar panels, plans dialog, election overlay,
   and responsive breakpoints for the redistricting sim.
   Colors/fonts injected by colors.js at runtime.
   ═══════════════════════════════════════════════════ */

/* ─── Layout Tokens ─── */
:root {
    --palette-h: 56px;
}

/* ─── Base ─── */
html, body {
    overflow: hidden;
}

body {
    font-size: 14px;
    line-height: 1.5;
    height: 100vh;
    height: 100dvh;
}

/* ─── Tool Button Overrides ─── */
/* Thicker strokes for small zoom/close icons to maintain legibility. */
#zoom-in-btn svg,
#zoom-out-btn svg,
#close-stats svg {
    stroke-width: 2.5;
}

/* Active tool states: tinted background matches each mode's party color. */
#delete-btn.active {
    color: var(--party-orange);
    background: var(--party-orange-tint);
    border-color: var(--party-orange-wash);
}

#erase-btn.active {
    color: var(--party-purple);
    background: var(--party-purple-tint);
    border-color: var(--party-purple-wash);
}

#move-btn.active {
    color: var(--party-lime);
    background: var(--party-lime-tint);
    border-color: var(--party-lime-wash);
}

#reset-btn:hover { color: var(--party-orange); }
#randomize-btn:hover { color: var(--party-lime); }

/* Gerrymander button + party dropdown inline pair */
.auto-district-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}
.party-select {
    font: 11px/1 var(--font-body);
    padding: 4px 2px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-panel);
    color: var(--text);
    cursor: pointer;
    height: 28px;
}


/* ═══════════════════════════════════
   Map (Full Viewport SVG)
   ═══════════════════════════════════ */
main {
    position: fixed;
    inset: 0;
    z-index: 1;
}

#map-container {
    width: 100%;
    height: 100%;
    background: var(--bg-canvas);
    cursor: crosshair;
    touch-action: none;
    position: relative;
    overflow: hidden;
    transition: background-color 0.5s var(--ease-out);
}

/* Inline SVG cursors: data-URI avoids extra network requests.
   Hotspot coordinates (12,12 / 4,20) position the tip over the click point. */
#map-container.delete-mode {
    cursor: url('data:image/svg+xml;utf8,<svg fill="none" stroke="%23c93c3c" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24" height="24" width="24" xmlns="http://www.w3.org/2000/svg"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>') 12 12, crosshair;
}

#map-container.erase-mode {
    cursor: url('data:image/svg+xml;utf8,<svg fill="none" stroke="%23b88a00" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" viewBox="0 0 24 24" height="22" width="22" xmlns="http://www.w3.org/2000/svg"><path d="M20 20H7L3 16c-.8-.8-.8-2 0-2.8L14.6 1.6c.8-.8 2-.8 2.8 0L21 5.2c.8.8.8 2 0 2.8L11 18"/></svg>') 4 20, crosshair;
}

#map-container.pan-mode {
    cursor: grab;
}

#map-container.panning {
    cursor: grabbing;
}

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

/* ─── Hex Tiles ─── */
/* transform-box: fill-box lets scale animations originate from each hex's center
   rather than the SVG viewport origin. */
.hex polygon {
    stroke: var(--hex-stroke);
    stroke-width: 1px;
    transform-origin: center;
    transform-box: fill-box;
    transition: stroke 0.15s ease, stroke-width 0.15s ease, fill 0.35s ease;
    animation: hexPopIn 0.55s var(--ease-out) both;
}

@keyframes hexPopIn {
    0% { transform: scale(0); opacity: 0; }
    65% { transform: scale(1.04); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Paused while intro screen is showing; unpaused on dismiss. */
#map-container.paused .hex polygon,
#map-container.paused .minority-marker {
    animation-play-state: paused;
}

.hex.hovered polygon {
    stroke: var(--hex-hover-stroke);
    stroke-width: 2px;
    filter: brightness(1.08);
    transition: stroke 0.1s ease, stroke-width 0.1s ease, filter 0.1s ease;
}

@keyframes hexPaintFlash {
    0% { filter: brightness(1.35); }
    100% { filter: none; }
}

.hex.just-painted polygon {
    animation: hexPaintFlash 0.2s ease-out forwards;
}

.minority-marker {
    fill: var(--party-blue);
    pointer-events: none;
    opacity: 0.7;
    transform-origin: center;
    transform-box: fill-box;
    animation: markerPopIn 0.45s var(--ease-out) both;
}

@keyframes markerPopIn {
    0% { transform: scale(0); opacity: 0; }
    100% { transform: scale(1); opacity: 0.7; }
}

/* ─── District Borders ─── */
/* Stroke-only paths clipped to each district's hex region.
   Active district gets heavier borders for selected-state emphasis. */
.district-path {
    fill: none;
    stroke-linejoin: miter;
    pointer-events: none;
    stroke-linecap: butt;
}

.district-path.outline {
    stroke-width: 5px;
    opacity: 0.8;
}

/* Green overlay for majority-minority districts. */
.district-path.mmd-overlay {
    stroke-width: 2px;
    stroke: var(--party-blue);
    opacity: 0.85;
}

.active-district-group .district-path.outline {
    stroke-width: 7px;
    opacity: 1;
}

.active-district-group .district-path.mmd-overlay {
    stroke-width: 2.5px;
    opacity: 1;
}

/* ─── District Labels ─── */
/* paint-order: stroke draws the halo behind the fill text,
   giving readable contrast over any hex color. */
.district-label {
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 700;
    fill: var(--label-fill);
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    paint-order: stroke;
    stroke: var(--label-stroke);
    stroke-width: 3px;
    stroke-linejoin: round;
    letter-spacing: 0.02em;
}

/* ─── Map Controls ─── */
.map-ctrl-btn {
    height: 30px;
    color: var(--text-secondary);
    font-size: 0;
}

.map-ctrl-btn:hover {
    border-color: transparent;
}

/* ═══════════════════════════════════
   District Palette
   ═══════════════════════════════════ */
.palette-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.2s var(--ease-out), font-weight 0.2s var(--ease-out);
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none;
    -webkit-appearance: none;
    padding: 0;
    position: relative;
}

.palette-btn:hover:not(.active) {
    color: var(--text);
}

.palette-btn.active {
    color: var(--accent);
    font-weight: 800;
    font-size: 0.88rem;
}

.palette-btn.has-district {
    color: var(--text-secondary);
}

.palette-btn.has-district.active {
    color: var(--accent);
}

/* ═══════════════════════════════════
   Stats Panel
   ═══════════════════════════════════ */
.tab-panels {
    font-variant-numeric: tabular-nums;
}

/* ─── Seats Grid ─── */
.seats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.seat-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 8px;
    border-radius: var(--radius-sm);
    background: var(--bg-hover);
    border: 1px solid var(--border);
    transition: background 0.2s, border-color 0.2s;
}

.seat-block:hover {
    border-color: var(--border-strong);
}

.seat-num {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 400;
    line-height: 1;
    margin-bottom: 2px;
}

.seat-block.orange .seat-num { color: var(--party-orange); }
.seat-block.lime .seat-num { color: var(--party-lime); }
.seat-block.purple .seat-num { color: var(--party-purple); }

.seat-label {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* ─── Stat Rows ─── */
.stat-note {
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.4;
    font-family: var(--font-body);
    padding: 2px 8px;
    margin-top: 2px;
}

/* ─── District Details ─── */
#selected-district-info {
    display: block;
}


.metric-note {
    font-family: var(--font-body);
    font-size: 0.68rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: -1px;
    margin-bottom: 8px;
    padding: 0 8px;
}

/* ─── Vote Bars ─── */
.vote-bar-container {
    height: 7px;
    background: var(--bar-track);
    border-radius: 4px;
    display: flex;
    overflow: hidden;
    margin-top: 8px;
    margin-bottom: 4px;
}

/* Initial width 0; JS sets inline width via style.width for animated bars. */
.vote-bar,
.prop-bar-fill {
    width: 0;
}

.vote-bar {
    transition: width 0.45s var(--ease-out);
}

.vote-bar.orange, .prop-bar-fill.orange { background: var(--party-orange); }
.vote-bar.lime, .prop-bar-fill.lime { background: var(--party-lime); }
.vote-bar.purple, .prop-bar-fill.purple { background: var(--party-purple); }

.vote-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.66rem;
    font-weight: 600;
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
}

.orange-text { color: var(--party-orange); }
.lime-text { color: var(--party-lime); }
.purple-text { color: var(--party-purple); }

/* ─── Proportionality Panel ─── */
/* Side-by-side vote% vs seat% bars; seat bars dimmed to distinguish. */
.proportionality-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.prop-label {
    font-family: var(--font-body);
    font-size: 0.72rem;
    font-weight: 600;
    width: 30px;
    flex-shrink: 0;
}

.prop-bars {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.prop-bar-track {
    height: 5px;
    background: var(--bar-track);
    border-radius: 3px;
    overflow: hidden;
}

.prop-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.45s var(--ease-out);
}

.prop-bar-fill.seat-fill {
    opacity: 0.38;
}

.prop-values {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
    width: 68px;
    flex-shrink: 0;
}

.prop-pct {
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1.35;
}

.prop-legend {
    display: flex;
    gap: 1rem;
    margin-top: 6px;
    justify-content: center;
}

.prop-legend-item {
    font-family: var(--font-body);
    font-size: 0.62rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-swatch {
    width: 12px;
    height: 5px;
    border-radius: 3px;
    display: inline-block;
    background: var(--text-secondary);
}

.legend-swatch.vote-swatch { opacity: 1; }
.legend-swatch.seat-swatch { opacity: 0.38; }


/* ─── Hex Tooltip (child classes for shared sim-tooltip) ─── */
.sim-tooltip .tt-pop { font-weight: 600; }

.sim-tooltip .tt-votes {
    display: flex;
    gap: 0.4rem;
    margin-top: 2px;
}

.sim-tooltip .tt-o { color: var(--tip-orange); }
.sim-tooltip .tt-l { color: var(--tip-lime); }
.sim-tooltip .tt-p { color: var(--tip-purple); }
.sim-tooltip .tt-m { color: var(--tip-blue); }

/* ─── Plans Dialog ─── */
.plans-content {
    max-width: 420px;
    padding: 1.25rem;
    gap: 0.75rem;
}

.plans-save-row {
    display: flex;
    gap: 0.5rem;
}

.plans-input {
    flex: 1;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-family: var(--font-body);
    font-size: 0.8rem;
    outline: none;
    transition: border-color 0.15s;
}
.plans-input:focus { border-color: var(--accent); }

.plans-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    min-height: 60px;
    max-height: 280px;
}

.plan-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.plan-item:hover { background: var(--bg-hover); }

.plan-item-name {
    flex: 1;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.plan-item-date {
    font-size: 0.65rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.plan-item-actions {
    display: flex;
    gap: 0.25rem;
}

.plan-item-btn {
    padding: 0.2rem 0.4rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.65rem;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.plan-item-btn:hover { background: var(--bg-hover); color: var(--text); }
.plan-item-btn.delete:hover { color: var(--party-orange); }

.plans-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

.plans-import-label {
    cursor: pointer;
}

.plans-empty {
    text-align: center;
    padding: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* ═══════════════════════════════════
   Responsive
   ═══════════════════════════════════ */
@media (max-width: 1100px) {
    :root {
        --panel-w: 320px;
    }
}

/* Mobile: sidebar becomes bottom sheet, palette/controls shrink. */
@media (max-width: 900px) {
    :root {
        --palette-h: 52px;
    }

    #district-palette {
        bottom: 6px;
        gap: 3px;
        padding: 5px 8px;
        z-index: 120;
    }

    .palette-btn {
        width: 32px;
        height: 32px;
        font-size: 0.78rem;
    }

    #map-controls {
        bottom: 8px;
        left: 10px;
    }

    #sidebar {
        top: auto;
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-height: 55vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        transform: translateY(100%);
        z-index: 110;
    }

    .app-ready #sidebar {
        animation: slideInRight 0.5s var(--ease-out) 0.15s both;
    }

    .app-ready #sidebar.open {
        transform: translateY(0);
    }

    .tab-panel {
        padding: 8px;
    }

    .stat-group {
        padding: 0;
    }

}

/* Small phones: tighter touch targets. */
@media (max-width: 600px) {
    .palette-btn {
        width: 28px;
        height: 28px;
        font-size: 0.72rem;
    }
}

/* ─── Election Simulation ─── */
.election-panel { padding: 20px; max-width: 380px; position: relative; }
.election-close { position: absolute; top: 8px; right: 12px; background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-muted); }
.election-controls { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.election-controls label { display: flex; align-items: center; gap: 8px; font-size: 0.82rem; }
#election-histogram { width: 100%; border-radius: var(--radius-sm); background: var(--bg-elevated); }

/* Extra small: handled by shared-base.css (hide .sim-brand, tight gap) */
