:root {
    --haccp-sidebar-bg: #0f172a;
    --haccp-sidebar-hover: #1e293b;
    --haccp-primary: #0f766e;
    --haccp-primary-dark: #115e59;
    --haccp-bg: #f1f5f9;
    --haccp-card-border: #e2e8f0;
}

html, body {
    overflow-x: hidden;
}

body {
    background-color: var(--haccp-bg);
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color: #0f172a;
}

.haccp-shell {
    min-height: 100vh;
    display: flex;
}

.haccp-sidebar {
    width: 268px;
    background: var(--haccp-sidebar-bg);
    color: #cbd5e1;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.haccp-sidebar .brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.haccp-sidebar .nav-section {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #64748b;
    padding: 1rem 1.25rem 0.35rem;
    font-weight: 700;
}

.haccp-sidebar .nav-link {
    color: #cbd5e1;
    padding: 0.62rem 1.25rem;
    font-size: 0.92rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    border-radius: 0.5rem;
    margin: 0.1rem 0.65rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.haccp-sidebar .nav-link:hover {
    background: var(--haccp-sidebar-hover);
    color: #ffffff;
}

.haccp-sidebar .nav-link.active {
    background: var(--haccp-primary);
    color: #ffffff;
    font-weight: 600;
}

.haccp-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.haccp-topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--haccp-card-border);
    padding: 0.75rem 1.25rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.haccp-content {
    padding: 1.5rem;
    flex: 1;
    min-width: 0;
}

.card-haccp {
    background: #ffffff;
    border: 1px solid var(--haccp-card-border);
    border-radius: 0.85rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.kpi-card {
    border-radius: 0.85rem;
    border: 1px solid var(--haccp-card-border);
    background: #ffffff;
    padding: 1.15rem 1.25rem;
    transition: transform 0.12s ease;
    height: 100%;
}

.kpi-icon {
    width: 42px;
    height: 42px;
    border-radius: 0.65rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.btn-haccp {
    background-color: var(--haccp-primary);
    border-color: var(--haccp-primary);
    color: #ffffff;
}

.btn-haccp:hover {
    background-color: var(--haccp-primary-dark);
    border-color: var(--haccp-primary-dark);
    color: #ffffff;
}

.auth-bg {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #134e4a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.check-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    gap: 0.75rem;
}

.check-row:last-child {
    border-bottom: none;
}

/* ==========================================================================
   OTTIMIZZAZIONE TABLET & MOBILE (< 992px e < 768px)
   ========================================================================== */
@media (max-width: 991.98px) {
    .haccp-sidebar {
        display: none;
    }
    .haccp-content {
        padding: 0.9rem;
    }
    .haccp-topbar {
        padding: 0.65rem 0.9rem;
    }
}

@media (max-width: 767.98px) {
    /* Evita zoom automatico di iOS Safari sugli input */
    input.form-control,
    select.form-select,
    textarea.form-control {
        font-size: 16px !important;
    }

    .haccp-topbar h1 {
        font-size: 1.02rem;
    }

    .haccp-topbar form,
    .haccp-topbar select {
        max-width: 100%;
    }

    .kpi-card {
        padding: 0.9rem;
    }
    .kpi-card .fs-3 {
        font-size: 1.45rem !important;
    }
    .kpi-icon {
        width: 34px;
        height: 34px;
        font-size: 1rem;
    }

    .check-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.4rem;
    }
    .check-row > .text-end {
        text-align: left !important;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    /* Barra filtri e pulsanti sopra le tabelle */
    .card-header form,
    .haccp-content > .d-flex form {
        width: 100%;
    }
    .card-header form .form-control,
    .card-header form .form-select,
    .haccp-content > .d-flex form .form-control,
    .haccp-content > .d-flex form .form-select {
        width: 100% !important;
        flex: 1 1 100%;
    }

    /* Nav pills Anagrafiche scrollabili comodamente */
    .nav-pills {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.5rem !important;
    }
    .nav-pills .nav-item {
        flex: 0 0 auto;
    }

    /* MODALI OTTIMIZZATE MOBILE: scroll fluido, mai tagliate */
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100vw - 1rem) !important;
    }
    .modal-content {
        max-height: calc(100dvh - 1rem);
        display: flex;
        flex-direction: column;
        border-radius: 0.9rem;
    }
    .modal-header {
        padding: 0.85rem 1rem;
        flex-shrink: 0;
    }
    .modal-title {
        font-size: 1rem;
    }
    .modal-body {
        padding: 1rem;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1 1 auto;
    }
    .modal-footer {
        padding: 0.75rem 1rem;
        flex-shrink: 0;
        flex-wrap: nowrap;
        gap: 0.5rem;
    }
    .modal-footer .btn {
        flex: 1 1 50%;
        min-height: 42px;
    }

    /* Dentro le modali su smartphone stretto, le colonne vanno a piena larghezza */
    .modal-body .row > .col-3,
    .modal-body .row > .col-4,
    .modal-body .row > .col-5,
    .modal-body .row > .col-6,
    .modal-body .row > .col-8 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* TABELLE DATI -> CARD VERTICALI LEGGIBILI SU SMARTPHONE */
    .table-responsive {
        overflow-x: visible !important;
    }
    table.mobile-cards thead {
        display: none;
    }
    table.mobile-cards,
    table.mobile-cards tbody,
    table.mobile-cards tr,
    table.mobile-cards td {
        display: block;
        width: 100%;
    }
    table.mobile-cards tbody {
        padding: 0.65rem;
        background: #f8fafc;
    }
    table.mobile-cards tbody tr {
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 0.75rem;
        margin-bottom: 0.75rem;
        padding: 0.35rem 0.75rem;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    }
    table.mobile-cards tbody tr:last-child {
        margin-bottom: 0;
    }
    table.mobile-cards tbody tr.table-danger {
        border-left: 4px solid #dc2626 !important;
        background: #fef2f2 !important;
    }
    table.mobile-cards tbody tr.table-warning {
        border-left: 4px solid #f59e0b !important;
        background: #fffbeb !important;
    }
    table.mobile-cards tbody tr.table-secondary {
        border-left: 4px solid #94a3b8 !important;
        background: #f1f5f9 !important;
    }
    table.mobile-cards tbody td {
        display: block;
        width: 100%;
        padding: 0.55rem 0 !important;
        border: none !important;
        border-bottom: 1px solid #f1f5f9 !important;
        text-align: left !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
        max-width: 100% !important;
    }
    table.mobile-cards tbody td:last-child {
        border-bottom: none !important;
        padding-top: 0.65rem !important;
    }
    table.mobile-cards tbody td::before {
        content: attr(data-label);
        display: block;
        font-weight: 700;
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: #64748b;
        margin-bottom: 0.22rem;
    }
    table.mobile-cards tbody td form.d-inline-flex {
        display: flex !important;
        width: 100%;
        gap: 0.5rem !important;
    }
    table.mobile-cards tbody td form.d-inline-flex .form-select {
        flex: 1 1 auto;
        width: auto !important;
    }
    table.mobile-cards tbody td[colspan] {
        display: block;
        text-align: center !important;
    }
    table.mobile-cards tbody td[colspan]::before {
        display: none;
    }
    table.mobile-cards .text-truncate {
        white-space: normal !important;
        overflow: visible !important;
        text-overflow: clip !important;
        max-width: 100% !important;
    }
    table.mobile-cards tbody td .btn {
        min-height: 36px;
    }
}
