:root {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #eeeeee;
  --text: #0a0a0a;
  --muted: #6e6e6e;
  --border: #e2e2e2;
  --accent: #0a0a0a;
  --accent-soft: #ececec;
  --in: #1a8a4e;
  --out: #c8362a;
  --hero-bg: #0a0a0a;
  --hero-text: #ffffff;
  --hero-in: #3ddc7a;
  --hero-out: #ff6b5e;
  --on-accent: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 10px 28px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 24px rgba(0,0,0,.16), 0 2px 6px rgba(0,0,0,.06);
  --radius: 22px;
  --radius-sm: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --warn: #b8730a;
  --warn-bg: #fdf3e3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000; --surface: #141414; --surface-2: #1e1e1e;
    --text: #f5f5f5; --muted: #8a8a8a; --border: #2a2a2a;
    --accent: #ffffff; --accent-soft: #232323;
    --in: #3ddc7a; --out: #ff6b5e;
    --hero-bg: #f5f5f5; --hero-text: #0a0a0a;
    --hero-in: #1a8a4e; --hero-out: #c8362a;
    --on-accent: #0a0a0a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 28px rgba(0,0,0,.5);
    --shadow-lg: 0 10px 24px rgba(0,0,0,.5), 0 2px 8px rgba(0,0,0,.4);
    --warn: #f0a94a; --warn-bg: #2a2011;
  }
}

