/**
 * Stili Principali - Sistema Ordinanze
 * Design responsive ibrido: Mobile-first + Desktop-friendly
 */

:root {
    /* Colori Stati Ordinanze */
    --color-in-attivazione: #ffc107;
    --color-attiva: #28a745;
    --color-scaduta: #dc3545;
    --color-annullata: #6c757d;
    --color-prorogata: #17a2b8;
    
    /* Colori UI */
    --primary: #007bff;
    --secondary: #6c757d;
    --light: #f8f9fa;
    --dark: #343a40;
    --border: #dee2e6;
    
    /* Dimensioni */
    --header-height: 56px;
    --bottom-nav-height: 56px;
    --sidebar-width: 280px;
    
    /* Animazioni */
    --transition: 0.3s ease;
    
    /* Z-index */
    --z-header: 1000;
    --z-sidebar: 999;
    --z-overlay: 998;
    --z-fab: 997;
    --z-bottom-nav: 996;
}

/* Reset e Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--dark);
    background-color: #f5f5f5;
    overflow-x: hidden;
}

/* Header Fisso */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background-color: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    z-index: var(--z-header);
}

.app-header .header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header .menu-toggle {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.app-header .menu-toggle:hover {
    opacity: 0.8;
}

.app-header .header-title {
    font-size: 18px;
    font-weight: 600;
}

.app-header .header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-header .header-icon {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
    position: relative;
    transition: var(--transition);
}

.app-header .header-icon:hover {
    opacity: 0.8;
}

.header-icon .badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background-color: #dc3545;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 11px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
}

/* Sidebar/Menu Laterale */
.app-sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: var(--sidebar-width);
    height: 100vh;
    background-color: white;
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    transition: left var(--transition);
    z-index: var(--z-sidebar);
    overflow-y: auto;
}

.app-sidebar.open {
    left: 0;
}

.sidebar-header {
    height: var(--header-height);
    background-color: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.sidebar-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.sidebar-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
}

.sidebar-menu {
    list-style: none;
    padding: 8px 0;
}

.sidebar-menu li {
    margin: 0;
}

.sidebar-menu a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--dark);
    text-decoration: none;
    transition: var(--transition);
}

.sidebar-menu a:hover,
.sidebar-menu a.active {
    background-color: var(--light);
    color: var(--primary);
}

.sidebar-menu i {
    width: 24px;
    text-align: center;
    font-size: 18px;
}

.sidebar-menu .menu-badge {
    margin-left: auto;
    background-color: var(--primary);
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: bold;
}

.sidebar-divider {
    height: 1px;
    background-color: var(--border);
    margin: 8px 16px;
}

.sidebar-section-title {
    padding: 16px 16px 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Overlay per sidebar mobile */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
    z-index: var(--z-overlay);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Main Content */
.app-content {
    margin-top: var(--header-height);
    padding: 16px;
    min-height: calc(100vh - var(--header-height) - var(--bottom-nav-height));
}

/* Bottom Navigation (solo mobile) */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background-color: white;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: var(--z-bottom-nav);
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
    color: var(--secondary);
    text-decoration: none;
    font-size: 12px;
    transition: var(--transition);
    position: relative;
}

.bottom-nav-item i {
    font-size: 20px;
}

.bottom-nav-item.active {
    color: var(--primary);
}

.bottom-nav-item .nav-badge {
    position: absolute;
    top: 4px;
    right: 25%;
    background-color: #dc3545;
    color: white;
    border-radius: 10px;
    padding: 2px 5px;
    font-size: 10px;
    font-weight: bold;
    min-width: 16px;
    text-align: center;
}

/* FAB - Floating Action Button */
.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + 16px);
    right: 16px;
    width: 56px;
    height: 56px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    cursor: pointer;
    transition: var(--transition);
    z-index: var(--z-fab);
}

.fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.fab:active {
    transform: scale(0.95);
}

/* Cards */
.card {
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 16px;
    overflow: hidden;
}

.card-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.card-body {
    padding: 16px;
}

.card-footer {
    padding: 12px 16px;
    background-color: var(--light);
    border-top: 1px solid var(--border);
}

/* Lista Ordinanze */
.ordinanza-item {
    background-color: white;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: var(--transition);
    border-left: 4px solid var(--border);
}

.ordinanza-item:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

.ordinanza-item.stato-in_attivazione {
    border-left-color: var(--color-in-attivazione);
}

.ordinanza-item.stato-attiva {
    border-left-color: var(--color-attiva);
}

.ordinanza-item.stato-scaduta {
    border-left-color: var(--color-scaduta);
}

.ordinanza-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 12px;
}

.ordinanza-numero {
    font-size: 14px;
    color: var(--secondary);
    font-weight: 500;
}

