* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ==================== SAFE AREA E WEBAPP (iPhone / PWA) ==================== */
/* Rispetta notch e home indicator su iPhone quando aggiunta alla Home */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --touch-target-min: 44px; /* Apple HIG: minimo 44pt per target touch */
}

/* Assicura che html e body non causino overflow */
html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100vw; /* Previene overflow oltre la viewport */
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Webapp / standalone: padding per safe area (notch, home indicator) */
body.standalone .container {
    padding-left: max(var(--safe-area-left), 8px);
    padding-right: max(var(--safe-area-right), 8px);
    padding-bottom: max(var(--safe-area-bottom), 8px);
}

body.standalone header {
    padding-top: max(15px, var(--safe-area-top));
}

body.standalone .tabs-container {
    padding-bottom: max(4px, var(--safe-area-bottom));
}

/* Touch device: target minimi per tap (accessibilità e usabilità su iPhone) */
body.touch-device button,
body.touch-device .tab-btn,
body.touch-device .filter-btn,
body.touch-device .config-tab-btn,
body.touch-device a[href].btn-like {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
}

body.touch-device .tab-btn {
    padding-top: 12px;
    padding-bottom: 12px;
}

body.touch-device .btn-icon-only,
body.touch-device .btn-small {
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
}

/* Mobile/narrow: layout ottimizzato per una colonna e azioni in evidenza */
body.device-mobile header,
body.device-mobile .main-header,
body.narrow-view header,
body.narrow-view .main-header {
    display: grid !important;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 8px 12px;
    padding: 10px 12px !important;
    align-items: center;
    text-align: left;
}
/* Mobile: riga 1 = titolo | status | riga 2 = Aggiungi + Notte affiancati */
body.device-mobile .main-header .header-brand,
body.narrow-view .main-header .header-brand {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
}
body.device-mobile .main-header .header-status,
body.narrow-view .main-header .header-status {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    font-size: 13px;
    margin-left: 0;
}
body.device-mobile .main-header .header-actions,
body.narrow-view .main-header .header-actions {
    grid-column: 1 / -1;
    grid-row: 2;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: flex-start;
}
body.device-mobile .main-header .header-title-full,
body.narrow-view .main-header .header-title-full {
    display: none !important;
}
body.device-mobile .main-header .header-title-short,
body.narrow-view .main-header .header-title-short {
    display: inline !important;
}
body.device-mobile .main-header .header-add-label,
body.narrow-view .main-header .header-add-label {
    display: none !important;
}
body.device-mobile .main-header .header-add-short,
body.narrow-view .main-header .header-add-short {
    display: inline !important;
}
body.device-mobile .main-header .header-btn,
body.narrow-view .main-header .header-btn {
    padding: 6px 10px !important;
    font-size: 12px !important;
    display: inline-flex !important;
    width: auto !important;
    max-width: fit-content !important;
}
body.device-mobile .main-header .header-actions .header-btn-add,
body.narrow-view .main-header .header-actions .header-btn-add {
    flex: 0 0 auto !important;
    width: auto !important;
    max-width: 140px !important;
}
.main-header .header-actions .header-btn-add {
    flex: 0 0 auto;
    width: auto;
    max-width: fit-content;
}
body.device-mobile header h1,
body.device-mobile .main-header .header-title,
body.narrow-view header h1,
body.narrow-view .main-header .header-title {
    font-size: clamp(17px, 4.5vw, 20px) !important;
}

body.device-mobile .tabs-container,
body.narrow-view .tabs-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

/* Mobile: nascondi completamente la barra statistiche (stats-wrapper) */
body.device-mobile .stats-wrapper,
body.narrow-view .stats-wrapper {
    display: none !important;
}

@media (max-width: 768px) {
    .stats-wrapper.panel-full-width {
        display: none !important;
    }
}

/* ==================== FILTRI PRENOTAZIONI: pulsante + pannello su mobile ==================== */
/* Desktop: filtri inline visibili, pulsante Filtri nascosto */
.btn-filtri-mobile {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--theme-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-filtri-mobile i { font-size: 16px; }
.btn-filtri-mobile:hover { background: #5568d3; }

.filters-inline { display: block; }

/* Mobile: Filtri piccolo solo icona, affiancato a DB e refresh */
@media (max-width: 768px) {
    .filters-inline {
        display: none !important;
    }
    .btn-filtri-mobile {
        display: inline-flex !important;
        width: auto !important;
        min-width: 40px;
        padding: 8px 10px !important;
        font-size: 14px;
    }
    .btn-filtri-mobile .btn-filtri-mobile-text {
        display: none !important;
    }
}

body.device-mobile .filters-inline,
body.narrow-view .filters-inline {
    display: none !important;
}
body.device-mobile .btn-filtri-mobile,
body.narrow-view .btn-filtri-mobile {
    display: inline-flex !important;
    width: auto !important;
    min-width: 40px;
    padding: 8px 10px !important;
}
body.device-mobile .btn-filtri-mobile .btn-filtri-mobile-text,
body.narrow-view .btn-filtri-mobile .btn-filtri-mobile-text {
    display: none !important;
}

/* Pannello Filtri overlay (stile Amazon / bottom sheet) */
.filter-panel-overlay {
    position: fixed;
    inset: 0;
    z-index: 10001;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.filter-panel-overlay.is-open {
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
}
.filter-panel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-tap-highlight-color: transparent;
}
.filter-panel-sheet {
    position: relative;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    background: var(--bg-color);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    overflow: hidden;
}
.filter-panel-overlay.is-open .filter-panel-sheet {
    transform: translateY(0);
}
.filter-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.filter-panel-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 10px;
}
.filter-panel-header h3 i { color: var(--theme-primary); }
.filter-panel-close {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    font-size: 28px;
    color: #666;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    -webkit-tap-highlight-color: transparent;
}
.filter-panel-close:hover { background: #f0f0f0; color: #333; }
body.dark-mode .filter-panel-close { color: #b0b0b0; }
body.dark-mode .filter-panel-close:hover { background: #2a2a2a; color: #fff; }

.filter-panel-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
}
.filter-panel-section {
    margin-bottom: 24px;
}
.filter-panel-section:last-child { margin-bottom: 0; }
.filter-panel-section-title {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
body.dark-mode .filter-panel-section-title { color: #b0b0b0; }

.filter-panel-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.filter-pill {
    padding: 10px 18px;
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    color: var(--text-color);
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}
.filter-pill:hover {
    border-color: var(--theme-primary);
    color: var(--theme-primary);
}
.filter-pill.active {
    background: var(--theme-primary);
    border-color: var(--theme-primary);
    color: white;
}
.filter-panel-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}
.filter-panel-apply {
    width: 100%;
    padding: 14px 20px;
    background: var(--theme-primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 48px;
    transition: background 0.2s;
}
.filter-panel-apply:hover { background: #5568d3; }

/* ==================== CLIENTI MOBILE: interfaccia semplificata ==================== */
.clienti-tag-filters-inline {
    margin-bottom: 15px;
    padding: 15px;
    background: var(--bg-color);
    border-radius: 8px;
    border: 2px solid var(--border-color);
}
.clienti-tag-filters-label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-weight: 600;
    color: var(--text-color);
    font-size: 14px;
}
.clienti-tag-filters-label i { color: var(--theme-primary); }
.clienti-tag-filters-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.clienti-search { margin-bottom: 12px; }

.btn-filtri-tag-mobile {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--theme-primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-filtri-tag-mobile i { font-size: 16px; }
.btn-filtri-tag-mobile:hover { background: #5568d3; }

/* Mobile: Filtri tag piccolo solo icona, affiancato ad Aggiorna */
@media (max-width: 768px) {
    #tab-content-clienti.active .clienti-tag-filters-inline {
        display: none !important;
    }
    #tab-content-clienti.active .btn-filtri-tag-mobile {
        display: inline-flex !important;
        width: auto !important;
        min-width: 40px;
        padding: 8px 10px !important;
    }
    #tab-content-clienti.active .btn-filtri-tag-mobile .btn-filtri-tag-text {
        display: none !important;
    }
    #tab-content-clienti.active .clienti-column-detail {
        display: none !important;
    }
    #tab-content-clienti.active .clienti-grid {
        display: block !important;
    }
    #tab-content-clienti.active .clienti-panel-list .panel-content {
        padding: 12px 16px;
    }
    #tab-content-clienti.active .clienti-panel-header {
        padding: 12px 16px;
        flex-wrap: wrap;
    }
    #tab-content-clienti.active .clienti-list {
        min-height: 280px;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: y proximity;
        scroll-padding: 12px 0;
    }
    #tab-content-clienti.active .clienti-list .prenotazione-card {
        scroll-snap-align: center;
        scroll-margin: 12px 0;
    }
}

body.device-mobile #tab-content-clienti.active .clienti-tag-filters-inline,
body.narrow-view #tab-content-clienti.active .clienti-tag-filters-inline {
    display: none !important;
}
body.device-mobile #tab-content-clienti.active .btn-filtri-tag-mobile,
body.narrow-view #tab-content-clienti.active .btn-filtri-tag-mobile {
    display: inline-flex !important;
    width: auto !important;
    min-width: 40px;
    padding: 8px 10px !important;
}
body.device-mobile #tab-content-clienti.active .btn-filtri-tag-mobile .btn-filtri-tag-text,
body.narrow-view #tab-content-clienti.active .btn-filtri-tag-mobile .btn-filtri-tag-text {
    display: none !important;
}
body.device-mobile #tab-content-clienti.active .clienti-column-detail,
body.narrow-view #tab-content-clienti.active .clienti-column-detail {
    display: none !important;
}

/* Overlay Dettaglio Cliente (mobile) */
.cliente-detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 10002;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}
.cliente-detail-overlay.is-open {
    pointer-events: auto;
    opacity: 1;
    visibility: visible;
}
.cliente-detail-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    -webkit-tap-highlight-color: transparent;
}
.cliente-detail-sheet {
    position: relative;
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    background: var(--bg-color);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    overflow: hidden;
}
.cliente-detail-overlay.is-open .cliente-detail-sheet {
    transform: translateY(0);
}
.cliente-detail-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    background: var(--panel-bg);
}
.cliente-detail-sheet-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 10px;
}
.cliente-detail-sheet-header h3 i { color: var(--theme-primary); }
.cliente-detail-sheet-body {
    padding: 16px 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
}
.filter-panel-sheet-tag .filter-panel-body {
    padding: 16px 20px;
}
.filter-panel-sheet-tag .filter-panel-pills {
    flex-direction: column;
    align-items: stretch;
}
.filter-panel-sheet-tag .filter-pill {
    justify-content: center;
}

body.device-mobile .tabs-container::-webkit-scrollbar,
body.narrow-view .tabs-container::-webkit-scrollbar {
    display: none;
}

body.device-mobile .tab-btn,
body.narrow-view .tab-btn {
    min-width: 64px;
    flex-shrink: 0;
}

/* Nascondi label tab su mobile per più spazio, solo icona */
body.device-mobile .tab-label,
body.narrow-view .tab-label {
    display: none;
}

body.device-mobile .tab-btn i,
body.narrow-view .tab-btn i {
    font-size: 1.25rem;
}

/* Link "Aggiungi prenotazione" su mobile: full width e touch-friendly */
body.device-mobile header a[href="/prenotazione-staff.html"],
body.narrow-view header a[href="/prenotazione-staff.html"] {
    min-height: var(--touch-target-min);
    justify-content: center;
    width: 100%;
}

body.device-mobile header > div:last-child,
body.narrow-view header > div:last-child {
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

/* Regole globali per prevenire overflow e migliorare allineamenti */
img, video, iframe, svg {
    max-width: 100%;
    height: auto;
}

/* Assicura che tutti i contenitori rispettino il box-sizing e non vadano fuori frame */
div, section, article, aside, main, header, footer, nav {
    box-sizing: border-box;
}

:root {
    --theme-primary: #667eea;
    --theme-secondary: #764ba2;
    --theme-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --bg-color: #ffffff;
    --text-color: #333;
    --panel-bg: #ffffff;
    --border-color: #e5e7eb;
    --shadow: rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--theme-gradient);
    min-height: 100vh;
    padding: clamp(8px, 1vw, 10px);
    color: var(--text-color);
    margin: 0;
    width: 100%;
    max-width: 100vw; /* Previene overflow oltre la viewport */
    overflow-x: hidden;
    box-sizing: border-box;
    transition: background 0.5s ease, color 0.3s ease;
}

