:root {
    /* Palette Light (Default) */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-body: #f3f4f6;       /* Grigio chiaro */
    --bg-card: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --input-bg: #ffffff;
    --nav-bg: #1e293b;
    --nav-text: #f8fafc;
    
    /* Status Colors */
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    
    /* Shadow & Radius */
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --radius: 12px;
}

/* Dark Theme Overrides */
/*[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --bg-body: #0f172a;        Slate 900 
    --bg-card: #1e293b;        Slate 800 
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --input-bg: #0f172a;
    --nav-bg: #020617;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}*/
/* DEFINIZIONE CORRETTA DARK MODE */
body[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --bg-body: #0f172a;       /* Blu scuro (Slate 900) */
    --bg-card: #1e293b;       /* Slate 800 */
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --input-bg: #0f172a;
    --nav-bg: #020617;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
}
/* Reset & Base */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
    /* Texture Sottile (Pattern a punti) */
    background-image: radial-gradient(var(--text-muted) 1px, transparent 1px);
    background-size: 20px 20px; /* Distanza tra i punti */
    background-attachment: fixed; /* L'effetto rimane fermo mentre scrolli */    
}

/* Riduciamo l'opacità dei punti in dark mode */
body[data-theme="dark"] {
    background-image: radial-gradient(rgba(255,255,255,0.1) 1px, transparent 1px);
}
/* Riduciamo l'opacità dei punti in light mode */
body:not([data-theme="dark"]) {
    background-image: radial-gradient(rgba(0,0,0,0.05) 1px, transparent 1px);
}

a {
    text-decoration: none;
    color: var(--primary);
    font-weight: 500;
}
a:hover {
    color: var(--primary-hover);
}

/* Layout */
.navbar {
    background-color: var(--nav-bg);
    padding: 0.8rem 1.5rem;
    color: var(--nav-text);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.navbar-brand a {
    font-weight: 700;
    font-size: 1.3rem;
    color: white;
    display: flex;
    align-items: center;
    gap: 8px;
}
.navbar-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.navbar-menu {
    display: flex;
    gap: 20px;
    align-items: center;
}
.navbar-menu a {
    color: #cbd5e1;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: color 0.2s;
}
.navbar-menu a:hover {
    color: white;
}
.logout-link {
    color: #fca5a5 !important;
}

.container {
    max-width: 1100px;
    margin: 2rem auto;
    padding: 0 20px;
}

/* Components: Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    justify-content: center;
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    transition: all 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.15);
    opacity: 0.95;
}
.btn-primary {
    background: var(--primary);
    color: white;
}
.btn-secondary {
  background: #a8a3a282;
  border: 1px solid var(--border);
  color: var(--text-main);
  box-shadow: none;
    
/*    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
    box-shadow: none;*/
}
.btn-danger {
    background: var(--danger);
    color: white;
}
.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.2s;
}
.icon-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* Components: Forms */
input, select {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}
label {
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* Components: Cards */
.card {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 25px;
    border: 1px solid var(--border);
}
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

/* Components: Tables */
.table-wrapper {
    overflow-x: auto;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
}
th {
    background-color: rgba(0,0,0,0.03);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
}
th, td {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
}
tr:last-child td {
    border-bottom: none;
}
tr:hover td {
    background-color: rgba(0,0,0,0.02);
}

/* Login Page Specifics */
/* Login Page Specifics */
body.auth-page {
    /* Rimuoviamo il background gradient specifico */
    /* background: var(--auth-bg); <--- RIMOSSO */
    
    /* Lasciamo che si vedano colore e puntini del body standard */
    min-height: 100vh; 
    display: flex; 
    align-items: center; 
    justify-content: center;
}
.auth-card { 
    width: 100%; 
    max-width: 400px; 
    background: var(--bg-card); /* Rispetta il tema */
    color: var(--text-main);
    padding: 2.5rem; 
    border-radius: 16px; 
    box-shadow: var(--shadow);
    border: 1px solid var(--border); /* Bordo sottile per contrasto in dark mode */
}

/* Mobile */
.menu-toggle {
    display: none;
}

@media (max-width: 768px) {
    .menu-toggle {
        display: block;
    }
    .navbar-menu {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        width: 100%;
        background: var(--nav-bg);
        padding: 1rem;
        border-top: 1px solid rgba(255,255,255,0.1);
        box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    }
    .navbar-menu.active {
        display: flex;
    }
    .navbar-menu a {
        width: 100%;
        padding: 12px;
        border-radius: 8px;
    }
    .navbar-menu a:hover {
        background: rgba(255,255,255,0.05);
    }
    .hide-mobile {
        display: none;
    }
    
     /* --- GESTIONE TABELLE MOBILE --- */
    
    /* 1. Comportamento STANDARD (Rifornimenti, Scadenze): Scroll orizzontale attivo */
    .table-wrapper {
        overflow-x: auto; /* IMPORTANTE: Ripristina lo scroll */
        -webkit-overflow-scrolling: touch;
    }
    table { 
        min-width: 700px; /* Forza la larghezza per garantire che le colonne non si schiaccino troppo */
    }

    /* 2. Comportamento COMPATTO (Solo per Veicoli): Adatta allo schermo */
    table.table-fit {
        min-width: 100%; /* Si adatta alla larghezza del telefono */
        width: 100%;
    }
    
    /* Regole specifiche per la tabella compatta */
    table.table-fit th, 
    table.table-fit td {
        white-space: normal; /* Testo a capo */
        padding: 10px 5px;
        font-size: 0.9rem;
    }

    /* Colonna Nome nella tabella compatta */
    table.table-fit td:first-child {
        word-wrap: break-word;
        max-width: 110px; /* Evita che un nome lungo allarghi la tabella */
        font-weight: 600;
    }

    /* Colonna Azioni nella tabella compatta */
    table.table-fit td:last-child {
        width: 1%;
        white-space: nowrap;
    }

    /* Bottoni full width su mobile */
    td .btn, td form { 
        margin-bottom: 8px; 
        width: 100%; 
        display: block;
    } 
}

/* Empty States */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: rgba(0,0,0,0.01);
    margin-top: 20px;
}
.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
    color: var(--primary);
}
.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text-main);
}
.empty-state p {
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}
/* --- GESTIONE ICONE TEMA (State-Based) --- */

