/* =============================================================================
   Financials v2 — design system (SPEC §7), con il brand ODRYON
   Un solo file: font, token, primitive, componenti. Niente framework, niente CDN.

   Il tema è quello della piattaforma (repository odryon-branding, Styles/), lo
   stesso di Agenda: lime #ccff00 come superficie firma (intestazione, bottone
   +, voce attiva), ink #454545 per testo e bottoni, bianco e paper per leggere.

   Regole non negoziabili:
   - contrasto WCAG AAA (7:1) per ogni testo, in entrambi i temi;
   - mai testo bianco su lime né lime su bianco: su lime solo ink o nero, il
     lime come testo solo su ink o sui fondi scuri;
   - testo mai sotto i 16px (il brand è più severo del §7.1), base 18px;
   - importi, date e percentuali in JetBrains Mono con tabular-nums;
   - entrate/uscite e stati (ok, avviso, errore) sempre con segno o icona,
     mai il colore da solo: il contesto si legge dal selettore, non dal colore.
   ========================================================================== */

/* --- Font (self-hosted: la CSP vuole font-src 'self') ---------------------- */

/* Solo il sottoinsieme latin (copre l'italiano, € e −) e solo i pesi usati.
   Il nome del file porta l'hash del contenuto: la cache del service worker
   resta corretta anche senza ?v=. */
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url("../fonts/poppins-latin-600.f4e80d9d.woff2") format("woff2");
}
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/poppins-latin-700.9338e65f.woff2") format("woff2");
}
@font-face {
    font-family: "Poppins";
    font-style: normal;
    font-weight: 900;
    font-display: swap;
    src: url("../fonts/poppins-latin-900.17ea1019.woff2") format("woff2");
}
@font-face {
    font-family: "Atkinson Hyperlegible Next";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/atkinson-hyperlegible-next-latin-400.5cb240a4.woff2") format("woff2");
}
@font-face {
    font-family: "Atkinson Hyperlegible Next";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/atkinson-hyperlegible-next-latin-700.0dbe07ed.woff2") format("woff2");
}
@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url("../fonts/jetbrains-mono-latin-400.14425ba9.woff2") format("woff2");
}
@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url("../fonts/jetbrains-mono-latin-700.d0d4e818.woff2") format("woff2");
}

/* --- Token ---------------------------------------------------------------- */

:root {
    /* Brand ODRYON (odryon-tokens.css). Non cambiano col tema. */
    --lime: #ccff00;
    --ink: #454545;
    --white: #ffffff;
    --black: #000000;
    --paper: #f5f5f5;
    --lime-wash: #f7ffd6;
    --ink-soft: #525252;       /* su bianco 7.8:1, su paper 7.2:1 — MAI su lime */
    --on-ink-soft: #dddddd;    /* su ink 7.1:1 */

    /* Tre ruoli, tre famiglie (odryon-type.css). */
    --font-display: "Poppins", "Segoe UI", system-ui, sans-serif;
    --font-text: "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;
    --font-tech: "JetBrains Mono", ui-monospace, Consolas, monospace;
    /* Nomi storici, tenuti perché li usano i componenti. */
    --font-sans: var(--font-text);
    --font-mono: var(--font-tech);

    /* Scala del brand: base 18px, mai sotto 16px. */
    --fs-xs: 16px;   /* etichette: il pavimento */
    --fs-sm: 16px;   /* testo denso dell'interfaccia (liste, campi, chip) */
    --fs-md: 18px;   /* corpo */
    --fs-lg: 22px;
    --fs-xl: 30px;
    --fs-hero: 40px;

    --lh-text: 1.5;  /* il minimo AAA per i paragrafi */
    --lh-title: 1.15;

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-6: 24px;
    --space-8: 32px;

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 20px;

    /* Un contenitore e il suo contenuto non possono avere lo stesso raggio: la
       curva interna va stretta di quanto e' spesso il bordo. */
    --radius-card: 16px;

    /* Tema chiaro: paper e bianco per leggere, ink per il testo. */
    --bg: var(--paper);
    --surface: #ffffff;
    --surface-2: var(--paper);
    --tint: var(--lime-wash);          /* hero, selezioni: ink 9.2:1, ink-soft 7.5:1 */
    --border: #dcdcdc;                 /* separatori decorativi */
    --border-strong: #767676;          /* bordi che delimitano un controllo: 4.5:1 sul bianco */
    --text: var(--ink);                /* 9.6:1 sul bianco, 8.8:1 su paper */
    --text-2: var(--ink-soft);         /* 7.8:1 sul bianco, 7.2:1 su paper */
    --text-3: var(--ink-soft);

    /* Funzionali: entrate, uscite, avvisi, informazioni. Sempre con segno o
       icona. Si usano le varianti "on-lime" del brand: le base (#0f663a…)
       passano il 7:1 sul bianco ma non sul paper (6.5:1) né sul lime-wash
       dell'hero (6.8:1); queste stanno sopra 7.6:1 su tutti e tre. */
    --pos: #0d5933;
    --neg: #9b1616;
    --warn: #7e3b0a;
    --info: #1b4c97;

    /* Il contesto (personale/business/totale) non cambia più colore: lo dice
       il selettore nell'intestazione, a parole. I nomi restano per chi li usa. */
    --ctx-personal: var(--ink);
    --ctx-business: var(--ink);
    --ctx-all: var(--ink);

    /* Accento: su superfici chiare è l'ink (il lime come testo sul bianco non
       si legge, 1.2:1). Il bottone primario è ink con scritta lime (8.2:1). */
    --accent: var(--ink);
    --accent-soft: var(--lime-wash);
    --on-accent: var(--lime);

    /* Intestazione: la superficie firma. */
    --chrome: var(--lime);
    --on-chrome: var(--ink);           /* 8.2:1 */
    --chrome-border: var(--ink);
    --tabbar-bg: #ffffff;

    --focus: var(--ink);
    --toast-bg: var(--ink);
    --toast-fg: #ffffff;               /* 9.6:1 */

    /* Grafici (uPlot li legge con getComputedStyle): linea ink su area lime,
       come una banda del brand. Il canvas non capisce color-mix: rgba. */
    --chart-line: var(--ink);
    --chart-fill: rgba(204, 255, 0, 0.55);
    --chart-axis: var(--ink-soft);
    --chart-grid: #dcdcdc;

    --hairline: var(--border);
    --highlight: transparent;

    --shadow-1: 0 1px 2px rgb(0 0 0 / .06);
    --shadow-2: 0 4px 16px rgb(0 0 0 / .10);

    --dur: 140ms;
    --ease: cubic-bezier(.32, .72, 0, 1);

    --header-h: 128px;
    --tabbar-h: 68px;
}