/* Modalità Notturna - Migliorata con contrasto elevato */
body.dark-mode {
    --bg-color: #0f0f0f;
    --text-color: #f5f5f5;
    --panel-bg: #1e1e1e;
    --border-color: #3a3a3a;
    --shadow: rgba(0, 0, 0, 0.7);
    background: linear-gradient(135deg, #0f0f1a 0%, #0a0e1a 100%);
    transition: background 0.5s ease, color 0.3s ease;
}

/* Miglioramenti contrasto modalità notturna */
body.dark-mode .panel {
    background: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
}

body.dark-mode .stat-card {
    background: var(--panel-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode .stat-card:hover {
    background: #252525;
    border-color: var(--theme-primary);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

body.dark-mode .stat-value {
    color: var(--text-color);
}

body.dark-mode .stat-label {
    color: #b0b0b0;
}

body.dark-mode .stats-toggle {
    background: var(--theme-primary);
    color: white;
}

body.dark-mode .stats-toggle:hover {
    background: #5568d3;
}

body.dark-mode .prenotazione-card {
    background: var(--panel-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

body.dark-mode .prenotazione-card:hover {
    background: #2a2a2a;
    border-color: var(--theme-primary);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

body.dark-mode .cliente-card {
    background: var(--panel-bg);
    color: var(--text-color);
    border-color: var(--border-color);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

body.dark-mode .cliente-card:hover {
    background: #2a2a2a;
    border-color: var(--theme-primary);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

body.dark-mode header {
    background: var(--panel-bg);
    color: var(--text-color);
}

body.dark-mode .panel {
    background: var(--panel-bg);
    color: var(--text-color);
}

body.dark-mode .stat-card {
    background: var(--panel-bg);
    color: var(--text-color);
}

body.dark-mode .prenotazione-card {
    background: var(--panel-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

body.dark-mode .modal-content {
    background: var(--panel-bg);
    color: var(--text-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border-color);
}

body.dark-mode input,
body.dark-mode textarea,
body.dark-mode select {
    background: var(--panel-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

body.dark-mode .config-section {
    background: rgba(255, 255, 255, 0.02);
}

/* ========== Contrasto sempre leggibile: Tag Editor e Config (light + dark) ========== */
/* Light: card tag e input readonly con testo scuro su sfondo chiaro (evita grigio su grigio) */
.tag-editor-item input,
.tag-editor-item input[readonly],
.prenotazione-tag-editor-item input,
.prenotazione-tag-editor-item input[readonly] {
    color: #1a1a1a !important;
    background: #e8e8e8 !important;
    border-color: #999 !important;
}
#configEditorTag input[readonly] {
    color: #1a1a1a !important;
    background: #e8e8e8 !important;
    border-color: #999 !important;
}
.tag-editor-item label,
.prenotazione-tag-editor-item label,
#configEditorTag label {
    color: #374151 !important;
}

/* Dark mode: override stili inline su card e input Config/Tag */
body.dark-mode .tag-editor-item,
body.dark-mode .prenotazione-tag-editor-item {
    background: #252525 !important;
    border-color: #444 !important;
    color: var(--text-color) !important;
}
body.dark-mode .tag-editor-item input,
body.dark-mode .tag-editor-item input[readonly],
body.dark-mode .prenotazione-tag-editor-item input,
body.dark-mode .prenotazione-tag-editor-item input[readonly],
body.dark-mode #configEditorTag input,
body.dark-mode #configEditorTag input[readonly],
body.dark-mode .config-section input,
body.dark-mode .config-section textarea,
body.dark-mode .config-section select {
    background: #1a1a1a !important;
    color: #e5e5e5 !important;
    border-color: #444 !important;
}
body.dark-mode .tag-editor-item label,
body.dark-mode .prenotazione-tag-editor-item label,
body.dark-mode #configEditorTag label,
body.dark-mode .config-section label {
    color: #c0c0c0 !important;
}
body.dark-mode .config-section-title {
    color: var(--text-color) !important;
}
body.dark-mode .config-help {
    color: #b0b0b0 !important;
}
body.dark-mode .config-section p {
    color: #b0b0b0 !important;
}
body.dark-mode .config-section code {
    background: #333 !important;
    color: #e5e5e5 !important;
    border-color: #555 !important;
}
/* Modal in dark mode: input sempre leggibili */
body.dark-mode .modal input,
body.dark-mode .modal textarea,
body.dark-mode .modal select {
    background: #1a1a1a !important;
    color: #e5e5e5 !important;
    border-color: #444 !important;
}
body.dark-mode .modal label {
    color: #c0c0c0 !important;
}
body.dark-mode .modal-close {
    color: #c0c0c0 !important;
}
body.dark-mode .modal-close:hover {
    background: #2a2a2a !important;
    color: #fff !important;
}

/* Override stili inline comuni in dark mode (contrasto ovunque) */
body.dark-mode [style*="background: #f9fafb"],
body.dark-mode [style*="background:#f9fafb"],
body.dark-mode [style*="background: #f8f9fa"],
body.dark-mode [style*="background:#f8f9fa"] {
    background: #252525 !important;
    color: #e5e5e5 !important;
    border-color: #444 !important;
}
body.dark-mode [style*="background: #ffffff"],
body.dark-mode [style*="background:#ffffff"],
body.dark-mode [style*="background: white"] {
    background: #1a1a1a !important;
    color: #e5e5e5 !important;
    border-color: #444 !important;
}
body.dark-mode [style*="color: #333"],
body.dark-mode [style*="color:#333"] {
    color: #e5e5e5 !important;
}
body.dark-mode [style*="color: #666"],
body.dark-mode [style*="color:#666"] {
    color: #b0b0b0 !important;
}
body.dark-mode [style*="color: #999"],
body.dark-mode [style*="color:#999"] {
    color: #a0a0a0 !important;
}
body.dark-mode [style*="background: #f0f0f0"],
body.dark-mode [style*="background:#f0f0f0"] {
    background: #2a2a2a !important;
    color: #e5e5e5 !important;
    border-color: #444 !important;
}
body.dark-mode [style*="background: #fff3cd"],
body.dark-mode [style*="background:#fff3cd"] {
    background: #78350f !important;
    color: #fcd34d !important;
    border-color: #b45309 !important;
}
body.dark-mode [style*="background: #e0f2fe"],
body.dark-mode [style*="background:#e0f2fe"] {
    background: #0c4a6e !important;
    color: #7dd3fc !important;
    border-color: #0369a1 !important;
}
body.dark-mode [style*="background: #fef3c7"],
body.dark-mode [style*="background:#fef3c7"] {
    background: #78350f !important;
    color: #fde68a !important;
    border-color: #b45309 !important;
}
body.dark-mode [style*="background: #d1fae5"],
body.dark-mode [style*="background:#d1fae5"] {
    background: #064e3b !important;
    color: #6ee7b7 !important;
}
body.dark-mode [style*="background: #fee2e2"],
body.dark-mode [style*="background:#fee2e2"] {
    background: #7f1d1d !important;
    color: #fecaca !important;
}
body.dark-mode [style*="color: #856404"],
body.dark-mode [style*="color:#856404"] {
    color: #fcd34d !important;
}
body.dark-mode pre[style*="background: #f8f9fa"],
body.dark-mode pre[style*="background:#f8f9fa"] {
    background: #1a1a1a !important;
    color: #e5e5e5 !important;
    border-color: #444 !important;
}
body.dark-mode code[style*="background: #fff"],
body.dark-mode code[style*="background:#fff"] {
    background: #333 !important;
    color: #e5e5e5 !important;
}

/* Contenuti modal dettaglio prenotazione e scheda cliente */
body.dark-mode #detailPrenotazioneContent div[style*="background"],
body.dark-mode #clienteDetailContent div[style*="background"] {
    border-color: #444 !important;
}
body.dark-mode .prenotazione-storico-item {
    background: var(--panel-bg) !important;
    color: var(--text-color) !important;
    border-color: var(--border-color) !important;
}
body.dark-mode .empty-state {
    color: #b0b0b0 !important;
}

/* Agenda in dark mode */
body.dark-mode .agenda-row {
    background: var(--panel-bg) !important;
    color: var(--text-color) !important;
    border-color: var(--border-color) !important;
}
body.dark-mode .agenda-row:hover {
    background: #2a2a2a !important;
}
body.dark-mode .agenda-row-header {
    background: #252525 !important;
    color: #b0b0b0 !important;
    border-bottom-color: var(--border-color) !important;
}
body.dark-mode .agenda-tavolo-select,
body.dark-mode .agenda-coperti,
body.dark-mode .agenda-note,
body.dark-mode .agenda-cognome {
    color: var(--text-color) !important;
}
body.dark-mode .agenda-row-arrivato {
    background: rgba(16, 185, 129, 0.2) !important;
    border-left-color: #10b981 !important;
}
body.dark-mode .agenda-stato-attesa { background: #78350f !important; color: #fcd34d !important; }
body.dark-mode .agenda-stato-avvisato { background: #1e3a8a !important; color: #93c5fd !important; }
body.dark-mode .agenda-stato-confermato { background: #064e3b !important; color: #6ee7b7 !important; }
body.dark-mode .agenda-stato-rifiutato { background: #7f1d1d !important; color: #fecaca !important; }
body.dark-mode .agenda-row-coda { background: #78350f !important; border-left-color: #f59e0b !important; }
body.dark-mode .agenda-row-coda-avvisato { background: #1e3a8a !important; border-left-color: #3b82f6 !important; }
body.dark-mode .agenda-row-coda-confermata { background: #064e3b !important; border-left-color: #10b981 !important; }
body.dark-mode .agenda-row-coda-annullata { background: #7f1d1d !important; border-left-color: #ef4444 !important; }
body.dark-mode .agenda-row-coda-timeout { background: #78350f !important; border-left-color: #f59e0b !important; }
body.dark-mode .agenda-stato-timeout { background: #78350f !important; color: #fcd34d !important; }

/* Form modifica prenotazione e modali */
body.dark-mode .edit-field-group label {
    color: #c0c0c0 !important;
}
body.dark-mode .edit-field-group input[type="text"],
body.dark-mode .edit-field-group input[type="date"],
body.dark-mode .edit-field-group input[type="time"],
body.dark-mode .edit-field-group input[type="number"],
body.dark-mode .edit-field-group textarea {
    background: #1a1a1a !important;
    color: #e5e5e5 !important;
    border-color: #444 !important;
}

/* Tab e hint configurazione */
body.dark-mode .config-tab-btn {
    color: var(--text-color) !important;
}
body.dark-mode .config-tab-btn:hover {
    color: var(--theme-primary) !important;
    background: rgba(102, 126, 234, 0.15) !important;
}
body.dark-mode .config-tab-btn.active {
    color: var(--theme-primary) !important;
}
body.dark-mode .config-password-hint {
    color: #b0b0b0 !important;
}

/* Pulsanti secondari e annulla */
body.dark-mode button[style*="background: #ccc"],
body.dark-mode button[style*="background:#ccc"] {
    background: #444 !important;
    color: #e5e5e5 !important;
    border-color: #555 !important;
}
body.dark-mode .btn-secondary {
    background: #444 !important;
    color: #e5e5e5 !important;
    border-color: #555 !important;
}
body.dark-mode .btn-secondary:hover {
    background: #555 !important;
    color: #fff !important;
}

/* Testo generico in container e panel */
body.dark-mode .container,
body.dark-mode .panel-content {
    color: var(--text-color);
}
body.dark-mode .config-info {
    color: #93c5fd !important;
    background: rgba(102, 126, 234, 0.2) !important;
    border-left-color: var(--theme-primary) !important;
}
body.dark-mode .config-readonly-notice {
    color: #b0b0b0 !important;
}
body.dark-mode small {
    color: #b0b0b0 !important;
}

body.dark-mode .theme-card {
    background: var(--panel-bg) !important;
    border-color: var(--border-color) !important;
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10000;
    min-width: 300px;
    max-width: 500px;
    opacity: 0;
    transform: translateX(400px);
    transition: all 0.3s ease;
}

body.dark-mode .toast {
    background: var(--panel-bg);
    color: var(--text-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.toast.show {
    opacity: 1;
    transform: translateX(0);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    font-weight: 500;
}

.toast-success {
    border-left: 4px solid #10b981;
}

.toast-success .toast-content i {
    color: #10b981;
}

.toast-error {
    border-left: 4px solid #ef4444;
}

.toast-error .toast-content i {
    color: #ef4444;
}

.toast-info {
    border-left: 4px solid #667eea;
}

.toast-info .toast-content i {
    color: #667eea;
}

/* Standalone: riduci bounce scroll su iOS e usa tutta l’area utile */
body.standalone {
    min-height: 100vh;
    min-height: -webkit-fill-available;
    overflow-x: hidden;
}

body.standalone .container {
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* Modal in standalone: rispetta safe area */
body.standalone .modal-content {
    margin-top: var(--safe-area-top);
    margin-bottom: var(--safe-area-bottom);
    max-height: calc(100vh - var(--safe-area-top) - var(--safe-area-bottom) - 20px);
}

/* Pannelli scrollabili su mobile/tablet: altezza utile senza coprire tab bar */
body.device-mobile #tab-content-dashboard.active .panel-content,
body.narrow-view #tab-content-dashboard.active .panel-content {
    -webkit-overflow-scrolling: touch;
    max-height: calc(100vh - 280px);
}

body.device-mobile .prenotazioni-list,
body.narrow-view .prenotazioni-list {
    -webkit-overflow-scrolling: touch;
}

/* Mobile: pannello Prenotazioni più alto e scroll fluido della lista */
@media (max-width: 768px) {
    #tab-content-dashboard.active .dashboard-top-left {
        display: flex;
        flex-direction: column;
        min-height: min(65vh, 500px);
        max-height: 75vh !important;
    }
    #tab-content-dashboard.active .dashboard-top-left .panel-content {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        max-height: none;
    }
    #tab-content-dashboard.active .dashboard-top-left .prenotazioni-list {
        min-height: 200px;
        max-height: none;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
}

body.device-mobile #tab-content-dashboard.active .dashboard-top-left,
body.narrow-view #tab-content-dashboard.active .dashboard-top-left {
    display: flex;
    flex-direction: column;
    min-height: min(65vh, 500px);
    max-height: 75vh !important; /* più spazio per scroll prenotazioni su mobile */
}
body.device-mobile #tab-content-dashboard.active .dashboard-top-left .panel-content,
body.narrow-view #tab-content-dashboard.active .dashboard-top-left .panel-content {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
body.device-mobile #tab-content-dashboard.active .dashboard-top-left .prenotazioni-list,
body.narrow-view #tab-content-dashboard.active .dashboard-top-left .prenotazioni-list {
    min-height: 200px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 8px;
        overflow-x: hidden;
    }
    
    .container {
        padding: 0;
        min-height: 100vh;
    }
    
    header,
    .main-header {
        padding: 10px 12px 12px !important;
        display: grid !important;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        gap: 8px 12px;
        align-items: center;
        margin-bottom: 12px;
        border-radius: 10px;
    }
    
    .main-header {
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
    }
    .main-header .header-brand { grid-column: 1; grid-row: 1; min-width: 0; }
    .main-header .header-status {
        grid-column: 2; grid-row: 1;
        justify-self: end;
        font-size: 13px;
        margin-left: 0 !important;
    }
    .main-header .header-actions {
        grid-column: 1 / -1;
        grid-row: 2;
        flex-wrap: nowrap;
        gap: 6px;
        justify-content: flex-start;
    }
    .main-header .header-title-full { display: none !important; }
    .main-header .header-title-short { display: inline !important; }
    .main-header .header-add-label { display: none !important; }
    .main-header .header-add-short { display: inline !important; }
    .main-header .header-btn {
        padding: 6px 10px !important;
        font-size: 12px !important;
        display: inline-flex !important;
        width: auto !important;
        max-width: fit-content !important;
    }
    .main-header .header-actions .header-btn-add {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: 140px !important;
    }
    .main-header .header-actions button.header-btn-dark {
        flex: 0 0 auto !important;
        width: auto !important;
        max-width: 100px !important;
    }
    
    header h1,
    .main-header .header-title {
        font-size: clamp(17px, 4.5vw, 20px) !important;
    }
    
    .stats-grid {
        grid-template-columns: repeat(8, minmax(100px, 1fr)); /* Una riga con scroll orizzontale */
        gap: clamp(6px, 1.5vw, 10px);
        margin-top: 40px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .stats-toggle {
        top: -35px;
        font-size: clamp(10px, 2.5vw, 12px);
        padding: clamp(5px, 1.2vw, 8px) clamp(8px, 2vw, 12px);
    }
    
    .stat-card {
        padding: clamp(8px, 1.5vw, 12px) clamp(10px, 2vw, 15px);
        min-height: clamp(50px, 8vh, 65px);
        min-width: 100px;
        flex-shrink: 0;
    }
    
    .stat-icon {
        width: clamp(32px, 5vw, 40px);
        height: clamp(32px, 5vw, 40px);
        font-size: clamp(14px, 2vw, 18px);
    }
    
    .stat-value {
        font-size: clamp(16px, 2.5vw, 22px);
    }
    
    .stat-label {
        font-size: clamp(9px, 1.5vw, 11px);
    }
    
    .main-content,
    .tab-content {
        grid-template-columns: 1fr;
        gap: 12px;
        display: flex;
        flex-direction: column;
    }
    
    .tab-content.active {
        display: flex !important;
        flex-direction: column;
        gap: 12px;
        min-height: auto;
    }
    
    .panel-full-width {
        grid-column: 1;
        width: 100%;
    }
    
    .tab-content > .panel {
        max-height: none;
        margin-bottom: 12px;
    }
    
    .panel {
        border-radius: 10px;
        overflow: hidden;
    }
    
    .tab-btn {
        min-width: 120px;
        padding: 15px 20px;
        font-size: 14px;
    }
    
    .tab-label {
        display: none;
    }
    
    .tab-btn i {
        font-size: 20px;
    }
    
    .panel-header {
        padding: 15px;
        flex-wrap: wrap;
        gap: 10px;
    }
    
    .panel-header h2 {
        font-size: 18px;
    }
    
    .prenotazione-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .prenotazione-info {
        grid-template-columns: 1fr;
    }
    
    .filters {
        flex-wrap: wrap;
    }
    
    .filter-btn {
        flex: 1;
        min-width: 80px;
    }
}

.container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    min-height: calc(100vh - 20px);
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Previene scroll orizzontale */
    box-sizing: border-box;
    position: relative;
}

@media (min-width: 769px) {
    .container {
        padding: clamp(10px, 1.5vw, 15px) clamp(15px, 2vw, 20px);
        max-width: 100%;
        width: 100%;
        box-sizing: border-box; /* Il padding è incluso nella larghezza */
    }
}

header {
    background: var(--bg-color);
    padding: clamp(15px, 2vw, 20px) clamp(20px, 2.5vw, 30px);
    border-radius: clamp(10px, 1.5vw, 12px);
    box-shadow: 0 4px 6px var(--shadow);
    margin-bottom: clamp(15px, 2vw, 20px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.3s ease, box-shadow 0.3s ease;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    flex-wrap: wrap;
    gap: clamp(10px, 1.5vw, 15px);
    overflow: hidden; /* Previene overflow del contenuto */
    min-width: 0; /* Permette al flex di ridurre la dimensione */
    position: relative;
    z-index: 100; /* Assicura che l'header sia sopra altri elementi */
}

/* ==================== FIX SAFARI COMPLETI ==================== */
/* Fix Safari: previene sovrapposizione della barra tab con il contenuto */
@supports (-webkit-appearance: none) {
    /* Rimuovi sticky su Safari per evitare sovrapposizioni */
    header {
        position: relative !important;
        z-index: 100;
        -webkit-transform: translateZ(0); /* Force hardware acceleration */
        transform: translateZ(0);
    }
    
    .tabs-container {
        position: relative !important;
        z-index: 10;
        margin-bottom: clamp(15px, 2vw, 20px);
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Assicura che il contenuto non venga coperto su Safari */
    .tab-content.active {
        position: relative;
        z-index: 1;
        margin-top: 0;
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
    }
    
    /* Fix specifico per sezione clienti su Safari - rimuovi padding extra */
    #tab-content-clienti.active {
        padding-top: 0 !important;
        margin-top: 0;
    }
    
    #tab-content-clienti.active .main-content-grid {
        margin-top: 0;
        padding-top: clamp(10px, 1.5vw, 20px);
    }
    
    /* Assicura che il contenuto clienti non venga coperto dalla barra tab su Safari */
    @media (min-width: 769px) {
        #tab-content-clienti.active {
            height: calc(100vh - clamp(100px, 15vh, 140px)) !important;
        }
    }
    
    /* Fix per gap in flexbox/grid su Safari < 14.1 */
    .stats-grid {
        -webkit-box-pack: start;
        -ms-flex-pack: start;
        justify-content: flex-start;
    }
    
    .stats-grid .stat-card:not(:last-child) {
        margin-right: clamp(8px, 1vw, 12px);
    }
    
    /* Fix per backdrop-filter su Safari */
    .modal {
        -webkit-backdrop-filter: blur(4px);
        backdrop-filter: blur(4px);
    }
    
    /* Fix per transform e transition su Safari */
    .stat-card,
    .prenotazione-card,
    .panel {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Fix per overflow su Safari */
    .container,
    .tab-content,
    .panel-content {
        -webkit-overflow-scrolling: touch;
        overflow-scrolling: touch;
    }
    
    /* Fix per grid con minmax su Safari */
    @media (min-width: 769px) {
        .tab-content.active {
            display: -webkit-grid;
            display: grid;
            -webkit-grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
            grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        }
        
        #tab-content-dashboard.active {
            display: -webkit-grid !important;
            display: grid !important;
            -webkit-grid-template-columns: minmax(0, 60%) minmax(0, 40%);
            grid-template-columns: minmax(0, 60%) minmax(0, 40%);
        }
    }
    
    /* Fix per flexbox gap su Safari < 14.1 */
    header > div,
    .panel-header,
    .status-indicator {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
    }
    
    header > div > *:not(:last-child),
    .panel-header > *:not(:last-child),
    .status-indicator > *:not(:last-child) {
        margin-right: 15px;
    }
    
    /* Fix per clamp() con fallback su Safari < 13.1 */
    body {
        padding: 10px;
    }
    
    @media (min-width: 769px) {
        body {
            padding: clamp(8px, 1vw, 10px);
        }
    }
    
    /* Fix per position sticky su Safari */
    .config-tabs-nav {
        position: -webkit-sticky;
        position: sticky;
        top: 0;
    }
    
    /* Fix per box-shadow su Safari */
    .panel,
    .stat-card,
    header {
        -webkit-box-shadow: 0 4px 6px var(--shadow);
        box-shadow: 0 4px 6px var(--shadow);
    }
    
    /* Fix per border-radius su Safari */
    .panel,
    .stat-card,
    .tab-btn {
        -webkit-border-radius: clamp(10px, 1.5vw, 12px);
        border-radius: clamp(10px, 1.5vw, 12px);
    }
    
    /* Fix per text rendering su Safari */
    body,
    h1, h2, h3,
    .stat-value,
    .stat-label {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        text-rendering: optimizeLegibility;
    }
    
    /* Fix per scrollbar su Safari */
    .panel-content::-webkit-scrollbar,
    .prenotazioni-list::-webkit-scrollbar {
        -webkit-appearance: none;
        width: 10px;
    }
    
    /* Fix per input e textarea su Safari */
    input,
    textarea,
    select {
        -webkit-appearance: none;
        -webkit-border-radius: clamp(6px, 1vw, 10px);
        border-radius: clamp(6px, 1vw, 10px);
    }
    
    /* Fix per button su Safari */
    button {
        -webkit-appearance: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Fix per immagini su Safari */
    img {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
    
    /* Fix per animazioni su Safari */
    @keyframes pulse {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.5; }
    }
    
    @-webkit-keyframes pulse {
        0%, 100% { opacity: 1; }
        50% { opacity: 0.5; }
    }
    
    /* Fix per gradient su Safari */
    body {
        background: -webkit-linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    }
    
    body.dark-mode {
        background: -webkit-linear-gradient(135deg, #0f0f1a 0%, #0a0e1a 100%);
        background: linear-gradient(135deg, #0f0f1a 0%, #0a0e1a 100%);
    }
    
    /* Fix per stats-grid su Safari - usa flexbox invece di grid */
    .stats-grid {
        display: -webkit-box;
        display: -ms-flexbox;
        display: flex;
        -webkit-box-orient: horizontal;
        -webkit-box-direction: normal;
        -ms-flex-direction: row;
        flex-direction: row;
        -ms-flex-wrap: nowrap;
        flex-wrap: nowrap;
    }
    
    .stats-grid .stat-card {
        -webkit-box-flex: 1;
        -ms-flex: 1 1 0;
        flex: 1 1 0;
        min-width: 140px;
        -ms-flex-negative: 0;
        flex-shrink: 0;
    }
    
    /* Fix per main-content-grid su Safari */
    .main-content-grid {
        display: -webkit-grid;
        display: grid;
        -webkit-grid-template-columns: minmax(0, 1fr) minmax(0, 1.8fr);
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.8fr);
    }
    
    /* Fix per statistiche-grid su Safari */
    .statistiche-grid {
        display: -webkit-grid;
        display: grid;
        -webkit-grid-template-columns: repeat(2, 1fr);
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Fix per agenda-content-grid su Safari */
    .agenda-content-grid {
        display: -webkit-grid;
        display: grid;
        -webkit-grid-template-columns: 1fr 1fr;
        grid-template-columns: 1fr 1fr;
    }
    
    /* Fix per prenotazione-info su Safari */
    .prenotazione-info {
        display: -webkit-grid;
        display: grid;
        -webkit-grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    
    /* Fix per z-index e stacking context su Safari (will-change non rompe position:fixed) */
    .modal {
        will-change: opacity;
    }
    
    .toast {
        -webkit-transform: translateX(400px) translateZ(0);
        transform: translateX(400px) translateZ(0);
    }
    
    .toast.show {
        -webkit-transform: translateX(0) translateZ(0);
        transform: translateX(0) translateZ(0);
    }
}

header h1 {
    color: var(--theme-primary);
    font-size: 28px;
    transition: color 0.3s ease;
}

header h1 i {
    margin-right: 10px;
}

/* Header snellito: struttura e azioni */
.main-header .header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}
.main-header .header-logo {
    max-height: 50px;
    max-width: 150px;
    display: none;
    object-fit: contain;
}
.main-header .header-logo[src]:not([src=""]) {
    display: block;
}
.main-header .header-title {
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.main-header .header-title-short {
    display: none;
}
.main-header .header-status {
    margin-left: auto; /* titolo a sinistra, status+azioni a destra su desktop */
}
.main-header .header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    flex-wrap: nowrap; /* Aggiungi prenotazione e Modalità notte sempre sulla stessa riga */
}
/* Desktop: status e azioni sulla stessa riga a destra */
.main-header .header-status {
    margin-left: auto;
}
.main-header .header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
    font-size: 14px;
}
.main-header .header-btn {
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.2s, transform 0.15s;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.main-header .header-btn-add {
    background: #667eea;
    color: white;
}
.main-header .header-btn-add:hover {
    background: #5568d3;
}
.main-header .header-btn-dark {
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
}
.main-header .header-btn-dark:hover {
    background: rgba(255,255,255,0.3);
}
body.dark-mode .main-header .header-btn-dark {
    background: #f59e0b;
    border-color: #f59e0b;
}
.main-header .header-btn-notify.notify-on {
    background: #10b981;
    border-color: #10b981;
    color: #fff;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.35);
}
.main-header .header-btn-notify.notify-off {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
}
.main-header .header-btn-notify.notify-on i {
    animation: notify-pulse 1.5s ease-in-out infinite;
}
@keyframes notify-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.12); }
}
.ios-pwa-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100001;
    background: linear-gradient(135deg, #1e3a8a 0%, #3730a3 100%);
    color: #fff;
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0));
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    font-size: 0.85rem;
}
.ios-pwa-banner p {
    margin: 8px 0;
    line-height: 1.45;
    opacity: 0.95;
}
.ios-pwa-banner-dismiss {
    margin-top: 8px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
}
.staff-alert-banner {
    display: none;
    position: fixed;
    top: env(safe-area-inset-top, 0);
    left: 0;
    right: 0;
    z-index: 100000;
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0));
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: #fff;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
    animation: staff-banner-in 0.35s ease-out;
}
.staff-alert-banner.visible {
    display: block;
}
.staff-alert-banner-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 6px 10px;
    max-width: 100%;
}
.staff-alert-title {
    flex: 1 1 100%;
    font-size: 1rem;
}
.staff-alert-body {
    flex: 1 1 auto;
    font-size: 0.9rem;
    opacity: 0.95;
}
.staff-alert-close {
    flex: 0 0 auto;
    border: none;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
}
@keyframes staff-banner-in {
    from { transform: translateY(-100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.main-header .header-add-short {
    display: none;
}

/* Header: pulsanti Aggiungi e Notte piccoli su mobile, mai a tutto schermo */
@media (max-width: 768px) {
    .main-header .header-actions a.header-btn-add,
    .main-header .header-actions button.header-btn-dark {
        flex: 0 0 auto !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: 140px !important;
    }
}
@media (max-width: 420px) {
    .main-header .header-add-label,
    .main-header .header-add-short {
        display: none !important;
    }
    .main-header .header-btn-add {
        padding: 6px 10px !important;
        min-width: 40px;
        max-width: 48px !important;
    }
}
body.device-mobile .main-header .header-add-short,
body.narrow-view .main-header .header-add-short {
    display: inline !important;
}
@media (max-width: 420px) {
    body.device-mobile .main-header .header-add-short,
    body.narrow-view .main-header .header-add-short {
        display: none !important;
    }
}

.status-indicator,
.main-header .header-status {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
}

/* Bottone Dark Mode con contrasto */
#darkModeToggle {
    padding: clamp(6px, 1vw, 8px) clamp(12px, 1.5vw, 16px) !important;
    background: var(--theme-primary) !important;
    border: 2px solid var(--theme-primary) !important;
    border-radius: clamp(6px, 0.8vw, 8px) !important;
    color: white !important;
    cursor: pointer !important;
    font-size: clamp(13px, 1.6vw, 14px) !important;
    font-weight: 600 !important;
    transition: all 0.2s ease !important;
    display: flex !important;
    align-items: center !important;
    gap: clamp(6px, 0.8vw, 8px) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
}

#darkModeToggle:hover {
    background: #5568d3 !important;
    border-color: #5568d3 !important;
    transform: translateY(-1px) !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15) !important;
}

#darkModeToggle:active {
    transform: translateY(0) !important;
}

body.dark-mode #darkModeToggle {
    background: #f59e0b !important;
    border-color: #f59e0b !important;
    color: white !important;
}

body.dark-mode #darkModeToggle:hover {
    background: #d97706 !important;
    border-color: #d97706 !important;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
    animation: pulse 2s infinite;
}

.status-dot.ready {
    background: #10b981;
    animation: none;
}

.status-dot.error {
    background: #ef4444;
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Wrapper per stats con pulsante sempre visibile */
.stats-wrapper {
    position: relative !important;
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: clamp(12px, 1.8vw, 20px);
    padding-top: clamp(40px, 5vh, 50px) !important; /* Spazio per il bottone sempre visibile */
    overflow: visible !important;
    min-height: clamp(40px, 5vh, 50px) !important; /* Altezza minima solo per il bottone quando collassato */
    box-sizing: border-box !important;
    z-index: 1; /* Assicura che il wrapper sia sopra altri elementi */
    transition: margin-bottom 0.3s ease;
}

/* Quando il grid è collassato, riduci il margin-bottom del wrapper */
.stats-wrapper:has(.stats-grid.collapsed) {
    margin-bottom: clamp(8px, 1.2vw, 12px) !important;
}

/* Rimuovi duplicazione - questa regola è già sopra */

.stats-grid {
    display: flex; /* Usa flexbox invece di grid per Safari */
    flex-wrap: nowrap; /* Mantiene tutto in una riga */
    gap: clamp(8px, 1vw, 12px);
    position: relative;
    transition: max-height 0.3s ease;
    width: 100%;
    overflow-x: auto; /* Permette scroll orizzontale su schermi piccoli */
    -webkit-overflow-scrolling: touch; /* Scroll fluido su iOS Safari */
}

/* Controllo Safari - prevenzione sovrapposizioni */
@supports (-webkit-appearance: none) {
    @media (min-width: 769px) and not (max-width: 768px) {
        /* Safari desktop - usa flexbox per prevenire sovrapposizioni */
        .stats-grid {
            display: flex;
            flex-wrap: nowrap;
            gap: clamp(10px, 1.2vw, 15px);
            overflow-x: auto;
            -webkit-overflow-scrolling: touch;
        }
        
        .stats-grid .stat-card {
            flex: 1 1 0;
            min-width: 140px;
            flex-shrink: 0;
            box-sizing: border-box;
        }
    }
}

@media (min-width: 769px) {
    .stats-grid {
        display: flex;
        flex-wrap: nowrap;
        gap: clamp(10px, 1.2vw, 15px);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .stats-grid .stat-card {
        flex: 1 1 0;
        min-width: 140px;
        flex-shrink: 0;
    }
}

/* Toggle per collassare le statistiche - sempre visibile, fuori dal grid */
.stats-toggle {
    position: absolute !important;
    top: clamp(5px, 1vh, 10px) !important;
    right: clamp(10px, 1.5vw, 20px) !important;
    background: #667eea !important;
    color: white !important;
    border: none !important;
    border-radius: clamp(6px, 0.8vw, 8px) !important;
    padding: clamp(6px, 1vw, 8px) clamp(10px, 1.5vw, 14px) !important;
    cursor: pointer !important;
    font-size: clamp(11px, 1.5vw, 13px) !important;
    font-weight: bold !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: clamp(4px, 0.8vw, 6px) !important;
    transition: all 0.2s ease !important;
    z-index: 10000 !important; /* Z-index molto alto per essere sempre sopra */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    white-space: nowrap !important;
    min-width: fit-content !important;
    max-width: none !important; /* Permette al bottone di essere più largo se necessario */
    overflow: visible !important;
}

.stats-toggle:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.stats-toggle:active {
    transform: translateY(0);
}

.stats-grid.collapsed {
    max-height: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
    transition: max-height 0.3s ease, height 0.3s ease;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Assicura che il pulsante sia sempre visibile anche su schermi piccoli */
@media (max-width: 768px) {
    .stats-toggle {
        top: clamp(5px, 1vh, 10px) !important;
        right: clamp(5px, 1vw, 10px) !important;
        font-size: clamp(10px, 1.2vw, 12px) !important;
        padding: clamp(5px, 0.8vw, 6px) clamp(8px, 1.2vw, 10px) !important;
        z-index: 10000 !important;
        position: absolute !important;
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    .stats-wrapper {
        padding-top: clamp(35px, 4vh, 45px) !important;
    }
}

/* Regole globali per prevenire overflow - escludi il bottone stats-toggle */
img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* Assicura che tutti i contenitori rispettino il box-sizing */
div, section, article, aside, main, header, footer {
    box-sizing: border-box;
}

/* Escludi il bottone stats-toggle dalla regola max-width globale */
.stats-toggle {
    max-width: none !important;
}

.stats-grid.collapsed .stat-card {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    transform: scale(0) !important;
}

.stats-grid.expanded {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    transition: max-height 0.3s ease, height 0.3s ease, opacity 0.3s ease, visibility 0.3s ease;
    opacity: 1 !important;
    visibility: visible !important;
}

.stats-grid.expanded .stat-card {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.3s ease;
}

.stat-card {
    background: var(--bg-color);
    padding: clamp(10px, 1.2vw, 15px) clamp(12px, 1.5vw, 18px);
    border-radius: clamp(8px, 1vw, 12px);
    box-shadow: 0 2px 4px var(--shadow);
    display: flex;
    align-items: center;
    gap: clamp(8px, 1vw, 12px);
    transition: transform 0.2s, background 0.3s ease;
    color: var(--text-color);
    cursor: pointer;
    min-height: clamp(55px, 6vh, 70px);
    flex: 1 1 0; /* Ogni card prende spazio equo */
    min-width: 140px; /* Larghezza minima fissa per evitare sovrapposizioni */
    max-width: none; /* Permette alle cards di espandersi */
    box-sizing: border-box; /* Include padding e border nella larghezza */
    flex-shrink: 0; /* Previene contrazione eccessiva su Safari */
    overflow: hidden; /* Nasconde contenuto che fuoriesce */
}

.stat-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px var(--shadow);
}

.stat-card.warning .stat-icon {
    background: #f59e0b;
}

.stat-card.danger .stat-icon {
    background: #ef4444;
}

.stat-card.success .stat-icon {
    background: #10b981;
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    flex-shrink: 0;
}

.stat-info {
    flex: 1;
    min-width: 0;
}

.stat-value {
    font-size: 22px;
    font-weight: bold;
    color: #333;
    line-height: 1.2;
}

.stat-label {
    font-size: 11px;
    color: #666;
    margin-top: 2px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

body.dark-mode .stat-value {
    color: var(--text-color);
}

body.dark-mode .stat-label {
    color: #b0b0b0;
}

/* Tab Navigation */
.tabs-container {
    background: white;
    border-radius: clamp(10px, 1.5vw, 12px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    margin-bottom: clamp(15px, 2vw, 20px);
    padding: 0;
    display: flex;
    gap: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    position: relative;
    z-index: 10; /* Assicura che la barra sia sopra altri elementi */
}

body.dark-mode .tabs-container {
    background: var(--panel-bg);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

/* Fix Safari: regole unificate per evitare sovrapposizioni - già definite sopra nell'header */

.tabs-container::-webkit-scrollbar {
    height: 4px;
}

.tabs-container::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 2px;
}

.tab-btn {
    flex: 1;
    min-width: 150px;
    padding: 18px 24px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    color: #666;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    white-space: nowrap;
}

body.dark-mode .tab-btn {
    color: #c0c0c0;
}

.tab-btn:hover {
    background: #f9fafb;
    color: #667eea;
}

.tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
    background: #f9fafb;
}

body.dark-mode .tab-btn {
    color: var(--text-color);
    background: transparent;
}

body.dark-mode .tab-btn:hover {
    background: #2a2a2a;
    color: var(--theme-primary);
}

body.dark-mode .tab-btn.active {
    color: var(--theme-primary);
    border-bottom-color: var(--theme-primary);
    background: #2a2a2a;
    font-weight: 700;
}

.tab-btn i {
    font-size: 18px;
}

.tab-label {
    display: inline-block;
}

.tab-content {
    display: none;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* Previene overflow orizzontale */
    box-sizing: border-box;
}

/* Desktop: layout dinamico e ottimizzato */
@media (min-width: 769px) {
    .tab-content.active {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); /* minmax(0, ...) previene overflow */
        gap: clamp(15px, 2vw, 20px);
        align-items: start;
        min-height: calc(100vh - 200px);
        flex: 1;
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        overflow-y: auto; /* Permette scroll verticale se necessario */
        box-sizing: border-box;
        /* Assicura che il contenuto non vada oltre la viewport */
        contain: layout style;
    }
    
    /* Dashboard: layout dinamico e full-screen (allungato su PC) */
    #tab-content-dashboard.active {
        display: grid !important;
        grid-template-columns: minmax(0, 60%) minmax(0, 40%); /* minmax(0, ...) previene overflow */
        grid-template-rows: auto auto auto; /* Prima riga: Stats, Seconda riga: Prenotazioni + Conversazioni, Terza riga: Log Messaggi + Log Sistema */
        gap: clamp(15px, 2.5vw, 25px);
        height: calc(100vh - 90px);
        min-height: 680px;
        overflow: hidden;
        overflow-y: auto; /* Permette scroll verticale se necessario */
        align-content: start;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
        /* Assicura che il contenuto non vada oltre la viewport */
        contain: layout style;
    }
    
    /* Stats grid full width - prima riga (subito sotto la barra delle tab) */
    #tab-content-dashboard.active .stats-grid.panel-full-width,
    #tab-content-dashboard.active .stats-wrapper {
        grid-column: 1 / -1;
        grid-row: 1; /* Prima riga (subito sotto la barra delle tab) */
        width: 100%;
    }
    
    /* Seconda riga: Prenotazioni 60% e Conversazioni 40% (più alte su PC) */
    #tab-content-dashboard.active .dashboard-top-left {
        grid-column: 1;
        grid-row: 2;
        height: 68vh;
        max-height: 68vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    #tab-content-dashboard.active .dashboard-top-right {
        grid-column: 2;
        grid-row: 2;
        height: 68vh;
        max-height: 68vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-width: 0;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Assicura che il contenuto delle conversazioni non venga tagliato */
    #tab-content-dashboard.active .dashboard-top-right .panel {
        width: 100%;
        min-width: 0;
        overflow: hidden;
    }
    
    #tab-content-dashboard.active .dashboard-top-right .panel-header {
        padding: clamp(15px, 2vw, 25px) !important;
        min-height: clamp(50px, 6vh, 70px) !important;
        overflow: visible !important;
        word-wrap: break-word;
        white-space: normal !important;
        flex-wrap: wrap;
        gap: clamp(8px, 1vw, 12px);
    }
    
    #tab-content-dashboard.active .dashboard-top-right .panel-content {
        width: 100%;
        min-width: 0;
        overflow-x: hidden;
        overflow-y: auto;
        padding: clamp(15px, 2vw, 25px);
    }
    
    #tab-content-dashboard.active .dashboard-top-right .conversazioni-list {
        width: 100%;
        min-width: 0;
        box-sizing: border-box;
    }
    
    /* Terza riga: Log Messaggi e Log Sistema sulla stessa linea (50% e 50%) */
    #tab-content-dashboard.active .panel-messages {
        grid-column: 1; /* Prima colonna */
        grid-row: 3; /* Terza riga (dopo Stats) */
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 60px; /* Altezza minima per il header */
    }
    
    #tab-content-dashboard.active .panel-logs {
        grid-column: 2; /* Seconda colonna */
        grid-row: 3; /* Terza riga (stessa riga di Log Messaggi) */
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 60px; /* Altezza minima per il header */
    }
    
    /* Quando sono collassati, mantengono lo spazio ma nascondono il contenuto */
    #tab-content-dashboard.active .panel-messages.collapsed,
    #tab-content-dashboard.active .panel-logs.collapsed {
        min-height: auto;
        max-height: fit-content;
    }
    
    #tab-content-dashboard.active .panel-messages.collapsed .panel-content,
    #tab-content-dashboard.active .panel-logs.collapsed .panel-content {
        max-height: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
        padding: 0 !important;
        display: none !important;
    }
    
    #tab-content-dashboard.active .panel-messages:not(.collapsed) {
        max-height: calc(32vh - 40px);
    }

    /* Log Sistema: più altezza per QR WhatsApp scansionabile (non limitare come i messaggi) */
    #tab-content-dashboard.active .panel-logs:not(.collapsed) {
        max-height: min(780px, 78vh);
    }
    
    /* Panel content scroll ottimizzato */
    #tab-content-dashboard.active > .panel .panel-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        min-height: 0;
    }
    
    /* Agenda occupa tutto lo schermo */
    #tab-content-agenda.active {
        display: block !important;
        grid-template-columns: none !important;
        height: calc(100vh - 80px);
        overflow: hidden;
    }
    
    .tab-content.active > .panel {
        margin-bottom: 0;
        height: fit-content;
        max-height: calc(100vh - 200px);
        display: flex;
        flex-direction: column;
    }

    .tab-content.active > .panel .panel-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Layout a 2 colonne per main-content-grid - Clienti più larga */
    .tab-content.active .main-content-grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1.8fr); /* minmax(0, ...) previene overflow */
        gap: clamp(15px, 2vw, 25px);
        align-items: start;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    /* Sezione clienti full-screen per migliore leggibilità */
    #tab-content-clienti.active {
        display: grid !important;
        grid-template-columns: 1fr;
        gap: 0;
        height: calc(100vh - 20px);
        overflow: hidden;
        min-height: calc(100vh - 20px);
        margin: 0;
        padding: 0;
        position: relative;
        z-index: 1;
    }
    
    /* Fix Safari: aggiungi spazio per la barra tab sticky */
    @supports (-webkit-appearance: none) {
        #tab-content-clienti.active {
            padding-top: clamp(5px, 1vh, 10px);
            height: calc(100vh - clamp(80px, 12vh, 100px)); /* Sottrae spazio per header e tab bar */
        }
    }
    
    #tab-content-clienti.active .main-content-grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); /* minmax(0, ...) previene overflow, 50% e 50% */
        gap: clamp(15px, 2vw, 25px);
        height: 100%;
        overflow: hidden;
        min-height: 0;
        padding: clamp(10px, 1.5vw, 20px);
        box-sizing: border-box;
        align-items: stretch;
        width: 100%;
        max-width: 100%;
    }
    
    .tab-content.active .main-content-grid .column-left,
    .tab-content.active .main-content-grid .column-right {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    .tab-content.active .main-content-grid .panel {
        margin-bottom: 0;
        height: 100%;
        max-height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    
    /* Pannello clienti full-screen */
    #tab-content-clienti.active .main-content-grid .panel {
        max-height: 100%;
        height: 100%;
    }
    
    #tab-content-clienti.active .main-content-grid .panel .panel-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        min-height: 0;
    }
    
    /* Dettaglio cliente: su desktop griglia info in 2 colonne */
    .cliente-detail-info-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .cliente-detail-info-grid .cliente-detail-info-full {
        grid-column: 1 / -1;
    }
    
    .tab-content.active .main-content-grid .panel .panel-content {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    /* Panel full width su desktop */
    .tab-content.active > .panel-full-width {
        grid-column: 1 / -1;
    }
}