.ordinanza-title {
    font-size: 16px;
    font-weight: 600;
    margin: 4px 0 8px;
    color: var(--dark);
}

.ordinanza-dates {
    font-size: 14px;
    color: var(--secondary);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ordinanza-dates i {
    width: 16px;
    margin-right: 8px;
}

.ordinanza-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

/* Badge Stati */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-in_attivazione {
    background-color: var(--color-in-attivazione);
    color: #000;
}

.badge-attiva {
    background-color: var(--color-attiva);
    color: white;
}

.badge-scaduta {
    background-color: var(--color-scaduta);
    color: white;
}

.badge-annullata {
    background-color: var(--color-annullata);
    color: white;
}

.badge-prorogata {
    background-color: var(--color-prorogata);
    color: white;
}

/* Statistiche Dashboard */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 16px;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: white;
}

.stat-icon.in-attivazione {
    background-color: var(--color-in-attivazione);
}

.stat-icon.attiva {
    background-color: var(--color-attiva);
}

.stat-icon.scaduta {
    background-color: var(--color-scaduta);
}

.stat-icon.totale {
    background-color: var(--primary);
}

.stat-info h4 {
    font-size: 14px;
    color: var(--secondary);
    margin-bottom: 4px;
}

.stat-info .stat-number {
    font-size: 32px;
    font-weight: bold;
    color: var(--dark);
}

/* Filtri */
.filter-bar {
    background-color: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.filter-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
}

.filter-chip {
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background-color: white;
    color: var(--dark);
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: var(--transition);
}

.filter-chip:hover {
    background-color: var(--light);
}

.filter-chip.active {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Mappa */
#map {
    width: 100%;
    height: 400px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

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

.popup-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.popup-info {
    font-size: 14px;
    color: var(--secondary);
    margin-bottom: 12px;
}

.popup-actions {
    display: flex;
    gap: 8px;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-secondary {
    background-color: var(--secondary);
    color: white;
}

.btn-success {
    background-color: var(--color-attiva);
    color: white;
}

.btn-danger {
    background-color: var(--color-scaduta);
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    padding: 8px;
    width: 36px;
    height: 36px;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--dark);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0,123,255,0.1);
}

.form-text {
    font-size: 12px;
    color: var(--secondary);
    margin-top: 4px;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.alert-warning {
    background-color: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.alert-info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Loading Spinner */
.spinner {
    border: 3px solid var(--border);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state-icon {
    font-size: 64px;
    color: var(--secondary);
    opacity: 0.5;
    margin-bottom: 16px;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 8px;
}

.empty-state-text {
    font-size: 14px;
    color: var(--secondary);
    margin-bottom: 24px;
}

/* Utilities */
.d-none { display: none !important; }
.d-flex { display: flex !important; }
.flex-column { flex-direction: column; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ============================================
   RESPONSIVE BREAKPOINTS
   ============================================ */

/* Tablet e oltre (≥ 768px) */
@media (min-width: 768px) {
    /* Header diventa top nav tradizionale */
    .app-header .menu-toggle {
        display: none;
    }
    
    /* Sidebar sempre visibile */
    .app-sidebar {
        left: 0;
        box-shadow: none;
        border-right: 1px solid var(--border);
    }
    
    .sidebar-close {
        display: none;
    }
    
    .sidebar-overlay {
        display: none;
    }
    
    /* Content con sidebar */
    .app-content {
        margin-left: var(--sidebar-width);
        padding: 24px;
    }
    
    /* Nascondi bottom nav su desktop */
    .bottom-nav {
        display: none;
    }
    
    /* FAB senza bottom nav */
    .fab {
        bottom: 24px;
        right: 24px;
    }
    
    /* App content senza padding bottom */
    .app-content {
        min-height: calc(100vh - var(--header-height));
    }
    
    /* Stats grid a 2 colonne */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Mappa più alta */
    #map {
        height: 500px;
    }
}

/* Desktop grande (≥ 1024px) */
@media (min-width: 1024px) {
    /* Stats grid a 4 colonne */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    /* Mappa ancora più alta */
    #map {
        height: 600px;
    }
    
    /* Layout a due colonne per dettagli */
    .detail-layout {
        display: grid;
        grid-template-columns: 2fr 1fr;
        gap: 24px;
    }
}

/* Desktop XL (≥ 1440px) */
@media (min-width: 1440px) {
    .app-content {
        max-width: 1400px;
        margin-left: auto;
        margin-right: auto;
        padding-left: calc(var(--sidebar-width) + 24px);
    }
}

/* Print styles */
@media print {
    .app-header,
    .app-sidebar,
    .bottom-nav,
    .fab,
    .filter-bar {
        display: none !important;
    }
    
    .app-content {
        margin: 0 !important;
        padding: 0 !important;
    }
    
    .card {
        break-inside: avoid;
    }
}
