/* =============================================
   HSELab - Main Stylesheet
   Color palette: #1e481e (primary green)
   ============================================= */

:root {
    --primary:       #1e481e;
    --primary-dark:  #153415;
    --primary-light: #2a6130;
    --primary-faded: rgba(30, 72, 30, 0.08);
    --accent:        #4caf50;
    --text-dark:     #1a1a1a;
    --text-muted:    #6b7280;
    --bg-light:      #f4f6f4;
    --bg-white:      #ffffff;
    --border:        #d1e0d1;
    --shadow:        0 2px 12px rgba(30, 72, 30, 0.10);
    --shadow-lg:     0 8px 32px rgba(30, 72, 30, 0.16);
    --radius:        10px;
    --radius-lg:     16px;
    --transition:    0.2s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    line-height: 1.6;
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

html {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-light); }

/* ---- TOP NAVBAR ---- */
.navbar {
    background: var(--primary);
    padding: 0 2rem;
    display: flex;
    align-items: center;
    height: 64px;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
}

.navbar-brand img {
    height: 42px;
    filter: brightness(0) invert(1);
    opacity: 0.95;
}

.navbar-brand img.navbar-brand-icon {
    height: 40px;
    width: auto;
    filter: none;
    opacity: 1;
    flex-shrink: 0;
}

.navbar-brand .brand-text {
    font-size: 1.35rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0.5px;
}

.navbar-brand .brand-sub {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.65);
    letter-spacing: 1.5px;
    text-transform: uppercase;
    display: block;
    line-height: 1;
    margin-top: -2px;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    list-style: none;
}

.navbar-nav a {
    color: rgba(255,255,255,0.85);
    padding: 8px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: background var(--transition), color var(--transition);
}

.navbar-nav a:hover,
.navbar-nav a.active {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: rgba(255,255,255,0.85);
    font-size: 0.9rem;
    margin-left: auto;
    padding-left: 16px;
    border-left: 1px solid rgba(255,255,255,0.2);
}

.navbar-user .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    color: #fff;
}

/* ---- SIDEBAR ---- */
.layout {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-height: calc(100vh - 64px);
}

.sidebar {
    width: 240px;
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    flex-shrink: 0;
}

.sidebar-section {
    padding: 0 1rem;
    margin-bottom: 1.5rem;
}

.sidebar-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-muted);
    padding: 0 0.75rem;
    margin-bottom: 0.4rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: var(--text-dark);
    font-size: 0.9rem;
    transition: background var(--transition), color var(--transition);
    margin-bottom: 2px;
}

.sidebar-link .icon {
    width: 20px;
    text-align: center;
    font-size: 1rem;
    color: var(--text-muted);
    transition: color var(--transition);
}

.sidebar-link:hover,
.sidebar-link.active {
    background: var(--primary-faded);
    color: var(--primary);
}

.sidebar-link:hover .icon,
.sidebar-link.active .icon {
    color: var(--primary);
}

.sidebar-link.active {
    font-weight: 600;
}

/* ---- MAIN CONTENT ---- */
.main-content {
    flex: 1 1 0;
    padding: 2rem;
    overflow-x: visible;
    min-width: 0;
    /* non usare width:100% qui: con sidebar aperta (desktop/landscape largo)
       sommerebbe 240px + 100% e lascia spazio/overflow a destra */
}

.page-header {
    margin-bottom: 1.75rem;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
}

/* ---- STAT CARDS ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 1.4rem 1.6rem;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 1.2rem;
    border-left: 4px solid transparent;
    transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

a.stat-card-link {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

a.stat-card-link.stat-card-active {
    box-shadow: var(--shadow-lg);
    outline: 2px solid var(--primary-faded);
    outline-offset: 2px;
}

.stat-card.green  { border-color: var(--primary); }
.stat-card.yellow { border-color: #f59e0b; }
.stat-card.red    { border-color: #ef4444; }
.stat-card.blue   { border-color: #3b82f6; }

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card.green  .stat-icon { background: rgba(30, 72, 30, 0.1);  color: var(--primary); }
.stat-card.yellow .stat-icon { background: rgba(245,158,11, 0.1);  color: #f59e0b; }
.stat-card.red    .stat-icon { background: rgba(239,68,68, 0.1);   color: #ef4444; }
.stat-card.blue   .stat-icon { background: rgba(59,130,246, 0.1);  color: #3b82f6; }

.stat-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
    color: var(--text-dark);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ---- CARDS ---- */