/* Mobile: layout a 1 colonna */
@media (max-width: 768px) {
    .tab-content.active {
        display: flex !important;
        flex-direction: column;
        gap: clamp(10px, 2vw, 15px);
    }
    
    /* Sezione clienti su mobile - full width */
    #tab-content-clienti.active {
        height: auto;
        min-height: calc(100vh - 120px);
    }
    
    #tab-content-clienti.active .main-content-grid {
        display: flex;
        flex-direction: column;
        gap: clamp(12px, 2vw, 18px);
        height: auto;
    }
    
    /* Dashboard mobile - layout ottimizzato */
    #tab-content-dashboard.active {
        grid-template-columns: 1fr !important;
        grid-template-rows: auto !important;
    }
    
    #tab-content-dashboard.active .dashboard-top-left,
    #tab-content-dashboard.active .dashboard-top-right {
        grid-column: 1 !important;
        grid-row: auto !important;
        height: auto !important;
        max-height: calc(50vh - 50px) !important;
    }
    
    #tab-content-dashboard.active .panel-messages {
        grid-column: 1 !important;
        grid-row: auto !important;
        max-height: calc(40vh - 50px) !important;
    }

    #tab-content-dashboard.active .panel-logs {
        grid-column: 1 !important;
        grid-row: auto !important;
        max-height: min(720px, 82vh) !important;
    }
    
    /* Su mobile: quando Log Messaggi/Log Sistema sono collassati, nascondi il contenuto */
    #tab-content-dashboard.active .panel-messages.collapsed .panel-content,
    #tab-content-dashboard.active .panel-logs.collapsed .panel-content {
        display: none !important;
        max-height: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
        padding: 0 !important;
    }
    
    /* Agenda occupa tutto lo schermo anche su mobile */
    #tab-content-agenda.active {
        height: calc(100vh - 80px);
        overflow: hidden;
    }
    
    .tab-content.active > .panel {
        margin-bottom: clamp(12px, 2vw, 18px);
        width: 100%;
    }
    
    .tab-content.active .main-content-grid {
        display: flex;
        flex-direction: column;
        gap: clamp(12px, 2vw, 18px);
    }
    
    .tab-content.active .main-content-grid .column-left,
    .tab-content.active .main-content-grid .column-right {
        margin-bottom: 0;
        width: 100%;
    }
}