html[data-theme="dark"],
html[data-theme="auto"] {
    color-scheme: light;
}

html[data-theme="dark"] {
    color-scheme: dark;
}

/* Tema scuro con le regole del brand: superficie ink, testo bianco o
   on-ink-soft, il lime come accento (8.2:1 sull'ink, di più sui fondi più
   scuri). I colori funzionali passano alle varianti "on-ink". Il blocco è
   ripetuto sotto per "auto": i token devono restare identici. */
html[data-theme="dark"] {
    --bg: #333333;
    --surface: var(--ink);
    --surface-2: #3c3c3c;
    --tint: #3d4226;                   /* ink con un filo di lime: bianco 10.5:1, lime 8.9:1 */
    --border: #5e5e5e;
    --border-strong: #a3a3a3;
    --text: #ffffff;                   /* 9.6:1 sull'ink */
    --text-2: var(--on-ink-soft);      /* 7.1:1 sull'ink */
    --text-3: var(--on-ink-soft);

    --pos: #92efc1;
    --neg: #f9d4d4;
    --warn: #fad6bd;
    --info: #cedef6;

    --ctx-personal: var(--lime);
    --ctx-business: var(--lime);
    --ctx-all: var(--lime);

    --accent: var(--lime);
    --accent-soft: #3d4226;
    --on-accent: var(--ink);

    --chrome: #2b2b2b;
    --on-chrome: #ffffff;
    --chrome-border: var(--lime);
    --tabbar-bg: #2b2b2b;

    --focus: var(--lime);
    --toast-bg: #ffffff;
    --toast-fg: var(--ink);

    --chart-line: var(--lime);
    --chart-fill: rgba(204, 255, 0, 0.16);
    --chart-axis: var(--on-ink-soft);
    --chart-grid: #5e5e5e;

    --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-2: 0 4px 16px rgb(0 0 0 / .5);
}

@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] {
        color-scheme: dark;

        --bg: #333333;
        --surface: var(--ink);
        --surface-2: #3c3c3c;
        --tint: #3d4226;
        --border: #5e5e5e;
        --border-strong: #a3a3a3;
        --text: #ffffff;
        --text-2: var(--on-ink-soft);
        --text-3: var(--on-ink-soft);

        --pos: #92efc1;
        --neg: #f9d4d4;
        --warn: #fad6bd;
        --info: #cedef6;

        --ctx-personal: var(--lime);
        --ctx-business: var(--lime);
        --ctx-all: var(--lime);

        --accent: var(--lime);
        --accent-soft: #3d4226;
        --on-accent: var(--ink);

        --chrome: #2b2b2b;
        --on-chrome: #ffffff;
        --chrome-border: var(--lime);
        --tabbar-bg: #2b2b2b;

        --focus: var(--lime);
        --toast-bg: #ffffff;
        --toast-fg: var(--ink);

        --chart-line: var(--lime);
        --chart-fill: rgba(204, 255, 0, 0.16);
        --chart-axis: var(--on-ink-soft);
        --chart-grid: #5e5e5e;

        --shadow-1: 0 1px 2px rgb(0 0 0 / .4);
        --shadow-2: 0 4px 16px rgb(0 0 0 / .5);
    }
}

/* --- Reset ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* Un elemento con l'attributo `hidden` deve sparire, qualunque `display` gli
   abbia dato un componente. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-text);
    font-size: var(--fs-md);
    line-height: var(--lh-text);
    overscroll-behavior-y: none;

    /* Sul fondo scuro l'antialiasing in scala di grigi tiene il testo nitido. */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, p, ul, ol { margin: 0; }

/* Titoli in Poppins, testo in Atkinson, dati in JetBrains Mono (brand). */
h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 700;
    line-height: var(--lh-title);
    letter-spacing: -0.01em;
}

strong, b { font-weight: 700; }

code, kbd, samp { font-family: var(--font-tech); font-size: max(0.91em, 16px); }

::selection { background: var(--lime); color: var(--ink); }
ul, ol { padding: 0; list-style: none; }

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

button {
    font: inherit;
    color: inherit;
    background: none;
    border: 0;
    cursor: pointer;
}

img, svg { max-width: 100%; display: block; }

/* Un anello spesso dello stesso colore del testo: ink sul chiaro (anche sul
   lime, 8.2:1), lime sullo scuro. */
:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Ogni importo, data o percentuale incolonnati: cifre della stessa larghezza. */
.num, .money,
.hero__value, .stat-pill__value, .list-row__amount, .day-group__total,
.month-line__value, .month-net, .stat-line__value, .money-input__display,
.money-input__key, .confidence, .fab__badge, .error-code {
    font-family: var(--font-tech);
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum" 1;
}

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

/* --- Struttura ------------------------------------------------------------ */

/* Salta al contenuto: prima voce raggiungibile da tastiera, invisibile finché
   non prende il fuoco (SPEC §7.5). */
.skip-link {
    position: absolute;
    left: var(--space-4);
    top: -100px;
    z-index: 100;
    padding: var(--space-2) var(--space-4);
    background: var(--lime);
    color: var(--ink);
    border: 2px solid var(--ink);
    border-radius: var(--radius-md);
    font-weight: 700;
    transition: top .15s ease;
}

.skip-link:focus { top: var(--space-2); }

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: calc(env(safe-area-inset-top) + var(--space-2)) var(--space-4) var(--space-3);
    background: var(--chrome);
    color: var(--on-chrome);
    border-bottom: 2px solid var(--chrome-border);
    /* Dentro l'intestazione l'anello del fuoco è del colore del testo. */
    --focus: currentColor;
}

.app-header__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.app-header__brand {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    min-height: 44px;
    padding-top: 10px;
    color: var(--on-chrome);
}

