/**
 * Emergenze Sidebar - Frontend CSS
 * Plugin: Emergenze
 * Note: Eredita font dal tema (no font-family forzati)
 */

/* ==========================================================================
   Variables
   ========================================================================== */

:root {
    --em-header: #006699;
    --em-white: #FFFFFF;
    --em-warning: #9A5200;        /* Scurito per contrasto WCAG AA (ratio 5.8:1 con bianco) */
    --em-danger: #C0392B;
    --em-info: #1A6DAD;           /* Scurito per contrasto WCAG AA (ratio 4.5:1 con bianco) */
    --em-gray-light: #F8F9FA;
    --em-text: #333333;
    --em-text-muted: #595959;     /* Scurito per contrasto WCAG AA (ratio 7:1 su #F8F9FA) */
    --em-text-light: #595959;     /* Scurito per contrasto WCAG AA (ratio 7:1 su #F8F9FA) */
    --em-shadow: 0 4px 24px rgba(0, 102, 153, 0.15);
    --em-radius: 8px;
    --em-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Sidebar Container
   ========================================================================== */

.em-sidebar {
    font-size: 14px;
    line-height: 1.5;
}

.em-sidebar *,
.em-sidebar *::before,
.em-sidebar *::after {
    box-sizing: border-box;
}

/* ==========================================================================
   Tab Toggle
   ========================================================================== */

.em-sidebar__tab {
    position: fixed !important;
    right: 0 !important;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 56px;
    background: var(--em-header) !important;
    border: none;
    border-radius: var(--em-radius) 0 0 var(--em-radius);
    color: var(--em-white) !important;
    cursor: pointer;
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-shadow: var(--em-shadow);
    transition: background var(--em-transition), right var(--em-transition);
    z-index: 100000;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Quando il pannello è aperto, sposta il tab a sinistra del pannello */
.em-sidebar--visible .em-sidebar__tab {
    right: 340px !important; /* larghezza del pannello */
}

.em-sidebar__tab:hover,
.em-sidebar__tab:focus {
    background: #00557a !important;  /* Darker shade of --em-header */
}

.em-sidebar__tab:focus-visible {
    outline: 3px solid var(--em-white);
    outline-offset: 2px;
    box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.3);
}


.em-sidebar__tab i {
    font-size: 20px;
    line-height: 1;
}

.em-sidebar__tab-count {
    font-size: 11px;
    font-weight: 700;
    background: var(--em-white);
    color: var(--em-header);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==========================================================================
   Panel
   ========================================================================== */

.em-sidebar__panel {
    position: fixed;
    right: 0;
    top: 50%;
    transform: translateY(-50%) translateX(100%);
    width: 340px;
    max-height: 80vh;
    background: var(--em-white);
    border-radius: var(--em-radius) 0 0 var(--em-radius);
    box-shadow: var(--em-shadow);
    display: flex;
    flex-direction: column;
    transition: transform var(--em-transition);
    overflow: hidden;
    z-index: 99999;
}

.em-sidebar--visible .em-sidebar__panel {
    transform: translateY(-50%) translateX(0);
}

.em-sidebar--collapsed .em-sidebar__panel {
    transform: translateY(-50%) translateX(100%);
}

/* Primo caricamento: nessuna transizione, così lo stato iniziale
   (aperto/chiuso) viene applicato istantaneamente senza scivolamenti.
   Il JS rimuove --preload dopo il primo frame per riattivare le
   animazioni nelle interazioni dell'utente. */
.em-sidebar--preload .em-sidebar__panel,
.em-sidebar--preload .em-sidebar__tab {
    transition: none !important;
}

/* ==========================================================================
   Header
   ========================================================================== */

.em-sidebar__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--em-header);
    color: var(--em-white);
    border-radius: var(--em-radius) 0 0 0;
    flex-shrink: 0;
}

.em-sidebar__title {
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
}

/* Pulsante "CHIUDI" ben visibile: pill bordata sull'header blu,
   con etichetta testuale + icona. 4 stati sempre attivi. */
