/* =============================================================================
   Diego10 — tema grafico
   Nessuna dipendenza esterna: font di sistema, icone SVG inline, solo CSS.
   ============================================================================= */

:root {
    /* Shell scura (barra superiore, pannello login) */
    --shell: #0b1220;
    --shell-2: #111a2e;
    --shell-text: #c9d3e6;

    /* Superfici */
    --bg: #f2f5fa;
    --surface: #ffffff;
    --surface-2: #f7f9fc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    /* Testo */
    --text: #0f172a;
    --text-2: #334155;
    --muted: #5b6b82;

    /* Brand */
    --primary: #3558f0;
    --primary-600: #2645d4;
    --primary-50: #eef2ff;
    --accent: #7c4dff;
    --gradient: linear-gradient(135deg, #3b6cff 0%, #6a4dff 100%);

    /* Stati */
    --ok: #15803d;
    --ok-50: #e8f7ee;
    --ok-strong: #16a34a;
    --warn: #b45309;
    --warn-50: #fff5e6;
    --warn-strong: #f59e0b;
    --error: #b91c1c;
    --error-50: #fdecec;
    --error-strong: #dc2626;

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .18);
    --shadow-lg: 0 24px 60px -24px rgba(30, 41, 90, .35);
    --ring: 0 0 0 4px rgba(53, 88, 240, .22);

    --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: "Cascadia Code", "JetBrains Mono", ui-monospace, Consolas, "Liberation Mono", monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); }
strong { font-weight: 650; }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.icon { width: 18px; height: 18px; flex: none; }

.visually-hidden {
    position: absolute !important;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.skip-link {
    position: absolute; left: -9999px; top: 0;
    background: var(--text); color: #fff;
    padding: 8px 12px; z-index: 200; border-radius: var(--radius-sm);
}
.skip-link:focus { left: 8px; top: 8px; }

.muted { color: var(--muted); }
.small { font-size: .85em; }
.mono { font-family: var(--mono); }
.inline-form { display: inline; margin: 0; }

/* ---------- Logo e avatar ---------- */

.logo {
    display: inline-grid;
    place-items: center;
    width: 36px; height: 36px;
    border-radius: 10px;
    background: var(--gradient);
    color: #fff;
    box-shadow: 0 6px 16px -6px rgba(80, 90, 255, .7), inset 0 1px 0 rgba(255, 255, 255, .25);
    flex: none;
}
.logo .icon { width: 60%; height: 60%; }
.logo img { width: 74%; height: 74%; display: block; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .25)); }
.logo-sm { width: 32px; height: 32px; border-radius: 9px; }
.logo-md { width: 44px; height: 44px; border-radius: 12px; }
.logo-lg { width: 72px; height: 72px; border-radius: 20px; }

