/* Event Interactive Map Styles */

/* Map Container */
.eim-map-container {
    position: relative;
    width: 100%;
    min-height: 400px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#event-map {
    width: 100%;
    height: 100%;
    min-height: 400px;
    z-index: 1;
    transition: opacity 0.3s ease;
}

/* Wrapper: rende i controlli absolute su desktop */
.eim-wrapper {
    position: relative;
}

/* Map Controls */
.eim-map-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    right: 10px;
    z-index: 1000;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.eim-control-group {
    display: flex;
    gap: 5px;
    flex: 1;
    min-width: 200px;
}

#eim-search-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

/* Autocomplete dropdown */
.eim-autocomplete {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 2000;
    max-height: 280px;
    overflow-y: auto;
}

.eim-ac-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f5f5f5;
    font-size: 13px;
    transition: background 0.15s;
}

.eim-ac-item:last-child { border-bottom: none; }
.eim-ac-item:hover { background: #f0f6fc; }

.eim-ac-band {
    font-weight: 600;
    color: #222;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.eim-ac-venue {
    color: #888;
    font-size: 12px;
    white-space: nowrap;
}

.eim-ac-time {
    color: #0073aa;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.eim-control-group { position: relative; }

/* Day filter buttons */
.eim-day-filter-group {
    display: flex;
    gap: 4px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}

.eim-day-filter-group::-webkit-scrollbar { display: none; }

.eim-day-btn {
    padding: 7px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.eim-day-btn:hover { background: #f5f5f5; }

.eim-day-btn.active,
.eim-day-btn.active:hover { color: white; border-color: transparent; }

.eim-day-btn[data-day=""].active    { background: #1d4a1d; }
.eim-day-btn.eim-day-color-0.active { background: #6a1b9a; }
.eim-day-btn.eim-day-color-1.active { background: #c8941a; }
.eim-day-btn.eim-day-color-2.active { background: #0097a7; }
.eim-day-btn.eim-day-color-3.active { background: #3498db; }
.eim-day-btn.eim-day-color-4.active { background: #e74c3c; }

.eim-cat-filter-group {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    flex-basis: 100%;
    margin-top: 4px;
}

.eim-cat-btn {
    padding: 7px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.eim-cat-btn:hover { background: #f5f5f5; }

.eim-cat-btn.active,
.eim-cat-btn.active:hover { background: #1d4a1d; color: white; border-color: transparent; }

.eim-btn {
    padding: 8px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.eim-btn:hover {
    background: #f5f5f5;
    border-color: #999;
}

.eim-btn:active {
    transform: scale(0.95);
}

.eim-btn .dashicons {
    width: 20px;
    height: 20px;
    font-size: 20px;
}

.eim-btn.loading {
    opacity: 0.6;
    cursor: wait;
}

.eim-btn-primary {
    background: #0073aa;
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.eim-btn-primary:hover {
    background: #005a87;
}

/* Custom Markers */
.eim-marker {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
}

.eim-marker-inner {
    width: 100%;
    height: 100%;
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid #e67e22;
    background: #fae5d322;
}

.eim-marker-inner .dashicons,
.eim-marker-inner span,
.eim-marker-inner svg {
    transform: rotate(45deg);
    font-size: 18px;
    width: 18px;
    height: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}

/* Eredita il colore del bordo per il pin SVG */
.eim-marker-inner {
    color: #555;
}

.eim-marker-concert {
    border-color: #9b59b6;
    background: #e8daef;
}

.eim-marker-concert .dashicons {
    color: #9b59b6;
}

.eim-marker-exhibition {
    border-color: #e74c3c;
    background: #fadbd8;
}

.eim-marker-exhibition .dashicons {
    color: #e74c3c;
}

.eim-marker-conference {
    border-color: #3498db;
    background: #d6eaf8;
}

.eim-marker-conference .dashicons {
    color: #3498db;
}

.eim-marker-workshop {
    border-color: #f39c12;
    background: #fef5e7;
}

.eim-marker-workshop .dashicons {
    color: #f39c12;
}

.eim-marker-festival {
    border-color: #e67e22;
    background: #fae5d3;
}

.eim-marker-festival .dashicons {
    color: #e67e22;
}

.eim-marker-sports {
    border-color: #27ae60;
    background: #d5f4e6;
}

.eim-marker-sports .dashicons {
    color: #27ae60;
}

.eim-marker-other {
    border-color: #95a5a6;
    background: #ecf0f1;
}

.eim-marker-other .dashicons {
    color: #95a5a6;
}

.eim-marker-user,
.eim-marker-search {
    background: #0073aa;
    border-color: #005a87;
}

.eim-marker-user .dashicons,
.eim-marker-search .dashicons {
    color: white;
}

/* Popup Styles */
.eim-popup .leaflet-popup-content-wrapper {
    border-radius: 8px;
    padding: 0;
    overflow: hidden;
}

.eim-popup .leaflet-popup-content {
    margin: 0;
    min-width: 250px;
}

.eim-popup-content {
    padding: 15px;
}

.eim-popup-content h3 {
    margin: 0 0 10px 0;
    font-size: 18px;
    color: #333;
    line-height: 1.4;
}

.eim-popup-type {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.eim-type-concert {
    background: #e8daef;
    color: #9b59b6;
}

.eim-type-exhibition {
    background: #fadbd8;
    color: #e74c3c;
}

.eim-type-conference {
    background: #d6eaf8;
    color: #3498db;
}

.eim-type-workshop {
    background: #fef5e7;
    color: #f39c12;
}

.eim-type-festival {
    background: #fae5d3;
    color: #e67e22;
}

.eim-type-sports {
    background: #d5f4e6;
    color: #27ae60;
}

.eim-type-other {
    background: #ecf0f1;
    color: #95a5a6;
}

.eim-popup-datetime {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    color: #666;
    font-size: 14px;
}

.eim-popup-datetime .dashicons {
    width: 16px;
    height: 16px;
    font-size: 16px;
}

.eim-popup-excerpt {
    margin-bottom: 15px;
    color: #555;
    font-size: 14px;
    line-height: 1.5;
}

.eim-popup-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 15px;
    background: #1d4a1d;
    color: white !important;
    text-decoration: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.2s ease;
}

.eim-popup-link:hover {
    background: #c8941a;
}

.eim-popup-link .dashicons {
    width: 16px;
    height: 16px;
    font-size: 16px;
}

/* Stage marker */
.eim-marker-stage { border-color: #e67e22; background: #fae5d3; }
.eim-marker-stage .dashicons { color: #e67e22; }

/* Program popup */
.eim-popup-program { margin: 8px 0 4px; }

.eim-popup-day-header {
    font-size: 11px;
    font-weight: 700;
    color: white;
    padding: 3px 8px;
    border-radius: 3px;
    margin: 8px 0 4px;
    display: inline-block;
}

.eim-popup-day-header.eim-day-color-0 { background: #9b59b6; }
.eim-popup-day-header.eim-day-color-1 { background: #e67e22; }
.eim-popup-day-header.eim-day-color-2 { background: #27ae60; }
.eim-popup-day-header.eim-day-color-3 { background: #3498db; }
.eim-popup-day-header.eim-day-color-4 { background: #e74c3c; }

.eim-slot {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 4px 0;
    border-bottom: 1px solid #f0f0f0;
    font-size: 13px;
}

.eim-slot:last-child { border-bottom: none; }

.eim-slot-time {
    color: #888;
    font-size: 12px;
    min-width: 42px;
    white-space: nowrap;
}

.eim-slot-band a { color: #1d4a1d; text-decoration: none; font-weight: 500; }
.eim-slot-band a:hover { text-decoration: underline; }

.eim-popup-empty { color: #999; font-size: 13px; margin: 8px 0 0; }

/* Loading State */
.eim-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    text-align: center;
}

.eim-spinner {
    width: 50px;
    height: 50px;
    margin: 0 auto 15px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #1d4a1d;
    border-radius: 50%;
    animation: eim-spin 1s linear infinite;
}

@keyframes eim-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.eim-loading p {
    margin: 0;
    color: #666;
    font-size: 14px;
}

/* Error State */
.eim-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1001;
    background: white;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    text-align: center;
    border-left: 4px solid #e74c3c;
}

.eim-error p {
    margin: 0 0 15px 0;
    color: #e74c3c;
    font-size: 16px;
    font-weight: 600;
}

/* Marker Clusters */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
    background-color: rgba(0, 115, 170, 0.6);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
    background-color: rgba(0, 115, 170, 0.8);
    color: white;
    font-weight: 600;
}

/* Header toggle: nascosto su desktop, visibile su mobile */
.eim-controls-header {
    display: none;
}

/* Su desktop il body dei controlli si comporta come se non ci fosse */
.eim-controls-body {
    display: contents;
}

/* Brand colors */
.eim-day-btn[data-day=""].active    { background: #1d4a1d; }
.eim-day-btn.eim-day-color-0.active { background: #6a1b9a; }
.eim-day-btn.eim-day-color-1.active { background: #c8941a; }
.eim-day-btn.eim-day-color-2.active { background: #0097a7; }

/* Responsive Design */
@media screen and (max-width: 768px) {
    /* Wrapper occupa tutta l'altezza schermo su mobile.
       Filter bar + mappa si dividono lo spazio via flex. */
    .eim-wrapper {
        height: 100dvh;
        height: 100vh; /* fallback browsers senza dvh */
        display: flex;
        flex-direction: column;
    }

    /* Controlli: sticky in cima, non overlay.
       Resettiamo left/right del desktop per evitare overflow. */
    .eim-map-controls {
        position: relative;
        top: auto;
        left: auto;
        right: auto;
        width: 100%;
        box-sizing: border-box;
        z-index: 500;
        flex-shrink: 0;
        border-radius: 0;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
        padding: 8px;
        gap: 0;
        flex-direction: column;
    }

    /* Mappa riempie il resto dello schermo */
    .eim-map-container {
        flex: 1 1 auto !important;
        height: auto !important;
        min-height: 0 !important;
        border-radius: 0;
    }

    #event-map {
        height: 100% !important;
        min-height: 0 !important;
    }

    /* Header toggle */
    .eim-controls-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 12px;
        cursor: pointer;
        user-select: none;
        background: #1d4a1d;
        border-radius: 6px 6px 0 0;
        margin: -8px -8px 0;
    }

    .eim-controls-label {
        font-size: 13px;
        font-weight: 600;
        color: #fff;
        letter-spacing: 0.03em;
    }

    .eim-toggle-btn {
        background: none;
        border: none;
        cursor: pointer;
        padding: 2px 4px;
        line-height: 1;
        color: #fff;
        transition: transform 0.2s ease;
        margin: 0;
    }

    .eim-toggle-btn .dashicons {
        width: 18px;
        height: 18px;
        font-size: 18px;
        display: block;
        color: #fff;
        transition: transform 0.2s ease;
    }

    /* Corpo dei filtri: animazione collasso.
       max-height generosa per non tagliare i filtri anche quando
       il tema WP aggiunge margin/padding agli input. */
    .eim-controls-body {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        overflow: hidden;
        max-height: 300px;
        opacity: 1;
        padding-top: 6px;
        transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.2s ease;
    }

    .eim-map-controls.eim-collapsed .eim-controls-body {
        max-height: 0;
        opacity: 0;
        padding-top: 0;
    }

    .eim-map-controls.eim-collapsed .eim-toggle-btn .dashicons {
        transform: rotate(180deg);
    }

    /* Resetta margini aggiuntivi che i temi WP applicano a form elements */
    .eim-controls-body input,
    .eim-controls-body button {
        margin: 0;
        box-sizing: border-box;
    }

    /* Search input occupa tutta la larghezza — i bottoni icona
       (search/locate/reset) usano dashicons non disponibili sul
       frontend mobile: li nascondiamo e usiamo l'autocomplete. */
    .eim-control-group {
        flex: 1;
        min-width: 0;
    }

    #eim-search-btn,
    #eim-locate-btn,
    #eim-reset-btn {
        display: none;
    }

    #eim-search-input {
        flex: 1;
        width: 100%;
        min-width: 0;
    }

    /* Filtri giorno: seconda riga a tutta larghezza, wrap per mostrare tutti i bottoni */
    #eim-day-filter {
        flex-basis: 100%;
        min-width: 100%;
        flex-wrap: wrap;
        overflow-x: visible;
    }

    /* Bottoni giornata: wrap visibile, tap target adeguato */
    #eim-day-filter .eim-day-btn {
        flex-shrink: 0;
        padding: 8px 12px;
        font-size: 13px;
        min-height: 36px;
    }

    .eim-popup .leaflet-popup-content {
        min-width: 200px;
    }

    .eim-popup-content h3 {
        font-size: 16px;
    }

    #event-map {
        min-height: 350px;
    }

    .eim-marker {
        width: 35px !important;
        height: 35px !important;
    }

    .eim-marker .dashicons {
        font-size: 18px;
        width: 18px;
        height: 18px;
    }
}

@media screen and (max-width: 480px) {
    #eim-search-input {
        font-size: 14px;
        padding: 9px 12px;
        margin: 0;
        border-radius: 6px;
    }

    /* Bottoni giornata: padding ridotto per schermi piccoli */
    #eim-day-filter .eim-day-btn {
        padding: 7px 10px;
        font-size: 12px;
    }

    #event-map {
        min-height: 300px;
    }

    .eim-loading,
    .eim-error {
        padding: 20px;
        max-width: 90%;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    .eim-btn,
    #eim-search-input,
    #eim-type-filter {
        min-height: 44px; /* iOS touch target size */
    }

    .leaflet-popup-content-wrapper {
        touch-action: manipulation;
    }
}

/* Dark mode: mantiene sfondo chiaro per coerenza col brand SBAF */
@media (prefers-color-scheme: dark) {
    .eim-map-controls {
        background: rgba(255, 255, 255, 0.97);
        border: 1px solid #dde6dd;
    }

    #eim-search-input,
    #eim-type-filter {
        background: #fff;
        color: #333;
        border-color: #cdd;
    }

    .eim-btn {
        background: #f4f7f4;
        color: #1d4a1d;
        border-color: #dde6dd;
    }

    .eim-btn:hover {
        background: #e8f0e8;
    }
}

/* Print styles */
@media print {
    .eim-map-controls {
        display: none;
    }

    .eim-loading,
    .eim-error {
        display: none;
    }
}

/* Gesture overlay (mobile two-finger hint) */
.eim-gesture-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.eim-gesture-overlay.eim-go-visible {
    opacity: 1;
}

.eim-gesture-msg {
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    padding: 12px 22px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    backdrop-filter: blur(4px);
    text-align: center;
}