.em-sidebar__close {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.65);
    border-radius: 999px;
    color: var(--em-white);
    cursor: pointer;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    transition: background var(--em-transition), border-color var(--em-transition);
}

.em-sidebar__close-label {
    display: inline-block;
}

.em-sidebar__close i {
    font-size: 16px;
    line-height: 1;
}

.em-sidebar__close:hover {
    background: rgba(255, 255, 255, 0.32);
    border-color: var(--em-white);
}

.em-sidebar__close:focus,
.em-sidebar__close:focus-visible {
    outline: 2px solid var(--em-white);
    outline-offset: 2px;
    background: rgba(255, 255, 255, 0.32);
}

.em-sidebar__close:active {
    background: rgba(255, 255, 255, 0.45);
    border-color: var(--em-white);
}

/* ==========================================================================
   List
   ========================================================================== */

.em-sidebar__list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 0;
    list-style: none;
}

.em-sidebar__list::-webkit-scrollbar {
    width: 6px;
}

.em-sidebar__list::-webkit-scrollbar-track {
    background: var(--em-gray-light);
    border-radius: 3px;
}

.em-sidebar__list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.em-sidebar__list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.em-sidebar__footer {
    padding: 10px 14px;
    font-size: 11px;
    color: var(--em-text-light);
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.em-sidebar__archive-link {
    display: inline-block;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--em-white);
    background: var(--em-header);
    text-decoration: none;
    border-radius: 4px;
    transition: background var(--em-transition);
}

.em-sidebar__archive-link:hover,
.em-sidebar__archive-link:focus {
    background: #00557a;
    color: var(--em-white);
    text-decoration: none;
}

.em-sidebar__last-sync {
    display: block;
}

/* ==========================================================================
   Card
   ========================================================================== */

.em-card {
    background: var(--em-gray-light);
    border-radius: 6px;
    padding: 14px;
    transition: box-shadow var(--em-transition);
    margin: 0;
}

.em-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

/* Badge */
.em-card__badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--em-white);
    background: var(--em-info);
    padding: 3px 8px;
    border-radius: 3px;
    margin-bottom: 8px;
}

.em-card--warning .em-card__badge {
    background: var(--em-warning);
}

.em-card--danger .em-card__badge {
    background: var(--em-danger);
}

.em-card--info .em-card__badge {
    background: var(--em-info);
}

/* Comune */
.em-card__comune {
    font-size: 14px;
    font-weight: 700;
    color: var(--em-text);
    margin: 0 0 4px 0;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Zona */
.em-card__zona {
    font-size: 13px;
    color: var(--em-text-muted);
    margin: 0 0 8px 0;
}

/* Note/Descrizione (da cartellonote) */
.em-card__note {
    font-size: 12px;
    color: var(--em-text-muted);
    margin: 0 0 10px 0;
    padding: 8px 10px;
    background: rgba(0, 102, 153, 0.05);
    border-radius: 4px;
    line-height: 1.5;
}

/* Time */
.em-card__time {
    font-size: 12px;
    color: var(--em-text-light);
    line-height: 1.6;
}

.em-card__time strong {
    color: var(--em-text);
    font-size: 13px;
}

.em-card__time span {
    margin-right: 4px;
}

/* ==========================================================================
   Pulse animation
   ========================================================================== */

@keyframes em-pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(0, 102, 153, 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(0, 102, 153, 0);
    }
}

.em-sidebar__tab--pulse {
    animation: em-pulse 2s infinite;
}

.em-sidebar__tab--pulse:hover,
.em-sidebar__tab--pulse:focus {
    animation: none;
}

/* ==========================================================================
   LEFT Position Variant
   ========================================================================== */

/* Tab on the left */
.em-sidebar--left .em-sidebar__tab {
    right: auto !important;
    left: 0 !important;
    border-radius: 0 var(--em-radius) var(--em-radius) 0;
}

.em-sidebar--left.em-sidebar--visible .em-sidebar__tab {
    left: 340px !important; /* larghezza del pannello */
    right: auto !important;
}