/* Panel full width quando necessario */
.panel-full-width {
    grid-column: 1 / -1;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden; /* Previene overflow orizzontale */
}

/* Lista prenotazioni con scroll migliorato - le regole generali sono definite sotto */
.prenotazioni-list {
    max-height: calc(100vh - 400px);
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
}

/* Autocentraggio: scroll snap nella lista prenotazioni (card si centrano nel frame) */
/* Prefissi -webkit- per Safari; standard per Firefox/Chrome */
#prenotazioniList.prenotazioni-list {
    -webkit-scroll-snap-type: y proximity;
    scroll-snap-type: y proximity;
    scroll-padding: 12px 0;
    -webkit-overflow-scrolling: touch;
}
#prenotazioniList .prenotazione-card {
    -webkit-scroll-snap-align: center;
    scroll-snap-align: center;
    -webkit-scroll-margin: 12px 0;
    scroll-margin: 12px 0;
}

.clienti-list {
    max-height: calc(100vh - 400px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: clamp(4px, 0.8vw, 8px);
    flex: 1;
    min-height: 0;
}

.messages-list {
    max-height: calc(100vh - 400px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: clamp(4px, 0.8vw, 8px);
    flex: 1;
    min-height: 0;
}

.conversazioni-list {
    max-height: calc(100vh - 400px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: clamp(4px, 0.8vw, 8px);
    flex: 1;
    min-height: 0;
}

.logs-list {
    max-height: calc(100vh - 400px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: clamp(4px, 0.8vw, 8px);
    flex: 1;
    min-height: 0;
}

.search-input {
    width: 100%;
    max-width: 100%;
    padding: clamp(10px, 1.5vw, 14px);
    border: 2px solid var(--border-color);
    border-radius: clamp(6px, 1vw, 10px);
    font-size: clamp(13px, 1.8vw, 15px);
    box-sizing: border-box;
    transition: all 0.2s ease;
    background: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-input::placeholder {
    color: #9ca3af;
}

.panel {
    background: var(--bg-color);
    border-radius: clamp(10px, 1.5vw, 16px);
    box-shadow: 0 clamp(2px, 0.5vw, 4px) clamp(4px, 0.8vw, 8px) var(--shadow);
    overflow: hidden;
    transition: background 0.3s ease, box-shadow 0.3s ease;
    width: 100%;
    max-width: 100%;
    min-width: 0; /* Permette al flex di ridurre la dimensione */
    box-sizing: border-box; /* Include padding e border nella larghezza */
}

.panel-header {
    padding: clamp(15px, 2vw, 25px);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.3s ease;
    flex-wrap: wrap;
    gap: clamp(8px, 1vw, 12px);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.panel-header h2 {
    color: var(--text-color);
    font-size: clamp(16px, 2vw, 22px);
    transition: color 0.3s ease;
    margin: 0;
}

.panel-header h2 i {
    margin-right: clamp(6px, 0.8vw, 12px);
    color: var(--theme-primary);
}

/* Panel header con filtri e ricerca */
.panel-header .search-input {
    margin-bottom: 0;
}

.panel-header .filters {
    width: 100%;
    margin-top: 0;
}

.panel-header .filters .filter-btn {
    font-size: clamp(11px, 1.4vw, 13px);
    padding: clamp(5px, 0.8vw, 8px) clamp(8px, 1.2vw, 12px);
}
    transition: color 0.3s ease;
    font-size: clamp(14px, 1.8vw, 20px);
}

.panel-content {
    padding: clamp(15px, 2vw, 25px);
    max-height: 600px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box; /* Include padding nella larghezza */
}

/* Dettaglio cliente: griglia info (1 col mobile, 2 col desktop) */
.cliente-detail-info-grid {
    display: grid;
    gap: 10px;
}

/* Scrollbar personalizzate */
.panel-content::-webkit-scrollbar,
.prenotazioni-list::-webkit-scrollbar,
.clienti-list::-webkit-scrollbar,
.messages-list::-webkit-scrollbar,
.conversazioni-list::-webkit-scrollbar,
.logs-list::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.panel-content::-webkit-scrollbar-track,
.prenotazioni-list::-webkit-scrollbar-track,
.clienti-list::-webkit-scrollbar-track,
.messages-list::-webkit-scrollbar-track,
.conversazioni-list::-webkit-scrollbar-track,
.logs-list::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

.panel-content::-webkit-scrollbar-thumb,
.prenotazioni-list::-webkit-scrollbar-thumb,
.clienti-list::-webkit-scrollbar-thumb,
.messages-list::-webkit-scrollbar-thumb,
.conversazioni-list::-webkit-scrollbar-thumb,
.logs-list::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
    border: 2px solid #f1f1f1;
}

body.dark-mode .panel-content::-webkit-scrollbar-track,
body.dark-mode .prenotazioni-list::-webkit-scrollbar-track,
body.dark-mode .clienti-list::-webkit-scrollbar-track,
body.dark-mode .messages-list::-webkit-scrollbar-track,
body.dark-mode .conversazioni-list::-webkit-scrollbar-track,
body.dark-mode .logs-list::-webkit-scrollbar-track {
    background: #404040;
}

body.dark-mode .panel-content::-webkit-scrollbar-thumb,
body.dark-mode .prenotazioni-list::-webkit-scrollbar-thumb,
body.dark-mode .clienti-list::-webkit-scrollbar-thumb,
body.dark-mode .messages-list::-webkit-scrollbar-thumb,
body.dark-mode .conversazioni-list::-webkit-scrollbar-thumb,
body.dark-mode .logs-list::-webkit-scrollbar-thumb {
    background: var(--theme-primary);
    border: 2px solid #404040;
}

.panel-content::-webkit-scrollbar-thumb:hover,
.prenotazioni-list::-webkit-scrollbar-thumb:hover,
.clienti-list::-webkit-scrollbar-thumb:hover,
.messages-list::-webkit-scrollbar-thumb:hover,
.conversazioni-list::-webkit-scrollbar-thumb:hover,
.logs-list::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Scrollbar per Firefox */
.panel-content,
.prenotazioni-list,
.clienti-list,
.messages-list,
.conversazioni-list,
.logs-list {
    scrollbar-width: thin;
    scrollbar-color: #667eea #f1f1f1;
}

body.dark-mode .panel-content,
body.dark-mode .prenotazioni-list,
body.dark-mode .clienti-list,
body.dark-mode .messages-list,
body.dark-mode .conversazioni-list,
body.dark-mode .logs-list {
    scrollbar-color: var(--theme-primary) #404040;
}

.filters {
    display: flex;
    gap: clamp(8px, 1.5vw, 12px);
    margin-bottom: clamp(15px, 2.5vw, 20px);
    flex-wrap: wrap;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.filter-btn {
    padding: clamp(6px, 1.2vw, 10px) clamp(12px, 2vw, 18px);
    border: 2px solid var(--border-color);
    background: var(--bg-color);
    border-radius: clamp(5px, 0.8vw, 8px);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-size: clamp(12px, 1.6vw, 14px);
    flex: 1;
    min-width: fit-content;
    white-space: nowrap;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-btn:hover {
    border-color: #667eea;
    color: #667eea;
    transform: translateY(-1px);
}

.filter-btn.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.2);
}

.filter-btn-novita {
    background: rgba(245, 158, 11, 0.2);
    border-color: #f59e0b;
    color: #d97706;
}
.filter-btn-novita:hover {
    background: rgba(245, 158, 11, 0.35);
    border-color: #f59e0b;
    color: #b45309;
}
.filter-btn-novita.active {
    background: #f59e0b;
    color: white;
    border-color: #f59e0b;
}
.filter-pill-novita {
    border-color: #f59e0b;
    color: #d97706;
}
.filter-pill-novita:hover, .filter-pill-novita.active {
    background: #f59e0b;
    border-color: #f59e0b;
    color: white;
}

body.dark-mode .filter-btn {
    background: var(--panel-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

body.dark-mode .filter-btn:hover {
    background: #2a2a2a;
    border-color: var(--theme-primary);
    color: var(--theme-primary);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

body.dark-mode .filter-btn.active {
    background: var(--theme-primary);
    color: white;
    border-color: var(--theme-primary);
}

.btn-refresh, .btn-clear {
    padding: clamp(6px, 1.2vw, 10px) clamp(12px, 2vw, 18px);
    background: #667eea;
    color: white;
    border: none;
    border-radius: clamp(5px, 0.8vw, 8px);
    cursor: pointer;
    font-weight: 500;
    font-size: clamp(12px, 1.6vw, 14px);
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-refresh:hover, .btn-clear:hover {
    background: #5568d3;
    transform: translateY(-1px);
}

.btn-small {
    padding: clamp(4px, 0.8vw, 6px) clamp(8px, 1.5vw, 12px) !important;
    font-size: clamp(10px, 1.4vw, 12px) !important;
}

.btn-icon-only {
    padding: clamp(6px, 1.2vw, 10px) !important;
    min-width: clamp(32px, 5vw, 38px) !important;
    width: clamp(32px, 5vw, 38px) !important;
    justify-content: center !important;
}

.btn-icon-only span {
    display: none !important;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: clamp(4px, 0.8vw, 8px);
}

.btn-refresh:hover, .btn-clear:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.btn-small {
    padding: clamp(4px, 0.8vw, 6px) clamp(8px, 1.5vw, 12px) !important;
    font-size: clamp(10px, 1.4vw, 12px) !important;
}

.btn-icon-only {
    padding: clamp(6px, 1.2vw, 10px) !important;
    min-width: clamp(32px, 5vw, 38px) !important;
    width: clamp(32px, 5vw, 38px) !important;
    justify-content: center !important;
}

.btn-icon-only span {
    display: none !important;
}

.prenotazioni-list, .clienti-list, .messages-list, .conversazioni-list {
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 1.8vw, 18px);
    padding: clamp(8px, 1.2vw, 12px); /* Padding per evitare attaccamento ai bordi */
    box-sizing: border-box;
}

.prenotazione-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    padding: clamp(15px, 2vw, 20px);
    border-radius: clamp(8px, 1.2vw, 12px);
    margin: 0; /* Il padding è gestito dalla lista */
    box-sizing: border-box;
    width: 100%;
    transition: all 0.2s ease;
}

.prenotazione-card.cliente-warning {
    background: #fee2e2 !important;
    border: 3px solid #ef4444 !important;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3) !important;
    animation: pulse-warning 2s infinite;
}

@keyframes pulse-warning {
    0%, 100% { 
        box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
    }
    50% { 
        box-shadow: 0 6px 20px rgba(239, 68, 68, 0.5);
    }
}

.prenotazione-card.cliente-warning:hover {
    background: #fecaca !important;
    border-color: #dc2626 !important;
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.4) !important;
    border-radius: clamp(6px, 1vw, 10px);
    padding: clamp(12px, 1.8vw, 20px);
    transition: all 0.2s ease;
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.prenotazione-card.has-tags {
    border-left: 4px solid #667eea;
}

.prenotazione-card.has-tags:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    transform: translateY(-2px);
    transition: all 0.2s;
}

.prenotazione-card:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
    transition: all 0.2s ease;
}

.prenotazione-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid #e5e7eb;
    flex-wrap: wrap;
    gap: 10px;
}

body.dark-mode .prenotazione-header {
    border-bottom-color: var(--border-color);
}

/* Allineamento migliorato per le card clienti su desktop */
@media (min-width: 1024px) {
    #tab-content-clienti.active .clienti-list {
        display: flex;
        flex-direction: column;
        gap: clamp(12px, 1.8vw, 18px);
        align-items: stretch;
        width: 100%;
    }
    
    #tab-content-clienti.active .prenotazione-card {
        display: flex;
        flex-direction: column;
        min-height: fit-content;
        padding: clamp(15px, 2vw, 20px);
        border-radius: clamp(8px, 1.2vw, 12px);
        transition: all 0.2s ease;
        width: 100%;
        box-sizing: border-box;
    }
    
    #tab-content-clienti.active .prenotazione-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
    
    /* Allineamento rettangoli clienti */
    #tab-content-clienti.active .prenotazione-card .prenotazione-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
    }
    
    #tab-content-clienti.active .prenotazione-card .prenotazione-info {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: clamp(8px, 1.2vw, 12px);
        width: 100%;
    }
}

