/* ==========================================================================
   WHW Electoral Map — Main Stylesheet
   Plugin: White House Watch Electoral Map
   Version: 1.0
   ========================================================================== */

/* ==========================================================================
   1. CSS VARIABLES & RESET
   ========================================================================== */

.whw-electoral-map {
    --whw-red: #E81B23;
    --whw-blue: #0033A0;
    --whw-green: #17AA5C;
    --whw-gold: #FFD700;
    --whw-orange: #FF8C00;
    --whw-purple: #6A0DAD;
    --whw-gray: #B0B0B0;
    --whw-dark-gray: #4A4A4A;
    --whw-light-gray: #F5F5F5;
    --whw-border: #E0E0E0;
    --whw-text: #333333;
    --whw-text-light: #666666;
    --whw-white: #FFFFFF;
    --whw-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    --whw-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.18);
    --whw-radius: 8px;
    --whw-radius-sm: 4px;
    --whw-transition: 0.3s ease;
    --whw-font: inherit;
    --whw-container-max: 1200px;
}

.whw-electoral-map *,
.whw-electoral-map *::before,
.whw-electoral-map *::after {
    box-sizing: border-box;
}

.whw-electoral-map {
    font-family: var(--whw-font);
    color: var(--whw-text);
    line-height: 1.6;
    max-width: var(--whw-container-max);
    margin: 0 auto;
    padding: 20px;
}

/* ==========================================================================
   2. SELETTORE ERA (Dropdown)
   ========================================================================== */

.whw-era-selector {
    margin-bottom: 30px;
    text-align: center;
}

.whw-era-selector label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--whw-text-light);
    margin-bottom: 8px;
}

.whw-era-selector select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-color: var(--whw-white);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23333' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
    border: 2px solid var(--whw-border);
    border-radius: var(--whw-radius);
    padding: 12px 48px 12px 20px;
    font-size: 1rem;
    font-family: var(--whw-font);
    color: var(--whw-text);
    cursor: pointer;
    min-width: 280px;
    transition: border-color var(--whw-transition), box-shadow var(--whw-transition);
}

.whw-era-selector select:hover {
    border-color: var(--whw-blue);
}

.whw-era-selector select:focus {
    outline: none;
    border-color: var(--whw-blue);
    box-shadow: 0 0 0 3px rgba(0, 51, 160, 0.15);
}

/* ==========================================================================
   3. PULSANTI ELEZIONI (Anno)
   ========================================================================== */

.whw-election-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 40px;
    padding: 20px;
    background: var(--whw-light-gray);
    border-radius: var(--whw-radius);
}

.whw-election-buttons .whw-btn-year {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 72px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--whw-font);
    color: var(--whw-text);
    background: var(--whw-white);
    border: 2px solid var(--whw-border);
    border-radius: var(--whw-radius-sm);
    cursor: pointer;
    transition: all var(--whw-transition);
    text-decoration: none;
}

.whw-election-buttons .whw-btn-year:hover {
    border-color: var(--whw-blue);
    color: var(--whw-blue);
    transform: translateY(-2px);
    box-shadow: var(--whw-shadow);
}

.whw-election-buttons .whw-btn-year.active {
    background: var(--whw-blue);
    border-color: var(--whw-blue);
    color: var(--whw-white);
    box-shadow: var(--whw-shadow);
}

.whw-election-buttons .whw-btn-year.active:hover {
    background: #002580;
    border-color: #002580;
    color: var(--whw-white);
}

/* Nasconde i pulsanti prima della selezione */
.whw-election-buttons.hidden {
    display: none;
}

/* ==========================================================================
   4. SEZIONE CANDIDATI
   ========================================================================== */

.whw-candidates {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.whw-candidate-card {
    position: relative;
    background: var(--whw-white);
    border-radius: var(--whw-radius);
    padding: 24px;
    box-shadow: var(--whw-shadow);
    border-top: 5px solid var(--whw-gray);
    transition: transform var(--whw-transition), box-shadow var(--whw-transition);
    overflow: hidden;
}

.whw-candidate-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--whw-shadow-hover);
}