.card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body { padding: 1.25rem 1.5rem; }

/* ---- MENU GRID ---- */
.menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.menu-item {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: 1.5rem 1.2rem;
    text-align: center;
    box-shadow: var(--shadow);
    border: 2px solid transparent;
    transition: all var(--transition);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-dark);
}

.menu-item:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    color: var(--primary);
}

.menu-item .mi-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-faded);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--primary);
    transition: background var(--transition);
}

.menu-item:hover .mi-icon {
    background: var(--primary);
    color: #fff;
}

.menu-item .mi-label {
    font-size: 0.85rem;
    font-weight: 600;
}

/* ---- BUTTONS ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 20px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(30,72,30,0.3);
}

.btn-outline {
    background: transparent;
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline:hover {
    background: var(--primary-faded);
    color: var(--primary);
}

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

/* ---- TABLES ---- */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

thead th {
    background: var(--primary-faded);
    color: var(--primary-dark);
    padding: 10px 14px;
    text-align: left;
    font-weight: 700;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--border);
}

tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-dark);
}

tbody tr:hover { background: var(--primary-faded); }
tbody tr:last-child td { border-bottom: none; }

/* ---- BADGES ---- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
    gap: 4px;
}

.badge-green  { background: rgba(30,72,30,0.1);  color: var(--primary); }
.badge-yellow { background: rgba(245,158,11,0.1); color: #b45309; }
.badge-red    { background: rgba(239,68,68,0.1);  color: #dc2626; }
.badge-blue   { background: rgba(59,130,246,0.1); color: #2563eb; }

/* ---- FOOTER ---- */
.footer {
    background: var(--bg-white);
    border-top: 1px solid var(--border);
    padding: 1rem 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.footer img { height: 24px; opacity: 0.7; background: transparent; }

/* ---- LOGIN PAGE ---- */
.login-page {
    background: #fff;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 40px rgba(30,72,30,0.13);
    padding: 2.5rem 2.5rem 2rem;
    border: 1px solid var(--border);
}

.login-logo-top {
    display: flex;
    justify-content: center;
    margin-bottom: 1.75rem;
}

.login-logo-top img {
    height: 72px;
}

.login-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary-dark);
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-bottom: 2rem;
}

.form-group {
    margin-bottom: 1.2rem;
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    color: var(--text-dark);
    background: #fff;
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30,72,30,0.1);
}

.btn-login {
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
    margin-top: 0.5rem;
    letter-spacing: 0.3px;
}

.btn-login:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(30,72,30,0.25);
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.88rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 8px;
}

.alert-danger {
    background: rgba(239,68,68,0.08);
    color: #dc2626;
    border: 1px solid rgba(239,68,68,0.2);
}

.alert-success {
    background: rgba(30,72,30,0.07);
    color: var(--primary);
    border: 1px solid rgba(30,72,30,0.2);
}

.login-footer-logo {
    margin-top: 2.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.login-footer-logo img {
    height: 40px;
    opacity: 0.8;
    background: transparent;
}

.login-footer-logo span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════
   HAMBURGER BUTTON (sempre presente, visibile solo su mobile)
   ═══════════════════════════════════════════ */
.hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    flex-shrink: 0;
    margin-right: 8px;
}
.hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: transform .25s, opacity .25s;
    transform-origin: center;
}
.hamburger.is-open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.is-open span:nth-child(2) { opacity: 0; }
.hamburger.is-open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ═══════════════════════════════════════════
   SIDEBAR OVERLAY (mobile)
   ═══════════════════════════════════════════ */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
}
.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ═══════════════════════════════════════════
   NAVBAR — testo logout
   ═══════════════════════════════════════════ */