.prenotazione-cognome {
    font-weight: bold;
    color: #667eea;
    font-size: clamp(16px, 2.2vw, 24px);
}

body.dark-mode .prenotazione-cognome {
    color: var(--theme-primary);
}
    text-transform: capitalize;
    padding-left: clamp(15px, 2vw, 25px);
    display: block;
    width: 100%;
}

.prenotazione-id-small {
    font-size: 12px;
    color: #999;
    font-weight: normal;
}

body.dark-mode .prenotazione-id-small {
    color: #b0b0b0;
}
}

.prenotazione-stato {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.prenotazione-stato.attesa {
    background: #fef3c7;
    color: #92400e;
}

.prenotazione-stato.coda {
    background: #fee2e2;
    color: #991b1b;
}

.prenotazione-stato.confermata {
    background: #d1fae5;
    color: #065f46;
}

.prenotazione-stato.coda-annullata {
    background: #dc3545;
    color: white;
}

.prenotazione-stato.coda-timeout {
    background: #fef3c7;
    color: #92400e;
}

body.dark-mode .prenotazione-stato.attesa {
    background: #78350f;
    color: #fcd34d;
}

body.dark-mode .prenotazione-stato.coda {
    background: #7f1d1d;
    color: #fca5a5;
}

body.dark-mode .prenotazione-stato.confermata {
    background: #064e3b;
    color: #6ee7b7;
}

body.dark-mode .prenotazione-stato.coda-annullata {
    background: #991b1b;
    color: #fecaca;
}

body.dark-mode .prenotazione-stato.coda-timeout {
    background: #78350f;
    color: #fcd34d;
}

.prenotazione-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: clamp(10px, 1.5vw, 15px);
    margin-top: clamp(10px, 1.5vw, 15px);
    padding: 0 clamp(5px, 0.8vw, 10px); /* Padding laterale per evitare attaccamento ai bordi */
}

.prenotazione-info-item {
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 8px);
    color: #666;
    font-size: clamp(13px, 1.6vw, 14px);
    padding: clamp(4px, 0.6vw, 6px) 0; /* Padding verticale per spaziatura */
}

body.dark-mode .prenotazione-info-item {
    color: var(--text-color);
}
    word-break: break-word; /* Evita che il testo esca dal contenitore */
    overflow-wrap: break-word;
}

.prenotazione-info-item i {
    color: #667eea;
    width: 16px;
}

body.dark-mode .prenotazione-info-item i {
    color: var(--theme-primary);
}

.message-item {
    background: #f9fafb;
    border-left: 3px solid #667eea;
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
}

body.dark-mode .message-item {
    background: var(--panel-bg);
    border-left-color: var(--theme-primary);
    color: var(--text-color);
}
}

.message-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-weight: 600;
}

.message-from {
    color: #667eea;
}

.message-time {
    color: #999;
    font-size: 11px;
}

.message-body {
    color: #333;
    margin-top: 5px;
    word-break: break-word;
}

