/* MoneyCloud — style.css */
:root {
  --bg: #0f1115; --bg2: #171a21; --bg3: #1e222b; --bg4: #262b36;
  --testo: #eef1f6; --testo2: #9aa4b2; --bordo: #2a2f3a;
  --verde: #17a05a; --verde-scuro: #0b6b3a; --rosso: #ef5350; --blu: #3b82f6; --giallo: #e2b93b;
  --ombra: 0 6px 24px rgba(0,0,0,.35); --r: 14px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bot: env(safe-area-inset-bottom, 0px);
  --sidebar: 232px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9; --bg2: #ffffff; --bg3: #eef1f5; --bg4: #e6eaf0;
    --testo: #131720; --testo2: #5b6472; --bordo: #dde2ea;
    --ombra: 0 6px 24px rgba(20,30,50,.10);
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--testo); overscroll-behavior: none;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, select { font: inherit; }
small { font-size: .78em; }
h1, h2, h3 { margin: 0; font-weight: 700; }
.pos { color: var(--verde); } .neg { color: var(--rosso); } .neu { color: var(--testo2); }

/* ============================ LOGIN / GATE ============================ */
.login { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(1200px 600px at 50% -10%, #123, var(--bg)); }
.login-box { width: 100%; max-width: 380px; text-align: center; }
.logo-badge { width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 22px; background: linear-gradient(160deg, var(--verde), var(--verde-scuro)); color: #fff; font-size: 40px; font-weight: 800; display: grid; place-items: center; box-shadow: var(--ombra); }
.login h1 { font-size: 30px; letter-spacing: -.5px; }
.login-sub { color: var(--testo2); margin: 6px 0 18px; }
.err { color: var(--rosso); min-height: 18px; }
.auth-tabs { display: flex; gap: 6px; background: var(--bg3); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.auth-tab { flex: 1; padding: 9px; border-radius: 9px; color: var(--testo2); font-weight: 600; }
.auth-tab.attiva { background: var(--bg2); color: var(--testo); box-shadow: var(--ombra); }
.au-note { color: var(--testo2); font-size: .85em; margin: 0 0 10px; }
.au-inp { width: 100%; padding: 13px 14px; margin: 6px 0; border-radius: 12px; background: var(--bg2); border: 1px solid var(--bordo); color: var(--testo); outline: none; }
.au-inp:focus { border-color: var(--verde); }
.au-inp.big { font-size: 26px; font-weight: 700; text-align: center; }
.au-go { width: 100%; margin-top: 10px; }
.au-msg { color: var(--testo2); min-height: 18px; }
.attesa p { color: var(--testo2); }

/* ============================ BOTTONI ============================ */
.btn { padding: 11px 16px; border-radius: 12px; font-weight: 600; background: var(--bg3); color: var(--testo); transition: filter .15s; }
.btn:active { filter: brightness(.92); }
.btn.verde { background: var(--verde); color: #fff; }
.btn.ghost { background: var(--bg3); }
.btn.pericolo { color: var(--rosso); }
.btn.largo { width: 100%; }
.btn.mini { padding: 6px 10px; font-size: .85em; border-radius: 9px; }
.badge { font-size: .7em; background: var(--verde-scuro); color: #fff; padding: 2px 7px; border-radius: 8px; vertical-align: middle; }

/* ============================ LAYOUT APP ============================ */
.app { display: flex; min-height: 100%; }
.sidebar { width: var(--sidebar); flex-shrink: 0; background: var(--bg2); border-right: 1px solid var(--bordo); padding: 16px 12px calc(12px + var(--safe-bot)); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; font-weight: 800; font-size: 18px; }
.brand-ico { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(160deg, var(--verde), var(--verde-scuro)); color: #fff; display: grid; place-items: center; font-weight: 800; }
.nav-lista { display: flex; flex-direction: column; gap: 3px; }
.nav { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 11px; color: var(--testo2); font-weight: 600; text-align: left; }
.nav .nic { font-size: 18px; width: 22px; text-align: center; }
.nav.attiva, .nav:hover { background: var(--bg3); color: var(--testo); }
.sidebar-fondo { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.sync-stato { font-size: .78em; color: var(--testo2); padding: 6px 10px; border-radius: 9px; background: var(--bg3); }
.sync-stato.sync { color: var(--blu); } .sync-stato.errore { color: var(--rosso); } .sync-stato.offline { color: var(--giallo); } .sync-stato.idle { color: var(--verde); }
.me { font-size: .85em; color: var(--testo2); padding: 4px 10px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--bordo); }
.vista-titolo { font-size: 20px; }
.search-wrap { flex: 1; }
#filtro { width: 100%; padding: 9px 14px; border-radius: 11px; background: var(--bg3); border: 1px solid var(--bordo); color: var(--testo); outline: none; }
.icona-btn { width: 40px; height: 40px; border-radius: 11px; background: var(--bg3); display: grid; place-items: center; font-size: 18px; }
.icona-btn.primario { background: var(--verde); color: #fff; font-size: 24px; font-weight: 700; }
.icona-btn .ic { width: 22px; height: 22px; }
.vista { padding: 16px 16px calc(90px + var(--safe-bot)); max-width: 820px; width: 100%; margin: 0 auto; }
@media (min-width: 821px) { .vista { padding-bottom: 32px; } }

/* tab bar mobile */
.tabbar { display: none; }
@media (max-width: 820px) {
  .sidebar { display: none; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: color-mix(in srgb, var(--bg2) 96%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--bordo); padding-bottom: var(--safe-bot); }
  .tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; color: var(--testo2); font-size: 20px; }
  .tab small { font-size: 10px; font-weight: 600; }
  .tab.attiva { color: var(--verde); }
  .tab-add .tab-add-ic { width: 46px; height: 46px; margin-top: -14px; border-radius: 50%; background: var(--verde); color: #fff; font-size: 28px; font-weight: 700; display: grid; place-items: center; box-shadow: var(--ombra); }
}

/* ============================ SEZIONI / LISTE ============================ */
.sez { margin-bottom: 20px; }
.sez-head { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 8px; color: var(--testo2); font-weight: 700; font-size: .9em; text-transform: uppercase; letter-spacing: .04em; }
.conti-lista, .tx-lista, .budget-lista { display: flex; flex-direction: column; gap: 2px; }
.conto-riga { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-radius: 12px; background: var(--bg2); text-align: left; }
.conto-riga:active { background: var(--bg3); }
.conto-ico { font-size: 22px; width: 30px; text-align: center; }
.conto-nome { flex: 1; font-weight: 600; display: flex; flex-direction: column; }
.conto-tipo { color: var(--testo2); font-weight: 400; }
.conto-saldo { font-weight: 700; text-align: right; display: flex; flex-direction: column; }
.conto-saldo small { color: var(--testo2); font-weight: 500; }
.conti-lista.big .conto-riga { padding: 15px 14px; }

.netto-card { background: linear-gradient(160deg, var(--verde-scuro), #094a2a); color: #fff; border-radius: var(--r); padding: 20px; margin-bottom: 20px; box-shadow: var(--ombra); }
.netto-lab { opacity: .85; font-size: .9em; }
.netto-val { font-size: 34px; font-weight: 800; letter-spacing: -.5px; }
.netto-val.neg { color: #ffd5d5; }

.vuoto { text-align: center; color: var(--testo2); padding: 40px 12px; display: flex; flex-direction: column; align-items: center; gap: 14px; }
.vuoto.small { padding: 12px; }

/* transazioni */
.mese-nav { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 12px; }
.mese-nav button { width: 34px; height: 34px; border-radius: 10px; background: var(--bg3); font-size: 20px; }
.mese-lab { font-weight: 700; min-width: 150px; text-align: center; }
.riepilogo-mese { display: flex; gap: 8px; margin-bottom: 16px; }
.rm-cell { flex: 1; background: var(--bg2); border-radius: 12px; padding: 12px; text-align: center; display: flex; flex-direction: column; gap: 2px; }
.rm-cell small { color: var(--testo2); }
.rm-cell b { font-size: 1.05em; }
.giorno-head { display: flex; justify-content: space-between; padding: 16px 4px 6px; color: var(--testo2); font-weight: 600; font-size: .85em; }
.tx-riga { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; background: var(--bg2); text-align: left; width: 100%; }
.tx-riga:active { background: var(--bg3); }
.tx-riga.statica:active { background: var(--bg2); }
.tx-ico { font-size: 20px; width: 30px; text-align: center; }
.tx-mid { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tx-tit { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-tit .ric { color: var(--verde); }
.tx-sub { color: var(--testo2); font-size: .82em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-imp { font-weight: 700; white-space: nowrap; }

/* budget */
.budget-card { display: block; text-align: left; background: var(--bg2); border-radius: 12px; padding: 14px; }
.bc-top { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 8px; gap: 10px; }
.bc-bar { height: 8px; background: var(--bg4); border-radius: 6px; overflow: hidden; }
.bc-bar i { display: block; height: 100%; border-radius: 6px; background: var(--verde); }
.bc-bar i.quasi { background: var(--giallo); } .bc-bar i.super { background: var(--rosso); }
.bc-sub { color: var(--testo2); font-size: .82em; margin-top: 7px; }

/* resoconti */
.res-card { background: var(--bg2); border-radius: var(--r); padding: 16px; margin-bottom: 16px; }
.res-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.res-head h3 { font-size: 1em; }
.seg { display: flex; background: var(--bg3); border-radius: 10px; padding: 3px; }
.seg-b { padding: 6px 12px; border-radius: 8px; color: var(--testo2); font-weight: 600; font-size: .85em; }
.seg-b.attiva { background: var(--bg2); color: var(--testo); }

/* charts */
.chart-pie { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.pie-svg { width: 160px; height: 160px; flex-shrink: 0; }
.pie-fetta { transition: opacity .15s; } .pie-fetta:hover { opacity: .85; }
.pie-centro { fill: var(--testo2); font-size: 12px; } .pie-centro-val { fill: var(--testo); font-size: 15px; font-weight: 700; }
.chart-legenda { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 6px; }
.chart-legenda.oriz { flex-direction: row; gap: 16px; margin-top: 8px; }
.leg-row { display: flex; align-items: center; gap: 8px; font-size: .88em; }
.leg-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.leg-nome { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leg-val { font-weight: 600; } .leg-perc { color: var(--testo2); width: 38px; text-align: right; }
.chart-vuoto { color: var(--testo2); text-align: center; padding: 20px; }
.bar-svg, .line-svg { width: 100%; height: 170px; }
.bar-lab { fill: var(--testo2); font-size: 9px; }
.line-path { stroke-width: 2.2; } .line-area { stroke: none; } .line-zero { stroke: var(--bordo); stroke-dasharray: 3 3; }

/* ============================ FOGLIO / MODALE ============================ */
.foglio { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.foglio-bg, .modale-bg { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.foglio-box { position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto; background: var(--bg2); border-radius: 20px 20px 0 0; padding: 0 18px calc(24px + var(--safe-bot)); box-shadow: var(--ombra); animation: su .22s ease; }
@media (min-width: 560px) { .foglio { align-items: center; } .foglio-box { border-radius: 20px; max-height: 88vh; } }
@keyframes su { from { transform: translateY(30px); opacity: .6; } }
.foglio-head { position: sticky; top: 0; background: var(--bg2); display: flex; align-items: center; gap: 12px; padding: 16px 0 12px; border-bottom: 1px solid var(--bordo); z-index: 2; }
.foglio-head h3 { flex: 1; font-size: 17px; }
.foglio-chiudi { width: 34px; height: 34px; border-radius: 10px; background: var(--bg3); font-size: 16px; }
.foglio-cont { padding-top: 12px; }
.campo { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.campo > span { font-size: .82em; color: var(--testo2); font-weight: 600; }
.campo.riga { flex-direction: row; align-items: center; justify-content: space-between; }
.campo.riga > span { font-size: .95em; color: var(--testo); }
.campo input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--verde); }
.scelta { text-align: left; }
.importo-campo .au-inp { }
.tx-tabs { display: flex; gap: 6px; background: var(--bg3); border-radius: 12px; padding: 4px; margin: 8px 0 14px; }
.tx-tab { flex: 1; padding: 9px; border-radius: 9px; color: var(--testo2); font-weight: 600; font-size: .9em; }
.tx-tab.attiva { background: var(--bg2); color: var(--testo); }
.pericolo.largo { width: 100%; margin-top: 12px; }

.catpick { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; }
.catpick-top { width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; background: var(--bg3); font-weight: 700; }
.catpick-figli { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 4px 0; }
.catpick-cat { padding: 8px 11px; border-radius: 20px; background: var(--bg3); font-size: .88em; }
.catpick-cat:active, .catpick-top:active { background: var(--bg4); }

.modale { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modale-box { position: relative; width: 100%; max-width: 420px; background: var(--bg2); border-radius: 16px; padding: 20px; box-shadow: var(--ombra); }
.modale-azioni { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.modale-azioni button { padding: 10px 16px; border-radius: 11px; background: var(--bg3); font-weight: 600; }
.modale-azioni .primario { background: var(--verde); color: #fff; }

.toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-bot)); transform: translateX(-50%); background: #000d; color: #fff; padding: 11px 18px; border-radius: 12px; z-index: 60; font-size: .9em; box-shadow: var(--ombra); }
@media (min-width: 821px) { .toast { bottom: 28px; } }

/* impostazioni */
.imp { display: flex; flex-direction: column; gap: 18px; }
.imp-sez { background: var(--bg2); border-radius: var(--r); padding: 14px 16px; }
.imp-sez h3 { font-size: .82em; text-transform: uppercase; letter-spacing: .04em; color: var(--testo2); margin-bottom: 10px; }
.imp-riga { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--bordo); }
.imp-riga:first-of-type { border-top: none; }
.imp-riga.small { font-size: .85em; color: var(--testo2); }
.token-box { display: flex; gap: 8px; align-items: center; margin-top: 10px; background: var(--bg3); border-radius: 10px; padding: 8px 10px; }
.token-box code { flex: 1; overflow-x: auto; font-size: .78em; white-space: nowrap; }
.sess-riga { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--bordo); }
.sess-riga:first-child { border-top: none; }
.sess-riga small.attesa { color: var(--giallo); }
.imp-footer { text-align: center; color: var(--testo2); font-size: .8em; margin: 6px 0 0; }
.dett-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.dett-nome { font-size: 18px; font-weight: 700; }
.dett-saldo { font-size: 24px; font-weight: 800; }

/* categorie */
.cat-lista { display: flex; flex-direction: column; gap: 3px; margin-bottom: 4px; }
.cat-riga { display: flex; align-items: center; gap: 10px; background: var(--bg2); border-radius: 12px; text-align: left; width: 100%; }
.cat-riga.top { padding-right: 6px; }
.cat-riga.sub { margin-left: 22px; background: var(--bg3); }
.cat-main { flex: 1; display: flex; align-items: center; gap: 10px; padding: 12px 14px; text-align: left; }
.cat-main:active { filter: brightness(1.12); }
.cat-ico { font-size: 20px; width: 26px; text-align: center; }
.cat-nome { font-weight: 600; }
.cat-sub-add { width: 34px; height: 34px; border-radius: 9px; background: var(--bg3); color: var(--verde); font-size: 18px; font-weight: 700; flex-shrink: 0; }
.emoji-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-b { width: 42px; height: 42px; border-radius: 10px; background: var(--bg3); font-size: 20px; }
.emoji-b:active { background: var(--bg4); }

/* chip data di oggi (apre il calendario) */
.oggi-chip { display: flex; align-items: center; gap: 5px; padding: 8px 11px; border-radius: 11px; background: var(--bg3); font-size: .84em; font-weight: 600; white-space: nowrap; flex-shrink: 0; }
.oggi-chip:active { background: var(--bg4); }
#oggi-data:empty { display: none; }

/* calendario: griglia in alto (fissa) + lista scorrevole in basso */
.cal-view { display: flex; flex-direction: column; gap: 10px; height: calc(100dvh - 150px); }
@media (min-width: 821px) { .cal-view { height: calc(100dvh - 118px); } }
.cal-wrap { flex-shrink: 0; }
.cal-dow { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.cal-dow span { text-align: center; font-size: .72em; color: var(--testo2); font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell { aspect-ratio: 1 / 1; border-radius: 10px; background: var(--bg2); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.cal-cell:active { background: var(--bg3); }
.cal-cell.fuori { opacity: .3; }
.cal-cell.oggi { outline: 2px solid var(--verde); }
.cal-cell.sel { background: var(--verde-scuro); color: #fff; }
.cal-n { font-size: .82em; font-weight: 600; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--testo2); }
.cal-dot.neg { background: var(--rosso); } .cal-dot.pos { background: var(--verde); } .cal-dot.neu { background: var(--blu); }
.cal-scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; border-top: 1px solid var(--bordo); padding-top: 4px; }
.giorno-head.flash { animation: flash 1s ease; border-radius: 8px; }
@keyframes flash { 0%, 100% { background: transparent; } 30% { background: color-mix(in srgb, var(--verde) 22%, transparent); } }
.imp-nota { font-size: .78em; color: var(--testo2); margin: 8px 0 0; }