.navbar-logout {
    color: rgba(255,255,255,.65);
    font-size: .82rem;
    margin-left: 10px;
    padding: 4px 10px;
    border: 1px solid rgba(255,255,255,.3);
    border-radius: 6px;
    transition: background .2s;
}
.navbar-logout:hover { background: rgba(255,255,255,.15); color: #fff; }
.navbar-user-role { color: rgba(255,255,255,.5); font-size: .75rem; margin-left: 4px; }
.navbar-date {
    font-size: .78rem;
    color: rgba(255,255,255,.6);
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: .03em;
    padding-right: 14px;
    border-right: 1px solid rgba(255,255,255,.25);
    margin-right: 4px;
}

/* ── Azioni tabella: testo su desktop, sola icona su tablet ── */
.tbl-actions {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    flex-wrap: nowrap;
}
.tbl-act {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    vertical-align: middle;
}

/* ═══════════════════════════════════════════
   RESPONSIVE — TABLET / LAPTOP STRETTO
   Idea Tab Pro 12.1" 2.5K (tipicamente ~1280 CSS px in landscape)
   e simili: menu laterale a scomparsa per liberare spazio
   a dashboard e tabelle.
   Breakpoint drawer: 1400px
   ═══════════════════════════════════════════ */
@media (max-width: 1400px) {
    .stats-grid  { grid-template-columns: repeat(2, 1fr); }
    .menu-grid   { grid-template-columns: repeat(2, 1fr); }

    .navbar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding: 0 .85rem;
        gap: .5rem;
        z-index: 1100;
    }
    /* Compensa la navbar fissa così il contenuto non finisce sotto */
    body {
        padding-top: 56px;
    }
    .layout {
        display: block;
        width: 100%;
        max-width: 100%;
        min-height: calc(100vh - 56px);
        min-height: calc(100dvh - 56px);
    }

    .hamburger { display: flex; }

    .navbar-brand { gap: 8px; min-width: 0; }
    .navbar-brand img { height: 30px; }
    .navbar-brand img.navbar-brand-icon { height: 28px; }
    .navbar-brand .brand-text { font-size: .95rem; letter-spacing: .2px; }
    .navbar-brand .brand-sub {
        font-size: .58rem;
        letter-spacing: .8px;
        margin-top: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 160px;
    }

    .navbar-user {
        gap: 6px;
        padding-left: 10px;
        font-size: .72rem;
        min-width: 0;
    }
    .navbar-user .avatar {
        width: 26px;
        height: 26px;
        font-size: .7rem;
        flex-shrink: 0;
    }
    .navbar-date {
        font-size: .65rem;
        padding-right: 8px;
        margin-right: 2px;
        letter-spacing: .02em;
    }
    .navbar-user-name {
        font-size: .72rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 110px;
    }
    .navbar-user-role {
        font-size: .65rem;
        white-space: nowrap;
    }
    .navbar-logout {
        font-size: .7rem;
        padding: 3px 8px;
        margin-left: 4px;
        flex-shrink: 0;
    }

    .sidebar {
        display: block !important;
        position: fixed;
        top: 56px;
        bottom: 0;
        left: 0;
        height: auto;
        width: 280px;
        max-width: 85vw;
        /* fuori dal flusso: non riservare colonna in landscape */
        flex: none;
        margin: 0;
        z-index: 1050;
        background: var(--bg-white);
        transform: translateX(-100%);
        transition: transform .28s cubic-bezier(.4,0,.2,1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        box-shadow: 4px 0 24px rgba(0,0,0,.18);
        padding: 1.25rem 0;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }
    .sidebar.sidebar-open { transform: translateX(0); }
    .sidebar-overlay {
        display: block;
        top: 56px;
        z-index: 1040;
    }

    .main-content {
        display: block;
        padding: 1.25rem 1.5rem;
        position: relative;
        z-index: 1;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0;
        box-sizing: border-box;
    }

    .main-content > * {
        max-width: 100%;
    }

    .page-header { margin-bottom: 1.25rem; }
    .page-title  { font-size: 1.35rem; }

    .table-wrap,
    .reg-wrap,
    .sc-wrap,
    .df-wrap,
    .kpi-wrap,
    .pf-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    .card-header { flex-wrap: wrap; gap: .5rem; }

    /* Azioni registro: sola icona (data-icon) */
    .tbl-act[data-icon],
    .btn-icon[data-icon] {
        font-size: 0 !important;
        min-width: 2.25rem;
        min-height: 2.25rem;
        padding: .4rem .5rem !important;
        line-height: 1;
        gap: 0;
    }
    .tbl-act[data-icon]::before,
    .btn-icon[data-icon]::before {
        content: attr(data-icon);
        font-size: 1.05rem;
        line-height: 1;
        speak: never;
    }
    .tbl-act[data-icon] .tbl-act-label,
    .tbl-act[data-icon] .presidi-act-label {
        display: none;
    }
}

/* Sotto ~1100px: nasconde data e ruolo per evitare sovrapposizioni */
@media (max-width: 1100px) {
    .navbar-date { display: none; }
    .navbar-user-role { display: none; }
    .navbar-brand .brand-sub { max-width: 120px; }
    .navbar-user-name { max-width: 140px; }
}

@media (max-width: 900px) {
    .stats-grid  { grid-template-columns: repeat(2, 1fr); gap: .85rem; }
    .menu-grid   { grid-template-columns: repeat(2, 1fr); gap: .85rem; }
    .main-content { padding: 1rem 1.15rem; }
}

/* ═══════════════════════════════════════════
   RESPONSIVE — MOBILE (max 768px)
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {

    /* --- Navbar più compatta --- */
    .navbar { padding: 0 1rem; height: 56px; }
    .navbar-brand img { height: 32px; }
    .navbar-brand img.navbar-brand-icon { height: 30px; }
    .navbar-brand .brand-text { font-size: 1.1rem; }
    .navbar-brand .brand-sub  { display: none; }
    .navbar-user-name  { display: none; }
    .navbar-user-role  { display: none; }
    .navbar-date       { display: none; }
    .navbar-user { margin-left: auto; padding-left: 0; border-left: none; gap: 6px; }
    .navbar-logout { margin-left: 0; }

    .sidebar { width: 260px; top: 56px; }

    .main-content { padding: 1rem; }

    .stats-grid  { grid-template-columns: repeat(2, 1fr); gap: .75rem; }
    .menu-grid   { grid-template-columns: repeat(2, 1fr); gap: .75rem; }

    .card { border-radius: 8px; }
    .page-header { margin-bottom: 1rem; }
    .page-title  { font-size: 1.2rem; }

    .btn { font-size: .82rem; padding: .45rem .9rem; }
    .btn-primary { min-height: 40px; }

    .form-row { grid-template-columns: 1fr; }
    .form-section-body { padding: 1rem; }
    .form-section-header { padding: .7rem 1rem; }

    .footer { flex-direction: column; gap: .4rem; text-align: center; font-size: .75rem; padding: .75rem 1rem; }
}