body.dark-mode .message-from {
    color: var(--theme-primary);
}

body.dark-mode .message-time {
    color: #b0b0b0;
}

body.dark-mode .message-body {
    color: var(--text-color);
}

.conversazione-item {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 15px;
}

body.dark-mode .conversazione-item {
    background: var(--panel-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}

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

.conversazione-header > div {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
}

.btn-delete-conversazione {
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-delete-conversazione:hover {
    background: #dc2626;
    transform: scale(1.05);
}

.conversazione-old {
    border-left: 4px solid #ef4444;
    background: #fef2f2;
}

body.dark-mode .conversazione-old {
    border-left-color: #dc2626;
    background: #7f1d1d;
}

.conversazione-user {
    font-weight: 600;
    color: #333;
}

.conversazione-nome-cliente {
    font-weight: 500;
    color: #667eea;
    font-size: 0.95em;
}

.conversazione-step {
    padding: 4px 12px;
    background: #667eea;
    color: white;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.conversazione-dati {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 10px;
    font-size: 13px;
    color: #666;
}

body.dark-mode .conversazione-user {
    color: var(--text-color);
}

body.dark-mode .conversazione-nome-cliente {
    color: #a5b4fc;
}

body.dark-mode .conversazione-dati {
    color: #b0b0b0;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #999;
    font-style: italic;
}

/* Logs — spazio sufficiente per QR WhatsApp scansionabile (header + area scroll) */
.panel-logs {
    grid-column: 1 / -1;
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 600px;
    height: auto;
}

.panel-logs .panel-content {
    flex: 1;
    min-height: 460px;
    height: auto;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.logs-list {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    height: 400px;
    overflow-y: auto;
    overflow-x: hidden;
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 15px;
    border-radius: 6px;
    resize: vertical;
    min-height: 200px;
    max-height: 800px;
}

.logs-list::-webkit-scrollbar {
    width: 12px;
}

.logs-list::-webkit-scrollbar-track {
    background: #2d2d2d;
    border-radius: 10px;
}

.logs-list::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 10px;
    border: 2px solid #2d2d2d;
}

.logs-list::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

.logs-list {
    scrollbar-width: thin;
    scrollbar-color: #667eea #2d2d2d;
}

/* Lista log nel pannello sistema — altezza #logsList da preview */
.panel-logs .logs-list {
    flex: 0 0 auto;
    min-height: 400px;
    max-height: min(70vh, 800px);
}

#logsList {
    height: 400px;
}

/* QR nei log: dimensione comoda per la fotocamera del telefono */
.log-qr-image {
    width: min(420px, 92vw);
    max-width: min(420px, 92vw);
    height: auto;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.logs-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: #667eea;
    cursor: ns-resize;
    opacity: 0;
    transition: opacity 0.2s;
}

.panel-logs:hover .logs-resize-handle {
    opacity: 0.5;
}

.logs-resize-handle:hover {
    opacity: 1;
}

/* Tab styles */
/* Rimuoviamo gli stili vecchi, ora gestiti da .tabs-container */

/* Config editor styles */
/* Campi di input e textarea migliorati */
#configEditor textarea,
#messagesEditor textarea,
#configEditor input[type="text"],
#messagesEditor input[type="text"],
#configEditor input[type="time"],
#messagesEditor input[type="time"] {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    width: 100%;
    padding: clamp(10px, 1.5vw, 14px);
    border: 2px solid var(--border-color);
    border-radius: clamp(6px, 1vw, 10px);
    font-size: clamp(13px, 1.8vw, 15px);
    transition: all 0.2s ease;
    background: var(--bg-color);
    color: var(--text-color);
    box-sizing: border-box;
}

#configEditor textarea,
#messagesEditor textarea {
    resize: vertical;
    min-height: clamp(80px, 12vh, 120px);
    line-height: 1.6;
}

#configEditor input[type="text"]:focus,
#messagesEditor input[type="text"]:focus,
#configEditor input[type="time"]:focus,
#messagesEditor input[type="time"]:focus,
#configEditor textarea:focus,
#messagesEditor textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#configEditor textarea:hover,
#messagesEditor textarea:hover,
#configEditor input[type="text"]:hover,
#messagesEditor input[type="text"]:hover,
#configEditor input[type="time"]:hover,
#messagesEditor input[type="time"]:hover {
    border-color: #cbd5e1;
}

/* Prenotazione actions */
.prenotazione-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
}

.btn-confirm:hover {
    background: #059669 !important;
    transform: translateY(-1px);
}

.btn-cancel:hover {
    background: #dc2626 !important;
    transform: translateY(-1px);
}

.btn-edit {
    background: #667eea !important;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s ease;
    touch-action: manipulation; /* evita ritardo 300ms e doppio-tap zoom su mobile */
    min-height: 44px;
    min-width: 44px;
}

.btn-edit:hover {
    background: #5568d3 !important;
    transform: translateY(-1px);
}

/* Stili per form modifica prenotazione */
.edit-field-group {
    margin-bottom: 20px;
}

.edit-field-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.edit-field-group input[type="text"],
.edit-field-group input[type="date"],
.edit-field-group input[type="time"],
.edit-field-group input[type="number"],
.edit-field-group textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s ease;
    background: white;
    color: #333;
}

.edit-field-group input[type="text"]:focus,
.edit-field-group input[type="date"]:focus,
.edit-field-group input[type="time"]:focus,
.edit-field-group input[type="number"]:focus,
.edit-field-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.edit-field-group textarea {
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
}

.log-entry {
    padding: 4px 8px;
    margin: 2px 0;
    border-left: 3px solid #666;
    white-space: pre-wrap;
    word-break: break-word;
}

.log-entry.info {
    border-left-color: #3b82f6;
}

.log-entry.success {
    border-left-color: #10b981;
}

.log-entry.warn {
    border-left-color: #f59e0b;
}

.log-entry.error {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.log-time {
    color: #888;
    margin-right: 8px;
}

.log-level {
    font-weight: bold;
    margin-right: 8px;
    text-transform: uppercase;
    font-size: 10px;
}

.log-level.info {
    color: #3b82f6;
}

.log-level.success {
    color: #10b981;
}

.log-level.warn {
    color: #f59e0b;
}

.log-level.error {
    color: #ef4444;
}

body.dark-mode .log-entry {
    background: var(--panel-bg);
    border-color: var(--border-color);
    color: var(--text-color);
}

body.dark-mode .log-entry.error {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.2);
}

body.dark-mode .log-time {
    color: #b0b0b0;
}

body.dark-mode .log-level.info {
    color: #60a5fa;
}

body.dark-mode .log-level.success {
    color: #34d399;
}

body.dark-mode .log-level.warn {
    color: #fbbf24;
}

body.dark-mode .log-level.error {
    color: #f87171;
}

.panel-header > div {
    display: flex;
    gap: 10px;
}

@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

/* Modal Password */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
    overflow-y: auto;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideDown 0.3s ease;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #333;
    font-size: 20px;
}

body.dark-mode .modal-header {
    border-bottom-color: var(--border-color);
}

body.dark-mode .modal-header h3 {
    color: var(--text-color);
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #f0f0f0;
    color: #333;
}

.modal-body {
    padding: 20px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Miglioramenti layout configurazione */
#configEditor form,
#messagesEditor form {
    max-width: 100%;
}

#configEditor input[type="text"],
#configEditor input[type="time"],
#configEditor textarea,
#messagesEditor textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}

#configEditor input[type="text"]:focus,
#configEditor input[type="time"]:focus,
#configEditor textarea:focus,
#messagesEditor textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#configEditor label,
#messagesEditor label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #333;
    font-size: 14px;
}

body.dark-mode #configEditor label,
body.dark-mode #messagesEditor label {
    color: var(--text-color);
}

body.dark-mode #configEditor input[type="text"],
body.dark-mode #configEditor input[type="time"],
body.dark-mode #configEditor textarea,
body.dark-mode #messagesEditor textarea {
    background: var(--panel-bg);
    color: var(--text-color);
    border-color: var(--border-color);
}

body.dark-mode #configEditor input[type="text"]:focus,
body.dark-mode #configEditor input[type="time"]:focus,
body.dark-mode #configEditor textarea:focus,
body.dark-mode #messagesEditor textarea:focus {
    border-color: var(--theme-primary);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2);
}

#configEditor h3 {
    margin-top: 30px;
    margin-bottom: 20px;
    color: #667eea;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
    font-size: 18px;
}

/* Stili per tag clienti evidenziati */
.cliente-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: normal;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.cliente-tag-noshow {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.cliente-tag-noshow.active {
    background: #ef4444;
    color: white;
    border: 1px solid #dc2626;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.3);
    transform: scale(1.05);
}

.cliente-tag-ritardatario {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.cliente-tag-ritardatario.active {
    background: #f59e0b;
    color: white;
    border: 1px solid #d97706;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
    transform: scale(1.05);
}

.cliente-tag-buontavolo {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.cliente-tag-buontavolo.active {
    background: #10b981;
    color: white;
    border: 1px solid #059669;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(16, 185, 129, 0.3);
    transform: scale(1.05);
}

.cliente-tag-ospitiinmeno {
    background: #e0f2fe;
    color: #0369a1;
    border: 1px solid #0ea5e9;
}

.cliente-tag-ospitiinmeno.active {
    background: #0ea5e9;
    color: white;
    border: 1px solid #0284c7;
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(14, 165, 233, 0.3);
    transform: scale(1.05);
}

/* Dark mode per tag clienti */
body.dark-mode .cliente-tag-noshow {
    background: #7f1d1d;
    color: #fca5a5;
    border: 1px solid #991b1b;
}

body.dark-mode .cliente-tag-noshow.active {
    background: #dc2626;
    color: white;
    border: 1px solid #991b1b;
}

body.dark-mode .cliente-tag-ritardatario {
    background: #78350f;
    color: #fcd34d;
    border: 1px solid #92400e;
}

body.dark-mode .cliente-tag-ritardatario.active {
    background: #d97706;
    color: white;
    border: 1px solid #92400e;
}

body.dark-mode .cliente-tag-bassaaffidabilita {
    background: #7f1d1d;
    color: #fca5a5;
    border: 1px solid #991b1b;
}

body.dark-mode .cliente-tag-bassaaffidabilita.active {
    background: #b91c1c;
    color: white;
    border: 1px solid #991b1b;
}

body.dark-mode .cliente-tag-buontavolo {
    background: #064e3b;
    color: #6ee7b7;
    border: 1px solid #065f46;
}

body.dark-mode .cliente-tag-buontavolo.active {
    background: #059669;
    color: white;
    border: 1px solid #065f46;
}

body.dark-mode .cliente-tag-ospitiinmeno {
    background: #0c4a6e;
    color: #7dd3fc;
    border: 1px solid #0369a1;
}

body.dark-mode .cliente-tag-ospitiinmeno.active {
    background: #0284c7;
    color: white;
    border: 1px solid #0369a1;
}

/* Stile campo di ricerca clienti */
.search-input {
    width: 100%;
    padding: clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 18px);
    border: 2px solid var(--border-color);
    border-radius: clamp(6px, 1vw, 10px);
    font-size: clamp(13px, 1.8vw, 15px);
    box-sizing: border-box;
    transition: all 0.2s ease;
    background: var(--bg-color);
    color: var(--text-color);
    font-family: inherit;
    transition: all 0.2s ease;
    background: white;
    color: #333;
}

.search-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-input:hover {
    border-color: #cbd5e1;
}

.search-input::placeholder {
    color: #9ca3af;
}

/* Miglioramenti per card clienti con tag */
.prenotazione-card.has-tags {
    border-left: 4px solid #667eea;
    background: linear-gradient(to right, rgba(102, 126, 234, 0.02) 0%, #f9fafb 4%);
}

.prenotazione-card.has-tags:hover {
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
    transform: translateY(-2px);
    border-left-color: #5568d3;
}

/* ========== STILI CONFIGURAZIONE CON TAB ========== */
.config-layout {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.config-tabs-nav {
    display: flex;
    gap: clamp(8px, 1.2vw, 15px);
    padding: 0;
    background: var(--bg-color);
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--theme-primary) transparent;
    -ms-overflow-style: none;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 5;
}

.config-tabs-nav::-webkit-scrollbar {
    height: 6px;
}

.config-tabs-nav::-webkit-scrollbar-track {
    background: transparent;
}

.config-tabs-nav::-webkit-scrollbar-thumb {
    background: var(--theme-primary);
    border-radius: 3px;
    opacity: 0.6;
}

.config-tabs-nav::-webkit-scrollbar-thumb:hover {
    opacity: 1;
}

.config-tab-btn {
    padding: clamp(12px, 1.8vw, 18px) clamp(16px, 2.5vw, 28px);
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: #6b7280;
    font-size: clamp(13px, 1.8vw, 16px);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 10px);
    flex-shrink: 0;
}

.config-tab-btn:hover {
    color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.config-tab-btn.active {
    color: #667eea;
    border-bottom-color: #667eea;
    background: rgba(102, 126, 234, 0.05);
}

.config-tab-btn i {
    font-size: clamp(14px, 1.8vw, 18px);
}

.config-tabs-content {
    width: 100%;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.config-tab-panel {
    display: none;
    animation: fadeIn 0.3s ease;
    height: 100%;
    overflow: hidden;
}

.config-tab-panel.active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Stili per sezione messaggi migliorata - Fullscreen su desktop */
.messages-fullscreen {
    width: 100%;
    max-width: 100%;
    position: relative;
}

.messages-panel-fullscreen {
    width: 100%;
    max-width: 100%;
    margin: 0;
}

.messages-header-with-tabs {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: nowrap;
    padding: 20px 25px;
    border-bottom: 2px solid var(--border-color);
    background: var(--panel-bg);
    position: relative;
}

.messages-header-with-tabs h2 {
    margin: 0;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: fit-content;
}

.messages-header-with-tabs > div:first-child {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.messages-header-with-tabs .btn-refresh {
    flex-shrink: 0;
    white-space: nowrap;
}

.messages-category-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 5px 10px;
    flex: 1;
    min-width: 200px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    margin-left: auto;
}

.messages-category-tabs::-webkit-scrollbar {
    height: 6px;
}

.messages-category-tabs::-webkit-scrollbar-track {
    background: transparent;
    border-radius: 3px;
}

.messages-category-tabs::-webkit-scrollbar-thumb {
    background: var(--theme-primary);
    border-radius: 3px;
    opacity: 0.6;
}

.messages-category-tabs::-webkit-scrollbar-thumb:hover {
    opacity: 1;
}

.messages-content-fullscreen {
    max-height: calc(100vh - 200px) !important;
    overflow-y: auto;
    padding: 25px;
    width: 100%;
    box-sizing: border-box;
}

.message-category-module {
    transition: all 0.3s ease;
}

.message-category-module:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.message-category-tab {
    position: relative;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.message-category-tab i {
    font-size: 12px;
}

.message-category-tab.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 3px;
    background: var(--theme-primary);
    border-radius: 2px 2px 0 0;
}

/* Migliora la visibilità delle tab su schermi più piccoli */
@media (max-width: 1200px) {
    .messages-category-tabs {
        min-width: 150px;
    }
    
    .message-category-tab {
        padding: 8px 14px !important;
        font-size: 12px !important;
    }
}

/* Desktop: layout fullscreen - sfrutta tutta la larghezza dello schermo */
@media (min-width: 1024px) {
    /* Forza la sezione messaggi a usare tutta la larghezza disponibile */
    .messages-fullscreen {
        grid-column: 1 / -1;
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
    
    /* Assicura che il container config-tabs-content non limiti la larghezza */
    .config-tabs-content {
        width: 100%;
        max-width: 100%;
    }
    
    .messages-panel-fullscreen {
        width: 100%;
        max-width: 100%;
        margin: 0;
        border-radius: 0;
    }
    
    .messages-panel-fullscreen .panel-header {
        border-radius: 0;
    }
    
    .messages-content-fullscreen {
        max-height: calc(100vh - 180px) !important;
        padding: 30px 40px;
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Grid a 2 colonne su desktop per i messaggi con larghezza ottimizzata */
    #messagesEditor {
        width: 100%;
        max-width: 100%;
    }
    
    #messagesEditor [style*="grid-template-columns: repeat(auto-fit, minmax(500px, 1fr))"] {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 25px !important;
        max-width: 100%;
        width: 100%;
    }
    
    /* Header con tabs migliorato */
    .messages-header-with-tabs {
        padding: 20px 40px;
    }
    
    .messages-category-tabs {
        padding: 5px 15px;
        gap: 10px;
    }
    
    /* Migliora la leggibilità delle tab */
    .message-category-tab {
        padding: 10px 18px !important;
        font-size: 14px !important;
    }
}

#messagesEditor textarea {
    transition: all 0.2s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}

#messagesEditor textarea:focus {
    outline: none;
    transform: translateY(-1px);
}

/* Responsive per sezione messaggi */
@media (max-width: 1200px) {
    #messagesEditor [style*="grid-template-columns: repeat(auto-fit, minmax(500px, 1fr))"] {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 768px) {
    .message-category-module {
        padding: 15px !important;
    }
    
    #messagesEditor textarea {
        min-height: 150px !important;
        font-size: 14px !important;
    }
}

.config-panel-content {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: clamp(15px, 2.5vw, 30px);
    flex: 1;
    min-height: 0;
}

/* Desktop: configurazione full-screen */
@media (min-width: 769px) {
    #tab-content-config.active {
        display: flex !important;
        flex-direction: column;
        height: calc(100vh - 140px);
        min-height: 600px;
        overflow: hidden;
    }
    
    .config-panel-content {
        max-height: calc(100vh - 250px);
        padding: clamp(20px, 3vw, 40px);
    }
}