.avatar {
    display: inline-grid;
    place-items: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--gradient);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .02em;
    flex: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: 12px; background: linear-gradient(135deg, #e0e7ff, #ede4ff); color: #3b3fbf; }

/* ---------- Barra superiore ---------- */

.topbar {
    position: sticky; top: 0; z-index: 40;
    background: var(--shell);
    background-image: linear-gradient(180deg, var(--shell-2), var(--shell));
    color: var(--shell-text);
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    box-shadow: 0 4px 20px -8px rgba(2, 6, 23, .5);
}
.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 12px 28px;
    min-height: 64px;
    padding: 0 24px;
}
.topbar-brand {
    display: flex; align-items: center; gap: 10px;
    color: #fff; text-decoration: none;
    font-weight: 700; font-size: 16px; letter-spacing: -.01em;
    white-space: nowrap;
}
.topbar-nav { display: flex; gap: 4px; flex: 1; }
.topbar-nav a {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px;
    border-radius: 10px;
    color: var(--shell-text);
    text-decoration: none;
    font-weight: 500;
    transition: background-color .15s, color .15s;
}
.topbar-nav a .icon { opacity: .8; }
.topbar-nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.topbar-nav a[aria-current="page"] { background: rgba(99, 118, 255, .22); color: #fff; box-shadow: inset 0 0 0 1px rgba(140, 155, 255, .35); }
.topbar-nav a[aria-current="page"] .icon { opacity: 1; }

.topbar-user { display: flex; align-items: center; gap: 12px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { color: #fff; font-weight: 600; font-size: 14px; }
.user-role { color: #8d9ab3; font-size: 12px; }
.btn-logout {
    display: inline-flex; align-items: center; gap: 8px;
    margin-left: 6px;
    padding: 8px 12px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 10px;
    background: transparent;
    color: var(--shell-text);
    font: inherit; font-size: 14px;
    cursor: pointer;
    transition: background-color .15s, color .15s, border-color .15s;
}
.btn-logout:hover { background: rgba(239, 68, 68, .15); border-color: rgba(239, 68, 68, .45); color: #fff; }

/* ---------- Pulsanti ---------- */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px;
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: 10px;
    font: inherit; font-size: 14.5px; font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    background: none; color: var(--text);
    transition: background-color .15s, border-color .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--gradient);
    color: #fff;
    box-shadow: 0 8px 18px -8px rgba(59, 92, 255, .8), inset 0 1px 0 rgba(255, 255, 255, .2);
}
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text-2); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); border-color: #94a3b8; color: var(--text); }
.btn-danger-soft { background: var(--error-50); color: var(--error); border-color: #f7c9c9; }
.btn-danger-soft:hover { background: #fbdada; }
.btn-success-soft { background: var(--ok-50); color: var(--ok); border-color: #bfe6cc; }
.btn-success-soft:hover { background: #d6f0df; }
.btn-sm { min-height: 34px; padding: 5px 12px; font-size: 13.5px; border-radius: 8px; }
.btn-sm .icon { width: 15px; height: 15px; }
.btn-lg { min-height: 50px; font-size: 16px; border-radius: 12px; }
.btn-block { width: 100%; }
.btn-ghost {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-2);
    font: inherit; font-size: 13.5px; font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}
.btn-ghost:hover { border-color: var(--border-strong); }

/* ---------- Campi ---------- */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 13.5px; color: var(--text-2); }
.field input, .field select {
    width: 100%;
    font: inherit; font-size: 15px;
    padding: 10px 14px;
    min-height: 44px;
    border: 1px solid var(--border-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder { color: #94a3b8; }
.field input:hover, .field select:hover { border-color: #94a3b8; }
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.field select:disabled { background: var(--surface-2); color: var(--muted); }
.field small { font-size: 12.5px; }

.input-icon { position: relative; }
.input-icon .icon {
    position: absolute; left: 13px; top: 50%;
    transform: translateY(-50%);
    color: #8a97ad;
    pointer-events: none;
}
.input-icon input { padding-left: 42px; }
.input-icon:focus-within .icon { color: var(--primary); }

.field-check { display: flex; align-items: center; gap: 10px; margin: 4px 0 20px; }
.field-check input { width: 18px; height: 18px; accent-color: var(--primary); }
.field-check label { font-weight: 500; }

/* ---------- Card, alert, messaggi ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 22px 24px;
}
.card-flush { padding: 0; overflow: hidden; }
.card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
}

.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    margin: 0 0 16px;
    font-size: 14px; font-weight: 500;
}
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--error-50); color: var(--error); border: 1px solid #f5c2c2; }

.flash-stack {
    position: fixed; top: 80px; right: 20px; z-index: 60;
    display: flex; flex-direction: column; gap: 10px;
    max-width: min(420px, calc(100vw - 40px));
}
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--ok-strong);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    animation: flash-in .25s ease-out, flash-out .4s ease-in 6s forwards;
}
.flash-success .icon { color: var(--ok-strong); }
.flash-error { border-left-color: var(--error-strong); }
.flash-error .icon { color: var(--error-strong); }
.page-auth .flash-stack { top: 20px; }

@keyframes flash-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes flash-out { to { opacity: 0; transform: translateX(16px); visibility: hidden; } }

.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12.5px; font-weight: 600;
    white-space: nowrap;
}
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-50); color: var(--ok); }
.badge-off { background: #eef1f5; color: var(--muted); }
.badge-admin { background: #f1eaff; color: #5b2fd6; }
.badge-role { background: var(--primary-50); color: #2d44c4; }

/* =============================================================================
   Login / Setup
   ============================================================================= */

.page-auth {
    background:
        radial-gradient(800px 420px at 50% -160px, rgba(99, 102, 241, .14), transparent 70%),
        var(--bg);
}
.auth { display: grid; place-items: center; min-height: 100vh; padding: 40px 20px; }
.auth-main { width: 100%; display: flex; justify-content: center; }
.auth-panel {
    width: 100%;
    max-width: 420px;
    padding: 36px 34px 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}
.auth-panel h1 { margin: 0 0 6px; font-size: 28px; letter-spacing: -.02em; font-weight: 750; }
.auth-subtitle { margin: 0 0 26px; color: var(--muted); }
.auth-form .btn-block { margin-top: 8px; }
.auth-note {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin: 22px 0 0;
    font-size: 12.5px; color: var(--muted);
}
.auth-note .icon { width: 15px; height: 15px; color: var(--ok-strong); }

/* =============================================================================
   Home — scansione
   ============================================================================= */

.page-home {
    background:
        radial-gradient(900px 420px at 50% -120px, rgba(99, 102, 241, .16), transparent 70%),
        var(--bg);
}
.home { display: flex; flex-direction: column; align-items: center; padding: 4vh 20px 60px; }

.home-hero { text-align: center; margin-bottom: 24px; }
.home-title { margin: 0; font-size: clamp(30px, 4.4vw, 46px); font-weight: 780; letter-spacing: -.03em; }
.home-subtitle { margin: 8px 0 0; color: var(--muted); font-size: 16px; }

.scan-form { width: 100%; max-width: 720px; }
.scan-box {
    position: relative;
    display: flex; align-items: center;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    transition: border-color .15s, box-shadow .15s, background-color .2s;
}
.scan-box:focus-within { border-color: var(--primary); box-shadow: var(--ring), var(--shadow-lg); }
.scan-icon { width: 30px; height: 30px; margin-left: 22px; color: var(--primary); }
.scan-input {
    flex: 1; min-width: 0;
    border: 0; outline: 0;
    background: transparent;
    padding: 22px 18px;
    font-family: var(--mono);
    font-size: clamp(20px, 2.8vw, 28px);
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text);
}
.scan-input::placeholder { color: #a3aec2; font-family: var(--font); font-weight: 500; letter-spacing: 0; text-transform: none; }
.scan-kbd {
    margin-right: 18px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-bottom-width: 3px;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--muted);
    font-family: var(--font); font-size: 12px; font-weight: 700;
    white-space: nowrap;
}

/* esito sull'input (colore visibile anche con la coda dell'occhio) */
.scan-box:has(.is-ok)    { border-color: var(--ok-strong);    background: var(--ok-50);    box-shadow: 0 0 0 6px rgba(22, 163, 74, .18), var(--shadow-lg); }
.scan-box:has(.is-warn)  { border-color: var(--warn-strong);  background: var(--warn-50);  box-shadow: 0 0 0 6px rgba(245, 158, 11, .2), var(--shadow-lg); }
.scan-box:has(.is-error) { border-color: var(--error-strong); background: var(--error-50); box-shadow: 0 0 0 6px rgba(220, 38, 38, .18), var(--shadow-lg); }
/* fallback per browser senza :has() */
.scan-input.is-ok    { color: var(--ok); }
.scan-input.is-warn  { color: var(--warn); }
.scan-input.is-error { color: var(--error); }

.scan-help {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    margin: 14px 0 0;
    font-size: 13.5px; color: var(--muted);
}
.live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--ok-strong);
    box-shadow: 0 0 0 0 rgba(22, 163, 74, .5);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(22, 163, 74, .5); }
    70% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); }
    100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); }
}