/* Il logo non esiste come file: è il wordmark, Poppins 900 (come in Agenda). */
.wordmark,
.app-header__logo {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: var(--fs-lg);
    line-height: 1;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

html[data-theme="dark"] .app-header__logo,
html[data-theme="dark"] .wordmark { color: var(--lime); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .app-header__logo,
    html[data-theme="auto"] .wordmark { color: var(--lime); }
}

.app-header__title {
    font-family: var(--font-display);
    font-size: var(--fs-md);
    font-weight: 600;
    line-height: 1.1;
    padding-left: var(--space-3);
    border-left: 2px solid currentColor;
}

.app-main {
    padding: var(--space-4) var(--space-4) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-8));
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.app-footer {
    margin-top: var(--space-6);
    color: var(--text-3);
    font-family: var(--font-tech);
    font-size: var(--fs-xs);
    text-align: center;
}

/* --- Segmented control ---------------------------------------------------- */

/* Segmented: contorno pieno, la voce scelta è piena (ink con scritta lime sul
   chiaro, lime con scritta ink sullo scuro). Lo stato lo dice anche il peso
   e aria-pressed, non solo il colore. */
.segmented {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
    padding: 0;
    background: var(--surface);
    border: 2px solid var(--accent);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.segmented__item {
    min-height: 44px;
    padding: 0 var(--space-2);
    border-radius: 0;
    font-family: var(--font-display);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text);
    transition: background-color .15s ease, color .15s ease;
}

.segmented__item + .segmented__item { border-left: 1px solid var(--border-strong); }

.segmented__item:hover { background: var(--surface-2); }

.segmented__item[aria-pressed="true"] {
    background: var(--accent);
    color: var(--on-accent);
    font-weight: 700;
}

/* Il selettore del contesto sta sul lime (o sullo scuro): contorno e voce
   piena prendono il colore del testo dell'intestazione. */
.app-header .segmented {
    background: transparent;
    border-color: var(--on-chrome);
}

.app-header .segmented__item { color: var(--on-chrome); }
.app-header .segmented__item + .segmented__item { border-left-color: var(--on-chrome); }
.app-header .segmented__item:hover { background: color-mix(in srgb, var(--on-chrome) 12%, transparent); }

.app-header .segmented__item[aria-pressed="true"] {
    background: var(--on-chrome);
    color: var(--chrome);
}

html[data-theme="dark"] .app-header .segmented__item[aria-pressed="true"] { background: var(--lime); color: var(--ink); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .app-header .segmented__item[aria-pressed="true"] { background: var(--lime); color: var(--ink); }
}

/* --- Tab bar + FAB -------------------------------------------------------- */

.tabbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: 1fr 1fr auto 1fr 1fr;
    align-items: center;
    gap: var(--space-1);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--tabbar-bg);
    border-top: 2px solid var(--chrome-border);
    gap: 0;
    padding-left: 2px;
    padding-right: 2px;
}

.tabbar__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    min-height: 44px;
    color: var(--text-2);
    font-size: var(--fs-xs);
}

/* La voce attiva: banda lime piena con testo e icona ink (8.2:1), etichetta
   in grassetto. Lo stato lo dicono anche il peso e la forma piena, non solo
   il colore. (L'icona è una maschera: un'ombra attorno verrebbe ritagliata,
   quindi il lime sta sulla voce intera.) */
.tabbar__item.is-active {
    margin: 4px 0;
    border-radius: var(--radius-sm);
    background: var(--lime);
    color: var(--ink);
    --focus: var(--text);
}

/* 16px è il pavimento: "Patrimonio" in un quinto di telefono sta appena,
   quindi al limite i puntini. */
.tabbar__label {
    line-height: 1.1;
    max-width: 100%;
    padding: 0 1px;
    letter-spacing: -0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fab {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    margin-top: -20px;
    border: 2px solid var(--ink);
    border-radius: 50%;
    background: var(--lime);
    color: var(--ink);
    box-shadow: var(--shadow-2);
    /* Il "+" è lime con un bordo ink: il lime da solo sul bianco non si vede
       (1.2:1), il bordo sì. L'anello del fuoco è del colore del testo. */
    --focus: var(--text);
}

.fab:hover { background: var(--ink); color: var(--lime); }

html[data-theme="dark"] .fab { border-color: var(--lime); }
html[data-theme="dark"] .fab:hover { background: var(--white); border-color: var(--white); color: var(--ink); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .fab { border-color: var(--lime); }
    html[data-theme="auto"] .fab:hover { background: var(--white); border-color: var(--white); color: var(--ink); }
}

.fab__plus {
    font-family: var(--font-display);
    font-size: 32px;
    line-height: 1;
    font-weight: 700;
    margin-top: 2px;
}

.icon-btn {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    color: var(--text);
}

.icon-btn:hover { background: var(--surface-2); }

.app-header .icon-btn { color: var(--on-chrome); border: 2px solid currentColor; }
.app-header .icon-btn:hover { background: var(--on-chrome); color: var(--chrome); }

/* Icone: quadrati con maschera, sostituite da SVG reali quando servono. */
.icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    background: currentColor;
    mask-repeat: no-repeat;
    mask-position: center;
    mask-size: contain;
    border-radius: 4px;
    opacity: .9;
}

/* --- Hero ----------------------------------------------------------------- */

/* L'hero è la cifra che conta: fondo lime-wash con un filo ink a sinistra,
   l'unica scheda tinta della pagina. */
.hero {
    padding: var(--space-6) var(--space-4);
    background: var(--tint);
    border: 1px solid var(--border);
    border-left: 6px solid var(--chrome-border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-1);
}

.hero__label {
    font-family: var(--font-display);
    font-size: var(--fs-xs);
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-2);
    font-weight: 600;
}

/* Il numero piu' grande della pagina, in JetBrains Mono: la gerarchia la fa
   la dimensione. Le cifre mono sono larghe, quindi si stringe appena. */
.hero__value {
    margin-top: var(--space-2);
    font-size: clamp(32px, 10vw, var(--fs-hero));
    font-weight: 700;
    letter-spacing: -0.04em;
    line-height: 1.08;
}

.hero__sub {
    margin-top: var(--space-2);
    font-size: var(--fs-xs);
    color: var(--text-2);
}

