/* Layout Generale Dashboard */
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden; /* Evita scrollbar sulla pagina intera, gestiamo lo scroll nei pannelli */
    font: 95% / 1 "Trebuchet MS", "Lucida Grande", Lucida, Verdana, sans-serif !important;
	font-family: "Trebuchet MS", "Lucida Grande", Lucida, Verdana, sans-serif !important;
    background-color: #f5f7fa;
}

/* --- LOGIN OVERLAY --- */
#login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: linear-gradient(135deg, rgba(84, 22, 146, 0.8), rgba(231, 143, 8, 0.8)), url(sfondo_25.jpg);
    background-size: cover;
    background-blend-mode: overlay;
    z-index: 5000;
    display: flex;
    align-items: center;
    justify-content: center;
}

#login-box {
    width: 350px;
    background: #fff;
    padding: 0;
    box-shadow: 0 15px 35px rgba(0,0,0,0.3);
    border: none;
    border-radius: 12px;
    overflow: hidden;
}

#login-form { padding: 30px; }

#login-form label {
    font-weight: bold;
    color: #555;
    font-size: 0.9em;
    margin-bottom: 5px;
    display: block;
}

#login-form input {
    margin-bottom: 15px;
    padding: 12px !important;
}

body.auth-pending #app-container {
    filter: blur(5px);
    pointer-events: none;
}

.ui-widget, .ui-widget input, .ui-widget select, .ui-widget textarea {
    font: "Trebuchet MS", "Lucida Grande", Lucida, Verdana, sans-serif !important;
    font-family: "Trebuchet MS", "Lucida Grande", Lucida, Verdana, sans-serif !important;
}

#app-container {
    display: flex;
    height: 100dvh; /* Altezza dinamica che si adatta alla presenza/assenza della barra indirizzi */
    width: 100vw;
}

/* --- SIDEBAR --- */
#sidebar {
    width: 240px;
    flex-shrink: 0;
    border-right: 1px solid #dce0e6;
    background: #fff;
    display: flex;
    flex-direction: column;
    z-index: 150; /* Deve essere superiore ai nomi dei mezzi (110) e all'angolo (120) */
    box-shadow: 2px 0 5px rgba(0,0,0,0.05);
}

.app-logo {
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 20px;
    font-size: 1.4em;
    font-weight: bold;
    color: #e78f08; /* Colore tema Cupertino header */
    border-bottom: 1px solid #eee;
}

.app-logo i {
    margin-right: 10px;
    font-size: 1.5em;
}

#main-menu {
    padding: 20px 10px;
    flex-grow: 1;
    overflow-y: auto;
}

/* Stile bottoni menu verticali */
.menu-item {
    display: block;
    width: 100%;
    box-sizing: border-box; /* Include padding e border nella larghezza totale */
    text-align: left;
    margin-bottom: 8px;
    padding: 10px 15px;
    cursor: pointer;
    border-radius: 4px;
    text-decoration: none;
    color: #444;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.menu-item:hover {
    background-color: #fdf5ce; /* Colore hover Cupertino */
    border-color: #fbcb09;
    color: #c77405;
}

.menu-item.active {
    background-color: #e78f08; /* Colore active Cupertino */
    color: #fff;
    border-color: #e78f08;
    font-weight: bold;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.menu-item i {
    display: inline-block;
    vertical-align: middle;
    margin-right: 12px;
    width: 20px;
    text-align: center;
    font-size: 1.3em;
}


/* --- MAIN CONTENT --- */
#main-wrapper {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Importante per far funzionare lo scroll orizzontale del Gantt dentro flex */
    background-color: #f5f7fa;
}

#top-bar {
    height: 60px;
    background-color: #fff;
    border-bottom: 1px solid #dce0e6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    flex-shrink: 0;
    z-index: 140; /* Sopra il planning ma sotto la sidebar */
}

#page-title {
    font-size: 1.5em;
    color: #555;
    font-weight: normal;
}