.scan-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin-top: 28px; }
.stat {
    display: flex; align-items: center; gap: 10px;
    min-width: 160px;
    padding: 12px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-sm);
    font-size: 14px; color: var(--muted);
}
.stat span { white-space: nowrap; }
.stat strong { color: var(--text); font-size: 20px; margin-right: 4px; font-variant-numeric: tabular-nums; }
.stat .icon { width: 32px; height: 32px; padding: 7px; border-radius: 9px; }
.stat-ok .icon    { background: var(--ok-50);    color: var(--ok); }
.stat-warn .icon  { background: var(--warn-50);  color: var(--warn); }
.stat-error .icon { background: var(--error-50); color: var(--error); }

.scan-tools { display: flex; align-items: center; gap: 16px; margin-top: 18px; }
.btn-ghost .icon { width: 16px; height: 16px; }
.btn-ghost[aria-pressed="true"] .icon-off,
.btn-ghost[aria-pressed="false"] .icon-on { display: none; }
.btn-ghost[aria-pressed="true"] .icon-on { color: var(--primary); }
.scan-pending { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; }
.scan-pending[hidden] { display: none; }
.spinner {
    width: 14px; height: 14px;
    border: 2px solid var(--border-strong);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.recent-card {
    width: 100%; max-width: 720px;
    margin-top: 30px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.recent-card[hidden] { display: none; }
.recent-title {
    margin: 0;
    padding: 14px 20px;
    font-size: 12px; font-weight: 700;
    letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}
.recent { list-style: none; margin: 0; padding: 0; }
.recent-item {
    display: grid;
    grid-template-columns: 96px 200px 1fr auto auto;
    align-items: center;
    gap: 14px;
    padding: 11px 20px;
    border-bottom: 1px solid #eef1f6;
    font-size: 14px;
    animation: row-in .25s ease-out;
}
.recent-item:last-child { border-bottom: 0; }
.recent-item:first-child { background: #fafbff; }
.recent-badge {
    justify-self: start;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px; font-weight: 700;
}
.recent-ok .recent-badge    { background: var(--ok-50);    color: var(--ok); }
.recent-warn .recent-badge  { background: var(--warn-50);  color: var(--warn); }
.recent-error .recent-badge { background: var(--error-50); color: var(--error); }
.recent-code { font-family: var(--mono); font-weight: 600; color: var(--text); user-select: all; -webkit-user-select: all; cursor: text; }
.recent-copy {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-2);
    font: inherit; font-size: 12.5px; font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.recent-copy:hover { border-color: var(--border-strong); color: var(--primary); }
.recent-copy.is-done { background: var(--ok-50); border-color: #bfe6cc; color: var(--ok); }
.recent-msg { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-time { color: #8a97ad; font-size: 13px; font-variant-numeric: tabular-nums; }

@keyframes row-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }

/* ---------- Toast ---------- */

.toasts {
    position: fixed; left: 50%; bottom: 32px; z-index: 70;
    transform: translateX(-50%);
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    pointer-events: none;
    width: max-content; max-width: calc(100vw - 32px);
}
.toast {
    min-width: 340px;
    padding: 16px 26px;
    border-radius: 16px;
    color: #fff;
    text-align: center;
    box-shadow: 0 20px 40px -12px rgba(2, 6, 23, .45);
    animation: toast-in .18s ease-out;
    transition: opacity .3s, transform .3s;
}
.toast-title { font-size: 21px; font-weight: 750; letter-spacing: -.01em; }
.toast-reason { margin-top: 4px; font-size: 15px; font-weight: 500; max-width: 520px; white-space: normal; }
.toast-code { margin-top: 2px; font-family: var(--mono); font-size: 14px; opacity: .9; }
.toast-ok    { background: linear-gradient(135deg, #16a34a, #0f8a3d); }
.toast-warn  { background: linear-gradient(135deg, #f59e0b, #d97706); }
.toast-error { background: linear-gradient(135deg, #ef4444, #c81e1e); }
.toast-hide { opacity: 0; transform: translateY(10px); }

@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* =============================================================================
   Pagine interne
   ============================================================================= */

.container { max-width: 1280px; margin: 0 auto; padding: 32px 24px 64px; }

.page-head {
    display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
    gap: 16px 24px;
    margin-bottom: 24px;
}
.page-head h1 { margin: 0; font-size: 28px; font-weight: 750; letter-spacing: -.02em; }
.page-subtitle { margin: 4px 0 0; color: var(--muted); }

.kpis { display: flex; gap: 10px; }
.kpi {
    display: flex; flex-direction: column; align-items: flex-start;
    min-width: 96px;
    padding: 10px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}
.kpi-value { font-size: 22px; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }

.filters {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.4fr) minmax(0, 1.4fr) auto;
    gap: 0 16px;
    align-items: end;
    margin-bottom: 20px;
}
.filters .field { margin-bottom: 0; }

/* Data + ora affiancate in un unico gruppo */
.field-datetime { border: 0; padding: 0; margin: 0; min-width: 0; }
.field-datetime legend { padding: 0; margin-bottom: 6px; font-weight: 600; font-size: 13.5px; color: var(--text-2); }
.datetime { display: flex; gap: 8px; }
.datetime input[type="date"] { flex: 1.5; min-width: 0; }
.datetime input[type="time"] { flex: 1; min-width: 0; }
.filters-actions { display: flex; gap: 8px; }
.filters-actions .btn { min-height: 44px; }

.results-summary { margin: 0; color: var(--text-2); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th, .table td { padding: 12px 20px; text-align: left; vertical-align: middle; border-bottom: 1px solid #edf1f6; }
.table th {
    background: var(--surface-2);
    color: var(--muted);
    font-size: 12px; font-weight: 700;
    letter-spacing: .06em; text-transform: uppercase;
    white-space: nowrap;
    position: sticky; top: 0;
}
.table tbody tr { transition: background-color .12s; }
.table tbody tr:hover { background: #f8faff; }
.table tbody tr:last-child td { border-bottom: 0; }
.table td { color: var(--text-2); }
.table .actions { white-space: nowrap; text-align: right; }
.table .actions .inline-form { margin-left: 6px; }
.is-inactive .person-name, .is-inactive .avatar-sm { opacity: .55; }

.code-chip {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 8px;
    background: #f1f4fb;
    border: 1px solid #e3e8f4;
    font-family: var(--mono);
    font-size: 14px; font-weight: 600;
    letter-spacing: .03em;
    color: var(--text);
    white-space: nowrap;
    user-select: all; -webkit-user-select: all; /* un click seleziona tutto il codice */
}

.code-cell { display: flex; align-items: center; gap: 8px; }
.btn-copy {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 9px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font: inherit; font-size: 12.5px; font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    opacity: .75;
    transition: opacity .12s, color .12s, border-color .12s, background-color .12s;
}
.btn-copy .icon { width: 14px; height: 14px; }
.table tbody tr:hover .btn-copy, .btn-copy:focus-visible { opacity: 1; }
.btn-copy:hover { color: var(--primary); border-color: var(--border-strong); }
.btn-copy.is-done { opacity: 1; background: var(--ok-50); border-color: #bfe6cc; color: var(--ok); }

.person { display: flex; align-items: center; gap: 12px; }
.person-meta { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.person-name { color: var(--text); font-weight: 600; }
.person-sub { color: var(--muted); font-size: 13px; }

.pagination {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}
.pagination-info { color: var(--muted); padding: 0 10px; font-size: 14px; }

.empty-state { text-align: center; padding: 56px 20px; }
.empty-state .icon { width: 52px; height: 52px; padding: 12px; border-radius: 14px; background: var(--primary-50); color: var(--primary); }
.empty-state p { margin: 6px 0 0; }
.empty-state p:first-of-type { margin-top: 14px; font-size: 16px; }

.user-form-card { margin-bottom: 24px; }
.user-form-card summary {
    display: flex; align-items: center; gap: 12px;
    cursor: pointer; list-style: none;
    font-weight: 700; font-size: 16px;
}
.user-form-card summary::-webkit-details-marker { display: none; }
.user-form-card summary::after { content: "▾"; margin-left: auto; color: var(--muted); transition: transform .15s; }
.user-form-card[open] summary::after { transform: rotate(180deg); }
.user-form-card[open] summary { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.summary-icon {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; border-radius: 10px;
    background: var(--primary-50); color: var(--primary);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.form-actions { display: flex; gap: 10px; }

/* =============================================================================
   Statistiche
   Una sola serie → un solo colore (blu); scala sequenziale blu per la mappa di calore.
   Il testo dei grafici usa sempre i colori del testo, mai quello della serie.
   ============================================================================= */

.page-stats {
    --viz: #2a78d6;
    --viz-hover: #256abf;
    --viz-emph: #1c5cab;
    --viz-grid: #e7ebf1;
    --viz-axis: #cbd5e1;
    --heat-0: #eef2f7;
    --heat-1: #cde2fb;
    --heat-2: #9ec5f4;
    --heat-3: #6da7ec;
    --heat-4: #3987e5;
    --heat-5: #256abf;
    --heat-6: #184f95;
}

.segmented {
    display: inline-flex;
    padding: 4px;
    gap: 2px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
}
.segmented a {
    padding: 7px 14px;
    border-radius: 9px;
    color: var(--text-2);
    text-decoration: none;
    font-size: 14px; font-weight: 600;
    white-space: nowrap;
}
.segmented a:hover { background: var(--surface-2); }
.segmented a[aria-current="page"] { background: var(--gradient); color: #fff; box-shadow: 0 6px 14px -8px rgba(59, 92, 255, .9); }

.tiles {
    display: grid;
    grid-template-columns: 1.25fr repeat(4, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}
.tile {
    display: flex; flex-direction: column; gap: 4px;
    min-width: 0;
    padding: 16px 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}
.tile-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
.tile-label .icon { width: 16px; height: 16px; color: var(--primary); }
.tile-value { font-size: 26px; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-sub { font-size: 13px; color: var(--muted); }
.tile-hero { background: var(--shell); background-image: linear-gradient(150deg, #1b2a55 0%, #0d1530 100%); border-color: transparent; }
.tile-hero .tile-label, .tile-hero .tile-sub { color: #a9b6d3; }
.tile-hero .tile-label .icon { color: #a5b4fc; }
.tile-hero .tile-value { color: #fff; font-size: 34px; }

.chart-card { margin-bottom: 20px; }
.chart-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.chart-head h2, .card-title { margin: 0; font-size: 16px; font-weight: 700; }
.chart-head p { margin: 2px 0 0; font-size: 13px; }

.grid-charts { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 20px; }

.chart { display: block; width: 100%; height: auto; overflow: visible; font-family: var(--font); }
.chart .grid { stroke: var(--viz-grid); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .axis { stroke: var(--viz-axis); stroke-width: 1; vector-effect: non-scaling-stroke; }
.chart .tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.chart .tick-sub { fill: #8a97ad; font-size: 11px; }
.chart .value { fill: var(--text); font-size: 13px; font-weight: 700; }
.chart .bar path { fill: var(--viz); transition: fill .12s; }
.chart .bar.is-emph path { fill: var(--viz-emph); }
.chart .bar.is-hover path { fill: var(--viz-hover); }
.chart .bar .hit { fill: transparent; cursor: default; }
.chart .bar.is-hover .hit { fill: rgba(53, 88, 240, .06); }

.hm { transition: opacity .12s; }
.hm.is-hover { stroke: var(--text); stroke-width: 2; }
.hm-0, .hm-sw-0 { fill: var(--heat-0); background: var(--heat-0); }
.hm-1, .hm-sw-1 { fill: var(--heat-1); background: var(--heat-1); }
.hm-2, .hm-sw-2 { fill: var(--heat-2); background: var(--heat-2); }
.hm-3, .hm-sw-3 { fill: var(--heat-3); background: var(--heat-3); }
.hm-4, .hm-sw-4 { fill: var(--heat-4); background: var(--heat-4); }
.hm-5, .hm-sw-5 { fill: var(--heat-5); background: var(--heat-5); }
.hm-6, .hm-sw-6 { fill: var(--heat-6); background: var(--heat-6); }
.heat-legend { display: flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); }
.heat-legend span { margin: 0 5px; }
.hm-sw { display: inline-block; width: 18px; height: 12px; border-radius: 3px; }
.heatmap-wrap { overflow-x: auto; }
.heatmap-wrap .chart { min-width: 640px; }

.callouts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.callout {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2);
    font-size: 14px;
}
.callout span { display: flex; flex-direction: column; line-height: 1.35; }
.callout strong { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.callout .icon { width: 34px; height: 34px; padding: 8px; border-radius: 10px; }
.callout-up .icon { background: var(--primary-50); color: var(--viz-emph); }
.callout-down .icon { background: #eef1f5; color: var(--muted); }

.data-table { margin-top: 14px; }
.data-table summary { cursor: pointer; color: var(--primary); font-size: 13.5px; font-weight: 600; }
.data-table .table { margin-top: 10px; }
.table-compact th, .table-compact td { padding: 7px 12px; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

.ranking { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.ranking li { display: flex; align-items: center; gap: 12px; }
.rank {
    display: inline-grid; place-items: center;
    width: 26px; height: 26px; flex: none;
    border-radius: 8px;
    background: #eef1f5;
    color: var(--muted);
    font-size: 12.5px; font-weight: 700;
}
.ranking li:first-child .rank { background: var(--gradient); color: #fff; }
.rank-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.rank-line { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.rank-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-value { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.rank-bar {
    -webkit-appearance: none; appearance: none;
    width: 100%; height: 8px;
    border: 0; border-radius: 4px;
    background: #edf1f7;
    overflow: hidden;
}
.rank-bar::-webkit-progress-bar { background: #edf1f7; border-radius: 4px; }
.rank-bar::-webkit-progress-value { background: var(--viz); border-radius: 4px; }
.rank-bar::-moz-progress-bar { background: var(--viz); border-radius: 4px; }

.day-link { color: var(--text); font-weight: 600; text-decoration: none; }
.day-link:hover { color: var(--primary); text-decoration: underline; }
.day-dow { display: inline-block; min-width: 30px; color: var(--muted); font-weight: 600; text-transform: capitalize; }
.table tr.is-empty td { color: #94a3b8; }
.page-stats .table td { white-space: nowrap; }

.chart-tip {
    position: fixed; z-index: 90;
    display: flex; flex-direction: column; gap: 2px;
    padding: 9px 12px;
    background: var(--shell);
    color: #dbe3f3;
    border-radius: 10px;
    box-shadow: 0 12px 28px -10px rgba(2, 6, 23, .5);
    font-size: 13px;
    pointer-events: none;
    white-space: nowrap;
}
.chart-tip[hidden] { display: none; }
.chart-tip strong { color: #fff; font-size: 13.5px; }

@media (max-width: 1100px) {
    .tiles { grid-template-columns: repeat(3, 1fr); }
    .tile-hero { grid-column: 1 / -1; }
    .grid-charts { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .tiles { grid-template-columns: 1fr 1fr; }
    .callouts { grid-template-columns: 1fr; }
    .segmented { width: 100%; }
    .segmented a { flex: 1; text-align: center; padding: 7px 6px; font-size: 13px; }
}

/* ---------- Pagina di errore ---------- */

.error-page {
    max-width: 520px;
    margin: 14vh auto;
    padding: 40px 32px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.error-page h1 {
    margin: 0;
    font-size: 72px; font-weight: 800; letter-spacing: -.04em;
    background: var(--gradient);
    -webkit-background-clip: text; background-clip: text;
    color: transparent;
}
.debug { text-align: left; white-space: pre-wrap; background: var(--surface-2); padding: 12px; border-radius: 10px; font-size: 13px; }

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 1020px) {
    .user-meta { display: none; }
    .topbar-nav a span { display: none; }
    .topbar-nav a { padding: 10px 12px; }
}

@media (max-width: 900px) {
    .filters { grid-template-columns: 1fr 1fr; }
    .filters .field:first-child, .filters-actions { grid-column: 1 / -1; }
    .filters .field { margin-bottom: 14px; }
    .grid-2 { grid-template-columns: 1fr; }
    .recent-item { grid-template-columns: 90px 1fr auto auto; }
    .recent-msg { display: none; }
}

@media (max-width: 560px) {
    .topbar-inner { padding: 0 14px; gap: 10px; }
    .auth-panel { padding: 28px 22px 24px; }
    .topbar-brand span { display: none; }
    .btn-logout span { display: none; }
    .container { padding: 22px 16px 48px; }
    .home { padding-top: 3vh; }
    .scan-kbd { display: none; }
    .filters { grid-template-columns: 1fr; }
    .stat { min-width: 0; flex: 1; }
    .kpis { width: 100%; }
    .kpi { flex: 1; }
    .toast { min-width: 0; }
    .toast-title { font-size: 18px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
    .flash { animation: none; }
}
