/* ==========================================================================
   FuelTrack — design system (v2, ottobre 2026)
   Colori come token: valori chiari su :root, scuri con [data-theme="dark"] su <html>
   (impostato da js/theme-init.js e applyTheme() in js/app.js). Nessuna regola !important per il tema.
   ========================================================================== */

:root {
    color-scheme: light;

    /* Superfici e testo */
    --bg: #f2f2f7;
    --surface: #ffffff;
    --surface-2: #f6f6f9;
    --fill: rgba(118, 118, 128, 0.12);
    --fill-strong: rgba(118, 118, 128, 0.2);
    --text: #1c1c1e;
    --text-2: #3a3a3c;
    --muted: #6e6e73;
    --faint: #8e8e93;
    --line: rgba(60, 60, 67, 0.13);
    --bar-bg: rgba(249, 249, 251, 0.78);
    --overlay: rgba(0, 0, 0, 0.32);
    --glass: rgba(255, 255, 255, 0.52);
    --glass-edge: rgba(255, 255, 255, 0.75);
    --glass-hi: rgba(255, 255, 255, 0.9);
    --glass-shadow: rgba(30, 40, 70, 0.22);
    --glass-pill: rgba(120, 120, 128, 0.16);

    /* Colori di significato */
    --accent: #0a63e8;
    --accent-hover: #0852c2;
    --accent-soft: rgba(10, 99, 232, 0.1);
    --on-accent: #ffffff;
    --gpl: #0f9d6a;
    --gpl-soft: rgba(16, 185, 129, 0.15);
    --gpl-text: #04694a;
    --benz: #e08a00;
    --benz-soft: rgba(245, 158, 11, 0.17);
    --benz-text: #8a4b06;
    --diesel: #5856d6;
    --diesel-soft: rgba(88, 86, 214, 0.14);
    --diesel-text: #3d3ab0;
    --ok: #1a8f4a;
    --ok-soft: rgba(52, 199, 89, 0.15);
    --warn: #b45309;
    --warn-soft: rgba(255, 159, 10, 0.16);
    --danger: #d70015;
    --danger-soft: rgba(255, 59, 48, 0.12);

    /* Grafici (letti da js/metrics.js) */
    --chart-grid: rgba(60, 60, 67, 0.1);
    --chart-text: #6e6e73;

    /* Forma */
    --radius-lg: 20px;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px -18px rgba(0, 0, 0, 0.18);
    --shadow-pop: 0 18px 50px -12px rgba(0, 0, 0, 0.3);

    /* Movimento: durate e curve in un solo punto */
    --ease: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
    --dur-fast: 0.2s;
    --dur: 0.45s;
    --dur-slow: 0.7s;

    /* Misure */
    --sidebar-w: 248px;
    --tabbar-h: 76px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --fill: rgba(118, 118, 128, 0.24);
    --fill-strong: rgba(118, 118, 128, 0.36);
    --text: #f5f5f7;
    --text-2: #d1d1d6;
    --muted: #a1a1a6;
    --faint: #8e8e93;
    --line: rgba(84, 84, 88, 0.55);
    --bar-bg: rgba(22, 22, 24, 0.78);
    --overlay: rgba(0, 0, 0, 0.55);
    --glass: rgba(58, 58, 64, 0.48);
    --glass-edge: rgba(255, 255, 255, 0.22);
    --glass-hi: rgba(255, 255, 255, 0.35);
    --glass-shadow: rgba(0, 0, 0, 0.6);
    --glass-pill: rgba(255, 255, 255, 0.14);

    --accent: #3b8bff;
    --accent-hover: #5c9dff;
    --accent-soft: rgba(59, 139, 255, 0.18);
    --on-accent: #ffffff;
    --gpl: #30d158;
    --gpl-soft: rgba(48, 209, 88, 0.18);
    --gpl-text: #5fe08a;
    --benz: #ffb340;
    --benz-soft: rgba(255, 179, 64, 0.18);
    --benz-text: #ffc670;
    --diesel: #8e8cff;
    --diesel-soft: rgba(142, 140, 255, 0.2);
    --diesel-text: #b0aeff;
    --ok: #30d158;
    --ok-soft: rgba(48, 209, 88, 0.18);
    --warn: #ffb340;
    --warn-soft: rgba(255, 179, 64, 0.18);
    --danger: #ff453a;
    --danger-soft: rgba(255, 69, 58, 0.2);

    --chart-grid: rgba(255, 255, 255, 0.08);
    --chart-text: #a1a1a6;

    --shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 10px 30px -18px rgba(0, 0, 0, 0.8);
    --shadow-pop: 0 20px 60px -10px rgba(0, 0, 0, 0.8);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; letter-spacing: -0.02em; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
img, svg, canvas { max-width: 100%; }
.tnum { font-variant-numeric: tabular-nums; }
[hidden], .hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- Struttura: menu laterale (desktop) e barra in basso (telefono) ---------- */
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
    display: none; flex-direction: column;
    padding: calc(20px + var(--safe-top)) 14px 16px calc(14px + var(--safe-left));
    background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar__brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
.sidebar__brand-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); font-size: 16px; }
.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar__link {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: var(--text-2); font-weight: 500; transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease;
}
.sidebar__link i { width: 20px; text-align: center; color: var(--muted); }
.sidebar__link:hover { background: var(--fill); }
.sidebar__link[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.sidebar__link[aria-current="page"] i { color: var(--accent); }
.sidebar__cta { margin: 14px 0 6px; }
.sidebar__footer { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.sidebar__user { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 0 6px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 13px; }
.sidebar__email { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

.tabbar {
    position: fixed; left: calc(12px + var(--safe-left)); right: calc(12px + var(--safe-right)); bottom: calc(10px + var(--safe-bottom)); z-index: 40;
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; gap: 2px;
    padding: 6px; border-radius: 999px;
    background: var(--glass);
    -webkit-backdrop-filter: blur(22px) saturate(190%); backdrop-filter: blur(22px) saturate(190%);
    border: 1px solid var(--glass-edge);
    box-shadow: inset 0 1px 0 var(--glass-hi), inset 0 -1px 0 rgba(0, 0, 0, 0.06), 0 14px 32px -10px var(--glass-shadow), 0 2px 6px rgba(0, 0, 0, 0.08);
}
@media (prefers-reduced-transparency: reduce) {
    .tabbar { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
.tabbar__item {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 48px; border-radius: 999px; color: var(--text); opacity: 0.62; font-size: 10px; font-weight: 600; border: 0; background: none; cursor: pointer;
    -webkit-tap-highlight-color: transparent; transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.tabbar__item i { font-size: 19px; }
.tabbar__item[aria-current="page"] { color: var(--accent); opacity: 1; background: var(--glass-pill); box-shadow: inset 0 1px 0 var(--glass-hi); }
.tabbar__plus {
    justify-self: center; width: 46px; height: 46px; border-radius: 50%;
    display: grid; place-items: center; color: var(--on-accent); font-size: 19px;
    background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 82%, #fff), var(--accent));
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), 0 8px 18px -6px var(--accent); transition: transform var(--dur-fast) var(--ease);
}
.tabbar__plus:active { transform: scale(0.92); }

.main { min-height: 100vh; min-height: 100dvh; padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px); }

@media (min-width: 1024px) {
    .sidebar { display: flex; }
    .tabbar { display: none; }
    .main { margin-left: var(--sidebar-w); padding-bottom: 40px; }
}

/* ---------- Intestazione pagina ---------- */
.page-header {
    position: sticky; top: 0; z-index: 30;
    padding: calc(12px + var(--safe-top)) max(16px, var(--safe-right)) 10px max(16px, var(--safe-left));
    background: var(--bar-bg);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid transparent;
    transition: border-color var(--dur-fast) ease;
}
.page-header.is-scrolled { border-bottom-color: var(--line); }
.page-header__inner { max-width: 1120px; margin: 0 auto; display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-header__titles { display: flex; flex-direction: column; gap: 8px; min-width: 0; flex: 1 1 auto; }
.page-title { font-size: 30px; font-weight: 700; line-height: 1.1; }
.page-subtitle { color: var(--muted); font-size: 14px; }
.page-actions { display: flex; align-items: center; gap: 8px; }
@media (min-width: 1024px) {
    .page-header { padding: 22px 32px 14px; }
    .page-title { font-size: 34px; }
}

/* Barra modulo (Annulla | Titolo | Salva) */
.form-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; max-width: 720px; margin: 0 auto; }
.form-bar__title { font-size: 16px; font-weight: 600; text-align: center; }
.form-bar .btn-text:first-child { justify-self: start; }
.form-bar .btn-text:last-child { justify-self: end; font-weight: 700; }

/* ---------- Contenuto ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 14px max(16px, var(--safe-right)) 8px max(16px, var(--safe-left)); display: flex; flex-direction: column; gap: 16px; }
.page--narrow { max-width: 720px; }
@media (min-width: 1024px) { .page { padding: 20px 32px; gap: 20px; } }

.section { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 4px; }
.section-title { font-size: 20px; font-weight: 700; }
.section-link { font-size: 14px; font-weight: 600; }
.caption { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

.card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card--flush { padding: 0; overflow: hidden; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-title small { font-weight: 500; color: var(--muted); font-size: 12.5px; }

/* Numero principale */
.hero { display: flex; flex-direction: column; gap: 4px; }
.hero__label { font-size: 13px; font-weight: 600; color: var(--muted); }
.hero__value { font-size: 44px; font-weight: 700; letter-spacing: -0.035em; line-height: 1.05; }
.hero__value small { font-size: 24px; font-weight: 600; letter-spacing: -0.02em; margin-left: 2px; }
.hero__note { font-size: 13px; color: var(--muted); }

.trend { display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; margin-top: 6px; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.trend--down { background: var(--ok-soft); color: var(--ok); }
.trend--up { background: var(--warn-soft); color: var(--warn); }
.trend--flat { background: var(--fill); color: var(--muted); }

/* Riquadri numerici */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 900px) { .tiles--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } .tiles--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tile__label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.tile__label i { font-size: 12px; }
.tile__value { font-size: 24px; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; overflow-wrap: anywhere; }
.tile__value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.tile__note { font-size: 12px; color: var(--faint); }
.tile--gpl .tile__value { color: var(--gpl-text); }
.tile--benz .tile__value { color: var(--benz-text); }

.badge-est { display: inline-flex; align-self: flex-start; margin-top: 4px; padding: 2px 8px; border-radius: 999px; background: var(--benz-soft); color: var(--benz-text); font-size: 11px; font-weight: 700; }

/* Schede per carburante: una colonna sul telefono, affiancate dove c'è spazio */
.tiles--fuel { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }

/* Griglie di pagina */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; } .grid-2--even { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ---------- Elenchi ---------- */
.list { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.list--plain { background: none; box-shadow: none; border-radius: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 52px; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--line); }
.row__main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row__title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__end { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 1px; flex-shrink: 0; }
.row__amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.row__actions { display: flex; gap: 2px; flex-shrink: 0; }
.row--link { color: inherit; cursor: pointer; transition: background-color var(--dur-fast) ease; }
.row--link:hover { background: var(--fill); }
.row--fresh { animation: rowFlash 1.8s var(--ease-out); }
@keyframes rowFlash { from { background: var(--ok-soft); } to { background: transparent; } }
.row__chevron { color: var(--faint); font-size: 13px; }
.row__icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; background: var(--fill); color: var(--muted); font-size: 14px; }

.group-label { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 4px 0; }

/* Etichette carburante */
.pill { display: inline-flex; align-items: center; justify-content: center; min-width: 64px; padding: 4px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.pill--gpl { background: var(--gpl-soft); color: var(--gpl-text); }
.pill--benzina { background: var(--benz-soft); color: var(--benz-text); }
.pill--diesel { background: var(--diesel-soft); color: var(--diesel-text); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot--gpl { background: var(--gpl); } .dot--benzina { background: var(--benz); } .dot--diesel { background: var(--diesel); }

/* ---------- Pulsanti ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 0; cursor: pointer;
    font-size: 15px; font-weight: 600; text-decoration: none; white-space: nowrap;
    transition: transform var(--dur-fast) var(--ease), background-color var(--dur-fast) ease, opacity var(--dur-fast) ease;
    -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--secondary { background: var(--fill); color: var(--text); }
.btn--secondary:hover { background: var(--fill-strong); }
.btn--danger { background: var(--danger-soft); color: var(--danger); }
.btn--block { width: 100%; }
.btn--lg { min-height: 52px; font-size: 16px; border-radius: 14px; }
.btn--sm { min-height: 34px; padding: 6px 12px; font-size: 13.5px; border-radius: 10px; }
.btn--ok { background: var(--ok); color: #fff; }
.btn-text { border: 0; background: none; color: var(--accent); font-size: 16px; padding: 10px 6px; min-height: 44px; cursor: pointer; }
.btn-text:disabled { color: var(--faint); cursor: default; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 0; display: inline-grid; place-items: center; background: transparent; color: var(--muted); cursor: pointer; transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease; }
.icon-btn:hover { background: var(--fill); color: var(--text); }
.icon-btn--danger:hover { background: var(--danger-soft); color: var(--danger); }

/* Controllo segmentato */
.seg { position: relative; display: flex; background: var(--fill); border-radius: 10px; padding: 2px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg__btn { flex: 1 0 auto; border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer; white-space: nowrap; transition: background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), color var(--dur-fast) ease; }
.seg__btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
:root[data-theme="dark"] .seg__btn[aria-pressed="true"] { background: var(--fill-strong); }
.seg--fuel .seg__btn[data-fuel="gpl"][aria-pressed="true"] { color: var(--gpl-text); }
.seg--fuel .seg__btn[data-fuel="benzina"][aria-pressed="true"] { color: var(--benz-text); }
.seg--fuel .seg__btn[data-fuel="diesel"][aria-pressed="true"] { color: var(--diesel-text); }

.vehicle-chip { display: inline-flex; align-items: center; gap: 8px; align-self: flex-start; padding: 6px 12px; border-radius: 999px; background: var(--fill); font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.vehicle-chip i { color: var(--accent); }

/* ---------- Moduli ---------- */
.form-group { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 16px; min-height: 52px; position: relative; }
.form-row + .form-row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 0.5px; background: var(--line); }
.form-row:focus-within { background: var(--surface-2); }
.form-row > label, .form-row__label { font-size: 15px; color: var(--text); white-space: nowrap; flex-shrink: 0; }
.form-row input, .form-row select, .form-row textarea {
    flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
    font: 16px var(--font); text-align: right; padding: 14px 0; font-variant-numeric: tabular-nums;
}
.form-row select { text-align-last: right; appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 2px; }
.form-row textarea { text-align: left; resize: vertical; min-height: 64px; }
.form-row--stack { flex-direction: column; align-items: stretch; gap: 0; padding-top: 12px; }
.form-row--stack textarea, .form-row--stack input { text-align: left; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus { outline: none; }
.form-row__unit { color: var(--faint); font-size: 14px; flex-shrink: 0; }
.form-row__value { color: var(--muted); font-variant-numeric: tabular-nums; }
.form-hint { font-size: 12.5px; color: var(--muted); padding: 0 6px; transition: color var(--dur-fast) ease; }
.form-hint--ok { color: var(--ok); }
.form-hint--error { color: var(--danger); font-weight: 600; }
.form-error { font-size: 12.5px; color: var(--danger); font-weight: 600; padding: 4px 6px 0; }
.form-row.is-invalid { box-shadow: inset 3px 0 0 var(--danger); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 4px; }
.input, .select {
    width: 100%; min-height: 46px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
    color: var(--text); font: 16px var(--font); padding: 10px 14px;
}
.input:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }

/* Moduli dentro una card: fondo leggermente diverso per distinguerli */
.card .form-group { background: var(--surface-2); box-shadow: none; }
.card .form-row:focus-within { background: var(--fill); }

/* Interruttore */
.switch { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--fill-strong); transition: background-color var(--dur-fast) ease; }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25); transition: transform var(--dur) var(--ease); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

/* ---------- Avvisi ---------- */
.banner { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.banner__icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; font-size: 14px; }
.banner__body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.banner__title { font-weight: 600; font-size: 14.5px; }
.banner__text { font-size: 13px; color: var(--muted); }
.banner--warn .banner__icon { background: var(--warn-soft); color: var(--warn); }
.banner--danger .banner__icon { background: var(--danger-soft); color: var(--danger); }
.banner--info .banner__icon { background: var(--accent-soft); color: var(--accent); }

/* ---------- Pannelli (dal basso su telefono, al centro su desktop) ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 60; background: var(--overlay); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
    width: 100%; max-width: 560px; max-height: calc(100dvh - 24px - var(--safe-top));
    background: var(--bg); border-radius: 18px 18px 0 0; box-shadow: var(--shadow-pop);
    display: flex; flex-direction: column; overflow: hidden;
    padding-bottom: var(--safe-bottom);
}
.sheet__grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--fill-strong); margin: 7px auto 0; }
.sheet__head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 4px 8px; border-bottom: 0.5px solid var(--line); }
.sheet__head .btn-text:first-child { justify-self: start; }
.sheet__head .btn-text:last-child, .sheet__head .icon-btn:last-child { justify-self: end; }
.sheet__title { font-size: 16px; font-weight: 600; text-align: center; }
.sheet__body { overflow-y: auto; padding: 14px 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.sheet__text { color: var(--muted); font-size: 14px; }
@media (min-width: 768px) {
    .sheet-backdrop { align-items: center; padding: 24px; }
    .sheet { border-radius: 18px; padding-bottom: 0; }
    .sheet__grabber { display: none; }
}
.action-sheet { display: flex; flex-direction: column; gap: 8px; padding: 0 10px calc(10px + var(--safe-bottom)); width: 100%; max-width: 460px; }
.action-sheet__group { background: var(--surface); border-radius: 14px; overflow: hidden; }
.action-sheet__msg { padding: 14px 16px; text-align: center; font-size: 13px; color: var(--muted); border-bottom: 0.5px solid var(--line); }
.action-sheet__title { font-weight: 600; color: var(--text); font-size: 14px; margin-bottom: 4px; }
.action-sheet__btn { display: block; width: 100%; min-height: 54px; border: 0; background: none; font-size: 17px; color: var(--accent); cursor: pointer; }
.action-sheet__btn + .action-sheet__btn { border-top: 0.5px solid var(--line); }
.action-sheet__btn--danger { color: var(--danger); }
.action-sheet__btn--bold { font-weight: 600; }
.action-sheet input { width: calc(100% - 32px); margin: 0 16px 12px; }
@media (min-width: 768px) { .action-sheet { padding-bottom: 0; } }

/* ---------- Grafici ---------- */
.chart-box { position: relative; height: 220px; }
.chart-box--tall { height: 280px; }
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

@media (min-width: 1024px) { .chart-box--fill { height: 340px; } }

/* ---------- Stati ---------- */
.skeleton { position: relative; overflow: hidden; background: var(--fill); border-radius: 8px; min-height: 1em; }
.skeleton::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent); animation: shimmer 1.4s infinite; }
:root[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent); }
@keyframes shimmer { to { transform: translateX(100%); } }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty i { font-size: 30px; color: var(--faint); }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid rgba(255, 255, 255, 0.45); border-top-color: #fff; animation: spin 0.7s linear infinite; }
.spinner--dark { border-color: var(--fill-strong); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Caricamento pagina */
#global-loader { position: fixed; inset: 0; z-index: 80; background: var(--overlay); display: none; align-items: center; justify-content: center; }
#global-loader.flex { display: flex; }

/* ---------- Tabelle compatte ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.tbl th { text-align: right; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 0.5px solid var(--line); white-space: nowrap; }
.tbl td { text-align: right; padding: 10px; border-bottom: 0.5px solid var(--line); white-space: nowrap; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
.tbl tr:last-child td { border-bottom: 0; }

/* Sezione apribile */
.disclosure { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.disclosure > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; font-weight: 600; }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary i { color: var(--faint); transition: transform var(--dur) var(--ease); }
.disclosure[open] > summary i { transform: rotate(90deg); }
.disclosure__body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 16px; }