/* --- Pill di stato -------------------------------------------------------- */

.stat-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-2);
}

/*
 * Griglia e non colonna flessibile: "Patrimonio netto" va a capo e gli altri
 * due no, e con il flex il suo importo scendeva di una riga. Tre numeri
 * affiancati che non stanno sulla stessa linea si notano subito, anche senza
 * saper dire perche'.
 */
.stat-pill {
    display: grid;
    grid-template-rows: 1fr auto;
    gap: var(--space-1);
    padding: var(--space-3);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.stat-pill__label {
    font-size: var(--fs-xs);
    color: var(--text-2);
    line-height: 1.25;
}

.stat-pill__value {
    font-size: var(--fs-md);
    font-weight: 700;
    white-space: nowrap;
}

/* Sul telefono tre importi in mono a 16px non stanno affiancati: le pill
   diventano righe (etichetta a sinistra, importo allineato a destra) invece
   di rimpicciolire il testo sotto il pavimento del brand. */
@media (max-width: 599px) {
    .stat-row {
        grid-template-columns: 1fr;
        gap: 0;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        padding: 0 var(--space-4);
    }

    .stat-pill {
        grid-template-rows: none;
        grid-template-columns: 1fr auto;
        align-items: baseline;
        padding: var(--space-3) 0;
        border: 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
    }

    .stat-pill:last-child { border-bottom: 0; }
}

/* --- Card e liste --------------------------------------------------------- */

.card {
    padding: var(--space-4);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-1);
}

.card__title {
    font-family: var(--font-display);
    font-size: var(--fs-md);
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    margin-bottom: var(--space-3);
}

.list-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 56px;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
}

.list-row:last-child { border-bottom: 0; }

.list-row__body { flex: 1; min-width: 0; }

.list-row__title {
    font-size: var(--fs-sm);
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-row__sub {
    font-size: var(--fs-xs);
    color: var(--text-2);
}

.list-row__amount {
    flex: 0 0 auto;
    font-size: var(--fs-sm);
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
}

.amount--pos { color: var(--pos); }
.amount--neg { color: var(--neg); }

/* Entrate e uscite non si leggono dal solo colore: gli importi hanno già il
   segno + / −, e in più una freccia (su = entra, giù = esce). Solo sui
   flussi (movimenti, totali, mese), non sui saldi, sulle barre o sul testo. */
.list-row--movement .list-row__amount.amount--pos::before,
.list-row--movement .list-row__amount.amount--neg::before,
.list-row--flow .list-row__amount.amount--pos::before,
.list-row--flow .list-row__amount.amount--neg::before,
.day-group__total.amount--pos::before,
.day-group__total.amount--neg::before,
.month-line__value.amount--pos::before,
.month-line__value.amount--neg::before,
.month-net.amount--pos::before,
.month-net.amount--neg::before,
.hero__change.amount--pos::before,
.hero__change.amount--neg::before {
    content: "";
    display: inline-block;
    width: .8em;
    height: .8em;
    margin-right: .3em;
    vertical-align: -0.05em;
    background: currentColor;
    mask: var(--arrow-up) center / contain no-repeat;
}

.list-row--movement .list-row__amount.amount--neg::before,
.list-row--flow .list-row__amount.amount--neg::before,
.day-group__total.amount--neg::before,
.month-line__value.amount--neg::before,
.month-net.amount--neg::before,
.hero__change.amount--neg::before { mask-image: var(--arrow-down); }

:root {
    --arrow-up: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8 1.5 14.5 9H10v5.5H6V9H1.5z" fill="black"/></svg>');
    --arrow-down: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="M8 14.5 1.5 7H6V1.5h4V7h4.5z" fill="black"/></svg>');
}

/* Contesto di un movimento nella vista Totale: a parole, non a colori. */
.ctx-tag {
    display: inline-block;
    margin-left: var(--space-1);
    padding: 0 6px;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    font-size: var(--fs-xs);
    line-height: 1.4;
    color: var(--text);
    vertical-align: 1px;
}

/* --- Bottoni -------------------------------------------------------------- */

/*
 * La risposta al tocco e' meta' della sensazione di qualita': un bottone che
 * non si muove sembra un'immagine. Scala appena, e torna. Chi ha chiesto meno
 * animazioni non vede niente di tutto questo: c'e' gia' la regola per
 * prefers-reduced-motion in fondo al file.
 */
.btn,
.chip,
.segmented__item,
.category-tile,
.money-input__key {
    transition:
        background-color var(--dur) var(--ease),
        border-color var(--dur) var(--ease),
        color var(--dur) var(--ease),
        transform var(--dur) var(--ease);
}

.btn:active,
.chip:active,
.category-tile:active,
.money-input__key:active {
    transform: scale(.97);
}

/* Primario: ink con scritta lime sul chiaro, lime con scritta ink sullo
   scuro (come in Agenda). */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 0 var(--space-4);
    border-radius: var(--radius-sm);
    font-family: var(--font-display);
    font-size: var(--fs-sm);
    font-weight: 600;
    letter-spacing: 0.01em;
    border: 2px solid transparent;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}

.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--black); border-color: var(--black); color: var(--lime); }

html[data-theme="dark"] .btn--primary:hover { background: var(--white); border-color: var(--white); color: var(--ink); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .btn--primary:hover { background: var(--white); border-color: var(--white); color: var(--ink); }
}

.btn--ghost {
    background: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}

.btn--ghost:hover { background: var(--surface-2); border-color: var(--text); }

.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn--block { width: 100%; }

/* --- Form ----------------------------------------------------------------- */

.stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.field {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.field:last-child { margin-bottom: 0; }

.field__label {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--text);
}