/* Avviso "dato non aggiornato" (prezzi ETF / quota fondi congelati in silenzio). */
.stale-warn {
  display: flex; align-items: center; gap: 7px;
  margin: 10px 2px 0; padding: 9px 12px;
  font-size: 13px; line-height: 1.35; font-weight: 600;
  color: var(--warn); background: var(--warn-bg);
  border-radius: var(--radius-sm);
}
.stale-warn svg { flex: 0 0 auto; }
.stale-inline { color: var(--warn); font-weight: 600; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
/* Comportamento da app, non da pagina web (feedback dal telefono Android reale):
   - overscroll-behavior spegne il pull-to-refresh di Chrome (tirare giù NON ricarica);
   - touch-action: manipulation (sopra) elimina lo zoom da doppio tap;
   - niente selezione del testo tenendo premuto per sbaglio (riabilitata sui campi). */
html, body { margin: 0; height: 100%; overscroll-behavior-y: none; }
body { user-select: none; -webkit-user-select: none; }
input, select, textarea { user-select: text; -webkit-user-select: text; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  font-size: 17px; line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  /* Android a volte ridimensiona da solo i testi ("boosting"): lo blocchiamo per avere le stesse
     dimensioni di iOS. */
  -webkit-text-size-adjust: 100%; text-size-adjust: 100%;
}
/* Aree scrollabili: Android Chrome disegna una barra con traccia visibile, iOS la sovrappone e
   sparisce. La nascondiamo così i fogli hanno lo stesso aspetto ovunque (lo scroll resta attivo). */
.sheet, #cat-detail-movs { scrollbar-width: none; }
.sheet::-webkit-scrollbar, #cat-detail-movs::-webkit-scrollbar { width: 0; height: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--out); font-size: 14px; margin-top: 10px; text-align: center; }

/* ---------- Login ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 40px 30px; width: 100%; max-width: 380px; text-align: center;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 8px; }
.brand h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center;
  background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 23px;
  box-shadow: var(--shadow-lg);
}
.login-card .muted { margin: 0 0 26px; }

/* ---------- Bottoni / campi ---------- */
.btn {
  font: inherit; font-weight: 600; border: none; border-radius: 999px;
  padding: 14px 20px; cursor: pointer; transition: transform .06s ease, opacity .2s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 16px rgba(0,0,0,.18); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-block { display: block; width: 100%; margin-top: 14px; }
input, select {
  font: inherit; font-size: 16px; width: 100%; padding: 14px 16px; margin-top: 8px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
}
/* I <select> nativi hanno altezza/padding/freccia diversi tra iOS e Android: azzeriamo l'aspetto
   di sistema e disegniamo una freccia identica ovunque (chevron come quello di icons.js, stroke 1.8,
   colorato via var(--muted)). Così i menu coincidono pixel su entrambi i telefoni. Restiamo sui soli
   <select>: gli input date/number con class="select" devono tenere le loro affordance native. */
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 42px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%236e6e6e' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
@media (prefers-color-scheme: dark) {
  select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%238a8a8a' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); }
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.icon-btn {
  background: none; border: none; color: var(--text);
  width: 32px; height: 32px; cursor: pointer; border-radius: 10px;
  display: grid; place-items: center; flex: 0 0 auto;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- App shell ---------- */
.app { min-height: 100vh; min-height: 100dvh; display: flex; }
.app-content { flex: 1; min-width: 0; display: flex; flex-direction: column; max-width: 720px; margin: 0 auto; width: 100%; }
.sidebar { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--bg);
  padding: 18px 16px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.topbar h2 { margin: 0; font-size: 21px; letter-spacing: -.02em; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.month-nav {
  display: flex; align-items: center; gap: 2px; font-size: 14px; color: var(--muted); font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px;
}
.month-nav span { min-width: 0; text-align: center; text-transform: capitalize; white-space: nowrap; }

main { flex: 1; padding: 18px 16px calc(96px + var(--safe-b)); }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px);} to { opacity:1; transform:none; } }
.section-title { font-size: 14px; color: var(--muted); font-weight: 700; margin: 26px 4px 12px; text-transform: uppercase; letter-spacing: .04em; }
.section-title.row-title { display: flex; align-items: center; justify-content: space-between; }
.mini-add {
  width: 26px; height: 26px; border-radius: 8px; border: none; background: var(--accent-soft);
  color: var(--accent); font-size: 17px; line-height: 1; cursor: pointer; text-transform: none; letter-spacing: 0;
}
.center { text-align: center; }

/* ---------- Card compatta (ricorrenze) ---------- */
.mini-card {
  display: flex; align-items: center; gap: 12px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.mini-card.static { cursor: default; }
.mini-card .mc-ico {
  width: 38px; height: 38px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--accent-soft); color: var(--accent);
}
.mini-card .mc-body { flex: 1; min-width: 0; }
.mini-card .mc-title { font-weight: 600; font-size: 15px; }
.mini-card .mc-sub { font-size: 13px; color: var(--muted); }
.mini-card .chevron { color: var(--muted); flex: 0 0 auto; }

/* ---------- Affordance riga modificabile ---------- */
.chevron-affordance { color: var(--muted); flex: 0 0 auto; margin-left: 4px; }

/* ---------- Interruttore ---------- */
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 15px; font-weight: 600; margin-top: 18px; cursor: pointer;
}
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch {
  width: 46px; height: 28px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); position: relative; transition: background .15s ease; flex: 0 0 auto;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; border: 1px solid var(--border); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s ease;
}
.switch-row input:checked + .switch { background: var(--accent); border-color: var(--accent); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }
.ricorrenze-margin { margin-top: 8px; }

/* ---------- Riepilogo: hero saldo ---------- */
.balance-card {
  background: var(--hero-bg); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 26px 24px; text-align: center; color: var(--hero-text);
}
.hero-label { color: var(--hero-text); opacity: .65; font-size: 14px; font-weight: 600; }
.balance { font-size: 42px; font-weight: 800; letter-spacing: -.03em; margin: 8px 0 4px; }
.delta {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px; font-weight: 700;
  background: color-mix(in srgb, var(--hero-text) 14%, transparent);
  padding: 5px 12px; border-radius: 999px; margin-bottom: 18px;
}
.delta.up { color: var(--hero-in); } .delta.down { color: var(--hero-out); }
/* Nel Riepilogo sotto il saldo non c'è più la pillola .delta (che dava lei il distacco): l'aria la
   restituisce qui. Sul Patrimonio la pillola c'è ancora e regge il suo margine da sé. */