/* Colori bordo superiore per partito */
.whw-candidate-card[data-party="Republican"] {
    border-top-color: var(--whw-red);
}

.whw-candidate-card[data-party="Democratic"] {
    border-top-color: var(--whw-blue);
}

.whw-candidate-card[data-party="Independent"] {
    border-top-color: var(--whw-green);
}

.whw-candidate-card[data-party="Libertarian"] {
    border-top-color: var(--whw-gold);
}

.whw-candidate-card[data-party="Green"] {
    border-top-color: #00A95C;
}

.whw-candidate-card[data-party="Reform"] {
    border-top-color: var(--whw-purple);
}

.whw-candidate-card[data-party="Progressive"] {
    border-top-color: var(--whw-purple);
}

.whw-candidate-card[data-party="Dixiecrat"],
.whw-candidate-card[data-party="States' Rights Democratic"] {
    border-top-color: #8B0000;
}

.whw-candidate-card[data-party="American Independent"] {
    border-top-color: var(--whw-orange);
}

/* Badge vincitore */
.whw-candidate-card.winner::after {
    content: "✓ ELETTO";
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.08);
    color: var(--whw-text);
}

.whw-candidate-card[data-party="Republican"].winner::after {
    background: rgba(232, 27, 35, 0.12);
    color: var(--whw-red);
}

.whw-candidate-card[data-party="Democratic"].winner::after {
    background: rgba(0, 51, 160, 0.12);
    color: var(--whw-blue);
}

/* Contenuti della card */
.whw-candidate-party {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
    color: var(--whw-text-light);
}

.whw-candidate-card[data-party="Republican"] .whw-candidate-party {
    color: var(--whw-red);
}

.whw-candidate-card[data-party="Democratic"] .whw-candidate-party {
    color: var(--whw-blue);
}

.whw-candidate-name {
    font-size: 1.3rem;
    font-weight: 700;
    margin-bottom: 2px;
    line-height: 1.3;
}

.whw-candidate-vp {
    font-size: 0.85rem;
    color: var(--whw-text-light);
    margin-bottom: 16px;
    font-style: italic;
}

.whw-candidate-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.whw-stat {
    text-align: center;
    padding: 10px 8px;
    background: var(--whw-light-gray);
    border-radius: var(--whw-radius-sm);
}

.whw-stat-value {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--whw-text);
}

.whw-stat-label {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--whw-text-light);
    margin-top: 2px;
}

/* Stat a larghezza piena per la percentuale */
.whw-stat.whw-stat-full {
    grid-column: 1 / -1;
}

/* ==========================================================================
   5. BARRA DISTRIBUZIONE VOTI ELETTORALI
   ========================================================================== */

.whw-electoral-bar-container {
    margin-bottom: 40px;
}

.whw-electoral-bar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.whw-electoral-bar-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--whw-text-light);
}

.whw-electoral-bar-majority {
    font-size: 0.8rem;
    color: var(--whw-text-light);
}

.whw-electoral-bar-majority span {
    font-weight: 700;
}

.whw-electoral-bar {
    position: relative;
    display: flex;
    width: 100%;
    height: 40px;
    border-radius: var(--whw-radius);
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

.whw-electoral-bar-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.whw-electoral-bar-segment span {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--whw-white);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    white-space: nowrap;
}

/* Nasconde il testo se segmento troppo piccolo */
.whw-electoral-bar-segment.small span {
    display: none;
}

/* Linea centrale per la maggioranza */
.whw-electoral-bar-majority-line {
    position: absolute;
    top: -6px;
    bottom: -6px;
    width: 3px;
    background: var(--whw-text);
    z-index: 10;
    border-radius: 2px;
}

.whw-electoral-bar-majority-line::after {
    content: attr(data-label);
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    color: var(--whw-text);
}

/* Legenda sotto la barra */
.whw-electoral-bar-legend {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 16px;
    margin-top: 12px;
}

.whw-electoral-bar-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--whw-text-light);
}

.whw-electoral-bar-legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ==========================================================================
   6. SEZIONE NOTE
   ========================================================================== */