.field__input {
    min-height: 48px;
    padding: 0 var(--space-3);
    font: inherit;
    font-size: var(--fs-md); /* ≥ 16px: evita lo zoom automatico su iOS */
    color: var(--text);
    background: var(--surface);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.field__input::placeholder { color: var(--text-2); opacity: 1; }

textarea.field__input { padding-top: var(--space-2); padding-bottom: var(--space-2); }

.field__input:focus,
.field__input:focus-visible {
    border-color: var(--text);
    outline: 3px solid var(--focus);
    outline-offset: 2px;
    box-shadow: none;
}

.field__error {
    font-size: var(--fs-xs);
    font-weight: 700;
    color: var(--neg);
}

.checkbox {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 44px;
    font-size: var(--fs-sm);
    color: var(--text-2);
}

.checkbox input {
    width: 22px;
    height: 22px;
    accent-color: var(--ink);
}

html[data-theme="dark"] .checkbox input,
html[data-theme="dark"] .import-row__head input[type="checkbox"] { accent-color: var(--lime); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .checkbox input,
    html[data-theme="auto"] .import-row__head input[type="checkbox"] { accent-color: var(--lime); }
}

/*
 * Avvisi: testo nel colore funzionale su superficie neutra, un filo pieno a
 * sinistra e un'icona davanti (triangolo = attenzione, cerchio con croce =
 * errore). Il significato non sta nel solo colore.
 */
.alert {
    padding: var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--fs-sm);
    border: 1px solid var(--border);
    border-left: 6px solid var(--text-2);
    background: var(--surface);
    color: var(--text);
    text-align: left;
}

.alert::before {
    content: "";
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    background: currentColor;
    mask: var(--icon-info) center / contain no-repeat;
}

.alert--error {
    color: var(--neg);
    border-left-color: var(--neg);
}

.alert--error::before { mask-image: var(--icon-error); }

.alert--warn {
    color: var(--warn);
    border-left-color: var(--warn);
}

.alert--warn::before { mask-image: var(--icon-warn); }

:root {
    /* Icone a contorno (solo nero opaco su trasparente): con mask-image il
       colore lo dà il testo intorno, e i "buchi" restano buchi. */
    --icon-ok: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m7.5 12.5 3 3 6-6.5"/></svg>');
    --icon-warn: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M12 2.5 22.5 21h-21z"/><path d="M12 9.5v5"/><path d="M12 17.8v.2"/></svg>');
    --icon-error: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="m8.5 8.5 7 7M15.5 8.5l-7 7"/></svg>');
    --icon-info: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M12 11v6"/><path d="M12 7.3v.2"/></svg>');
}

.page-title {
    font-size: var(--fs-xl);
    font-weight: 700;
    letter-spacing: -0.02em;
}

/* --- Login ---------------------------------------------------------------- */

.login {
    width: min(400px, 100%);
    margin: 0 auto;
    align-items: stretch;
    text-align: left;
}

.login.centered-panel { text-align: left; }

/* L'accesso non ha intestazione: il marchio sta in una banda lime (scura nel
   tema scuro) in cima al pannello. */
.login__brand {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    justify-content: center;
    margin-bottom: var(--space-4);
    padding: var(--space-4);
    background: var(--chrome);
    color: var(--on-chrome);
    border: 2px solid var(--chrome-border);
    border-radius: var(--radius-card);
}

.login__logo {
    font-family: var(--font-display);
    font-weight: 900;
    font-size: var(--fs-xl);
    line-height: 1;
    letter-spacing: 0.02em;
}

html[data-theme="dark"] .login__logo { color: var(--lime); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .login__logo { color: var(--lime); }
}

.login__title {
    font-family: var(--font-display);
    font-size: var(--fs-lg);
    font-weight: 600;
    line-height: 1;
    padding-left: var(--space-3);
    border-left: 2px solid currentColor;
}

.login__form {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* --- Stati ---------------------------------------------------------------- */

.empty-state {
    padding: var(--space-6) var(--space-4);
    text-align: center;
    color: var(--text-2);
    font-size: var(--fs-sm);
}

.skeleton {
    background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
    background-size: 400% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
    border-radius: var(--radius-sm);
    color: transparent;
}

.skeleton--hero { max-width: 260px; height: 44px; }

@keyframes skeleton-shimmer {
    from { background-position: 100% 50%; }
    to   { background-position: 0 50%; }
}

/* --- Chip ----------------------------------------------------------------- */

.chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 var(--space-3);
    border-radius: 999px;
    border: 2px solid var(--border-strong);
    background: var(--surface);
    font-size: var(--fs-sm);
    font-weight: 400;
    color: var(--text);
    white-space: nowrap;
}

.chip:hover { border-color: var(--text); }

/* Scelta: piena e in grassetto, con la spunta davanti. */
.chip[aria-pressed="true"] {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 700;
}

.chip[aria-pressed="true"]::before {
    content: "";
    width: 14px;
    height: 14px;
    background: currentColor;
    mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="m2.5 8.5 3.5 3.5 7.5-8" fill="none" stroke="black" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"/></svg>') center / contain no-repeat;
}

.chip--ghost {
    background: transparent;
    border-style: dashed;
    color: var(--text-2);
}

/* --- Bottom sheet --------------------------------------------------------- */

.sheet-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgb(0 0 0 / .45);
    /* La sfocatura dietro dice "quello che c'e' sotto non e' spento, e'
       solo dietro": e' la differenza fra una tendina e un pannello. */
    backdrop-filter: blur(3px);
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 51;
    display: flex;
    flex-direction: column;
    max-height: 92dvh;
    padding: var(--space-2) var(--space-4) calc(env(safe-area-inset-bottom) + var(--space-4));
    background: var(--surface);
    border-top: 2px solid var(--chrome-border);
    border-top-left-radius: var(--radius-xl);
    border-top-right-radius: var(--radius-xl);
    box-shadow: var(--shadow-2);
    transform: translateY(100%);
    /* Piu' lunga delle altre perche' la superficie e' grande, e con una curva
       che frena alla fine invece di fermarsi di colpo. */
    transition: transform 300ms var(--ease);
    overscroll-behavior: contain;
}

.sheet.is-open { transform: none; }

.sheet__handle {
    width: 36px;
    height: 5px;
    margin: var(--space-2) auto;
    border-radius: 999px;
    background: var(--border-strong);
}

.sheet__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding-bottom: var(--space-2);
}

.sheet__title {
    font-size: var(--fs-lg);
    font-weight: 700;
    letter-spacing: -0.01em;
}

.sheet__close {
    width: 44px;
    height: 44px;
    font-size: 28px;
    line-height: 1;
    color: var(--text);
    border-radius: var(--radius-sm);
}

.sheet__close:hover { background: var(--surface-2); }