#page-title i {
    display: inline-block;
    vertical-align: middle;
    margin-right: 15px;
    margin-top: -3px;
    font-size: 1.2em;
}

.role-admin { color: #541692; } /* Viola per Amministratore */
.role-operator { color: #e78f08; } /* Arancio per Operatore */
.role-admin i, .role-operator i { margin-right: 8px; }

#user-info {
    position: relative;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.2s;
    user-select: none;
    font-weight: bold;
    font-size: 0.95em;
}
#user-info:hover { background: rgba(0,0,0,0.05); }

#user-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    width: 200px;
    margin-top: 5px;
    z-index: 4000;
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
    
    border: 1px solid #ddd;
    display: none;
    padding: 5px 0;
}

.dropdown-item {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: #444;
    font-size: 0.9em;
    transition: background 0.2s;
    border-bottom: 1px solid #eee;
}
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: #f8f9fa; color: #e78f08; }
.dropdown-item i { margin-right: 10px; width: 18px; text-align: center; }

#content-area {
    flex-grow: 1;
    padding: 10px;
    overflow: auto; /* Scrolla il contenuto se necessario */
    position: relative;
    background-image: url(sfondo_25.jpg);
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover;
    background-color: #fff;
}

/* --- DASHBOARD WIDGETS --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    padding: 10px;
}

.widget-box {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-top: 4px solid #e78f08;
    display: flex;
    flex-direction: column;
}

.widget-box h3 {
    margin: 0 0 15px 0 !important;
    font-size: 1.1em !important;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    font-weight: bold;
}

.widget-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.widget-list li {
    padding: 10px 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 0.9em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.widget-list li:last-child { border-bottom: none; }

.stats-flex {
    display: flex;
    justify-content: space-around;
    text-align: center;
    padding: 10px 0;
}

.stat-val { font-size: 2em; font-weight: bold; color: #e78f08; }
.stat-item small { color: #888; text-transform: uppercase; font-size: 0.75em; }

#dashboard-quick-notes {
    height: 120px !important;
    resize: none !important;
    font-family: inherit !important;
    background-color: #fafafa !important;
}
#dashboard-quick-notes:focus { background-color: #fff !important; }

/* --- Grafico a Barre CSS --- */
.chart-container {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    height: 120px;
    padding-top: 25px;
    margin-top: 10px;
}
.chart-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}
.chart-bar {
    width: 60%;
    background: #e78f08;
    border-radius: 4px 4px 0 0;
    transition: height 1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    min-height: 2px;
}
.chart-bar:hover { background: #541692; }
.chart-bar::after {
    content: attr(data-value);
    position: absolute;
    top: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8em;
    font-weight: bold;
}
.bar-label { font-size: 0.7em; color: #888; text-transform: uppercase; }

.widget-box.clickable { cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; }
.widget-box.clickable:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0,0,0,0.12); }

/* --- Layout Form nelle Modali --- */
/* --- Layout Form nelle Modali (Desktop & Mobile) --- */
/* --- Struttura Universale Modali Scorrevoli --- */
.ui-dialog {
    max-height: 85dvh !important; 
    position: fixed !important; /* Rimane fissa nella viewport */
    flex-direction: column !important;
    box-shadow: 0 5px 25px rgba(0,0,0,0.3) !important;
    overflow: hidden !important;
    z-index: 3000; /* Base alta per stare sopra sidebar/header, ma senza !important per permettere la sovrapposizione tra modali */
}

/* Applica il layout flex solo quando la modale è effettivamente aperta (non ha display:none) */
.ui-dialog:not([style*="display: none"]) {
    display: flex !important;
}

.ui-dialog .ui-dialog-content {
    flex: 1 1 auto !important; /* Il contenuto occupa lo spazio centrale */
    overflow-y: auto !important; 
    padding: 20px !important;
    -webkit-overflow-scrolling: touch;
}

.ui-dialog .ui-dialog-buttonpane {
    flex: 0 0 auto !important; /* I pulsanti restano sempre fissi in basso */
    margin-top: 0 !important;
    background: #fff;
    border-top: 1px solid #eee !important;
}