.whw-notes {
    background: var(--whw-light-gray);
    border-left: 4px solid var(--whw-blue);
    border-radius: 0 var(--whw-radius) var(--whw-radius) 0;
    padding: 20px 24px;
    margin-bottom: 40px;
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--whw-text-light);
}

.whw-notes-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--whw-text);
    margin-bottom: 8px;
}

.whw-notes p {
    margin: 0;
}

/* Nasconde se vuote */
.whw-notes.hidden {
    display: none;
}

/* ==========================================================================
   7. MAPPA SVG
   ========================================================================== */

.whw-map-container {
    position: relative;
    width: 100%;
    margin-bottom: 40px;
    background: var(--whw-white);
    border-radius: var(--whw-radius);
    box-shadow: var(--whw-shadow);
    padding: 20px;
    overflow: hidden;
}

.whw-map-container svg {
    width: 100%;
    height: auto;
    display: block;
}

/* Stati base */
.whw-map-container svg path,
.whw-map-container svg polygon,
.whw-map-container svg g[id] {
    fill: var(--whw-light-gray);
    stroke: var(--whw-white);
    stroke-width: 1;
    cursor: pointer;
    transition: fill var(--whw-transition), opacity var(--whw-transition);
}

/* Stato hover */
.whw-map-container svg path:hover,
.whw-map-container svg polygon:hover,
.whw-map-container svg g[id]:hover {
    opacity: 0.8;
    filter: brightness(1.1);
}

/* Stato attivo (cliccato) */
.whw-map-container svg .whw-state-active {
    stroke: var(--whw-text);
    stroke-width: 2.5;
    filter: brightness(1.05);
}

/* Colorazione per partito */
.whw-map-container svg .whw-state-rep {
    fill: var(--whw-red);
}

.whw-map-container svg .whw-state-dem {
    fill: var(--whw-blue);
}

.whw-map-container svg .whw-state-ind {
    fill: var(--whw-green);
}

.whw-map-container svg .whw-state-lib {
    fill: var(--whw-gold);
}

.whw-map-container svg .whw-state-green {
    fill: #00A95C;
}

.whw-map-container svg .whw-state-dixiecrat {
    fill: #8B0000;
}

.whw-map-container svg .whw-state-ai {
    fill: var(--whw-orange);
}

.whw-map-container svg .whw-state-progressive {
    fill: var(--whw-purple);
}

/* Stato non esistente */
.whw-map-container svg .whw-state-disabled {
    fill: #E8E8E8;
    cursor: default;
    opacity: 0.5;
}

.whw-map-container svg .whw-state-disabled:hover {
    opacity: 0.5;
    filter: none;
}

/* Split state — pattern a righe oblique */
.whw-map-container svg .whw-state-split {
    fill: url(#whw-pattern-split);
}

/* Pattern SVG per split state (inserito dinamicamente via JS) */
.whw-pattern-split-red {
    fill: var(--whw-red);
}

.whw-pattern-split-blue {
    fill: var(--whw-blue);
}

/* ==========================================================================
   8. TOOLTIP STATO (popup al click)
   ========================================================================== */

.whw-state-tooltip {
    position: absolute;
    z-index: 1000;
    background: var(--whw-white);
    border-radius: var(--whw-radius);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    padding: 20px;
    min-width: 280px;
    max-width: 320px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
    pointer-events: none;
}

.whw-state-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

.whw-state-tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--whw-border);
}

.whw-state-tooltip-name {
    font-size: 1.1rem;
    font-weight: 700;
    line-height: 1.2;
}

.whw-state-tooltip-ev {
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--whw-light-gray);
    padding: 4px 10px;
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 12px;
}

.whw-state-tooltip-winner {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 14px;
}

.whw-state-tooltip-winner-name {
    font-weight: 700;
}

/* Risultati nel tooltip */
.whw-state-tooltip-results {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
}

.whw-state-tooltip-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
}

.whw-state-tooltip-result-party {
    display: flex;
    align-items: center;
    gap: 6px;
}

.whw-state-tooltip-result-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.whw-state-tooltip-result-pct {
    font-weight: 700;
}