.inout { display: flex; gap: 10px; margin-top: 18px; }
.inout > div {
  flex: 1; background: color-mix(in srgb, var(--hero-text) 10%, transparent); border-radius: var(--radius-sm);
  padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 13px; color: color-mix(in srgb, var(--hero-text) 75%, transparent);
}
.inout strong { font-size: 18px; color: var(--hero-text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.in { background: var(--hero-in); } .dot.out { background: var(--hero-out); }

/* Confronto con lo stesso tratto del mese precedente. Riga propria e non appiccicato ai due numeri:
   nelle caselle di .inout non ci starebbe (a 320px "↓ 1.401 € vs settembre" sfora), e qui può
   dichiarare quale tratto sta confrontando. */
.confronto { display: flex; flex-direction: column; align-items: center; gap: 3px; margin-top: 14px; }
.cf-quando { font-size: 12px; color: color-mix(in srgb, var(--hero-text) 60%, transparent); }
.cf-righe { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; font-size: 13px; }
.cf-voce { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; color: color-mix(in srgb, var(--hero-text) 70%, transparent); }
.cf-val { font-weight: 700; }
.cf-val.meglio { color: var(--hero-in); }
.cf-val.peggio { color: var(--hero-out); }

/* ---------- Donut categorie ---------- */
.donut-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; display: flex; align-items: center; gap: 20px;
}
.donut-wrap { position: relative; flex: 0 0 auto; width: 128px; height: 128px; }
.donut { width: 100%; height: 100%; }
.donut-center {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; text-align: center; pointer-events: none;
  padding: 0 12px;
}
.donut-center .amt { font-size: 17px; font-weight: 700; letter-spacing: -.02em; }
/* Totale in valuta al centro: un filo più compatto per starci sempre dentro il buco del donut. */
.donut-center .amt.amt-euro { font-size: 15px; letter-spacing: -.03em; white-space: nowrap; }
.donut-center .lbl { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.25; }
.legend { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 14px; cursor: pointer; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.legend-row .lname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .lamt { font-weight: 600; white-space: nowrap; }
/* Per cifre grandi (patrimonio): l'importo va a capo sotto il nome invece di troncare il nome. */
.legend-row.wrap-amt { flex-wrap: wrap; }
.legend-row.wrap-amt .lname { white-space: normal; overflow: visible; text-overflow: clip; }
.legend-row.wrap-amt .lamt { flex: 0 0 100%; padding-left: 18px; margin-top: -2px; }

/* Badge icona generico: base condivisa da .ico/.badge/.emoji ovunque compaiano */
.ico, .badge, .emoji { display: grid; place-items: center; border-radius: 12px; width: 38px; height: 38px; flex: 0 0 auto; }
.ico svg, .badge svg, .emoji svg, .mc-ico svg { display: block; }
.rec-tag { display: inline-flex; vertical-align: middle; color: var(--muted); margin-left: 2px; }

.cat-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.cat-row { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; cursor: pointer; }
.cat-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.cat-head .name { display: flex; align-items: center; gap: 10px; }
.cat-head .badge { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; font-size: 15px; }
.cat-head .amt { font-weight: 700; }
/* Due segmenti sulla stessa barra: lo speso pieno, l'impegnato (spese future già segnate) tenue.
   L'arrotondamento sta sul contenitore, così le due parti restano attaccate senza tacca in mezzo. */
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }
.bar > span.impegnato { opacity: .38; }
.bar.over > span { background: var(--out) !important; }
.cat-head .impegnato-amt { font-weight: 600; color: var(--muted); }

/* ---------- Movimenti ---------- */
.mov-list { display: flex; flex-direction: column; }
.mov-day {
  font-size: 12px; font-weight: 700; color: var(--muted); margin: 20px 6px 9px;
  text-transform: uppercase; letter-spacing: .04em;
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
}
.mov-day .day-total { text-transform: none; letter-spacing: 0; font-weight: 600; }
.mov.ghost { opacity: .62; border-style: dashed; }
/* Movimento datato avanti: c'è ma non è ancora successo. Bordo tratteggiato come le ricorrenze in
   arrivo (stessa idea: futuro noto), senza smorzarlo — è una riga vera, si tocca e si corregge. */
.mov.futuro { border-style: dashed; }
.mov-day.futuro { color: var(--muted); opacity: .8; }
.tag-previsto {
  display: inline-block; vertical-align: middle; margin-left: 6px; padding: 1px 6px;
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: var(--surface-2); border-radius: 999px;
}
.mov.clickable { cursor: pointer; }
.mov {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 8px;
}
.mov .emoji { font-size: 20px; width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; flex: 0 0 auto; }
.mov .info { flex: 1; min-width: 0; }
.mov .info .cat { font-weight: 600; overflow-wrap: anywhere; }
.mov .info .meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.mov .amt { font-weight: 700; white-space: nowrap; }
.mov .amt.in { color: var(--in); } .mov .amt.out { color: var(--text); }
.mov .del { background: none; border: none; color: var(--muted); padding: 4px 6px; cursor: pointer; display: flex; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 52px 20px; line-height: 1.6; }

/* ---------- Conti ---------- */
.conti-list { display: flex; flex-direction: column; gap: 10px; }
.conto-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 15px 16px;
}
.conto-row.clickable { cursor: pointer; }
/* Feedback al tocco: l'elemento "risponde" sotto il dito */
.mov.clickable:active, .conto-row.clickable:active, .chip:active,
.mini-card:not(.static):active, .legend-row:active, .cat-row.clickable:active {
  transform: scale(.985);
  transition: transform .06s ease;
}
.conto-row .nm { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
/* Il nome lungo va a capo TRA le parole (non a metà parola) invece di sovrapporsi alla cifra;
   niente troncamento: i due conti "Arancio Ilaria" e "Arancio Cointestato" resterebbero
   indistinguibili se tagliati. */
.conto-row .nm > span:last-child, .conto-row .nm .row-nome { min-width: 0; overflow-wrap: break-word; }
/* Su telefono il chevron è ridondante (tutta la riga è toccabile) e ruba spazio al nome:
   lo mostriamo solo da desktop, dove c'è margine. */
.conti-list .chevron-affordance { display: none; }
.conto-row .right { flex: 0 0 auto; }
.conto-row.wrap-safe { align-items: flex-start; }
.conto-row.wrap-safe .ico { margin-top: 1px; }
.conto-row.wrap-safe .right { align-items: flex-start; padding-top: 2px; }
.conto-row .ico { font-size: 19px; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: 0 0 auto; }
.conto-row .saldo { font-weight: 700; font-size: 18px; letter-spacing: -.01em; white-space: nowrap; }
.conto-row .right { display: flex; align-items: center; gap: 10px; margin-left: 10px; }
.conto-row .del { background: none; border: none; color: var(--muted); padding: 4px 2px; cursor: pointer; display: flex; align-items: center; }

/* ---------- Tabbar + FAB ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--border);
  /* space-evenly con schede a larghezza naturale: gli spazi ai due lati e fra le voci sono uguali,
     quindi la fila resta bilanciata sia con tre voci sia con quattro. (Con schede a flex:1 e un
     numero dispari di voci il "+" finiva fuori centro o lasciava un buco in fondo.) */
  display: flex; justify-content: space-evenly; align-items: center;
  padding: 8px 8px calc(8px + var(--safe-b)); max-width: 720px; margin: 0 auto;
}
/* Dove il vetro smerigliato non è supportato (Samsung Internet / WebView datate) la barra sarebbe
   semi-trasparente e lascerebbe intravedere il contenuto: la rendiamo opaca. */