.sheet__body {
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    padding-bottom: var(--space-4);
}

body.has-sheet { overflow: hidden; }

/* --- Tastierino importo --------------------------------------------------- */

.money-input {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.money-input__display {
    display: block;
    text-align: center;
    font-size: clamp(32px, 10vw, var(--fs-hero));
    font-weight: 700;
    letter-spacing: -0.04em;
    padding: var(--space-2) 0;
    border-bottom: 2px solid var(--chrome-border);
}

.money-input__display.is-empty { color: var(--text-2); }

.money-input__keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-2);
}

.money-input__key {
    min-height: 56px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: var(--fs-lg);
    font-weight: 700;
}

.money-input__key:hover { border-color: var(--border-strong); }
.money-input__key:active { background: var(--lime); color: var(--ink); border-color: var(--ink); }

/* --- Registratore --------------------------------------------------------- */

.recorder__types,
.recorder__amount,
.recorder__actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.recorder__advanced-summary {
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--text);
    min-height: 44px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: var(--space-2);
    max-height: 220px;
    overflow-y: auto;
}

.category-tile {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: var(--space-1);
    min-height: 56px;
    padding: var(--space-2);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    text-align: left;
}

.category-tile:hover { border-color: var(--border-strong); }

/* La categoria scelta: bordo pieno, fondo tinto e il punto che diventa una
   spunta. */
.category-tile[aria-pressed="true"] {
    border-color: var(--text);
    background: var(--accent-soft);
}

.category-tile__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-2);
}

.category-tile[aria-pressed="true"] .category-tile__dot {
    width: 16px;
    height: 16px;
    border-radius: 0;
    background: var(--text);
    mask: var(--icon-ok) center / contain no-repeat;
}

.category-tile__name {
    font-size: var(--fs-xs);
    line-height: 1.2;
    color: var(--text);
}

/* --- Movimenti ------------------------------------------------------------ */

.page-head {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
}

.page-sub {
    font-size: var(--fs-xs);
    color: var(--text-2);
}

.filters {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.filters__more summary {
    min-height: 44px;
    display: flex;
    align-items: center;
    font-size: var(--fs-sm);
    font-weight: 700;
    color: var(--text);
    cursor: pointer;
}

.filters__dates {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
}

.field--inline { margin-bottom: 0; }

.movements {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.day-group {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0 var(--space-4);
}

.day-group__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 0;
    border-bottom: 2px solid var(--border);
    font-family: var(--font-display);
    font-size: var(--fs-xs);
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: .04em;
    font-weight: 600;
}

.day-group__total { letter-spacing: 0; text-transform: none; white-space: nowrap; }

.list-row--movement { position: relative; }

.list-row--movement.is-cancelled { opacity: .55; }
.list-row--movement.is-cancelled .list-row__amount { text-decoration: line-through; }
.list-row--movement.is-planned .list-row__amount { color: var(--text-2); font-style: italic; }

.list-row__open {
    position: absolute;
    inset: 0;
    width: 100%;
    background: none;
}

.detail-list {
    display: grid;
    grid-template-columns: minmax(96px, auto) 1fr;
    gap: var(--space-2) var(--space-4);
    margin: 0;
}

.detail-list__label {
    font-size: var(--fs-xs);
    color: var(--text-2);
}

.detail-list__value {
    margin: 0;
    font-size: var(--fs-sm);
}

.detail-actions {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.btn--danger { background: var(--surface); color: var(--neg); border-color: var(--neg); }
.btn--danger:hover { background: var(--neg); color: var(--surface); border-color: var(--neg); }

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

.toast-host {
    position: fixed;
    left: 50%;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-4));
    transform: translateX(-50%);
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: min(440px, calc(100vw - var(--space-8)));
    pointer-events: none;
}

/* Toast: ink con testo bianco sul chiaro, bianco con testo ink sullo scuro;
   un filo a sinistra e un'icona per il tipo. */
.toast {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-sm);
    background: var(--toast-bg);
    color: var(--toast-fg);
    border: 0;
    border-left: 6px solid var(--lime);
    box-shadow: var(--shadow-2);
    font-size: var(--fs-sm);
    pointer-events: auto;
    animation: toast-in .18s ease-out;
}

.toast::before {
    content: "";
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    background: currentColor;
    mask: var(--icon-info) center / contain no-repeat;
}

.toast--success::before { mask-image: var(--icon-ok); }
.toast--error::before { mask-image: var(--icon-error); }
.toast--error { border-left-color: #f9d4d4; }

html[data-theme="dark"] .toast--error { border-left-color: #af1919; }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .toast--error { border-left-color: #af1919; }
}

/* Il bottone d'azione ("Annulla") ha il colore del testo del toast,
   sottolineato: nessun colore aggiunto su un fondo già scuro o chiaro. */
.toast__action {
    margin-left: auto;
    font-family: var(--font-display);
    font-weight: 700;
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
    min-height: 44px;
    padding: 0 var(--space-2);
    --focus: currentColor;
}

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

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

.centered-panel {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    padding: var(--space-8) var(--space-4);
    text-align: center;
}

.error-code {
    font-size: var(--fs-hero);
    font-weight: 700;
    color: var(--text);
}

.error-title {
    font-size: var(--fs-lg);
    font-weight: 700;
    max-width: 32ch;
}

/* --- Desktop: la tab bar diventa sidebar (SPEC §7.4) ---------------------- */

@media (min-width: 900px) {
    /* L'intestazione lime corre per tutta la larghezza, come in Agenda; la
       barra di navigazione diventa la colonna di sinistra sotto di lei. */
    body {
        display: grid;
        grid-template-columns: 248px 1fr;
        grid-template-areas:
            "header header"
            "sidebar main";
        grid-template-rows: auto 1fr;
    }

    .app-header {
        grid-area: header;
        position: static;
    }

    .app-header__row { margin-bottom: 0; }

    .app-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: var(--space-6);
        padding: var(--space-3) var(--space-6);
    }

    .app-header .segmented { width: 380px; }

    .app-header__brand { padding-top: 0; align-items: baseline; }

    .app-main {
        grid-area: main;
        padding: var(--space-6);
        max-width: 1080px;
        width: 100%;
    }

    .tabbar {
        grid-area: sidebar;
        position: sticky;
        top: 0;
        /* Il bottom: 0 della barra fissa su mobile qui va tolto: con sticky
           tirerebbe su la colonna fin sopra l'intestazione. */
        bottom: auto;
        align-self: start;
        height: 100dvh;
        display: flex;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: var(--space-1);
        padding: var(--space-6) var(--space-3);
        border-top: 0;
        border-right: 1px solid var(--border);
    }

    .tabbar__item {
        flex-direction: row;
        justify-content: flex-start;
        gap: var(--space-3);
        min-height: 48px;
        padding: 0 var(--space-3);
        border-radius: var(--radius-sm);
        font-size: var(--fs-md);
    }

    .tabbar__item:hover { background: var(--surface-2); color: var(--text); }

    /* Voce attiva: banda lime piena con testo ink (8.2:1). */
    .tabbar__item.is-active,
    .tabbar__item.is-active:hover {
        background: var(--lime);
        color: var(--ink);
        --focus: var(--text);
    }

    .tabbar__item.is-active { margin: 0; font-weight: 700; }

    .fab {
        order: -1;
        width: 100%;
        height: 48px;
        margin: 0 0 var(--space-4);
        border-radius: var(--radius-sm);
    }

    .toast-host { bottom: var(--space-6); left: auto; right: var(--space-6); transform: none; }
}