/* Elenco semplice con numeri (diagnostica import) */
.plain-list { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* Zona di rilascio file */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius-lg); padding: 28px 16px; text-align: center; cursor: pointer; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 6px; transition: border-color var(--dur-fast) ease, background-color var(--dur-fast) ease; }
.dropzone:hover, .dropzone.is-over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone i { font-size: 30px; color: var(--faint); }
.dropzone strong { color: var(--text); }
.code { background: var(--fill); border-radius: 10px; padding: 10px 12px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; white-space: pre; color: var(--text-2); }
.radio-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; cursor: pointer; }
.radio-row input { margin-top: 3px; accent-color: var(--accent); width: 18px; height: 18px; }

/* Pillole scorrevoli (es. anni) */
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; border: 0; padding: 8px 14px; border-radius: 999px; background: var(--fill); color: var(--text-2); font-size: 14px; font-weight: 600; cursor: pointer; transition: background-color var(--dur-fast) ease, color var(--dur-fast) ease; }
.chip[aria-pressed="true"] { background: var(--text); color: var(--bg); }

/* Footer versione */
.app-footer { text-align: center; font-size: 12px; color: var(--faint); padding: 18px 16px 8px; }

/* ---------- Notifiche (Toastify): capsula con sfocatura e icona, colori dal tema ---------- */
.toastify.ft-toast {
    background: var(--surface) !important;
    color: var(--text); box-shadow: var(--shadow-pop); border: 0.5px solid var(--line);
    border-radius: 18px; padding: 12px 16px; font: 600 14.5px/1.3 var(--font);
    max-width: min(420px, calc(100vw - 32px));
    display: flex; align-items: center; gap: 10px;
}
.toastify.ft-toast::before { font: 900 18px "Font Awesome 6 Free"; flex-shrink: 0; }
.ft-toast--success::before { content: "\f058"; color: var(--ok); }
.ft-toast--error::before { content: "\f057"; color: var(--danger); }
.ft-toast--warning::before { content: "\f071"; color: var(--warn); }
.ft-toast--info::before { content: "\f05a"; color: var(--accent); }