@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .tabbar { background: var(--bg); }
}
.tab {
  /* Larghezza naturale (non flex:1): la spaziatura la decide space-evenly sulla .tabbar. */
  flex: 0 0 auto; background: none; border: none; color: var(--muted); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11px; font-weight: 600; padding: 4px;
}
.tab-icon { display: flex; }
.tab.active { color: var(--text); }
.fab {
  width: 56px; height: 56px; border-radius: 50%; border: none; flex: 0 0 auto;
  background: var(--accent); color: var(--on-accent); font-size: 28px; line-height: 1; cursor: pointer;
  box-shadow: var(--shadow-lg); margin-top: -18px;
}
.fab:active { transform: scale(.94); }

/* ---------- Patrimonio: grafico andamento ---------- */
.chart-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 16px 12px; margin-top: 16px;
}
.chart-card svg { width: 100%; height: 100px; display: block; overflow: visible; }
.chart-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

/* Vista "Composizione": area impilata. Stessa altezza della linea del totale, così le due viste
   non ballano quando si tocca l'interruttore. */

/* Ispezione della linea (tocca/trascina) */
.storico-wrap { position: relative; touch-action: none; }
.scrub-line { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--accent); opacity: .35; transform: translateX(-0.5px); pointer-events: none; }
.scrub-tip {
  position: absolute; top: -4px; transform: translateX(-50%);
  background: var(--accent); color: var(--on-accent); border-radius: 10px;
  padding: 5px 9px; font-size: 12px; line-height: 1.3; white-space: nowrap;
  box-shadow: var(--shadow); pointer-events: none; z-index: 2; text-align: center;
}
.scrub-tip .muted { color: var(--on-accent); opacity: .7; }
.scrub-tip .delta-inv.gain { color: var(--hero-in); }
.scrub-tip .delta-inv.loss { color: var(--hero-out); }