/* --- Layout Form nelle Modali --- */
/* --- Layout Form nelle Modali (Desktop & Mobile) --- */
.form-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    margin-bottom: 15px;
    align-items: flex-end; /* Allinea gli input se le label hanno lunghezze diverse */
}

.form-row > div {
    display: flex;
    flex-direction: column;
    min-width: 0; /* Previene overflow dei flex item */
}

.form-row label {
    font-weight: bold;
    margin-bottom: 5px;
    color: #555;
    font-size: 0.85em;
}

.readonly-code {
    background-color: #f0f0f0 !important;
    color: #999 !important;
    cursor: default;
    border: 1px solid #ddd !important;
}

/* Reset per tutti gli input nelle modali */
input.text, select, textarea {
    width: 100% !important;
    box-sizing: border-box !important;
    padding: 10px !important;
    border: 1px solid #ced4da !important;
    border-radius: 4px !important;
    background-color: #fff !important;
    transition: border-color 0.2s, box-shadow 0.2s !important;
    font-size: 14px !important;
}

input.text:focus, select:focus, textarea:focus {
    border-color: #e78f08 !important;
    outline: 0 !important;
    box-shadow: 0 0 0 0.2rem rgba(231, 143, 8, 0.15) !important;
}

/* Stile Toolbar per le sezioni (Mezzi, Contratti, Scadenze, Clienti) */
.section-toolbar {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    flex-wrap: nowrap !important; /* Forza una riga sola */
    overflow-x: auto !important; /* Permette lo scorrimento orizzontale su schermi piccoli */
    padding: 10px !important;
    margin-bottom: 15px !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap !important;
}

.section-toolbar input.text, 
.section-toolbar select {
    width: auto !important;
    min-width: 160px !important;
    flex-shrink: 0 !important;
}

.password-wrapper {
    position: relative;
    width: 100%;
}

.password-wrapper input {
    padding-right: 40px !important;
}

.toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: #adb5bd;
    z-index: 10;
    transition: color 0.2s;
}

.toggle-password:hover {
    color: #e78f08;
}

.short-text {
    display: none;
}

/* --- VISTE (Tabs) --- */
.app-view {
    display: none; 
    min-width: 100%;
    height: auto;
}

.app-view.active {
    display: block; 
    width: fit-content; /* Permette alla vista di espandersi con il grafico */
    min-width: 100%;
}