/* --- Accessibilità -------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
    }
}

/* Su desktop il registratore è un pannello laterale, non un foglio dal basso. */
@media (min-width: 900px) {
    .sheet {
        left: auto;
        right: 0;
        top: 0;
        bottom: 0;
        width: min(460px, 100%);
        max-height: 100dvh;
        border-radius: 0;
        border-left: 1px solid var(--border);
        transform: translateX(100%);
        padding: var(--space-6);
    }

    .sheet.is-open { transform: none; }

    .sheet__handle { display: none; }
}

/* --- Home: mese corrente, avvisi, grafico -------------------------------- */

.hero__change {
    margin-top: var(--space-1);
    font-family: var(--font-tech);
    font-size: var(--fs-xs);
    font-weight: 700;
}

.card__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.card__head .card__title { margin-bottom: 0; }

.card__link {
    font-family: var(--font-display);
    font-size: var(--fs-xs);
    font-weight: 600;
    color: var(--text);
    text-decoration: underline;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    text-decoration-color: var(--accent);
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.month-summary {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.month-line {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.month-line__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.month-line__label {
    font-size: var(--fs-sm);
    color: var(--text);
}

.month-line__value {
    font-size: var(--fs-md);
    font-weight: 700;
    white-space: nowrap;
}

.month-line__hint {
    font-size: var(--fs-xs);
    color: var(--text-2);
}

/*
 * La pista e' un solco, non un rettangolo grigio: piu' bassa, e con un tratto
 * appena accennato che le da' profondita' invece di farla sembrare disegnata
 * sopra la scheda.
 */
.month-bar {
    height: 8px;
    border-radius: 999px;
    background: var(--surface-2);
    box-shadow: inset 0 0 0 1px var(--border);
    overflow: hidden;
}

.month-bar__fill {
    height: 100%;
    border-radius: 999px;
    /* Un filo di superficie dentro il colore: resta riconoscibile a colpo
       d'occhio ma smette di essere la cosa piu' accesa dello schermo. */
    background: currentColor;
    min-width: 3px;
    transition: width var(--dur) var(--ease);
}

.month-net {
    font-size: var(--fs-sm);
    font-weight: 700;
    padding-top: var(--space-2);
    border-top: 1px solid var(--border);
}

.alert {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-2);
}

.alert:last-child { margin-bottom: 0; }

.alert__action {
    margin-left: auto;
    font-family: var(--font-display);
    font-weight: 700;
    color: var(--text);
    text-decoration: underline;
    text-underline-offset: 3px;
    white-space: nowrap;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}

.chart {
    width: 100%;
    min-height: 200px;
}

.btn--small {
    min-height: 44px;
    padding: 0 var(--space-3);
    font-size: var(--fs-xs);
}

/* uPlot: adatta il tema del grafico ai token dell'app */
.u-legend { display: none; }
.u-select { background: var(--accent-soft); }

/* --- Patrimonio: schede e liste ------------------------------------------ */

.tabs {
    display: flex;
    gap: var(--space-1);
    overflow-x: auto;
    padding-bottom: var(--space-1);
    border-bottom: 1px solid var(--border);
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar { display: none; }

.tabs__item {
    flex: 0 0 auto;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    padding: 0 var(--space-3);
    font-family: var(--font-display);
    font-size: var(--fs-sm);
    font-weight: 600;
    color: var(--text-2);
    border-bottom: 4px solid transparent;
    margin-bottom: -1px;
}

.tabs__item:hover { color: var(--text); border-bottom-color: var(--border-strong); }

/* Scheda attiva: testo pieno e una riga spessa (ink sul chiaro, lime sullo
   scuro), non solo un cambio di colore. */
.tabs__item.is-active {
    color: var(--text);
    font-weight: 700;
    border-bottom-color: var(--accent);
}

.list-row--tappable {
    width: 100%;
    text-align: left;
    background: none;
}

.list-row__stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.allocation-card .month-bar { margin: var(--space-2) 0; }

.note {
    font-size: var(--fs-xs);
    color: var(--text-2);
    padding: 0 var(--space-2);
}

/* --- Control Center ------------------------------------------------------- */

.control {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.control-section { padding: 0; }

.control-section__summary {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 52px;
    padding: 0 var(--space-4);
    cursor: pointer;
    list-style: none;
}

.control-section__summary::-webkit-details-marker { display: none; }

.control-section__title {
    font-family: var(--font-display);
    font-size: var(--fs-md);
    font-weight: 700;
}

/* La freccia del details, disegnata: aperto/chiuso si vede anche senza colore. */
.control-section__summary::after {
    content: "";
    margin-left: auto;
    width: 14px;
    height: 14px;
    background: var(--text);
    mask: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path d="m3 6 5 5 5-5" fill="none" stroke="black" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"/></svg>') center / contain no-repeat;
    transition: transform var(--dur) var(--ease);
}

.control-section[open] > .control-section__summary::after { transform: rotate(180deg); }

.control-section__body {
    padding: 0 var(--space-4) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

/* Stato di una sezione: non un pallino colorato ma un'icona di forma
   diversa (spunta, triangolo, croce), colorata in più. */
.status-dot {
    width: 22px;
    height: 22px;
    flex: 0 0 auto;
    background: var(--text-2);
    mask: var(--icon-info) center / contain no-repeat;
}

.status-dot--ok      { background: var(--pos); mask-image: var(--icon-ok); }
.status-dot--warning { background: var(--warn); mask-image: var(--icon-warn); }
.status-dot--error   { background: var(--neg); mask-image: var(--icon-error); }

.stat-line {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--border);
}

.stat-line:last-child { border-bottom: 0; }

.stat-line { flex-wrap: wrap; }

.stat-line__label {
    font-size: var(--fs-sm);
    color: var(--text);
    flex: 1;
}

.stat-line__value {
    font-size: var(--fs-sm);
    font-weight: 700;
    text-align: right;
}

.stat-line__hint {
    flex-basis: 100%;
    font-size: var(--fs-xs);
    color: var(--text-2);
}

.disclaimer {
    font-size: var(--fs-xs);
    color: var(--text-2);
    font-style: italic;
    padding-top: var(--space-2);
}

.field__hint {
    font-size: var(--fs-xs);
    color: var(--text-2);
}

/* --- Import estratti conto ------------------------------------------------ */

.import-month {
    font-family: var(--font-display);
    font-size: var(--fs-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text);
    margin: var(--space-4) 0 var(--space-2);
}

.import-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 6px solid var(--pos);
    border-radius: var(--radius-sm);
    padding: var(--space-3);
    margin-bottom: var(--space-2);
}

/* Righe saltate: tratteggiate, non solo sbiadite (l'opacità da sola
   abbassa il contrasto del testo sotto il 7:1). */
.import-row--skip {
    border-left-style: dashed;
    border-left-color: var(--border-strong);
    background: var(--surface-2);
}

.import-row--transfer { border-left-color: var(--info); border-left-style: double; }

.import-row__head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.import-row__head input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-top: 2px;
    accent-color: var(--ink);
    flex: 0 0 auto;
}

.import-row__body { flex: 1; min-width: 0; }

.import-row__category {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: var(--space-2);
    padding-left: 32px;
}

.field__input--small {
    min-height: 44px;
    font-size: var(--fs-sm);
    flex: 1;
}

.confidence {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--fs-xs);
    font-weight: 700;
    padding: 0 8px;
    border: 1px solid currentColor;
    border-radius: 999px;
    background: var(--surface);
}

.confidence::before {
    content: "";
    width: 14px;
    height: 14px;
    background: currentColor;
    mask: var(--icon-ok) center / contain no-repeat;
}

.confidence--high { color: var(--pos); }
.confidence--low  { color: var(--warn); }
.confidence--low::before { mask-image: var(--icon-warn); }

/* --- Analisi -------------------------------------------------------------- */

.cashflow-month {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-3) 0;
    border-bottom: 1px solid var(--border);
}