/* Panel on the left */
.em-sidebar--left .em-sidebar__panel {
    right: auto;
    left: 0;
    transform: translateY(-50%) translateX(-100%);
    border-radius: 0 var(--em-radius) var(--em-radius) 0;
}

.em-sidebar--left.em-sidebar--visible .em-sidebar__panel {
    transform: translateY(-50%) translateX(0);
}

.em-sidebar--left.em-sidebar--collapsed .em-sidebar__panel {
    transform: translateY(-50%) translateX(-100%);
}

/* Header radius */
.em-sidebar--left .em-sidebar__header {
    border-radius: 0 var(--em-radius) 0 0;
}

/* ==========================================================================
   MOBILE: Bottom sheet (< 600px)
   ========================================================================== */

@media (max-width: 600px) {
    .em-sidebar__panel {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 65vh;
        border-radius: var(--em-radius) var(--em-radius) 0 0;
        transform: translateY(100%);
    }

    .em-sidebar--visible .em-sidebar__panel {
        transform: translateY(0);
    }

    .em-sidebar--collapsed .em-sidebar__panel {
        transform: translateY(100%);
    }

    .em-sidebar__header {
        border-radius: var(--em-radius) var(--em-radius) 0 0;
        position: relative;
    }

    /* Drag handle indicator */
    .em-sidebar__header::before {
        content: '';
        position: absolute;
        top: 6px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(255, 255, 255, 0.3);
        border-radius: 2px;
    }

    /* FAB button */
    .em-sidebar__tab {
        bottom: 20px;
        right: 20px;
        top: auto;
        transform: none;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        box-shadow: 0 4px 16px rgba(0, 102, 153, 0.35);
    }

    .em-sidebar__tab-count {
        position: absolute;
        top: -4px;
        right: -4px;
        width: 22px;
        height: 22px;
        font-size: 12px;
    }

    /* Hide FAB when panel open */
    .em-sidebar--visible .em-sidebar__tab {
        right: 20px; /* reset desktop shift */
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s;
    }

    /* Left position on mobile */
    .em-sidebar--left .em-sidebar__tab {
        right: auto;
        left: 20px;
        border-radius: 50%; /* FAB is always round on mobile */
    }

    .em-sidebar--left.em-sidebar--visible .em-sidebar__tab {
        left: 20px; /* reset desktop shift */
        right: auto;
    }

    .em-sidebar--left .em-sidebar__tab-count {
        right: auto;
        left: -4px;
    }

    /* Panel same as right on mobile (full width bottom sheet) */
    .em-sidebar--left .em-sidebar__panel {
        right: 0;
        left: 0;
        border-radius: var(--em-radius) var(--em-radius) 0 0;
        transform: translateY(100%);
    }

    .em-sidebar--left.em-sidebar--visible .em-sidebar__panel {
        transform: translateY(0);
    }

    .em-sidebar--left.em-sidebar--collapsed .em-sidebar__panel {
        transform: translateY(100%);
    }

    .em-sidebar--left .em-sidebar__header {
        border-radius: var(--em-radius) var(--em-radius) 0 0;
    }

    /* Show overlay */
    .em-overlay {
        display: block;
    }
}

/* ==========================================================================
   Overlay (mobile only)
   ========================================================================== */

.em-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 99998;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--em-transition);
}

.em-sidebar--visible ~ .em-overlay {
    opacity: 1;
    pointer-events: auto;
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

/* Screen reader only - visually hidden but accessible */
.screen-reader-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (prefers-reduced-motion: reduce) {
    .em-sidebar__panel,
    .em-sidebar__tab,
    .em-card,
    .em-overlay {
        transition: none;
    }

    .em-sidebar__tab--pulse {
        animation: none;
    }
}

/* High contrast mode */
@media (forced-colors: active) {
    .em-card {
        border: 2px solid CanvasText;
    }

    .em-card__badge {
        border: 1px solid CanvasText;
    }

    .em-sidebar__header {
        border: 1px solid CanvasText;
    }
}