/* Barra ripartizione nel tooltip */
.whw-state-tooltip-bar {
    display: flex;
    width: 100%;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: var(--whw-light-gray);
}

.whw-state-tooltip-bar-segment {
    height: 100%;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Pulsante chiudi tooltip */
.whw-state-tooltip-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--whw-text-light);
    cursor: pointer;
    border-radius: 50%;
    transition: background var(--whw-transition);
    line-height: 1;
}

.whw-state-tooltip-close:hover {
    background: var(--whw-light-gray);
    color: var(--whw-text);
}

/* ==========================================================================
   9. STATI DI CARICAMENTO E VUOTO
   ========================================================================== */

.whw-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--whw-text-light);
}

.whw-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--whw-border);
    border-top-color: var(--whw-blue);
    border-radius: 50%;
    animation: whw-spin 0.8s linear infinite;
    margin-bottom: 16px;
}

@keyframes whw-spin {
    to { transform: rotate(360deg); }
}

.whw-empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--whw-text-light);
    font-size: 0.95rem;
}

/* ==========================================================================
   10. RESPONSIVE — TABLET (max-width: 768px)
   ========================================================================== */

@media (max-width: 768px) {
    .whw-electoral-map {
        padding: 12px;
    }

    .whw-era-selector select {
        min-width: 100%;
        font-size: 0.95rem;
    }

    .whw-election-buttons {
        gap: 8px;
        padding: 14px;
    }

    .whw-election-buttons .whw-btn-year {
        min-width: 60px;
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .whw-candidates {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .whw-candidate-card {
        padding: 18px;
    }

    .whw-candidate-name {
        font-size: 1.15rem;
    }

    .whw-electoral-bar {
        height: 32px;
    }

    .whw-electoral-bar-segment span {
        font-size: 0.7rem;
    }

    .whw-map-container {
        padding: 10px;
    }

    .whw-state-tooltip {
        min-width: 240px;
        max-width: 280px;
        padding: 16px;
    }

    .whw-state-tooltip-name {
        font-size: 1rem;
    }
}

/* ==========================================================================
   11. RESPONSIVE — MOBILE (max-width: 480px)
   ========================================================================== */

@media (max-width: 480px) {
    .whw-electoral-map {
        padding: 8px;
    }

    .whw-election-buttons {
        gap: 6px;
        padding: 10px;
    }

    .whw-election-buttons .whw-btn-year {
        min-width: 52px;
        padding: 7px 10px;
        font-size: 0.8rem;
    }

    .whw-candidate-card {
        padding: 14px;
    }

    .whw-candidate-name {
        font-size: 1.05rem;
    }

    .whw-candidate-stats {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .whw-stat-value {
        font-size: 1rem;
    }

    .whw-electoral-bar {
        height: 26px;
    }

    .whw-electoral-bar-legend {
        gap: 10px;
    }

    .whw-notes {
        padding: 14px 16px;
        font-size: 0.85rem;
    }

    /* Tooltip su mobile: full width in basso */
    .whw-state-tooltip {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        min-width: 100%;
        max-width: 100%;
        border-radius: var(--whw-radius) var(--whw-radius) 0 0;
        transform: translateY(100%);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }

    .whw-state-tooltip.visible {
        transform: translateY(0);
    }
}

/* ==========================================================================
   12. ANIMAZIONI
   ========================================================================== */

@keyframes whw-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.whw-candidate-card {
    animation: whw-fade-in 0.4s ease forwards;
}

.whw-candidate-card:nth-child(1) { animation-delay: 0.05s; }
.whw-candidate-card:nth-child(2) { animation-delay: 0.1s; }
.whw-candidate-card:nth-child(3) { animation-delay: 0.15s; }
.whw-candidate-card:nth-child(4) { animation-delay: 0.2s; }
.whw-candidate-card:nth-child(5) { animation-delay: 0.25s; }
.whw-candidate-card:nth-child(6) { animation-delay: 0.3s; }

/* ==========================================================================
   13. DARK MODE (opzionale, segue le preferenze di sistema)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .whw-electoral-map.whw-auto-dark {
        --whw-text: #E8E8E8;
        --whw-text-light: #AAAAAA;
        --whw-white: #1E1E1E;
        --whw-light-gray: #2A2A2A;
        --whw-border: #3A3A3A;
        --whw-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
        --whw-shadow-hover: 0 4px 16px rgba(0, 0, 0, 0.5);
    }
}

/* ==========================================================================
   14. UTILITY & ACCESSIBILITÀ
   ========================================================================== */

.whw-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Focus visibile per navigazione da tastiera */
.whw-electoral-map *:focus-visible {
    outline: 3px solid var(--whw-blue);
    outline-offset: 2px;
}

/* Riduce animazioni per chi lo preferisce */
@media (prefers-reduced-motion: reduce) {
    .whw-electoral-map *,
    .whw-electoral-map *::before,
    .whw-electoral-map *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print */
@media print {
    .whw-electoral-map {
        box-shadow: none;
    }

    .whw-state-tooltip {
        display: none !important;
    }

    .whw-map-container svg path,
    .whw-map-container svg polygon {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* ==========================================================================
   15. CARD CANDIDATI COLLASSABILI
   ========================================================================== */

/* Di default su mobile: dettagli nascosti */
@media (max-width: 768px) {
    .whw-candidate-details {
        display: none;
        margin-top: 12px;
        padding-top: 12px;
        border-top: 1px solid var(--whw-border);
    }

    .whw-candidate-card.whw-card-expanded .whw-candidate-details {
        display: block;
    }

    /* Freccia indicatore espansione */
    .whw-candidate-header::after {
        content: "▼";
        float: right;
        font-size: 0.7rem;
        color: var(--whw-text-light);
        transition: transform var(--whw-transition);
    }

    .whw-candidate-card.whw-card-expanded .whw-candidate-header::after {
        transform: rotate(180deg);
    }
}

/* Su desktop: sempre visibile */
@media (min-width: 769px) {
    .whw-candidate-details {
        display: block;
        margin-top: 12px;
    }

    .whw-candidate-header {
        cursor: default !important;
    }

    .whw-candidate-header::after {
        display: none;
    }
}

/* ==========================================================================
   16. FIX BARRA ELETTORALE — Linea maggioranza
   ========================================================================== */

.whw-electoral-bar-wrapper {
    position: relative;
    padding-top: 20px;
    padding-bottom: 10px;
}

.whw-electoral-bar-majority-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--whw-text);
    z-index: 10;
    pointer-events: none;
}

.whw-electoral-bar-majority-line::after {
    content: attr(data-label);
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
    color: var(--whw-text);
    background: var(--whw-white);
    padding: 0 4px;
}

/* ==========================================================================
   17. FIX TOOLTIP POSIZIONAMENTO DESKTOP
   ========================================================================== */

/* Il parent deve avere position relative per il tooltip assoluto */
.whw-map-section {
    position: relative;
}

/* Tooltip desktop: posizionamento assoluto rispetto a .whw-map-section */
.whw-state-tooltip {
    position: absolute;
    z-index: 1000;
    background: var(--whw-white);
    border-radius: var(--whw-radius);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    padding: 20px;
    min-width: 280px;
    max-width: 320px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s ease;
    pointer-events: none;
}

.whw-state-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    pointer-events: auto;
}

/* ==========================================================================
   18. FIX TOOLTIP MOBILE — Sfondo opaco + bottom sheet
   ========================================================================== */

@media (max-width: 480px) {
    .whw-state-tooltip {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        min-width: 100%;
        max-width: 100%;
        border-radius: var(--whw-radius) var(--whw-radius) 0 0;
        transform: translateY(100%);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        background: #FFFFFF;
        opacity: 1;
        visibility: hidden;
        padding: 24px 20px;
        padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    }

    .whw-state-tooltip.visible {
        visibility: visible;
        transform: translateY(0);
    }
}

/* Anche per tablet */
@media (min-width: 481px) and (max-width: 768px) {
    .whw-state-tooltip {
        background: #FFFFFF;
    }
}

/* ==========================================================================
   19. FIX STATI MULTI-PATH (Alaska, Michigan, Virginia, ecc.)
   Quando un <g> riceve la classe di partito, i figli ereditano il fill
   ========================================================================== */

.whw-map-container svg g.whw-state-rep path,
.whw-map-container svg g.whw-state-rep polygon,
.whw-map-container svg g.whw-state-rep rect {
    fill: var(--whw-red);
}

.whw-map-container svg g.whw-state-dem path,
.whw-map-container svg g.whw-state-dem polygon,
.whw-map-container svg g.whw-state-dem rect {
    fill: var(--whw-blue);
}

.whw-map-container svg g.whw-state-ind path,
.whw-map-container svg g.whw-state-ind polygon,
.whw-map-container svg g.whw-state-ind rect {
    fill: var(--whw-green);
}

.whw-map-container svg g.whw-state-lib path,
.whw-map-container svg g.whw-state-lib polygon,
.whw-map-container svg g.whw-state-lib rect {
    fill: var(--whw-gold);
}

.whw-map-container svg g.whw-state-green path,
.whw-map-container svg g.whw-state-green polygon,
.whw-map-container svg g.whw-state-green rect {
    fill: #00A95C;
}

.whw-map-container svg g.whw-state-dixiecrat path,
.whw-map-container svg g.whw-state-dixiecrat polygon,
.whw-map-container svg g.whw-state-dixiecrat rect {
    fill: #8B0000;
}

.whw-map-container svg g.whw-state-ai path,
.whw-map-container svg g.whw-state-ai polygon,
.whw-map-container svg g.whw-state-ai rect {
    fill: var(--whw-orange);
}

.whw-map-container svg g.whw-state-progressive path,
.whw-map-container svg g.whw-state-progressive polygon,
.whw-map-container svg g.whw-state-progressive rect {
    fill: var(--whw-purple);
}

.whw-map-container svg g.whw-state-split path,
.whw-map-container svg g.whw-state-split polygon,
.whw-map-container svg g.whw-state-split rect {
    fill: url(#whw-pattern-split);
}

.whw-map-container svg g.whw-state-disabled path,
.whw-map-container svg g.whw-state-disabled polygon,
.whw-map-container svg g.whw-state-disabled rect {
    fill: #E8E8E8;
}

/* Hover per gruppi */
.whw-map-container svg g[id]:hover path,
.whw-map-container svg g[id]:hover polygon {
    opacity: 0.8;
    filter: brightness(1.1);
}

/* Active per gruppi */
.whw-map-container svg g.whw-state-active path,
.whw-map-container svg g.whw-state-active polygon {
    stroke: var(--whw-text);
    stroke-width: 2.5;
}

/* ==========================================================================
   ETICHETTE STATI — Sigla + Voti Elettorali
   ========================================================================== */

/* Etichette inline (sopra lo stato) */
.whw-label-abbr {
    font-size: 10px;
    font-weight: 700;
    fill: #FFFFFF;
    stroke: rgba(0, 0, 0, 0.3);
    stroke-width: 0.2px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    paint-order: stroke;
}

.whw-label-ev {
    font-size: 10px;
    font-weight: 600;
    fill: #FFFFFF;
    stroke: rgba(0, 0, 0, 0.3);
    stroke-width: 0.2px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    paint-order: stroke;
}

.whw-state-label text {
    paint-order: stroke;
}

/* Callout (stati piccoli costa atlantica) */
.whw-callout-line {
    stroke: #666666;
}

.whw-callout-dot {
    stroke: #FFFFFF;
    stroke-width: 0.3px;
}

.whw-callout-text {
    font-size: 8px;
    font-weight: 700;
    fill: #333333;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Mobile: etichette ridotte per leggibilità */
@media (max-width: 768px) {
    .whw-label-abbr {
        font-size: 6px;
        stroke-width: 0.3px;
    }

    .whw-label-ev {
        font-size: 5px;
        stroke-width: 0.3px;
    }

    .whw-callout-text {
        font-size: 5px;
    }

    .whw-callout-line {
        stroke-width: 0.5px;
    }
}

