@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

/* --- DESIGN SYSTEM & VARIABILI --- */
:root {
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Plus Jakarta Sans', sans-serif;

    /* Palette Colori - Dark Mode Premium */
    --bg-main: #090d16;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(31, 41, 55, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.2);
    
    /* Accenti HSL */
    --primary: #6366f1; /* Indigo */
    --primary-glow: rgba(99, 102, 241, 0.4);
    --success: #10b981; /* Emerald */
    --success-glow: rgba(16, 185, 129, 0.3);
    --warning: #f59e0b; /* Amber */
    --warning-glow: rgba(245, 158, 11, 0.3);
    --danger: #f43f5e; /* Rose */
    --danger-glow: rgba(244, 63, 94, 0.3);
    
    /* Testi */
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --text-bright: #ffffff;
    
    /* Effetti */
    --glass-blur: blur(16px);
    --shadow-main: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- RESET & SETUP --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(16, 185, 129, 0.08) 0px, transparent 50%);
    background-attachment: fixed;
}

/* --- SCROLLBAR --- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* --- LAYOUT PRINCIPALE --- */
.app-container {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: rgba(10, 15, 30, 0.85);
    backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    position: fixed;
    height: 100vh;
    z-index: 100;
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.brand-logo {
    font-size: 2rem;
    background: linear-gradient(135deg, var(--primary), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-name {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
    color: var(--text-bright);
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: 12px;
    font-weight: 500;
    transition: var(--transition);
}

.nav-item.active a, .nav-item a:hover {
    color: var(--text-bright);
    background: rgba(99, 102, 241, 0.15);
    box-shadow: inset 0 0 12px rgba(99, 102, 241, 0.05);
    border-left: 3px solid var(--primary);
}

.nav-item a i {
    font-size: 1.2rem;
}

.user-profile {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--danger));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--text-bright);
}

.user-info .name {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-bright);
}

.user-info .role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- MAIN CONTENT AREA --- */
.main-content {
    margin-left: 280px;
    flex: 1;
    padding: 2.5rem;
    min-width: 0; /* previene rotture di flexbox */
}