/* Stili specifici per la griglia anagrafica (Demo) */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #ddd;
}
.data-table th {
    background: #eff3f8;
    padding: 12px;
    text-align: left;
    border-bottom: 2px solid #ddd;
    color: #555;
}
.data-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
}
.data-table tr:hover { background: #f9f9f9; }

/* --- Report Boxes (Stampe & Report) --- */
.report-box {
    background-color: #fff;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 4px;
    min-width: 300px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.report-box h4 {
    font-weight: bold;
    color: #555;
}

.report-button {
    margin-top: auto;
    padding: 8px 15px !important;
}

#update-notification {
    border: 1px solid #444;
    animation: slideInLeft 0.5s ease-out;
}

/* --- Badge Notifiche Scadenze --- */
.bell-badge {
    position: absolute;
    top: 5px;
    left: 26px; /* Posizionato sopra l'icona della campana */
    background-color: #dc3545;
    color: #fff;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 0.7em;
    font-weight: bold;
    line-height: 1;
    z-index: 10;
    pointer-events: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

/* --- Animazione Scuotimento Campana --- */
@keyframes bell-shake {
    0% { transform: rotate(0); }
    10% { transform: rotate(20deg); }
    20% { transform: rotate(-20deg); }
    30% { transform: rotate(15deg); }
    40% { transform: rotate(-15deg); }
    50% { transform: rotate(10deg); }
    60% { transform: rotate(-10deg); }
    100% { transform: rotate(0); }
}

.bell-shake {
    display: inline-block !important; /* Necessario per le trasformazioni */
    animation: bell-shake 1.2s cubic-bezier(0.36, 0.07, 0.19, 0.97) infinite;
    color: #dc3545 !important; /* Rosso alert */
}

/* Stile monospaziato per le liste autocomplete (Articoli e Clienti) */
.ui-autocomplete {
    font-family: monospace !important;
    font-size: 0.85em !important;
    white-space: pre;
    max-height: 350px;
    overflow-y: auto;
    overflow-x: hidden; /* Previene la comparsa della barra di scorrimento orizzontale */
    max-width: 95vw; /* Impedisce alla tendina di uscire dai bordi dello schermo */
    box-sizing: border-box;
    z-index: 3100 !important; /* Deve essere superiore ai 3000 della modale */
}

/* Rimuove l'effetto grassetto sull'elemento selezionato per evitare micro-spostamenti del layout */
.ui-autocomplete .ui-menu-item-wrapper.ui-state-active {
    font-weight: normal !important;
}

/* Spinner di caricamento per Autocomplete */
.ui-autocomplete-loading {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' preserveAspectRatio='xMidYMid' width='20' height='20'%3E%3Ccircle cx='50' cy='50' fill='none' stroke='%23e78f08' stroke-width='10' r='35' stroke-dasharray='164.93361431346415 56.97787143782138'%3E%3CanimateTransform attributeName='transform' type='rotate' repeatCount='indefinite' dur='1s' values='0 50 50;360 50 50' keyTimes='0;1'/%3E%3C/circle%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 10px center !important;
}

/* Badge per eventi inviati a Mexal (pallino viola) */
.ganttview-block-mexal-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 8px;
    height: 8px;
    background-color: #541692; /* Colore viola del tema */
    border-radius: 50%;
    border: 1px solid #fff;
    box-shadow: 0 0 2px rgba(0,0,0,0.5);
}

/* Icona Lucchetto per blocchi protetti (bottom-right) */
.ganttview-block-lock {
    position: absolute;
    bottom: 3px;
    right: 3px;
    font-size: 0.7em;
    color: #fff;
    opacity: 0.7;
    pointer-events: none;
}

/* Animazione Shake per blocchi protetti */
@keyframes shake {
    0% { transform: translate(1px, 1px) rotate(0deg); }
    10% { transform: translate(-1px, -2px) rotate(-1deg); }
    20% { transform: translate(-3px, 0px) rotate(1deg); }
    30% { transform: translate(3px, 2px) rotate(0deg); }
    40% { transform: translate(1px, -1px) rotate(1deg); }
    50% { transform: translate(-1px, 2px) rotate(-1deg); }
    60% { transform: translate(-3px, 1px) rotate(0deg); }
    70% { transform: translate(3px, 1px) rotate(-1deg); }
    80% { transform: translate(-1px, -1px) rotate(1deg); }
    90% { transform: translate(1px, 2px) rotate(0deg); }
    100% { transform: translate(1px, -2px) rotate(-1deg); }
}

.shake-animation {
    animation: shake 0.5s;
    animation-iteration-count: 1;
}

/* Nasconde le maniglie di ridimensionamento se l'evento ha il lucchetto */
.ganttview-block:has(.ganttview-block-lock) .ui-resizable-handle {
    display: none !important;
}

/* Validazione Conducente */
.invalid-driver {
    border: 1px solid #dc3545 !important;
    background-color: #fff5f5 !important;
}

/* Evidenziazione mezzi senza Codice Articolo */
.resource-missing-code td {
    background-color: #ffe6e6 !important; /* Rosso chiarissimo */
}

.resource-missing-code td:first-child {
    border-left: 4px solid #cd0a0a;
}

/* Link PDF compatto */
.pdf-link-short {
    text-decoration: none;
    color: #0d6efd;
    font-weight: bold;
    white-space: nowrap;
}

/* --- Sticky Header Logic --- */
/* --- Sticky Layout Logic --- */
.ganttview-hzheader {
    position: sticky !important; 
    top: 0; /* Si blocca al top del #content-area */
    z-index: 105; /* Sopra la griglia e i blocchi */
    touch-action: pan-x pan-y !important;
    cursor: grab;
}

.ganttview-slide-container {
    overflow-y: visible !important; 
    position: relative !important; /* Fondamentale: i blocchi (absolute) ora restano ancorati alla griglia temporale */
}

.ganttview-vtheader-sticky-corner {
    position: sticky !important; /* Preserva l'altezza dell'header e allinea correttamente la prima riga dei nomi */
    top: 0;
    left: 0;
    z-index: 120; /* L'elemento più in alto di tutti */
    border-bottom: 1px solid #ddd;
    touch-action: none !important;
}

#ganttChart {
    width: fit-content;
    min-width: 100%;
}