/* Il delta del periodo sotto la linea: una riga che si legge, non un bottone da aprire. */
.periodo-riga { margin: 10px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

.chart-toggle { display: flex; justify-content: flex-end; gap: 4px; margin-bottom: 8px; }
.pill-toggle {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font: inherit; font-weight: 700; font-size: 11px; padding: 4px 10px; border-radius: 999px; cursor: pointer;
}
.pill-toggle.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chart-empty { text-align: center; padding: 28px 16px; }

/* ---------- Foglio di export ---------- */
/* Le pillole del periodo si leggono da sinistra come una frase, non allineate a destra come
   quelle dei grafici; e riempiono la riga perché sul telefono devono essere prese col pollice. */
.export-toggle { justify-content: flex-start; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.export-toggle .pill-toggle { font-size: 13px; padding: 7px 14px; }
/* Azione testuale discreta: apre le date a mano, e sta anche in cima ai Movimenti. */
.mini-action {
  background: none; border: none; padding: 4px 0; margin: 0;
  font: inherit; font-size: 13px; font-weight: 600; color: var(--accent); cursor: pointer;
}
.export-custom-link { display: block; margin: 2px 0 10px; }
.export-date { margin-bottom: 4px; }
/* Il riquadro che dice cosa sta per uscire: si legge, non si tocca. */
.export-riepilogo {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; margin: 12px 0 0; font-size: 13px; line-height: 1.5; text-align: center;
}

/* ---------- Pagina FIRE ---------- */
.pill-toggle:disabled { opacity: .45; cursor: default; }
/* Il toggle 12/24 mesi vive dentro la card scura dell'eroe: variante sui toni hero */
.balance-card .chart-toggle { justify-content: center; margin: 12px 0 0; }
.balance-card .pill-toggle {
  background: color-mix(in srgb, var(--hero-text) 12%, transparent);
  border-color: transparent; color: var(--hero-text); opacity: .7;
}
.balance-card .pill-toggle.active {
  background: color-mix(in srgb, var(--hero-text) 24%, transparent);
  border-color: transparent; color: var(--hero-text); opacity: 1;
}
/* Solo su schermi molto stretti riduciamo il testo delle schede */
@media (max-width: 360px) { .tabbar .tab { font-size: 10px; } }

/* ---------- Sheet aggiungi ---------- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 55; background: rgba(10,12,20,.4);
  display: flex; align-items: flex-end; animation: fade .2s ease;
}
.sheet {
  background: var(--surface); width: 100%; max-width: 720px; margin: 0 auto;
  border-radius: 26px 26px 0 0; padding: 22px 20px calc(24px + var(--safe-b));
  animation: slideup .28s cubic-bezier(.2,.8,.2,1); max-height: 92dvh; overflow-y: auto;
  overscroll-behavior: contain; /* lo scroll del foglio non trascina la pagina sotto */
}
#cat-detail-movs { overscroll-behavior: contain; }
@keyframes slideup { from { transform: translateY(100%);} to { transform: none; } }
.sheet-title { font-size: 18px; font-weight: 700; text-align: center; margin: 0 0 18px; letter-spacing: -.01em; }
.type-toggle { display: flex; background: var(--surface-2); border-radius: 999px; padding: 4px; margin-bottom: 18px; }
.tg, .tg-bene { flex: 1; border: none; background: none; color: var(--muted); font: inherit; font-weight: 700; padding: 10px; border-radius: 999px; cursor: pointer; }
.tg.active, .tg-bene.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.type-toggle.three .tg-bene, .type-toggle.three .tg { font-size: 12px; padding: 10px 4px; }
.sheet-small { max-width: 340px; }
.amount { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 8px 0 20px; }
.amount .cur { font-size: 30px; color: var(--muted); font-weight: 600; }
.amount input { font-size: 44px; font-weight: 700; text-align: center; border: none; margin: 0; padding: 0; background: none; width: auto; max-width: 60%; }
.amount input:focus { outline: none; box-shadow: none; }
.field-label { font-size: 12px; color: var(--muted); font-weight: 700; display: block; margin: 16px 2px 0; text-transform: uppercase; letter-spacing: .04em; }
.select { margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip {
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 8px 13px; font-size: 14px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 7px;
}
.chip .dot { width: 8px; height: 8px; margin: 0; }
.chip-ico { display: flex; }
.chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.sheet-actions { display: flex; gap: 12px; margin-top: 26px; }
.sheet-actions .btn { flex: 1; }

.pref-star { color: var(--muted); display: inline-flex; vertical-align: middle; margin-left: 2px; }
.saldo-attuale-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 6px; flex-wrap: wrap; }
.saldo-attuale-val { font-weight: 700; font-size: 22px; letter-spacing: -.01em; }
.btn-sm { padding: 8px 14px; font-size: 14px; width: auto; flex: 0 0 auto; }

/* ---------- Flussi 6 mesi ---------- */
.flussi-card { margin-top: 0; }
.flussi-svg { width: 100%; height: 130px; display: block; }
.flussi-svg .bar-label { font-size: 9px; fill: var(--muted); font-family: inherit; }
/* Il mese toccato resta pieno, gli altri si smorzano: l'etichetta accesa dice quale si sta leggendo. */
#flussi-chart .flussi-svg { cursor: pointer; }
.flussi-svg .bar-group { transition: opacity .15s ease; }
.flussi-svg.has-sel .bar-group:not(.sel) { opacity: .28; }
/* Con gli importi dentro, la legenda è più lunga: se non ci sta va a capo invece di tagliarsi. */
.flussi-legend { display: flex; flex-wrap: wrap; gap: 4px 18px; justify-content: center; font-size: 12px; color: var(--muted); margin-top: 4px; }
.flussi-legend strong { color: var(--text); font-weight: 600; }
.flussi-legend .dot.in { background: var(--in); }
.flussi-legend .dot.out { background: var(--out); }

/* ---------- Investimenti ---------- */
.invest-summary {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 16px; margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 14px;
}
.delta-inv { font-weight: 700; }
.delta-inv.gain { color: var(--in); }
.delta-inv.loss { color: var(--out); }
.delta-inv.small { font-size: 12px; }
.conto-row .right.invest-right { flex-direction: column; align-items: flex-end; gap: 2px; }
.acquisto-totale { text-align: center; font-weight: 700; font-size: 18px; margin: 14px 0 0; }
.etf-head {
  background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin-top: 4px;
  display: flex; flex-direction: column; gap: 8px; font-size: 14px;
}
.etf-head-row { display: flex; justify-content: space-between; gap: 12px; }

/* ---------- Fondi pensione ---------- */
.inline-form { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.inline-form.wrap { flex-wrap: wrap; }
.inline-form .grow { flex: 1 1 120px; }
.inline-form .amount {
  margin: 0; justify-content: flex-start; flex: 1 1 120px; padding: 8px 12px;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
}
.inline-form .amount .cur { font-size: 18px; }
.inline-form .amount input { font-size: 20px; text-align: left; max-width: 100%; width: 100%; }
.inline-form .btn { width: auto; flex: 0 0 auto; }
.inline-form .select { margin-top: 0; }
.btn.danger { color: var(--out); }
.empty.small { padding: 16px 20px; font-size: 13px; }

/* ---------- Analisi del portafoglio ---------- */
.analisi-link { margin-top: 14px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; }
.analisi-arrow { color: var(--muted); }
.analisi-block { margin-top: 22px; }
.analisi-block:first-child { margin-top: 4px; }
.analisi-block h4 { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 0 2px 10px; }
.analisi-nudge { margin-top: 10px; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-tile {
  background: var(--surface-2); border-radius: 12px; padding: 12px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat-val { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.stat-val.gain { color: var(--in); }
.stat-val.loss { color: var(--out); }
.legend-inline { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 8px; }
.legend-inline .legend-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.risk-bar { display: flex; height: 22px; border-radius: 999px; overflow: hidden; background: var(--surface-2); }
.risk-seg { height: 100%; }
.risk-seg.rischioso { background: var(--out); }
.risk-seg.bilanciato { background: #d9a23a; }
.risk-seg.difensivo { background: var(--in); }
.risk-dot-rischioso { background: var(--out); }
.risk-dot-bilanciato { background: #d9a23a; }
.risk-dot-difensivo { background: var(--in); }

/* Card apribili nell'analisi: legenda dell'allocazione e tile degli indicatori */
.legend-row.clickable, .stat-tile.clickable { cursor: pointer; }
.legend-row.clickable .lamt { display: inline-flex; align-items: center; gap: 4px; }
.legend-row.clickable .lamt svg { color: var(--muted); }
.stat-tile.clickable { transition: background .12s; }
.stat-tile.clickable:hover { background: var(--border); }
.info-text { font-size: 15px; line-height: 1.6; color: var(--text); margin: 4px 2px; }

/* ---------- Gestione categorie ---------- */
.cat-manage-section { margin-top: 18px; }
.cat-manage-section:first-of-type { margin-top: 4px; }
.section-head-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-head-row span { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.link-btn { background: none; border: none; color: var(--accent); font: inherit; font-weight: 700; font-size: 13px; cursor: pointer; padding: 4px; }
.icon-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.icon-choice {
  width: 42px; height: 42px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--surface);
  color: var(--text); display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-choice.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.color-choice {
  width: 42px; height: 42px; border-radius: 50%; border: 2px solid transparent;
  cursor: pointer; padding: 0; display: flex; align-items: center; justify-content: center;
}
.color-choice.auto { background: var(--surface-2); border-color: var(--border); }
.color-choice .auto-label { font-size: 10px; font-weight: 700; color: var(--muted); }
.color-choice.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.archivia-btn { margin-top: 10px; color: var(--muted); }
.conto-row.archiviata { opacity: .55; }
#cat-detail-title { display: flex; align-items: center; justify-content: center; gap: 10px; }
.cat-detail-chart { margin-top: 12px; }
.cat-detail-chart svg { width: 100%; height: 110px; display: block; }
#cat-detail-movs { margin-top: 4px; max-height: 260px; overflow-y: auto; }

/* ---------- Onboarding ---------- */
.onboarding {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  overflow-y: auto;
}
.ob-card { width: 100%; max-width: 420px; }
.ob-icon {
  width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center; font-size: 26px; margin: 0 auto 20px; box-shadow: var(--shadow-lg);
}
.ob-title { font-size: 24px; font-weight: 700; letter-spacing: -.02em; text-align: center; margin: 0 0 8px; }
.ob-subtitle { color: var(--muted); text-align: center; margin: 0 0 28px; line-height: 1.5; }
.ob-progress { display: flex; gap: 6px; justify-content: center; margin-bottom: 28px; }
.ob-progress span { width: 24px; height: 4px; border-radius: 999px; background: var(--border); }
.ob-progress span.done { background: var(--accent); }
.ob-field { margin-bottom: 14px; }
.ob-field label { font-size: 14px; font-weight: 600; display: block; margin-bottom: 6px; }
.ob-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 10px;
}
.ob-row .lbl { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.ob-row input {
  width: 130px; margin: 0; text-align: right; padding: 10px 12px; border-radius: 10px;
}
.ob-actions { display: flex; gap: 12px; margin-top: 24px; }
.ob-actions .btn { flex: 1; }
.ob-list-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; margin-bottom: 8px;
}
.ob-list-item .del { background: none; border: none; color: var(--muted); cursor: pointer; display: flex; align-items: center; }
.ob-add-row { display: flex; gap: 8px; margin-top: 4px; }
.ob-add-row input:first-child { flex: 2; }
.ob-add-row input:last-child { flex: 1; text-align: right; }
.ob-skip { display: block; text-align: center; margin-top: 14px; color: var(--muted); background: none; border: none; font: inherit; font-weight: 600; cursor: pointer; }

/* ---------- Caricamento ---------- */
.loading { position: fixed; inset: 0; z-index: 70; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--text); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.confirm-message { font-size: 16px; font-weight: 600; margin: 6px 0 4px; }

/* ---------- Barra laterale (attiva solo da desktop, vedi media query sotto) ---------- */
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 12px 22px; }
.sidebar-tab {
  flex: none; display: flex; flex-direction: row; align-items: center; gap: 12px; justify-content: flex-start;
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 600;
}
.sidebar-tab.active { background: var(--surface-2); }
.sidebar-add {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 14px; padding: 12px;
  border: none; border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent);
  font: inherit; font-weight: 700; font-size: 15px; cursor: pointer;
}
.sidebar-logout {
  display: flex; align-items: center; gap: 10px; width: 100%; margin-top: auto; padding: 11px 12px;
  border: none; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; border-radius: var(--radius-sm);
}

/* ---------- Griglia dashboard: colonna unica su telefono, righe affiancate da desktop ---------- */
.dashboard-grid { display: flex; flex-direction: column; gap: 16px; }
.grid-side { display: flex; flex-direction: column; gap: 16px; }

/* ==================== Da qui in giù: solo desktop ==================== */
@media (min-width: 900px) {
  .app-content { max-width: none; margin: 0; width: auto; }
  .sidebar {
    display: flex; flex-direction: column; width: 260px; flex: 0 0 auto;
    padding: 24px 16px; border-right: 1px solid var(--border); background: var(--surface);
  }
  .tabbar, .fab { display: none; }
  .topbar { padding: 26px 40px 16px; }
  #logout-btn { display: none; } /* il logout vive nella barra laterale */
  main { padding: 24px 40px calc(40px + var(--safe-b)); max-width: 1100px; }

  .dashboard-grid { flex-direction: row; align-items: stretch; }
  .dashboard-grid > .balance-card { flex: 1.1; }
  .grid-side { flex: 1; }

  /* I fogli a comparsa diventano finestre modali centrate */
  .sheet-overlay { align-items: center; }
  .sheet { border-radius: var(--radius); max-width: 440px; animation: modal-in .18s ease; }
  .sheet-handle { display: none; }

  /* Movimenti: riga singola invece di card impilata pensata per il dito */
  .mov .info { display: flex; flex-direction: row; align-items: center; gap: 16px; }
  .mov .info .cat { flex: 0 0 220px; }
  .mov .info .meta { flex: 1; }

  .toast { bottom: 28px; }
  .conti-list .chevron-affordance { display: inline-flex; } /* su desktop c'è spazio: rimettiamo il chevron */
}
@keyframes modal-in { from { opacity: 0; transform: scale(.97); } to { opacity: 1; transform: none; } }

@media (min-width: 900px) and (hover: hover) {
  .conto-row.clickable:hover, .cat-row:hover, .legend-row:hover, .mini-card:hover { background: var(--surface-2); }
  .btn-ghost:hover { background: var(--border); }
  .btn-primary:hover { opacity: .88; }
  .sidebar-tab:hover:not(.active) { background: var(--surface-2); }
  .sidebar-logout:hover { background: var(--surface-2); color: var(--text); }
  .sidebar-add:hover { opacity: .88; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(100px + var(--safe-b)); left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 999px;
  font-size: 15px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); animation: fade .2s ease;
}

/* ---------- Movimento ridotto ----------
   Per chi ha attivato "riduci animazioni" nel sistema (accessibilità) e per togliere micro-scatti
   percepiti come "bug" su telefoni meno potenti: niente comparse/scivolamenti, transizioni istantanee.
   Lo spinner del caricamento resta (serve a comunicare l'attesa). */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important; animation-iteration-count: 1 !important;
    transition-duration: .001ms !important; scroll-behavior: auto !important;
  }
  .spinner { animation: spin .8s linear infinite !important; }
}