/* ═══════════════════════════════════════════
   RESPONSIVE — VERY SMALL (max 480px)
   ═══════════════════════════════════════════ */
@media (max-width: 480px) {
    .navbar-brand .brand-text { font-size: 1rem; }
    .main-content { padding: .75rem; }
    .stats-grid  { grid-template-columns: 1fr 1fr; gap: .5rem; }
    .stat-card   { padding: .9rem; }
    .stat-value  { font-size: 1.5rem; }
    .menu-grid   { grid-template-columns: 1fr 1fr; }
    .menu-item   { padding: .85rem .5rem; }
    .mi-icon     { font-size: 1.5rem; }
    .mi-label    { font-size: .78rem; }
}

/* ---- FORMS (moduli) ---- */
.form-section {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.form-section-header {
    padding: .85rem 1.5rem;
    background: var(--primary-faded);
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: .9rem;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-section-body {
    padding: 1.4rem 1.5rem;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row:last-child { margin-bottom: 0; }

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

textarea.form-control {
    resize: vertical;
    min-height: 90px;
}

.form-check {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: .9rem;
}

.form-check input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* ---- SIGNATURE PAD ---- */
.sig-wrapper {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
}

.sig-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--primary-faded);
    border-bottom: 1px solid var(--border);
    font-size: .78rem;
    color: var(--text-muted);
}

.sig-canvas {
    display: block;
    width: 100%;
    height: 140px;
    cursor: crosshair;
    touch-action: none;
}

.sig-canvas.signed { background: #fffef5; }

.btn-sig-clear {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 10px;
    font-size: .75rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: all .15s;
}

.btn-sig-clear:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }

.sig-preview {
    margin-top: 6px;
    text-align: center;
}

.sig-preview img {
    max-height: 80px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    padding: 4px;
}

/* ---- STATUS BADGES in tables ---- */
.status-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .3px;
    text-transform: uppercase;
}