/* --- Fix Anti-Collasso Griglia Gantt --- */
div.ganttview {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    width: auto !important; /* Lascia che sia il contenuto a decidere */
    min-width: 100%;
    box-sizing: border-box;
    overflow: visible !important; /* Fondamentale per far funzionare lo sticky dei figli */
    border: 1px solid #ddd;
    background: #fff;
}

div.ganttview-vtheader {
    float: none !important;
    flex-shrink: 0 !important;
    position: sticky !important;
    left: 0;
    z-index: 110; /* Sopra la griglia e i blocchi (50), sotto l'angolo (120) */
    touch-action: pan-y !important;
    background-color: #fff;
}

div.ganttview-slide-container {
    float: none !important;
    flex-grow: 1 !important;
    min-width: 0 !important; /* Cruciale per permettere lo scroll interno in flex */
    width: auto !important; /* Rimuove il blocco alla larghezza dello schermo */
    overflow-x: visible !important; 
    overflow-y: visible !important; 
    -webkit-overflow-scrolling: touch; /* Scrolling fluido su iOS */
    touch-action: pan-x pan-y !important; /* Permette al browser di gestire entrambi gli scroll */
}

/* Piccoli aggiustamenti specifici per i componenti interni */
#gantt-toolbar {
    background-color: #fff;
    border-bottom: 1px solid #dce0e6;
    display: none; /* Nascosta all'avvio */
    justify-content: space-between; 
    align-items: center; 
    padding: 10px 30px;
    flex-shrink: 0;
    box-sizing: border-box;
    z-index: 135;
}
.section-box {
    background: #fff;
    padding: 20px;
    border: 1px solid #dce0e6;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.section-box .ui-state-default i {
    font-size: 1.3em;
    display: block;
}

.section-box h3 {
	font-size: 1.5em !important;
    margin-left: 2px;
}

#confirmDeleteDialog i {
    float: left;
    margin: 3px 7px 20px 0;
    font-size: 1.5em;
    color: #cd0a0a;
}

/* Stili per Scadenze */
.data-table tr.deadline-warning td {
    background-color: #faf0bf !important; /* Giallo chiaro */
}
.data-table tr.deadline-expired td {
    background-color: #f4bbb6 !important; /* Rosso chiaro */
    font-weight: bold;
}
/* Stile per scadenze completate */
.data-table tr.deadline-completed td {
    background-color: #f2f2f2 !important;
    color: #999;
    text-decoration: line-through;
}