/* Stili per form configurazione */
.config-section {
    background: var(--bg-color);
    padding: clamp(18px, 2.5vw, 30px);
    border-radius: clamp(10px, 1.5vw, 14px);
    margin-bottom: clamp(18px, 2.5vw, 30px);
    border: 1px solid var(--border-color);
    width: 100%;
    box-sizing: border-box;
}

.config-section-title {
    margin: 0 0 clamp(15px, 2vw, 25px) 0;
    color: #667eea;
    font-size: clamp(16px, 2.2vw, 20px);
    font-weight: 700;
    padding-bottom: clamp(10px, 1.5vw, 15px);
    border-bottom: 2px solid #667eea;
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.2vw, 12px);
}

.config-section-title i {
    font-size: clamp(18px, 2.2vw, 22px);
}

.config-field {
    margin-bottom: clamp(15px, 2vw, 25px);
}

.config-field:last-child {
    margin-bottom: 0;
}

.config-field label {
    display: block;
    margin-bottom: clamp(6px, 1vw, 10px);
    font-weight: 600;
    color: var(--text-color);
    font-size: clamp(13px, 1.8vw, 15px);
}

.config-field input[type="text"],
.config-field input[type="time"],
.config-field textarea {
    width: 100%;
    padding: clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 18px);
    border: 2px solid var(--border-color);
    border-radius: clamp(6px, 1vw, 10px);
    font-size: clamp(13px, 1.8vw, 15px);
    font-family: inherit;
    transition: all 0.2s ease;
    box-sizing: border-box;
    background: white;
    color: #333;
}

.config-field input[type="text"]:focus,
.config-field input[type="time"]:focus,
.config-field textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.config-field textarea {
    resize: vertical;
    min-height: clamp(80px, 12vh, 120px);
    font-family: 'Courier New', monospace;
    line-height: 1.6;
}

.config-field input[type="text"] {
    font-family: 'Courier New', monospace;
}

.config-help {
    font-size: clamp(11px, 1.5vw, 13px);
    color: #6b7280;
    margin-top: clamp(4px, 0.8vw, 8px);
    line-height: 1.5;
}

/* Sezione config in sola lettura (es. Gruppi WhatsApp gestiti automaticamente) */
.config-section-readonly .config-readonly-notice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: rgba(102, 126, 234, 0.1);
    border: 1px solid var(--theme-primary);
    border-radius: 8px;
    color: var(--text-color);
    font-size: 14px;
    line-height: 1.5;
}
.config-section-readonly .config-readonly-notice i {
    color: var(--theme-primary);
    flex-shrink: 0;
    margin-top: 2px;
}
.config-field-readonly .config-value-readonly {
    padding: 10px 14px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: monospace;
    font-size: 13px;
    color: #666;
    word-break: break-all;
}
body.dark-mode .config-field-readonly .config-value-readonly {
    background: rgba(255,255,255,0.05);
    border-color: var(--border-color);
    color: #b0b0b0;
}
body.dark-mode .config-section-readonly .config-readonly-notice {
    background: rgba(102, 126, 234, 0.15);
    border-color: var(--theme-primary);
}

.config-info {
    font-size: clamp(12px, 1.7vw, 14px);
    color: #667eea;
    background: rgba(102, 126, 234, 0.1);
    padding: clamp(10px, 1.5vw, 15px);
    border-radius: clamp(5px, 0.8vw, 8px);
    margin-bottom: clamp(12px, 2vw, 20px);
    border-left: 3px solid #667eea;
}

.config-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr));
    gap: clamp(15px, 2.5vw, 25px);
}

.config-form-footer {
    text-align: center;
    margin-top: clamp(24px, 4vw, 40px);
    padding-top: clamp(18px, 3vw, 30px);
    border-top: 2px solid var(--border-color);
}

.btn-save-config {
    padding: clamp(12px, 1.8vw, 16px) clamp(24px, 4vw, 40px);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: clamp(6px, 1vw, 10px);
    cursor: pointer;
    font-weight: bold;
    font-size: clamp(14px, 2vw, 18px);
    box-shadow: 0 clamp(2px, 0.5vw, 4px) clamp(8px, 1.5vw, 16px) rgba(102, 126, 234, 0.3);
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: clamp(6px, 1vw, 10px);
}

.btn-save-config:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(102, 126, 234, 0.4);
}

.btn-save-config:active {
    transform: translateY(0);
}

.config-password-hint {
    font-size: 12px;
    color: #9ca3af;
    margin-top: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-sync-operatori {
    margin-top: 10px;
    padding: 10px 18px;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}
.btn-sync-operatori:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}
.btn-sync-operatori:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
.config-operatori-list {
    max-height: 120px;
    overflow-y: auto;
}
.config-section-operatori {
    padding-bottom: 20px;
}
.config-section-operatori .config-operatori-actions {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}
.config-section-operatori .btn-sync-operatori {
    margin-top: 0;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .stats-grid {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .stats-grid .stat-card {
        flex: 1 1 0;
        min-width: 100px;
        flex-shrink: 0;
    }
    
    header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .cliente-tag {
        font-size: 12px;
        padding: 5px 10px;
    }
    
    /* Configurazione mobile - layout ottimizzato */
    #tab-content-config.active {
        height: auto;
        min-height: calc(100vh - 120px);
    }
    
    .config-tabs-nav {
        gap: clamp(4px, 1vw, 8px);
        padding: 0 clamp(8px, 2vw, 12px);
    }
    
    .config-tab-btn {
        padding: clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 18px);
        font-size: clamp(11px, 1.6vw, 13px);
    }
    
    .config-tab-btn span {
        display: none;
    }
    
    .config-tab-btn i {
        font-size: clamp(14px, 2vw, 16px);
    }
    
    .config-grid-2 {
        grid-template-columns: 1fr;
        gap: clamp(12px, 2vw, 18px);
    }
    
    .config-panel-content {
        max-height: calc(100vh - 200px);
        padding: clamp(12px, 2vw, 18px);
    }
    
    .config-section {
        padding: clamp(14px, 2.2vw, 20px);
        margin-bottom: clamp(14px, 2.2vw, 20px);
    }
    
    .config-section-title {
        font-size: clamp(14px, 2vw, 18px);
    }
    
    .btn-save-config {
        width: 100%;
        justify-content: center;
        padding: clamp(14px, 2.2vw, 18px) clamp(20px, 4vw, 32px);
    }
}

/* ==================== STILI AGENDA ==================== */
#tab-content-agenda {
    padding: 0 !important;
    margin: 0 !important;
    height: calc(100vh - 80px);
    overflow: hidden;
}

.agenda-container {
    width: 100%;
    height: 100%;
    margin: 0;
    background: #f8f9fa;
    border-radius: 0;
    padding: 15px;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.agenda-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    padding: 15px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.agenda-nav-btn {
    background: var(--theme-gradient);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.agenda-nav-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

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

.agenda-push-tavoli-btn {
    padding: 8px 14px;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.agenda-push-icon-mobile { display: none; }
.agenda-push-text-short { display: none; }
.agenda-push-tavoli-btn:hover {
    background: #059669;
}
.agenda-push-tavoli-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* Wrapper per data: l'input sovrapposto riceve il tap e apre il calendario nativo (anche su mobile) */
.agenda-date-wrap {
    position: relative;
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 44px; /* area touch minima per iOS/Android */
}
.agenda-date-picker-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 44px;
    opacity: 0;
    cursor: pointer;
    pointer-events: auto;
    z-index: 1;
    font-size: 16px; /* evita zoom su iOS quando si apre il picker */
}
.agenda-date-picker-hidden {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.agenda-date-info {
    display: flex;
    align-items: center;
    gap: 20px;
    flex: 1;
    justify-content: center;
    cursor: pointer;
    user-select: none;
    border-radius: 8px;
    padding: 4px 8px;
    transition: background 0.2s;
    pointer-events: none; /* il tap va all'input sovrapposto */
}
.agenda-date-info:hover {
    background: rgba(102, 126, 234, 0.1);
}
.agenda-date-info:focus {
    outline: 2px solid var(--theme-primary);
    outline-offset: 2px;
}

.agenda-date-number {
    font-size: 72px;
    font-weight: bold;
    color: var(--theme-primary);
    line-height: 1;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

.agenda-date-details {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.agenda-day-month {
    font-size: clamp(24px, 3.5vw, 36px);
    font-weight: 600;
    color: #333;
}

.agenda-date-filter-str {
    font-size: 12px;
    font-weight: 400;
    color: #666;
    margin-top: 2px;
    text-transform: capitalize;
}

.agenda-content-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.agenda-column {
    background: #ffffff;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.agenda-column-header {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--theme-primary);
    text-align: center;
    letter-spacing: 0.02em;
}

.agenda-date-section {
    margin-bottom: 20px;
}
.agenda-date-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--theme-primary);
    margin-bottom: 8px;
    padding: 6px 10px;
    background: rgba(102, 126, 234, 0.1);
    border-radius: 6px;
    border-left: 4px solid var(--theme-primary);
}
body.dark-mode .agenda-date-section-title {
    background: rgba(102, 126, 234, 0.2);
}

.agenda-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.agenda-row {
    padding: clamp(10px, 1.5vw, 14px) clamp(12px, 2vw, 16px);
    border-bottom: 1px solid #cbd5e1;
    font-size: 14px;
    color: #1e293b;
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1vw, 10px);
    min-height: clamp(50px, 7vh, 70px);
    align-items: stretch;
    background: #ffffff;
}

.agenda-row:nth-child(even) {
    background: #f8fafc;
}

.agenda-row.cliente-warning {
    background: #fef2f2 !important;
    border: 2px solid #dc2626 !important;
    border-bottom: 2px solid #dc2626 !important;
    box-shadow: 0 2px 8px rgba(220, 38, 38, 0.25) !important;
    color: #991b1b !important;
    animation: pulse-warning 2s infinite;
}

.agenda-row.cliente-warning .agenda-cognome,
.agenda-row.cliente-warning .agenda-coperti,
.agenda-row.cliente-warning .agenda-note,
.agenda-row.cliente-warning .agenda-orario {
    color: #7f1d1d !important;
}

.agenda-row.cliente-warning:hover {
    background: #fee2e2 !important;
    border-color: #b91c1c !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(220, 38, 38, 0.35) !important;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.agenda-row:hover {
    background: #f1f5f9 !important;
}

.agenda-row:nth-child(even):hover {
    background: #e2e8f0 !important;
}

.agenda-row-arrivato {
    text-decoration: line-through;
    opacity: 0.6;
    background: #f0fdf4;
    border-left: 3px solid #10b981;
}

.agenda-row-main {
    display: grid;
    grid-template-columns: 2fr 0.8fr 0.6fr 1.5fr 0.8fr;
    gap: clamp(8px, 1.2vw, 12px);
    align-items: center;
    width: 100%;
    min-height: clamp(30px, 4vh, 40px);
}

.agenda-row-header {
    display: grid;
    grid-template-columns: 2fr 0.8fr 0.6fr 1.5fr 0.8fr;
    gap: clamp(8px, 1.2vw, 12px);
    align-items: center;
    padding: 10px 12px;
    font-size: clamp(11px, 1.3vw, 13px);
    font-weight: 700;
    color: #334155;
    border-bottom: 2px solid #cbd5e1;
    background: #e2e8f0;
    letter-spacing: 0.02em;
}

.agenda-tavolo-wrap {
    display: flex;
    align-items: center;
    min-width: 0;
    position: relative;
    z-index: 2;
    cursor: pointer;
}

.agenda-tavolo-select {
    width: 100%;
    max-width: 80px;
    min-width: 56px;
    padding: 6px 8px;
    font-size: clamp(11px, 1.3vw, 13px);
    border-radius: 6px;
    border: 1px solid var(--border-color, #ddd);
    background: var(--input-bg, #fff);
    color: var(--text-color, #333);
    cursor: pointer;
    pointer-events: auto;
    position: relative;
    z-index: 2;
}

.agenda-coperti {
    font-weight: 700;
    text-align: center;
    color: #1e293b;
}

.agenda-note {
    font-size: clamp(10px, 1.2vw, 12px);
    color: #475569;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.agenda-row-status {
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.2vw, 12px);
    flex-wrap: wrap;
    font-size: clamp(11px, 1.5vw, 13px);
    width: 100%;
    margin-top: clamp(2px, 0.5vw, 4px);
}

.agenda-stato-badge {
    padding: 5px 12px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.agenda-stato-attesa {
    background: #fef3c7;
    color: #78350f;
    border: 1px solid #f59e0b;
}

.agenda-stato-avvisato {
    background: #dbeafe;
    color: #1e3a8a;
    border: 1px solid #3b82f6;
}

.agenda-stato-confermato {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #10b981;
}

.agenda-stato-rifiutato,
.agenda-stato-noshow {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #dc2626;
}

.agenda-row-coda {
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
}

.agenda-row-coda-avvisato {
    background: #dbeafe;
    border-left: 3px solid #3b82f6;
}

.agenda-row-coda-confermata {
    background: #d1fae5;
    border-left: 3px solid #10b981;
}

.agenda-stato-timeout {
    background: #fef3c7;
    color: #92400e;
}

.agenda-row-coda-timeout {
    background: #fef3c7;
    border-left: 3px solid #b45309;
}

.agenda-row-coda-annullata {
    background: #fee2e2;
    border-left: 3px solid #ef4444;
    opacity: 0.7;
}

.agenda-coda-actions {
    display: inline-flex;
    gap: 8px;
    margin-left: 12px;
    flex-wrap: wrap;
    align-items: center;
}
.agenda-btn-avvisa,
.agenda-btn-annulla {
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.agenda-btn-avvisa {
    background: #3b82f6;
    color: #fff;
}
.agenda-btn-avvisa:hover {
    background: #2563eb;
}
.agenda-btn-annulla {
    background: #6b7280;
    color: #fff;
}
.agenda-btn-annulla:hover {
    background: #4b5563;
}
.agenda-row-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.agenda-timer {
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.agenda-timer-ok {
    background: #d1fae5;
    color: #065f46;
}

.agenda-timer-warning {
    background: #fee2e2;
    color: #991b1b;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

.agenda-cognome {
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: clamp(6px, 1vw, 10px);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

body.dark-mode .agenda-cognome {
    color: var(--text-color);
}

.agenda-cognome i {
    color: var(--theme-primary);
    font-size: 12px;
    opacity: 0.7;
}

.agenda-persone {
    text-align: center;
    color: #666;
    display: flex;
}

body.dark-mode .agenda-persone {
    color: #b0b0b0;
}
    align-items: center;
    justify-content: center;
    gap: clamp(4px, 0.8vw, 8px);
    min-width: fit-content;
    white-space: nowrap;
}

.agenda-persone i {
    color: #666;
    font-size: 12px;
    opacity: 0.7;
}

.agenda-orario {
    text-align: right;
    font-weight: 700;
    color: #4338ca;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: clamp(4px, 0.8vw, 8px);
    min-width: fit-content;
    white-space: nowrap;
}

.agenda-orario i {
    color: var(--theme-primary);
    font-size: 12px;
    opacity: 0.7;
}

/* Dark mode per agenda */
body.dark-mode .agenda-container {
    background: var(--panel-bg);
}

body.dark-mode .agenda-header,
body.dark-mode .agenda-column {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
}

body.dark-mode .agenda-date-number {
    color: var(--theme-primary);
}

/* ==================== SEZIONE STATISTICHE ==================== */

/* Tab Statistiche: larghezza dinamica (full width del container) */
#tab-content-statistiche.tab-content {
    display: none;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}
#tab-content-statistiche.tab-content.active {
    display: flex !important;
    flex-direction: column !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 0;
    align-items: stretch;
}
#tab-content-statistiche .statistiche-container {
    flex: 1;
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.statistiche-container {
    width: 100%;
    max-width: 100%;
    padding: clamp(10px, 2vw, 24px);
    box-sizing: border-box;
    margin: 0;
    min-width: 0;
}

.statistiche-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: clamp(10px, 1.5vw, 20px); /* Margine ridotto */
    padding-bottom: clamp(10px, 1.5vw, 15px); /* Padding ridotto */
    border-bottom: 2px solid var(--border-color);
}

.statistiche-header h2 {
    font-size: clamp(24px, 3vw, 32px);
    color: var(--text-color);
    margin: 0;
    display: flex;
    align-items: center;
    gap: clamp(10px, 1.5vw, 15px);
}

.btn-refresh {
    padding: clamp(8px, 1.2vw, 12px) clamp(16px, 2vw, 24px);
    background: var(--theme-primary);
    color: white;
    border: none;
    border-radius: clamp(6px, 0.8vw, 8px);
    cursor: pointer;
    font-size: clamp(13px, 1.6vw, 15px);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: clamp(6px, 0.8vw, 8px);
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    background: #5568d3;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.btn-refresh:active {
    transform: translateY(0);
}

/* Grid a larghezza dinamica: 1 col sotto 400px, 2 colonne fino a 900px, poi si espandono */
.statistiche-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    gap: clamp(12px, 1.5vw, 20px);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    min-width: 0;
    margin: 0;
    padding: 0;
}

/* Prevenzione sovrapposizioni su Safari per la sezione Statistiche */
@supports (-webkit-appearance: none) {
    .statistiche-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr));
    }
}

.statistica-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: clamp(10px, 1.5vw, 12px);
    box-shadow: 0 2px 8px var(--shadow);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    min-width: 0; /* Previene overflow su Safari */
    box-sizing: border-box;
    width: 100%; /* Si espande a tutta la larghezza disponibile */
    max-width: 100%; /* Nessun limite di larghezza massima */
}