/* 1. Impostazioni base icone nel bottone */
#theme-toggle i {
    pointer-events: none; /* Il click deve passare al bottone */
    display: none;       /* Di base nascoste */
}

/* 2. Se siamo in LIGHT mode (nessun attributo data-theme) */
body:not([data-theme="dark"]) #theme-toggle .theme-icon-moon {
    display: inline-block; /* Mostra Luna */
}

/* 3. Se siamo in DARK mode */
body[data-theme="dark"] #theme-toggle .theme-icon-sun {
    display: inline-block; /* Mostra Sole */
     /* Sfondo Auth Dark (Blu Notte profondo) */
    /*--auth-bg: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);*/
}

/* --- OTTIMIZZAZIONI DESKTOP (Bottoni Uniformi) --- */
@media (min-width: 769px) {
    /* 
       Target: Bottoni dentro le tabelle che NON sono piccoli (.btn-sm).
       Questo intercetta i tasti della Dashboard (Rifornimenti, Scadenze, ecc.)
    */
    table td .btn:not(.btn-sm) {
        min-width: 145px;        /* Larghezza fissa uguale per tutti */
        justify-content: center; /* Centra testo e icona */
        display: inline-flex;    /* Usa flexbox per l'allineamento */
        align-items: center;
        margin: 2px;             /* Spaziatura uniforme tra i bottoni */
        vertical-align: middle;
    }

    /* 
       Assicura che il form del bottone "Elimina" stia in linea 
       con gli altri bottoni (altrimenti va a capo)
    */
    table td form {
        display: inline-block;
        margin: 0;
    }
}

/* --- FEEDBACK MODULE --- */

/* Bottone Flottante (FAB) */
/* --- FEEDBACK MODULE (COMPLETO) --- */

/* 1. STILE BOTTONE FLOTTANTE (FAB) */
#feedback-fab {
    position: fixed;
    bottom: 25px;
    right: 25px;
    height: 56px;
    min-width: 56px; /* Parte da cerchio */
    border-radius: 28px; /* Pillola */
    background-color: var(--primary);
    color: white;
    border: none;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
    cursor: pointer;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 18px;
    gap: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: pulse-glow 3s infinite;
}

#feedback-fab i {
    font-size: 1.5rem;
    flex-shrink: 0;
}