.header-panel {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.header-title h1 {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 2.25rem;
    color: var(--text-bright);
    margin-bottom: 0.25rem;
}

.header-title p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.header-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* --- CARD GLOBALI --- */
.card {
    background: var(--bg-card);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 1.75rem;
    box-shadow: var(--shadow-main);
    transition: var(--transition);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 10px 40px 0 rgba(0, 0, 0, 0.45);
}

/* --- DASHBOARD VIEW --- */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.primary { background: rgba(99, 102, 241, 0.15); color: var(--primary); }
.stat-icon.success { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.stat-icon.warning { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.stat-icon.danger { background: rgba(244, 63, 94, 0.15); color: var(--danger); }

.stat-info .value {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1.75rem;
    color: var(--text-bright);
    line-height: 1.2;
}

.stat-info .label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.dashboard-details {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
}

.section-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.35rem;
    color: var(--text-bright);
    margin-bottom: 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* --- SCANNER VIEW (LA PARTE "WOW") --- */
.scanner-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.scan-zone-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 450px;
    border: 2px dashed rgba(255, 255, 255, 0.15);
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.scan-zone-card:hover {
    border-color: var(--primary);
}

.scan-placeholder {
    text-align: center;
    padding: 2rem;
}

.scan-placeholder i {
    font-size: 4rem;
    background: linear-gradient(135deg, var(--primary), var(--success));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 1.5rem;
    display: inline-block;
}

.scan-placeholder p {
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.preset-invoices {
    width: 100%;
    margin-top: 2rem;
    padding: 0 1rem;
}

.preset-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.btn-preset {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    padding: 0.75rem;
    border-radius: 12px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.btn-preset:hover {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
    transform: translateY(-2px);
}

/* --- ANIMAZIONE DI SCANSIONE LASER --- */
.invoice-preview-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.invoice-image-preview {
    max-width: 90%;
    max-height: 380px;
    border-radius: 12px;
    opacity: 0.5;
    transition: filter 0.5s ease;
}

/* Laser Overlay */
.laser-line {
    position: absolute;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, transparent, var(--primary), var(--success), transparent);
    box-shadow: 0 0 15px 3px rgba(99, 102, 241, 0.8);
    left: 0;
    top: 0;
    animation: scanAnim 2.5s ease-in-out infinite;
    z-index: 10;
}

.scanning-grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(rgba(99, 102, 241, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(99, 102, 241, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    pointer-events: none;
    z-index: 5;
}

.scanning-text-popup {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(9, 13, 22, 0.85);
    border: 1px solid var(--primary);
    padding: 1rem 2rem;
    border-radius: 16px;
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.3);
    z-index: 20;
    text-align: center;
    font-family: var(--font-heading);
    font-weight: 600;
    letter-spacing: 1px;
}

.scanning-text-popup i {
    color: var(--success);
    margin-right: 0.5rem;
    animation: spin 1s linear infinite;
}

@keyframes scanAnim {
    0% { top: 0%; }
    50% { top: 98%; }
    100% { top: 0%; }
}

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

/* --- TABELLE E LISTE PRODOTTI --- */
.haccp-table-container {
    overflow-x: auto;
    width: 100%;
}

.haccp-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.haccp-table th {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.haccp-table td {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    font-size: 0.92rem;
    vertical-align: middle;
}

.haccp-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

/* Badge di categoria/alert */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
}

.badge.success { background: rgba(16, 185, 129, 0.12); color: var(--success); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge.warning { background: rgba(245, 158, 11, 0.12); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge.danger { background: rgba(244, 63, 94, 0.12); color: var(--danger); border: 1px solid rgba(244, 63, 94, 0.2); }
.badge.primary { background: rgba(99, 102, 241, 0.12); color: var(--primary); border: 1px solid rgba(99, 102, 241, 0.2); }

/* --- COMPONENTI INTERATTIVI (INPUT E BOTTONI) --- */
.btn {
    background: var(--primary);
    color: var(--text-bright);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-family: var(--font-body);
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: var(--transition);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

.btn-danger {
    background: var(--danger);
}
.btn-danger:hover {
    box-shadow: 0 4px 15px rgba(244, 63, 94, 0.4);
}

.form-control {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.65rem 1rem;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.9rem;
    width: 100%;
    outline: none;
    transition: var(--transition);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--border-glow);
}

.form-control option {
    background-color: var(--bg-main);
    color: var(--text-main);
}

/* --- TAB NAVIGATION INTERNA --- */
.view-panel {
    display: none;
}

.view-panel.active {
    display: block;
    animation: fadeIn 0.4s ease;
}

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

/* --- SCHEDE RICETTA --- */
.recipes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.recipe-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.recipe-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.recipe-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--text-bright);
}

.recipe-ingredients-list {
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    list-style-position: inside;
}

.recipe-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
}

/* Modal e Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(9, 13, 22, 0.8);
    backdrop-filter: var(--glass-blur);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1.5rem;
}

.modal-content {
    background: #111827;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    max-width: 600px;
    width: 100%;
    padding: 2rem;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-title {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--text-bright);
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-muted);
    cursor: pointer;
}

.close-btn:hover {
    color: var(--text-bright);
}

/* Registro temperature griglia */
.temp-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.temp-item-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.25rem;
}

.temp-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.temp-limits {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Stampa Etichette */
.label-preview {
    border: 2px dashed rgba(255, 255, 255, 0.2);
    background: #fff;
    color: #000;
    padding: 1.5rem;
    border-radius: 8px;
    font-family: monospace;
    max-width: 320px;
    margin: 1.5rem auto;
}

.label-preview h4 {
    border-bottom: 2px solid #000;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
    text-align: center;
    font-family: var(--font-heading);
    font-weight: bold;
}

.label-preview p {
    font-size: 0.85rem;
    margin-bottom: 0.35rem;
}

/* Alti avvisi in Dashboard */
.alert-row {
    background: rgba(244, 63, 94, 0.08);
    border-left: 4px solid var(--danger);
    padding: 1rem;
    border-radius: 0 12px 12px 0;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.alert-row.warning {
    background: rgba(245, 158, 11, 0.08);
    border-left-color: var(--warning);
}

.alert-row .title {
    font-weight: 600;
    font-size: 0.92rem;
}

.alert-row .meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Stili di stampa per i reports */
@media print {
    .sidebar, .header-actions, .btn, .no-print {
        display: none !important;
    }
    body {
        background: #fff !important;
        color: #000 !important;
    }
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .card {
        background: none !important;
        border: none !important;
        box-shadow: none !important;
    }
    .haccp-table th {
        color: #000 !important;
        border-bottom: 2px solid #000 !important;
    }
    .haccp-table td {
        border-bottom: 1px solid #ddd !important;
        color: #000 !important;
    }
}

/* --- ADATTABILITÀ MOBILE --- */
@media (max-width: 1024px) {
    .sidebar {
        width: 80px;
        padding: 2rem 0.5rem;
        align-items: center;
    }
    .brand-name, .user-info, .nav-item span {
        display: none;
    }
    .main-content {
        margin-left: 80px;
    }
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    body {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        justify-content: space-between;
        padding: 1rem;
    }
    .brand {
        margin-bottom: 0;
    }
    .nav-links {
        flex-direction: row;
        width: auto;
    }
    .main-content {
        margin-left: 0;
        padding: 1.5rem;
    }
    .dashboard-grid {
        grid-template-columns: 1fr;
    }
    .dashboard-details {
        grid-template-columns: 1fr;
    }
    .scanner-container {
        grid-template-columns: 1fr;
    }
}
