/* --- STILI ORIGINALI LWSi --- */
* { box-sizing: border-box; }
:root {
  --bg:#0f172a;
  --card:#111827;
  --text:#e5e7eb;
  --muted:#94a3b8;
  --accent:#22c55e;
  --accent-2:#3b82f6;
  --danger:#ef4444;
  --border:#1f2937;
  --input-disabled-bg: #1e40af;
}
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, 'Helvetica Neue', Arial, 'Noto Sans';
  background: var(--bg);
  color: var(--text);
}
main { max-width: 800px; margin: 0 auto; padding: 16px; } /* Max width ridotta leggermente per focus mobile */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin: 12px 0; }
.card.sub { background: #0b1220; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.9rem; }
.error { color: var(--danger); }
.success { color: var(--accent); }
.status { font-weight: 600; }

/* Header */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.right { display: flex; align-items: center; gap: 10px; }
.chip { background: #0b1220; border: 1px solid var(--border); border-radius: 999px; padding: 6px 10px; font-size: .9rem; }

/* ============================================================
   STILE MENU PRINCIPALE (Stile LWSi "Bottoni Separati")
   ============================================================ */

/* 1. Rimuove lo stile "contenitore unito" della barra */
.mode-switch {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    gap: 8px; /* Spazio tra i bottoni */
    display: flex;
    flex-wrap: wrap; /* Permette di andare a capo su mobile */
    justify-content: center;
}

/* 2. Stile Base dei Bottoni */
.mode-switch .tab {
    background-color: #1f2937; /* Sfondo Grigio Scuro */
    border: 1px solid var(--border); /* Bordo sottile */
    color: var(--muted); /* Testo Grigio */
    border-radius: 6px; /* Angoli arrotondati */
    padding: 10px 16px; /* Spaziatura interna comoda */
    font-weight: 700; /* Grassetto */
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease-in-out; /* Animazione fluida */
    margin: 0 !important;
    
    /* Flex per centrare il testo */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px; /* Altezza minima per il dito */
}

/* 3. Effetto Hover (Passaggio del mouse) */
.mode-switch .tab:hover {
    background-color: #374151; /* Grigio più chiaro */
    color: #fff; /* Testo Bianco */
    border-color: #4b5563;
}

/* 4. STATO ATTIVO (BLU ACCESO + GLOW LUMINOSO) */
.mode-switch .tab.active {
    background-color: var(--accent-2) !important; /* Blu LWSi */
    color: #ffffff !important; /* Bianco */
    border-color: var(--accent-2) !important;
    box-shadow: 0 0 15px rgba(59, 130, 246, 0.5); /* Alone Blu luminoso */
    transform: translateY(-2px); /* Leggero sollevamento 3D */
}

/* 5. Ottimizzazione Mobile */
@media (max-width: 600px) {
    .mode-switch .tab {
        flex: 1 1 auto; /* I bottoni si allargano per riempire la riga */
        font-size: 0.9rem;
        padding: 8px 10px;
    }
}

/* Form Grid */
.form-grid { display: grid; gap: 12px; }

/* Input standard */
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
    width: 100%; padding: 12px; background: #0b1220; border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 1rem;
}
input:disabled, select:disabled { background: #1f2937; opacity: 0.7; cursor: not-allowed; }

button { padding: 12px 16px; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; font-size: 1rem; font-weight: 600; }
button.primary { background: var(--accent-2); color: #fff; border-color: var(--accent-2); } /* Blu primario per HACCP */
button.secondary { background: #374151; color: var(--text); border-color: #4b5563; }
button.danger { background-color: var(--danger); color: white; border-color: #b91c1c; }

/* KV (Key-Value) Pairs per Dettagli */
.kv {
    display:flex;
    justify-content:space-between;
    align-items: center;
    gap:8px;
    padding: 10px 12px;
    border:1px solid var(--border);
    border-radius:6px;
    background:#0b1220;
}

/* Stile per le righe modificate manualmente */
.card.sub.modified-entry {
    background-color: #2e1065 !important; /* Viola Scuro */
    border: 1px solid #8b5cf6; /* Bordo Viola Chiaro */
}
.card.sub.modified-entry .muted {
    color: #e9d5ff !important; /* Testo più chiaro su sfondo scuro */
}

/* --- STILE BOTTONE DISABILITATO --- */
.disabled-state {
    opacity: 0.5;
    background-color: #6c757d !important; /* Grigio scuro */
    cursor: not-allowed !important;
    pointer-events: none; /* BLOCCA IL CLICK: Fondamentale */
    box-shadow: none !important;
}

/* --- TASTIERINO VIRTUALE --- */
.keypad-overlay {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(0,0,0,0.5); /* Sfondo scuro semitrasparente dietro */
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* Allinea in basso */
    height: 100%; /* Copre tutto lo schermo per bloccare click altrove */
}

.keypad-container {
    width: 100%;
    max-width: 500px; /* Non troppo largo su tablet */
    background: #1f2937; /* Grigio scuro app */
    border-top: 2px solid var(--accent-2);
    padding: 15px;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.keypad-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 15px; border-bottom: 1px solid #374151; padding-bottom: 10px;
}

.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 colonne */
    gap: 10px;
    margin-bottom: 10px;
}

.keypad-actions {
    display: grid;
    grid-template-columns: 1fr 2fr; /* Cancella piccolo, Conferma grande */
    gap: 10px;
}

.key-btn {
    background: #374151;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    padding: 15px 0;
    border-radius: 8px;
    border: none;
    box-shadow: 0 4px 0 rgba(0,0,0,0.2);
}
.key-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}
.key-btn.primary { background: var(--accent-2); box-shadow: 0 4px 0 #1e40af; }
.key-btn.danger { background: #b91c1c; box-shadow: 0 4px 0 #7f1d1d; }

/* --- GESTIONE MACCHINARI (ADMIN) - STILE MIGLIORATO --- */
.machine-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1f2937; /* Grigio scuro base */
    padding: 15px;       /* Più spazio interno */
    margin-bottom: 10px; /* Più spazio tra uno e l'altro */
    border-radius: 8px;
    border: 1px solid #374151; /* Bordo sottile */
    border-left: 4px solid var(--accent-2); /* Linea colorata a sinistra */
    transition: all 0.2s ease; /* Animazione fluida */
}

.machine-item:hover {
    background: #2d3748; /* Diventa più chiaro al passaggio */
    transform: translateY(-1px); /* Si alza leggermente */
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
}

.machine-info {
    display: flex;
    flex-direction: column;
    gap: 4px; /* Spazio tra il Nome e i dettagli */
}

/* Stile per il testo piccolo (Range e Foto) */
.machine-item .small {
    font-size: 0.85rem;
    color: #9ca3af;
}

.btn-delete {
    background: rgba(239, 68, 68, 0.1); /* Rosso trasparente */
    border: 1px solid #ef4444;
    color: #ef4444;
    padding: 8px 12px; /* Bottone più comodo */
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-delete:hover {
    background: #ef4444; /* Rosso pieno al passaggio */
    color: white;
}

/* =========================================
   STILI STAMPA V10 (FIX TAGLI E FOOTER)
   ========================================= */

#print-content { display: none; }

@media print {
    
    /* 1. RESET E PULIZIA */
    html, body {
        background-color: #ffffff !important;
        color: #000000 !important;
        height: auto !important; /* Fix pagina infinita/bianca */
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* Nasconde tutto tranne l'area di stampa */
    body > *:not(#print-content) { display: none !important; }
    #app, .topbar, .tabs-bar, .mode, .card { display: none !important; }

    /* 2. AREA DI STAMPA */
    #print-content { 
        display: block !important;
        position: relative;
        width: 100%;
        margin: 0; 
        padding-bottom: 30px; /* Spazio extra per sicurezza */
    }

    /* 3. SETUP PAGINA */
    @page {
        size: A4 landscape; /* Default Landscape per avere più spazio laterale */
        /* Margini: Top, Right, Bottom (25mm per il footer), Left */
        margin: 10mm 10mm 25mm 10mm; 
    }

    /* 4. HEADER */
    .report-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2px solid #000;
        padding-bottom: 10px;
        margin-bottom: 20px;
        break-inside: avoid;
    }
    .header-left, .header-right { width: 20%; }
    .header-left { text-align: left; }
    .header-right { text-align: right; }
    
    .report-logo { 
        max-height: 45px; 
        width: auto;
        object-fit: contain; 
    }

    .header-center {
        width: 60%;
        text-align: center;
        display: flex; flex-direction: column;
    }
    .header-line-1 { font-size: 14pt; font-weight: 900; text-transform: uppercase; margin-bottom: 2px; }
    .header-line-2 { font-size: 11pt; font-weight: bold; text-transform: uppercase; margin-bottom: 2px; }
    .header-line-3 { font-size: 9pt; font-weight: normal; text-transform: uppercase; color: #444; }

    /* 5. GESTIONE TABELLE (Anti-Taglio Rigoroso) */
    .section-container {
        display: block;
        width: 100%;
        margin-bottom: 25px;
        /* Evita che l'intestazione della sezione resti sola a fine pagina */
        break-inside: auto; 
    }

    h3 {
        background: #333 !important; color: #fff !important;
        padding: 5px 10px; margin: 0; font-size: 11pt; border: 1px solid #000;
        break-after: avoid; /* Non spezzare subito dopo il titolo */
    }
    
    table.report-table { 
        width: 100%; 
        border-collapse: collapse; 
        margin-top: 0; 
        background: white;
    }
    
    table.report-table th, table.report-table td {
        border: 1px solid #666; 
        padding: 5px; 
        font-size: 9pt; 
        vertical-align: middle;
    }
    
    table.report-table th { 
        background-color: #e5e7eb !important; 
        font-weight: bold; 
        text-transform: uppercase; 
    }
    
    /* REGOLE FONDAMENTALI PER NON TAGLIARE LE RIGHE */
    tr { 
        break-inside: avoid; 
        page-break-inside: avoid; 
    }
    
    thead { 
        display: table-header-group; /* Ripete l'intestazione su ogni pagina */
    }

    /* 6. FIRMA */
    .final-signature-box {
        margin-top: 50px;
        break-inside: avoid;
        display: flex; justify-content: flex-end;
    }
    .signature-placeholder { width: 200px; text-align: center; }
    .signature-line { border-bottom: 1px solid #000; height: 30px; margin-top: 5px; }

    /* 7. FOOTER FISSO (Su OGNI pagina) */
    .report-footer-fixed {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 20px;
        border-top: 1px solid #000;
        padding-top: 5px;
        font-size: 8pt;
        background: white;
        display: flex; 
        justify-content: space-between;
        align-items: center;
        z-index: 9999;
    }

    /* Utility */
    .text-center { text-align: center; }
    .text-left { text-align: left; }
    .print-danger { color: red !important; font-weight: bold; }
    
    /* Liste merci compatte */
    .merci-list { margin: 0; padding-left: 15px; list-style-type: square; text-align: left; }
}

/* --- DASHBOARD INTELLIGENTE --- */
.hero-card {
    text-align: center;
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* Colori delle fasi */
.phase-apertura { background: linear-gradient(135deg, #f59e0b, #d97706); } /* Arancione Alba */
.phase-turno    { background: linear-gradient(135deg, #3b82f6, #1d4ed8); } /* Blu Giorno */
.phase-chiusura { background: linear-gradient(135deg, #8b5cf6, #5b21b6); } /* Viola Notte */
.phase-riposo   { background: linear-gradient(135deg, #374151, #1f2937); } /* Grigio Spento */

.task-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.task-item {
    background: #1f2937;
    margin-bottom: 8px;
    padding: 15px;
    border-radius: 8px;
    border-left: 4px solid #4b5563;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.task-item.completed {
    border-left-color: var(--accent);
    opacity: 0.6;
}
.task-icon { font-size: 1.2rem; margin-right: 10px; }

.big-clock {
    font-size: 2.5rem;
    font-weight: 800;
    margin: 10px 0;
    letter-spacing: 2px;
}

/* --- WIZARD / CHECKLIST --- */
.checklist-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.check-item {
    background: #1f2937;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #374151;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: all 0.2s;
}

/* Quando selezionato */
.check-item.checked {
    background: #064e3b; /* Verde scuro */
    border-color: #10b981;
}

.check-item input[type="checkbox"] {
    width: 24px;
    height: 24px;
    accent-color: #22c55e; /* Colore spunta */
}

.check-label {
    flex: 1;
    font-size: 1rem;
    font-weight: 500;
}

/* --- FIX MENU IN ALTO (STICKY) --- */
.tabs-bar {
    position: -webkit-sticky; /* Per compatibilità Safari/iOS */
    position: sticky;
    top: 0;
    z-index: 9999; /* Altissimo per stare sopra a tutto */
    background-color: var(--bg); /* Sfondo uguale alla pagina */
    border-bottom: 1px solid var(--border);
    padding: 10px 0 5px 0; /* Spaziatura interna */
    margin-bottom: 20px;
    width: 100%;
}

/* Correzione per evitare che il menu copra il contenuto quando si scrolla */
body {
    scroll-padding-top: 80px; 
}

/* Allineamento altezza input e select */
input[type="text"], 
input[type="number"], 
select, 
.checkbox-container {
    height: 46px; /* Altezza fissa uniforme per tutti */
    box-sizing: border-box;
}

/* Fix per le label sopra gli input */
label.small.muted {
    display: block;
    margin-bottom: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* --- LOGIN SCREEN IDENTICO WMS+ --- */

/* Centramento totale e sfondo radiale */
.full-page-center {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, #1e293b 0%, #0f172a 100%);
    z-index: 10000;
}

.login-container {
    width: 100%;
    max-width: 400px;
    background: #1e293b; /* Colore card scura */
    border: 1px solid #1f2937;
    border-top: 5px solid #22c55e; /* Barra blu superiore distintiva */
    border-radius: 12px;
    padding: 40px 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.login-brand {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo {
    max-width: 100px;
    height: auto;
    /* Rende il logo fluido e integrato */
}

.app-subtitle {
    font-size: 1.5rem;
    font-weight: 900;
    color: white;
    letter-spacing: -1px;
    margin: 0;
}

.login-form .input-group {
    text-align: left;
    margin-bottom: 20px;
}

.login-form label {
    display: block;
    font-size: 0.8rem;
    color: #94a3b8;
    margin-bottom: 8px;
    font-weight: 700;
    text-transform: uppercase;
}

/* Input stile WMS+ (Sfondo scuro) */
#login-form input {
    width: 100%;
    /* Definiamo un'altezza esatta per garantire l'uniformità */
    height: 50px; 
    /* Il padding interno mantiene il testo centrato verticalmente */
    padding: 0 15px; 
    background: #0b1220;
    border: 1px solid #1f2937;
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    /* Importante per far sì che padding e border non aumentino l'altezza totale */
    box-sizing: border-box; 
    margin-bottom: 15px;
}

/* Rimuoviamo eventuali differenze di colore viste negli screenshot */
#login-form input[type="email"], 
#login-form input[type="password"] {
    background-color: #0b1220 !important;
}

.login-form input:focus {
    border-color: #3b82f6;
    outline: none;
}

/* Bottone identico */
#btn-login {
    width: 100%;
    background-color: #3b82f6;
    color: white;
    border: none;
    padding: 16px;
    border-radius: 8px;
    font-weight: 800;
    font-size: 1rem;
    text-transform: uppercase;
    cursor: pointer;
    margin-top: 10px;
}

.login-footer {
    margin-top: 35px;
    padding-top: 20px;
    border-top: 1px solid #1f2937;
    font-size: 0.7rem;
    color: #94a3b8;
    line-height: 1.5;
}

.version-tag {
    color: #22c55e;
    font-weight: bold;
}

.error-msg {
    color: #ef4444;
    font-size: 0.85rem;
    margin-top: 10px;
    font-weight: 600;
}

/* Classe helper per nascondere */
.hidden {
    display: none !important;
}

.app-footer {
    padding: 20px;
    text-align: center;
    background-color: #0f172a; /* Coerente con il manifest */
    color: #64748b; /* Grigio tenue per non distrarre */
    font-size: 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    margin-top: 40px;
}

.version-tag {
    font-weight: bold;
    color: var(--accent, #3b82f6);
    margin-top: 5px;
}

.legal-notice {
    font-style: italic;
    font-size: 0.7rem;
    opacity: 0.6;
}



