*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { overflow-x: hidden; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 3px; }
::selection { background: #dbeafe; color: var(--text); }
/* Token unificati: vedi assets/css/components/00-tokens.css (unica fonte di
   verita'). Il :root storico che stava qui e' stato rimosso per eliminare la
   divergenza di valori (--sidebar-bg, --shadow*). Le custom property si
   risolvono a computed-value time, quindi l'ordine di caricamento dei file
   non conta: 00-tokens.css definisce tutti i nomi usati sotto. */
body { font-family: 'Inter', 'Segoe UI', system-ui, sans-serif; font-size: 13px; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
.stage-banner { background: #d97706; color: #fff; text-align: center; padding: 5px; font-size: 11px; font-weight: 600; letter-spacing: .03em; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #0c0f16; position: relative; overflow: hidden; }
.login-page::before { content: ''; position: absolute; width: 700px; height: 700px; background: radial-gradient(circle, rgba(37,99,235,.1) 0%, transparent 60%); top: -200px; right: -200px; pointer-events: none; }
.login-page::after { content: ''; position: absolute; width: 600px; height: 600px; background: radial-gradient(circle, rgba(37,99,235,.06) 0%, transparent 60%); bottom: -200px; left: -200px; pointer-events: none; }
.login-container { width: 100%; max-width: 420px; padding: 24px; position: relative; z-index: 1; animation: loginFadeIn .5s ease-out; }
@keyframes loginFadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
.login-box { background: var(--white); border-radius: 20px; box-shadow: 0 25px 80px rgba(0,0,0,.25), 0 0 0 1px rgba(255,255,255,.05); padding: 44px 40px 40px; }
.login-logo { text-align: center; margin-bottom: 36px; }
.login-logo-icon { width: 56px; height: 56px; background: linear-gradient(135deg, var(--primary) 0%, #1d4ed8 100%); border-radius: 16px; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 16px; box-shadow: 0 6px 20px rgba(37,99,235,.35); }
.login-logo-icon svg { width: 28px; height: 28px; stroke: #fff; stroke-width: 1.8; fill: none; }
.login-logo h1 { font-size: 26px; font-weight: 700; color: var(--text); letter-spacing: -.04em; margin-bottom: 6px; }
.login-logo p { font-size: 14px; color: var(--text-light); font-weight: 400; }
.stage-tag { display: inline-block; background: #d97706; color: #fff; font-size: 10px; padding: 3px 10px; border-radius: 99px; font-weight: 600; margin-top: 8px; letter-spacing: .05em; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 8px; letter-spacing: .01em; }
.form-group .input-wrap { position: relative; }
.form-group .input-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; stroke: #94a3b8; stroke-width: 1.8; fill: none; pointer-events: none; transition: stroke .2s; }
.form-group .input-wrap input { width: 100%; padding: 12px 14px 12px 42px; border: 1.5px solid var(--border); border-radius: 10px; font-size: 14px; font-family: inherit; transition: all .2s; background: #f8fafc; color: var(--text); }
.form-group .input-wrap input::placeholder { color: #b0bec5; font-weight: 400; }
.form-group .input-wrap input:hover { border-color: #cbd5e1; }
.form-group .input-wrap input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3.5px rgba(37,99,235,.1); }
.form-group .input-wrap input:focus ~ svg,
.form-group .input-wrap:focus-within svg { stroke: var(--primary); }
.btn-primary { width: 100%; padding: 13px 16px; background: var(--primary); color: #fff; border: none; border-radius: 10px; font-size: 14.5px; font-weight: 600; cursor: pointer; transition: all .2s; letter-spacing: .01em; font-family: inherit; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn-primary:hover { background: var(--primary-dk); transform: translateY(-1px); box-shadow: 0 6px 20px rgba(37,99,235,.35); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 2px 8px rgba(37,99,235,.2); }
.btn-primary .btn-spinner { display: none; width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
.btn-primary.loading .btn-spinner { display: block; }
.btn-primary.loading .btn-label { display: none; }
.btn-primary.loading { opacity: .85; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.forgot-link { display: block; text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-light); text-decoration: none; transition: color .15s; font-weight: 500; }
.forgot-link:hover { color: var(--primary); }
.login-divider { height: 1px; background: var(--border); margin: 22px 0 18px; }
.error-msg { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; border-radius: 10px; padding: 11px 14px; font-size: 13px; margin-bottom: 18px; display: flex; align-items: center; gap: 10px; animation: msgSlideIn .25s ease-out; }
.error-msg svg { width: 16px; height: 16px; stroke: #dc2626; fill: none; stroke-width: 2; flex-shrink: 0; }
.success-msg { background: #f0fdf4; color: #16a34a; border: 1px solid #bbf7d0; border-radius: 10px; padding: 11px 14px; font-size: 13px; margin-bottom: 18px; display: flex; align-items: center; gap: 10px; animation: msgSlideIn .25s ease-out; }
.success-msg svg { width: 16px; height: 16px; stroke: #16a34a; fill: none; stroke-width: 2; flex-shrink: 0; }
@keyframes msgSlideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.login-footer { text-align: center; margin-top: 28px; font-size: 11.5px; color: rgba(255,255,255,.3); letter-spacing: .02em; }
@media (max-width: 480px) {
    .login-container { padding: 16px; }
    .login-box { padding: 32px 24px 28px; border-radius: 16px; }
    .login-logo h1 { font-size: 22px; }
}

/* ─── Layout ─────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--sidebar-bg);
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    transition: transform .25s ease;
    overflow: hidden;
}
.sidebar-logo {
    padding: 18px 18px 16px;
    font-size: 15px; font-weight: 700;
    color: #f8fafc; letter-spacing: -.015em;
    border-bottom: 1px solid var(--sidebar-divider);
    display: flex; align-items: center; justify-content: space-between;
    flex-shrink: 0;
}
.sidebar-logo-text { color: #f8fafc; letter-spacing: -.02em; }
.sidebar-logo-mark { display: none; font-size: 13px; font-weight: 800; color: var(--sidebar-accent); letter-spacing: .02em; }
body.sidebar-collapsed .sidebar-logo-text { display: none; }
body.sidebar-collapsed .sidebar-logo-mark { display: inline-block; }
.sidebar-close { display: none; background: none; border: none; cursor: pointer; color: #64748b; padding: 2px; line-height: 1; }
.sidebar-close i { width: 16px; height: 16px; }
.sidebar-nav { flex: 1; padding: 10px 0; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; color: #94a3b8; text-decoration: none; font-size: 12px; font-weight: 500; border-radius: 7px; margin: 2px 10px; transition: background-color .15s cubic-bezier(.4,0,.2,1), color .15s cubic-bezier(.4,0,.2,1); white-space: nowrap; position: relative; }
.nav-item i { width: 16px; height: 16px; flex-shrink: 0; stroke-width: 1.6; transition: color .15s cubic-bezier(.4,0,.2,1); }
.nav-item:hover { background: rgba(255,255,255,.04); color: #e2e8f0; }
.nav-item:hover i { color: #cbd5e1; }
/* a11y: focus da tastiera con accento oro (sovrascrive il :focus-visible globale blu, poco leggibile su navy);
   offset INTERNO per non venire tagliato al bordo della sidebar. Vale anche per .nav-sub-item (stessa classe). */
.nav-item:focus-visible { outline: 2px solid var(--sidebar-accent-light); outline-offset: -2px; }
.nav-group-header:focus-visible { outline: 2px solid var(--sidebar-accent-light); outline-offset: -2px; border-radius: 7px; }
.nav-item.active { background: rgba(212,165,116,.10); color: var(--sidebar-accent-light); font-weight: 600; }
.nav-item.active i { color: var(--sidebar-accent); }
.nav-item.active::before { content: ''; position: absolute; left: -10px; top: 6px; bottom: 6px; width: 3px; background: var(--sidebar-accent); border-radius: 0 2px 2px 0; }
/* Nav groups */
.nav-group { margin: 6px 0 4px; padding-top: 6px; border-top: 1px solid var(--sidebar-divider); }
.nav-group:first-of-type { border-top: none; padding-top: 0; }
.nav-group-header { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 9px 14px; background: none; border: none; cursor: pointer; color: #64748b; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; transition: color .15s cubic-bezier(.4,0,.2,1); }
.nav-group-header:hover { color: #cbd5e1; }
.nav-group.open > .nav-group-header { color: var(--sidebar-accent-light); }
.nav-group-left { display: flex; align-items: center; gap: 9px; }
.nav-group-left i { width: 14px; height: 14px; stroke-width: 1.6; }
.nav-chevron { width: 12px; height: 12px; stroke-width: 1.8; transition: transform .22s cubic-bezier(.4,0,.2,1); flex-shrink: 0; opacity: .6; }
.nav-group.open .nav-chevron { transform: rotate(180deg); opacity: 1; }
.nav-sub { overflow: hidden; max-height: 0; transition: max-height .25s cubic-bezier(.4,0,.2,1); }
.nav-group.open .nav-sub { max-height: 600px; }
.nav-sub-item { margin-left: 18px; padding-left: 14px; font-size: 11.5px; color: #7e8a9b; }
.nav-sub-item:hover { color: #e2e8f0; background: rgba(255,255,255,.03); }
.nav-sub-item.active { background: rgba(212,165,116,.08); color: var(--sidebar-accent-light); }
.nav-sub-item i { width: 14px; height: 14px; stroke-width: 1.5; }
.nav-sub-item::before { content: ''; display: inline-block; width: 2px; height: 11px; background: #334155; margin-right: 6px; flex-shrink: 0; border-radius: 1px; transition: background .15s; }
.nav-sub-item:hover::before, .nav-sub-item.active::before { background: var(--sidebar-accent); }
.sidebar-footer { padding: 14px 16px; border-top: 1px solid var(--sidebar-divider); display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.sidebar-email { color: #64748b; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge { display: inline-block; background: rgba(212,165,116,.12); color: var(--sidebar-accent-light); padding: 2px 9px; border-radius: 99px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; width: fit-content; border: 1px solid rgba(212,165,116,.18); }
.btn-logout { display: flex; align-items: center; gap: 7px; padding: 8px 11px; color: #64748b; border: 1px solid var(--sidebar-divider); border-radius: 7px; text-decoration: none; font-size: 12px; font-weight: 500; transition: background-color .15s cubic-bezier(.4,0,.2,1), color .15s cubic-bezier(.4,0,.2,1), border-color .15s cubic-bezier(.4,0,.2,1); }
.btn-logout:hover { background: rgba(127,29,29,.4); color: #fca5a5; border-color: #7f1d1d; }
.btn-logout i { width: 12px; height: 12px; stroke-width: 1.8; }
/* Overlay + topbar mobile */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 199; }
.topbar { display: none; align-items: center; gap: 12px; padding: 10px 16px; background: var(--sidebar-bg); position: sticky; top: 0; z-index: 150; border-bottom: 1px solid var(--sidebar-divider); }
.topbar-menu { background: none; border: none; cursor: pointer; color: #94a3b8; display: flex; align-items: center; }
.topbar-menu i { width: 20px; height: 20px; }
.topbar-title { font-size: 14px; font-weight: 700; color: #f1f5f9; }

/* Main content */
/* ⚠️ overflow-x: hidden implica overflow-y: auto → .main-content diventa uno scrollport e
   position:sticky non si attacca più a nulla. `clip` taglia uguale ma NON crea lo scrollport.
   La riga `hidden` resta come ripiego per i browser che non conoscono `clip`. */
.main-content { margin-left: var(--sidebar-w); flex: 1; min-width: 0; padding: 24px 28px; overflow-x: hidden; overflow-x: clip; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.page-header h1 { font-size: 18px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.card { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border: 1px solid var(--border); }
.card h3 { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-light); margin-bottom: 10px; }

/* ─── Sticky footer per tabelle scrollabili ──────
   NOTA: usa overflow: visible per non tagliare popover.
   Lo scroll verticale è gestito dal viewport principale.
   Il footer si fissa alla bottom del viewport via position: sticky.
   ──────────────────────────────────────────────── */
.table-wrapper.tw-sticky-footer {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    position: relative;
}
.table-wrapper.tw-sticky-footer > .table-footer {
    position: sticky;
    bottom: 0;
    left: 0;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    z-index: 5;
    box-shadow: 0 -2px 8px rgba(0,0,0,.04);
}

/* ─── Responsive ──────────────────────────────────── */
@media (max-width: 900px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: flex; }
    .sidebar-overlay.open { display: block; }
    .topbar { display: flex; }
    .main-content { margin-left: 0; padding: 16px 14px; }
}
@media (max-width: 600px) {
    .page-header h1 { font-size: 16px; }
    .main-content { padding: 12px 10px; }
}