/* Testo nascosto di default */
.fab-label {
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    white-space: nowrap;
    font-weight: 600;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

/* Hover Effect (Solo Desktop) */
@media (min-width: 769px) {
    #feedback-fab:hover {
        padding-right: 25px;
        background-color: var(--primary-hover);
        transform: translateY(-3px);
        gap: 10px;
    }
    
    #feedback-fab:hover .fab-label {
        max-width: 200px;
        opacity: 1;
    }
}

/* Animazione Pulsazione */
@keyframes pulse-glow {
    0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(37, 99, 235, 0); }
    100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}

/* 2. STILE MODALE (Quello che mancava/era rotto) */
.modal-overlay {
    display: none; /* FONDAMENTALE: Nascosto di default */
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); /* Sfondo scuro */
    z-index: 2100; /* Sopra il bottone */
    align-items: center; justify-content: center;
    backdrop-filter: blur(3px);
}

/* Questa classe viene aggiunta da JS quando clicchi */
.modal-overlay.open { 
    display: flex; 
}

.modal-content {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: 16px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    border: 1px solid var(--border);
    animation: slideUp 0.3s ease-out;
    color: var(--text-main);
}

.modal-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
}
.modal-header h3 { margin: 0; }

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

/* --- TOAST NOTIFICATIONS (Messaggi Flash) --- */
.flash-message {
    position: fixed;
    top: 30px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    color: var(--text-main);
    padding: 15px 25px;
    border-radius: 50px; /* Arrotondato a pillola */
    box-shadow: 0 10px 40px rgba(0,0,0,0.2); /* Ombra profonda */
    z-index: 9999; /* Sopra a tutto, anche alla modale */
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 600;
    font-size: 0.95rem;
    min-width: 300px;
    max-width: 90%;
    border: 1px solid var(--border);
    
    /* Animazione Ingresso */
    animation: toastSlideIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Colori bordo o icona in base al tipo */
.flash-message.success { border-left: 5px solid var(--success); }
.flash-message.error { border-left: 5px solid var(--danger); }

.flash-message i { font-size: 1.4rem; }
.flash-message.success i { color: var(--success); }
.flash-message.error i { color: var(--danger); }

/* Animazione Uscita (gestita poi via JS) */
.flash-message.hide {
    animation: toastSlideOut 0.5s forwards;
}

@keyframes toastSlideIn {
    from { transform: translate(-50%, -150%); opacity: 0; }
    to { transform: translate(-50%, 0); opacity: 1; }
}

@keyframes toastSlideOut {
    to { transform: translate(-50%, -150%); opacity: 0; }
}

/* --- NOTIFICATION CENTER --- */
.notification-wrapper { display: flex; align-items: center; }

/* Badge Rosso */
.badge {
    position: absolute;
    top: -2px; right: -2px;
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    font-weight: bold;
    height: 16px; min-width: 16px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--nav-bg); /* Per staccare dall'icona */
    padding: 0 4px;
}

/* Dropdown Container */
.notif-dropdown {
    display: none; /* Nascosto */
    position: absolute;
    top: 100%; right: -10px; /* Allineato a destra */
    width: 300px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    margin-top: 10px;
    z-index: 2000;
    overflow: hidden;
    animation: slideDown 0.2s ease-out;
}
.notif-dropdown.show { display: block; }

/* Header */
.notif-header {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    font-weight: bold;
    display: flex; justify-content: space-between;
    background: rgba(0,0,0,0.02);
    color: var(--text-main);
}

/* List */
.notif-list {
    max-height: 300px;
    overflow-y: auto;
}

/* Item */
.notif-item {
    display: flex;
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    text-decoration: none !important;
    transition: background 0.2s;
    align-items: flex-start;
    gap: 12px;
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: rgba(0,0,0,0.03); }

/* Item Content */
.notif-title { font-size: 0.9rem; font-weight: 600; color: var(--text-main); margin-bottom: 2px; }
.notif-meta { font-size: 0.8rem; color: var(--text-muted); }

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

/* Mobile Fix: centra il dropdown se lo schermo è piccolo */
@media (max-width: 500px) {
    .notif-dropdown {
        right: -60px; /* Sposta un po' a sinistra */
        width: 280px;
    }
}
/* Toggle Switch */
.slider {
  position: absolute; cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--border);
  transition: .4s; border-radius: 34px;
}
.slider:before {
  position: absolute; content: "";
  height: 16px; width: 16px;
  left: 4px; bottom: 4px;
  background-color: white;
  transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--success); }
input:checked + .slider:before { transform: translateX(16px); }