/* --- Stile Lista Allegati (Chips) --- */
.attachment-list {
    list-style: none;
    padding: 0;
    margin: 5px 0 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 0.9em;
    color: #333;
    text-decoration: none;
    transition: all 0.2s;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.attachment-link:hover {
    background-color: #f8f9fa;
    border-color: #bbb;
    color: #000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.attachment-link i { margin-right: 6px; color: #666; font-size: 1.1em; }

/* Stile pulsante elimina allegato */
.btn-del-res-file {
    border: none;
    background: none;
    color: #cd0a0a;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.btn-del-res-file:hover {
    opacity: 1;
    color: #ff0000;
}

.btn-del-deadline-file {
    border: none;
    background: none;
    color: #cd0a0a;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.btn-del-deadline-file:hover {
    opacity: 1;
    color: #ff0000;
}

/* --- Checklist Styles (Mobile Friendly) --- */
.checklist-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px;
    margin-top: 10px;
}

.checklist-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
}
.checklist-item:active { background: #f0f0f0; }
.checklist-item input[type="checkbox"] {
    width: 22px;
    height: 22px;
    margin-right: 15px;
    cursor: pointer;
}
.checklist-item label { margin: 0; cursor: pointer; flex-grow: 1; font-weight: normal !important; }

/* Icone colorate per tipo */
.attachment-link i.fa-file-pdf { color: #dc3545; }
.attachment-link i.fa-file-image { color: #198754; }
.attachment-link i.fa-file-word { color: #0d6efd; }
.attachment-link i.fa-file-excel { color: #198754; }

/* --- Bookings Drawer (in Sidebar) --- */
#bookings-drawer {
    position: fixed;
    top: 0;
    right: -320px; /* Nascosto a destra */
    width: 300px;
    height: 100dvh;
    background: #fff;
    z-index: 2500; /* Sopra a tutto */
    box-shadow: -5px 0 15px rgba(0,0,0,0.1);
    transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex !important;
    flex-direction: column;
    border-left: 1px solid #dce0e6;
}

#bookings-drawer.open {
    right: 0;
}

.drawer-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8f9fa;
}

.drawer-header h4 { margin: 0; font-weight: bold; color: #555; }

#bookings-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
}

#bookings-list .external-event {
    display: block; /* Vertical list */
    margin-bottom: 10px;
    padding: 10px;
    cursor: move;
    font-size: 0.9em;
    line-height: 1.4;
    border: 1px solid #ccc;
    background: #fff;
    color: #333;
    border-radius: 4px;
}
#bookings-list .external-event:hover {
    border-color: #fbcb09;
    background-color: #fdf5ce;
}
#bookings-list .external-event strong {
    font-weight: bold;
    color: #3a87ad;
}
#bookings-list .external-event small {
    color: #777;
}

/* Badge for booking count */
.booking-count {
    float: right;
    background-color: #e74c3c;
    color: white;
    border-radius: 10px;
    padding: 2px 6px;
    font-size: 0.8em;
    font-weight: bold;
    margin-top: 2px;
}

/* Tabs Modale */
#movementModal .ui-tabs-panel {
    max-height: 480px;
    overflow-y: auto;
}

/* --- STILI DI STAMPA --- */
@media print {
    /* Nascondi elementi di navigazione e interfaccia */
    #sidebar, 
    #top-bar, 
    #gantt-toolbar,
    .ui-dialog, 
    .section-box,
    #bookings-drawer {
        display: none !important;
    }

    /* Reset layout per la stampa */
    html, body, #app-container, #main-wrapper, #content-area {
        height: auto !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background-color: #fff !important;
    }

    /* Forza la visualizzazione del Planning anche se siamo in un'altra tab */
    #view-planning {
        display: block !important;
    }

    /* Adattamenti specifici per il Gantt in stampa */
    div.ganttview {
        border: none;
        /* FLEXBOX FIX: Mantiene header e griglia sulla stessa riga evitando il "drop" */
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
    }
    
    /* Forza la stampa dei colori di sfondo (essenziale per le barre del Gantt) */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Header Verticale (Nomi) */
    div.ganttview-vtheader {
        float: none !important; /* Rimuove float che causa problemi */
        flex-shrink: 0 !important; /* Impedisce che si rimpicciolisca */
        position: relative !important;
        z-index: 1000 !important; /* Assicura che stia sopra agli eventi */
        background-color: #fff !important; /* Copre eventuali sbordature */
        border-right: 2px solid #ccc !important;
    }

    /* Se il grafico è molto largo, permettiamo lo scroll orizzontale o il taglio pulito */
    .ganttview-slide-container {
        float: none !important;
        overflow: visible !important;
        flex-grow: 1 !important;
        /* Sovrascrive la larghezza fissa JS per adattarsi al flex, ma lascia vedere il contenuto */
        width: auto !important; 
    }
}