.statistica-panel:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow);
}

.statistica-panel.panel-full-width {
    grid-column: 1 / -1; /* Full width quando necessario */
    min-width: 0;
}

.statistica-panel .panel-header {
    padding: clamp(10px, 1.2vw, 15px); /* Padding ridotto per sfruttare tutto lo schermo */
    background: linear-gradient(135deg, var(--theme-primary) 0%, var(--theme-secondary) 100%);
    color: white;
    border-bottom: 2px solid var(--border-color);
}

.statistica-panel .panel-header h3 {
    margin: 0;
    font-size: clamp(16px, 2vw, 20px);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.2vw, 12px);
}

.statistica-panel .panel-content {
    padding: clamp(10px, 1.2vw, 15px); /* Padding ridotto per sfruttare tutto lo schermo */
    min-height: 250px;
    position: relative;
    width: 100%;
    box-sizing: border-box;
}

.statistica-panel canvas {
    max-height: 300px;
}

.stats-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* 2 colonne dinamiche */
    gap: clamp(12px, 1.5vw, 18px);
    min-width: 0; /* Previene overflow su Safari */
    box-sizing: border-box;
}

/* Prevenzione sovrapposizioni su Safari per stats-detail-grid */
@supports (-webkit-appearance: none) {
    .stats-detail-grid {
        grid-template-columns: repeat(2, 1fr); /* Mantiene 2 colonne anche su Safari */
    }
}

.stat-detail-item {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: clamp(8px, 1.2vw, 10px);
    padding: clamp(15px, 2vw, 20px);
    text-align: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-detail-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow);
}

.stat-detail-label {
    font-size: clamp(12px, 1.6vw, 14px);
    color: #666;
    margin-bottom: clamp(8px, 1.2vw, 12px);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(6px, 0.8vw, 8px);
}

.stat-detail-value {
    font-size: clamp(24px, 3vw, 32px);
    font-weight: 700;
    color: var(--theme-primary);
}

body.dark-mode .stat-detail-label {
    color: #b0b0b0;
}

body.dark-mode .stat-detail-item {
    background: var(--panel-bg);
    border-color: var(--border-color);
}

/* Responsive per statistiche */
@media (max-width: 768px) {
    .statistiche-grid {
        grid-template-columns: 1fr;
    }
    
    .statistica-panel.panel-full-width {
        grid-column: 1;
    }
    
    .statistiche-header {
        flex-direction: column;
        align-items: flex-start;
        gap: clamp(10px, 1.5vw, 15px);
    }
    
    .stats-detail-grid {
        grid-template-columns: 1fr; /* Una colonna su mobile */
    }
}

/* Tablet - 2 colonne con gap ridotto */
@media (min-width: 769px) and (max-width: 1024px) {
    .statistiche-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: clamp(12px, 1.5vw, 20px);
    }
}

body.dark-mode .agenda-day-month {
    color: var(--text-color);
}

body.dark-mode .agenda-date-filter-str {
    color: var(--text-muted, #999);
}

body.dark-mode .agenda-column-header {
    color: var(--text-color);
}

body.dark-mode .agenda-row-header {
    background: var(--panel-bg);
    color: var(--text-color);
    border-bottom-color: var(--border-color);
}

body.dark-mode .agenda-row {
    border-bottom-color: var(--border-color);
    color: var(--text-color);
    background: var(--panel-bg);
}

body.dark-mode .agenda-row:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

body.dark-mode .agenda-row:hover {
    background: #2a2a2a;
    border-color: var(--theme-primary);
}

body.dark-mode .agenda-row-arrivato {
    background: #1a3a2a;
}

body.dark-mode .agenda-row-coda {
    background: #3a2e1a;
}

/* Dark mode per elementi aggiuntivi */
body.dark-mode h1, body.dark-mode h2, body.dark-mode h3 {
    color: var(--text-color);
}

/* ==================== FIX SAFARI AGGIUNTIVI ==================== */
/* Fix per rendering font su Safari */
body,
input,
textarea,
select,
button {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

/* Fix per subpixel rendering su Safari */
.stat-value,
.stat-label,
.prenotazione-cognome {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

/* Fix per will-change su Safari (performance) */
.stat-card,
.prenotazione-card,
.panel,
.tab-btn {
    will-change: transform;
    -webkit-will-change: transform;
}

/* Fix per contain su Safari */
.container,
.tab-content,
.panel {
    contain: layout style;
    -webkit-contain: layout style;
}

/* Fix per aspect-ratio su Safari (se usato) */
.stat-icon {
    aspect-ratio: 1 / 1;
    -webkit-aspect-ratio: 1 / 1;
}

/* Fix per object-fit su Safari */
img {
    object-fit: contain;
    -webkit-object-fit: contain;
}

/* Fix per filter su Safari */
.stat-card:hover,
.prenotazione-card:hover {
    -webkit-filter: brightness(1.02);
    filter: brightness(1.02);
}

/* Fix per appearance su Safari */
input[type="checkbox"],
input[type="radio"] {
    -webkit-appearance: checkbox;
    appearance: checkbox;
}

input[type="range"] {
    -webkit-appearance: slider-horizontal;
    appearance: slider-horizontal;
}

/* Fix per selection su Safari */
::selection {
    background: rgba(102, 126, 234, 0.3);
    color: inherit;
}

::-moz-selection {
    background: rgba(102, 126, 234, 0.3);
    color: inherit;
}

/* Fix per focus outline su Safari */
*:focus {
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

*:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Fix per touch-action su Safari mobile */
@media (max-width: 768px) {
    .panel-content,
    .prenotazioni-list,
    .clienti-list {
        touch-action: pan-y;
        -webkit-touch-action: pan-y;
    }
    
    button,
    .tab-btn,
    .filter-btn {
        touch-action: manipulation;
        -webkit-touch-action: manipulation;
    }
}

/* Fix per overscroll-behavior su Safari */
body,
html {
    overscroll-behavior: none;
    -webkit-overscroll-behavior: none;
}

/* Fix per position fixed su Safari iOS */
.modal {
    position: fixed;
    -webkit-position: fixed;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
}

/* Fix per calc() con clamp() su Safari */
@media (min-width: 769px) {
    .container {
        min-height: calc(100vh - 20px);
        min-height: -webkit-calc(100vh - 20px);
    }
}

/* Fix per grid-auto-rows su Safari */
.stats-grid {
    grid-auto-rows: minmax(55px, auto);
    -webkit-grid-auto-rows: minmax(55px, auto);
}

/* Fix per gap con fallback margin su Safari < 14.1 */
@supports not (gap: 1px) {
    .stats-grid {
        margin: 0 -6px;
    }
    
    .stats-grid .stat-card {
        margin: 0 6px;
    }
    
    .panel-header {
        margin: 0 -6px;
    }
    
    .panel-header > * {
        margin: 0 6px;
    }
    
    .filters {
        margin: 0 -6px;
    }
    
    .filters .filter-btn {
        margin: 0 6px;
    }
}

/* Fix per min() e max() su Safari < 13.1 */
@media (max-width: 768px) {
    .stat-card {
        min-width: 100px;
    }
    
    @supports (min-width: 100px) {
        .stat-card {
            min-width: min(100px, 20vw);
        }
    }
}

/* ==================== PERFORMANCE SAFARI ==================== */
/* Ottimizzazioni performance per Safari */
.safari-browser .stat-card,
.safari-browser .prenotazione-card,
.safari-browser .panel {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    -webkit-perspective: 1000;
    perspective: 1000;
}

/* Riduci animazioni su Safari per migliorare performance */
@media (prefers-reduced-motion: no-preference) {
    .safari-browser * {
        -webkit-animation-duration: 0.3s;
        animation-duration: 0.3s;
        -webkit-transition-duration: 0.3s;
        transition-duration: 0.3s;
    }
}

/* Disabilita animazioni se l'utente preferisce movimento ridotto */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        -webkit-animation-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        -webkit-transition-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Fix per rendering compositing su Safari */
.safari-browser .modal,
.safari-browser .toast,
.safari-browser .panel-header {
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-perspective: 1000;
    perspective: 1000;
}

/* Fix per GPU acceleration su Safari */
.safari-browser .stat-card:hover,
.safari-browser .prenotazione-card:hover,
.safari-browser .tab-btn:hover {
    -webkit-transform: translateY(-1px) translateZ(0);
    transform: translateY(-1px) translateZ(0);
}

/* Fix per scroll performance su Safari */
.safari-browser .panel-content,
.safari-browser .prenotazioni-list,
.safari-browser .clienti-list {
    -webkit-overflow-scrolling: touch;
    overflow-scrolling: touch;
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
}

body.dark-mode .panel-header h2 {
    color: var(--text-color);
}

body.dark-mode .panel-header h2 i {
    color: var(--theme-primary);
}

body.dark-mode .statistica-panel {
    background: var(--panel-bg);
    border-color: var(--border-color);
}

body.dark-mode .statistica-panel .panel-header {
    background: var(--panel-bg);
    border-bottom-color: var(--border-color);
}

body.dark-mode .statistica-panel .panel-header h3 {
    color: var(--text-color);
}

body.dark-mode .statistica-panel .panel-header h3 i {
    color: var(--theme-primary);
}

/* Responsive agenda: pulsante compatto (aereo + g) e campo data compresso */
@media (max-width: 768px) {
    .agenda-content-grid {
        grid-template-columns: 1fr;
    }
    
    .agenda-header {
        padding: 10px 12px;
        gap: 8px;
    }
    
    .agenda-date-info {
        gap: 8px;
        flex: 1;
        min-width: 0;
    }
    
    .agenda-date-number {
        font-size: 36px;
    }
    
    .agenda-date-details {
        font-size: 12px;
    }
    
    .agenda-day-month {
        font-size: clamp(14px, 3.5vw, 18px);
    }
    
    .agenda-nav-btn {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    /* Pulsante Invia tavoli: icona aereo + "g", compatto */
    .agenda-push-tavoli-btn .agenda-push-icon-desktop,
    .agenda-push-tavoli-btn .agenda-push-text-full {
        display: none !important;
    }
    .agenda-push-tavoli-btn .agenda-push-icon-mobile,
    .agenda-push-tavoli-btn .agenda-push-text-short {
        display: inline !important;
    }
    .agenda-push-tavoli-btn {
        padding: 6px 10px;
        font-size: 12px;
    }
}