.status-aperto, .status-aperta, .status-nuovo {
    background: rgba(239,68,68,.1); color: #dc2626;
}
.status-in_corso, .status-in_valutazione {
    background: rgba(245,158,11,.1); color: #b45309;
}
.status-chiuso, .status-chiusa, .status-approvato, .status-completato {
    background: rgba(30,72,30,.1); color: var(--primary);
}
.status-rifiutato {
    background: rgba(107,114,128,.1); color: #6b7280;
}

/* Priorità */
.prio-bassa    { background: rgba(30,72,30,.1);  color: var(--primary); }
.prio-media    { background: rgba(59,130,246,.1); color: #2563eb; }
.prio-alta     { background: rgba(245,158,11,.1); color: #b45309; }
.prio-urgente  { background: rgba(239,68,68,.1);  color: #dc2626; }

/* Potenziale danno */
.danno-basso  { background: rgba(30,72,30,.1);  color: var(--primary); }
.danno-medio  { background: rgba(245,158,11,.1); color: #b45309; }
.danno-alto   { background: rgba(239,68,68,.1);  color: #dc2626; }

/* ---- EMPTY STATE ---- */
.empty-state {
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state p { font-size: .9rem; }

/* ---- PRINT ---- */
.hselab-print-header,
.hselab-print-title,
.hselab-print-date { display: none; }

@media print {
    .navbar, .sidebar, .footer, .sidebar-overlay,
    .btn, .sig-toolbar, form button,
    .no-print, .alert, .hselab-print-btn, .hselab-print-toolbar,
    .ds-mirror,
    .main-content > nav, .main-content > p,
    .page-header, .page-title, .page-subtitle,
    .stats-grid, .stat-box, .obs-stats, .oss-fb, .filter-bar, .legenda,
    .view-toggle, .hselab-dual-scroll,
    .empty-state, .card-header,
    .no-print-col, .col-act { display: none !important; }

    html, body {
        overflow: visible !important;
        height: auto !important;
        background: #fff !important;
    }

    .main-content { padding: 0 !important; margin: 0 !important; }
    .layout { display: block !important; }
    .sig-preview img { max-height: 120px; }

    /* Nasconde il resto della pagina; il blocco lista resta nel flusso (page-break ok). */
    body.hselab-printing .main-content > *:not([data-hselab-print]) {
        display: none !important;
    }

    body.hselab-printing .main-content {
        visibility: visible !important;
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
    }

    body.hselab-printing-reg .main-content > *:not([data-hselab-print]) {
        display: none !important;
    }

    body.hselab-printing-reg [data-hselab-print].reg-export-wrap,
    body.hselab-printing-reg [data-hselab-print].reg-export-wrap * {
        visibility: visible;
    }

    body.hselab-printing #hselab-print-header,
    body.hselab-printing #hselab-print-header *,
    body.hselab-printing #hselab-print-title,
    body.hselab-printing #hselab-print-title *,
    body.hselab-printing #hselab-print-date,
    body.hselab-printing [data-hselab-print],
    body.hselab-printing [data-hselab-print] * {
        visibility: visible;
    }

    body.hselab-printing [data-hselab-print] {
        position: relative !important;
        left: auto !important;
        top: auto !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
    }

    body.hselab-printing [data-hselab-print].reg-export-wrap {
        position: relative;
        left: auto;
        top: auto;
        width: 100% !important;
        max-width: 100% !important;
    }

    body.hselab-printing #viewGrid { display: none !important; }
    body.hselab-printing #viewList {
        display: block !important;
        visibility: visible !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .hselab-print-header {
        display: block !important;
        margin: 0 0 4mm;
        padding-bottom: 2.5mm;
        border-bottom: 1px solid #bbb;
    }

    .hselab-print-title {
        display: block !important;
        margin: 0;
    }

    .hselab-print-title h1 {
        font-size: 16pt;
        font-weight: 700;
        margin: 0;
        color: #000;
    }

    .hselab-print-subtitle {
        margin: .35rem 0 0;
        font-size: 11pt;
        font-weight: 400;
        color: #444;
    }

    .hselab-print-date {
        display: block !important;
        margin-top: 1.5mm;
        font-size: 8pt;
        color: #555;
    }

    .card, .table-wrap, .reg-wrap, .sc-wrap, .df-wrap, .kpi-wrap, .pf-wrap,
    [data-hselab-print] {
        box-shadow: none !important;
        border: none !important;
        overflow: visible !important;
        page-break-inside: auto;
        max-height: none !important;
        height: auto !important;
    }

    .table-wrap, .reg-wrap, .sc-wrap, .df-wrap, .kpi-wrap, .pf-wrap {
        overflow: visible !important;
        max-height: none !important;
    }

    table, .sc-table, .df-table, .pf-table, .kpi-tbl, .dash-table {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        table-layout: auto !important;
        font-size: 8.5pt !important;
        border-collapse: collapse !important;
        white-space: normal !important;
        page-break-inside: auto;
    }

    .reg-print-list {
        display: block !important;
        width: 100% !important;
    }

    .reg-print-item {
        break-inside: auto;
        page-break-inside: auto;
    }

    .reg-print-item.reg-print-page-start {
        break-before: page;
        page-break-before: always;
    }

    .reg-print-list > .hselab-print-header + .reg-print-item {
        break-before: auto !important;
        page-break-before: auto !important;
    }

    .reg-wrap .reg-table {
        display: none !important;
    }

    thead { display: table-header-group; }
    tr { page-break-inside: avoid; }

    th, td {
        border: 1px solid #bbb !important;
        padding: 3px 5px !important;
        vertical-align: top !important;
        white-space: normal !important;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    th {
        background: #e8e8e8 !important;
        color: #111 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .badge, .tipo-badge, .cat-pill, .badge-exp, .badge-fare,
    .s-aperta, .s-ongoing, .s-chiusa,
    .g-nullo, .g-basso, .g-medio, .g-alto {
        border: 1px solid #999 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        white-space: normal !important;
    }

    a { color: inherit !important; text-decoration: none !important; }

    @page { margin: 12mm; }
}

/* ---- DIPENDENTI CARD GRID ---- */
.dip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 1.25rem;
}

.dip-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.5rem 1.2rem 1.2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 8px;
    transition: transform var(--transition), box-shadow var(--transition);
    border: 2px solid transparent;
    position: relative;
}

.dip-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.dip-card.inattivo {
    opacity: .6;
    filter: grayscale(.5);
}

.dip-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid var(--primary);
    background: var(--primary-faded);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
    flex-shrink: 0;
    overflow: hidden;
}

.dip-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.dip-avatar-fallback {
    font: inherit;
    font-weight: inherit;
    color: inherit;
}

/* Anteprima foto ingrandita al passaggio del mouse (scheda dipendente) */
.dip-avatar-preview {
    position: relative;
    width: 76px;
    height: 76px;
    flex-shrink: 0;
    z-index: 1;
}

.dip-avatar-preview .dip-avatar {
    cursor: zoom-in;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    transform-origin: center center;
}

.dip-avatar-preview:hover {
    z-index: 1000;
}

.dip-avatar-preview:hover .dip-avatar {
    transform: scale(5);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}

.dip-card-name {
    font-size: .98rem;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1.2;
    min-height: 40px;
}

.dip-card-sub {
    font-size: .78rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.dip-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    margin-top: 2px;
}

.dip-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.dip-cert-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 4px;
}

.view-toggle {
    display: flex;
    gap: 4px;
    background: var(--primary-faded);
    border-radius: var(--radius);
    padding: 3px;
}

.view-toggle button {
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 5px 10px;
    cursor: pointer;
    font-size: .95rem;
    color: var(--text-muted);
    transition: all var(--transition);
}

.view-toggle button.active {
    background: var(--primary);
    color: #fff;
}

/* Dual scroll (tabelle larghe) */
.ds-mirror {
    overflow-x: auto;
    overflow-y: hidden;
    height: 10px;
    width: 100%;
    border-radius: 4px 4px 0 0;
    background: #e8f0e8;
    scrollbar-width: thin;
    scrollbar-color: var(--primary, #1e481e) #e8f0e8;
    margin-bottom: 2px;
}
.ds-mirror::-webkit-scrollbar { height: 8px; }
.ds-mirror::-webkit-scrollbar-track { background: #e8f0e8; border-radius: 4px; }
.ds-mirror::-webkit-scrollbar-thumb { background: var(--primary, #1e481e); border-radius: 4px; }
.ds-mirror-inner { height: 1px; }

/* Overlay invio moduli */
body.hselab-submit-busy {
    overflow: hidden;
}

.hselab-submit-overlay {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(15, 35, 15, 0.55);
    backdrop-filter: blur(3px);
}

.hselab-submit-overlay[hidden] {
    display: none !important;
}

.hselab-submit-overlay-card {
    width: min(100%, 320px);
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.5rem 1.25rem;
    text-align: center;
}

.hselab-submit-overlay-spinner {
    width: 44px;
    height: 44px;
    margin: 0 auto 1rem;
    border: 4px solid var(--primary-faded);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: hselab-spin .85s linear infinite;
}

.hselab-submit-overlay-text {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: .35rem;
}

.hselab-submit-overlay-hint {
    font-size: .82rem;
    color: var(--text-muted);
    line-height: 1.4;
}

@keyframes hselab-spin {
    to { transform: rotate(360deg); }
}

/* Lightbox anteprima allegati (foto) */
.hselab-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100060;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(10, 18, 28, 0.82);
    backdrop-filter: blur(4px);
}
.hselab-lightbox.is-open { display: flex; }
.hselab-lightbox-inner {
    position: relative;
    width: min(100%, 960px);
    max-height: min(92vh, 920px);
    display: flex;
    flex-direction: column;
    gap: .65rem;
}
.hselab-lightbox-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-shrink: 0;
}
.hselab-lightbox-title {
    color: #fff;
    font-size: .88rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.hselab-lightbox-close {
    flex-shrink: 0;
    border: 0;
    border-radius: 8px;
    background: #fff;
    color: #0f172a;
    font-size: .88rem;
    font-weight: 700;
    padding: .45rem .9rem;
    cursor: pointer;
    min-height: 2.4rem;
}
.hselab-lightbox-close:hover { background: #f1f5f9; }
.hselab-lightbox-stage {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,.25);
    border-radius: 12px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}
.hselab-lightbox-stage img {
    max-width: 100%;
    max-height: min(78vh, 820px);
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
}
.hselab-lightbox-frame {
    width: 100%;
    height: min(78vh, 820px);
    border: 0;
    border-radius: 8px;
    background: #fff;
}
.hselab-lightbox-fallback {
    text-align: center;
    color: #fff;
    padding: 2rem 1rem;
}
.hselab-lightbox-fallback p {
    margin: 0 0 .75rem;
    font-size: .92rem;
    color: rgba(255,255,255,.9);
}
.hselab-lightbox-docicon {
    font-size: 2.4rem;
    line-height: 1;
    margin-bottom: .75rem;
}
.hselab-lightbox-filename {
    font-size: .78rem !important;
    color: rgba(255,255,255,.65) !important;
    word-break: break-all;
    margin-bottom: 1rem !important;
}
.hselab-lightbox-actions {
    display: flex;
    justify-content: center;
    gap: .5rem;
    flex-wrap: wrap;
}
.hselab-lightbox-hint {
    color: rgba(255,255,255,.72);
    font-size: .75rem;
    text-align: center;
}
.hselab-pdf-viewer {
    width: 100%;
    height: min(78vh, 820px);
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: #1e293b;
    border-radius: 8px;
    overflow: hidden;
}
.hselab-pdf-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    flex-wrap: wrap;
    padding: .45rem .55rem;
    background: rgba(15, 23, 42, .92);
    flex-shrink: 0;
}
.hselab-pdf-page {
    color: #fff;
    font-size: .85rem;
    font-weight: 600;
    min-width: 4.5rem;
    text-align: center;
}
.hselab-pdf-pages {
    flex: 1;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: .55rem;
    background: #334155;
}
.hselab-pdf-canvas {
    display: block;
    max-width: 100%;
    height: auto;
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .35);
}