/* --- OTTIMIZZAZIONE PER DISPOSITIVI MOBILE --- */
/* Attiviamo il layout compatto sotto i 992px di larghezza OPPURE se l'altezza è ridotta (Smartphone Landscape) */
@media (max-width: 992px), (max-height: 500px) {
    #sidebar {
        width: 65px;
        overflow: hidden;
    }

    .app-logo span, .menu-item strong, .menu-item span:not(.booking-count) {
        display: none !important;
    }

    .app-logo {
        padding: 0 !important;
        justify-content: center;
    }

    .menu-item i {
        margin-right: 0;
        font-size: 1.6em;
        width: 100%;
    }

    .menu-item {
        padding: 10px 0 !important;
        text-align: center;
    }
    
    .bell-badge {
        left: 50%;
        margin-left: 5px; /* Sposta il badge a destra dell'icona centrata */
    }

    #main-wrapper {
        width: calc(100vw - 65px);
    }

    #top-bar {
        padding: 0 15px;
        height: 45px; /* Riduciamo l'altezza della top bar */
    }

    #page-title {
        font-size: 1.1em;
    }

    /* Rende le modali jQuery UI responsive a tutto schermo */
    .ui-dialog {
        width: 100% !important;
        height: 100% !important;
        max-height: 100dvh !important;
        left: 0 !important;
        top: 0 !important;
        border: none !important;
        border-radius: 0 !important;
    }

    .form-row {
        flex-direction: column !important;
        gap: 15px !important; /* Più spazio per il touch */
        margin-bottom: 20px !important;
    }

    .form-row > div {
        width: 100% !important;
        flex: none !important;
    }

    /* Sblocca lo scroll verticale del browser sulle righe del Gantt */
    div.ganttview-grid-row {
        touch-action: pan-x pan-y !important;
    }

    /* Forza il contenitore a occupare tutto lo spazio e aggiunge aria in fondo */
    #content-area {
        padding-bottom: 150px !important; 
        display: flex;
        flex-direction: column;
    }

    /* --- Toolbar Planning Compatta --- */
    #gantt-toolbar {
        flex-wrap: nowrap !important;
        padding: 2px 5px !important;
        gap: 5px !important;
        justify-content: space-between !important;
        margin-bottom: 5px !important; /* Meno margine sotto la toolbar */
    }

    #gantt-toolbar #dateRangeLabel {
        min-width: auto !important;
        font-size: 0.9em !important;
        margin: 0 5px !important;
    }

    #resolution-controls {
        display: flex !important; /* Riattiviamo i bottoni */
        gap: 2px;
    }

    #resolution-controls .full-text {
        display: none !important;
    }

    #resolution-controls .short-text {
        display: inline !important;
        font-weight: bold;
    }

    #resolution-controls button {
        padding: 2px 6px !important;
        min-width: 28px;
    }

    #view-mode-controls {
        margin-left: 5px !important;
    }

    /* Nascondiamo il testo nei bottoni principali per lasciare solo icone */
    #btnViewVehicles span, #btnViewOperators span, #btnToday span {
        display: none !important;
    }

    #btnViewVehicles i, #btnViewOperators i, #btnToday i {
        margin-right: 0 !important;
    }

    /* Riduciamo il padding dell'area contenuti per guadagnare spazio */
    #content-area {
        padding: 0px !important;
    }

    /* Aumenta la dimensione degli input per il touch */
    input, select, textarea {
        font-size: 16px !important; /* Previene lo zoom automatico su iOS */
        padding: 10px !important;
    }

    .section-box {
        padding: 10px;
    }

    /* Ottimizzazione tendina autocomplete per mobile */
    .ui-autocomplete {
        max-height: 40dvh !important; /* Limita l'altezza al 40% del display per permettere lo scorrimento del form sottostante */
    }
}