/* ---------- Animazioni (attivate da js/motion-ui.js) ---------- */
@keyframes enterUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes popIn { from { opacity: 0; transform: translateY(16px) scale(0.98); } to { opacity: 1; transform: none; } }
.sheet-backdrop.is-open { animation: fadeIn var(--dur) var(--ease) both; }
.sheet-backdrop.is-open .sheet { animation: sheetUp var(--dur-slow) var(--ease) both; }
.sheet-backdrop.is-open .action-sheet { animation: sheetUp var(--dur) var(--ease) both; }
@media (min-width: 768px) {
    .sheet-backdrop.is-open .sheet, .sheet-backdrop.is-open .action-sheet { animation: popIn var(--dur) var(--ease) both; }
}

/* Ingresso a cascata: nascosto solo finché js/motion-ui.js non lo anima; rete di sicurezza dopo 3 s */
.anim-ready .a-in:not(.in) { opacity: 0; }
.anim-failsafe .a-in { opacity: 1 !important; }

/* Cambio pagina (View Transitions tra documenti) */
@view-transition { navigation: auto; }
.sidebar { view-transition-name: sidebar; }
.tabbar { view-transition-name: tabbar; }
::view-transition-old(root) { animation: 0.22s ease both fadeOut; }
::view-transition-new(root) { animation: var(--dur) var(--ease) both enterUpSoft; }
@keyframes fadeOut { to { opacity: 0; } }
@keyframes enterUpSoft { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
    @view-transition { navigation: none; }
}