.cashflow-month:last-child { border-bottom: 0; }

.cashflow-month .month-bar { height: 6px; }

.list-row.is-critical {
    background: var(--surface-2);
    box-shadow: inset 4px 0 0 var(--neg);
    border-radius: var(--radius-sm);
    padding-left: var(--space-2);
    padding-right: var(--space-2);
}

/* --- Icone ----------------------------------------------------------------
   SVG inline come maschera: un solo file CSS, nessuna richiesta in più, e il
   colore lo decide il testo intorno. Tutte con tratto 1.75 su griglia 24.
   -------------------------------------------------------------------------- */

.icon--home {
    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M3 10.5 12 3l9 7.5"/><path d="M5.5 9.5V20h13V9.5"/><path d="M9.5 20v-6h5v6"/></svg>');
}

.icon--list {
    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.75" stroke-linecap="round"><path d="M4 7h16"/><path d="M4 12h16"/><path d="M4 17h10"/></svg>');
}

.icon--wallet {
    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="6" width="18" height="13" rx="2.5"/><path d="M3 10h18"/><circle cx="16.5" cy="14" r="1.25" fill="black" stroke="none"/></svg>');
}

.icon--shield {
    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><path d="M12 3l7 3v6c0 4.2-2.9 7.8-7 9-4.1-1.2-7-4.8-7-9V6z"/><path d="M9 12l2 2 4-4"/></svg>');
}

.icon--settings {
    mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="1.75" stroke-linecap="round"><circle cx="12" cy="12" r="3.2"/><path d="M12 3v2.2M12 18.8V21M21 12h-2.2M5.2 12H3M18.4 5.6l-1.6 1.6M7.2 16.8l-1.6 1.6M18.4 18.4l-1.6-1.6M7.2 7.2 5.6 5.6"/></svg>');
}

/* Il quadrato di ripiego serve solo se una classe icona non esiste. */
.icon { border-radius: 0; opacity: 1; }

.fab { position: relative; }

.fab__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    border: 2px solid var(--surface);
    background: var(--ink);
    color: var(--lime);
    /* Il minimo dell'app è 12px, badge compreso (SPEC §7.1). */
    font-size: var(--fs-xs);
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

html[data-theme="dark"] .fab__badge { background: var(--white); color: var(--ink); }
@media (prefers-color-scheme: dark) {
    html[data-theme="auto"] .fab__badge { background: var(--white); color: var(--ink); }
}

.search-results {
    display: flex;
    flex-direction: column;
    max-height: 320px;
    overflow-y: auto;
}

.list-row--tappable.is-disabled {
    cursor: default;
}

.list-row--tappable.is-disabled .list-row__title { text-decoration: line-through; }

.list-row--tappable:not(.is-disabled):hover { background: var(--surface-2); }

/* Movimento annullato: barrato e in corsivo, non solo sbiadito. */
.list-row--movement.is-cancelled { opacity: 1; }
.list-row--movement.is-cancelled .list-row__title,
.list-row--movement.is-cancelled .list-row__amount { text-decoration: line-through; color: var(--text-2); }
.list-row--movement.is-cancelled .list-row__amount::before { display: none; }
