/* Budget Casa — stile */
:root {
  --bg: #f5f4f0; --surface: #ffffff; --surface2: #efede7; --ink: #1c1f1e; --text: #2a2e2c; --muted: #7a7f7b;
  --line: #e4e1da; --accent: #2f6b55; --accent-ink: #ffffff; --accent-soft: #e3eee8;
  --pos: #2f7a55; --neg: #b4453a; --warn: #a8731c; --warn-soft: #f7eedd; --neg-soft: #f6e4e1;
  --hero: #1f2b27; --hero-ink: #f3f5f2; --hero-muted: #a9b6b0;
  --radius: 18px; --shadow: 0 1px 2px rgba(20, 30, 25, .05), 0 4px 16px rgba(20, 30, 25, .04);
  --nav-h: 64px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111413; --surface: #1a1e1c; --surface2: #232826; --ink: #f1f3f1; --text: #dfe3e0; --muted: #8d9590;
    --line: #2b312e; --accent: #6fb596; --accent-ink: #0d1a14; --accent-soft: #1f3129;
    --pos: #74c29a; --neg: #e3887c; --warn: #d9a650; --warn-soft: #2e2617; --neg-soft: #33201d;
    --hero: #1e2a25; --hero-ink: #f1f5f2; --hero-muted: #93a59c; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif; font-variant-numeric: tabular-nums; overscroll-behavior-y: none; }
body.noscroll { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { color: var(--ink); margin: 0; letter-spacing: -.01em; }
h3 { font-size: 17px; margin-bottom: 8px; }
a { color: var(--accent); cursor: pointer; }
.ic { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); } .small { font-size: 13.5px; } .center { text-align: center; } .pad { padding: 14px; } .mt { margin-top: 10px; }
.pos { color: var(--pos); } .neg { color: var(--neg) !important; } .warn b, .warn { color: var(--warn); }

/* barra superiore */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); padding-top: var(--safe-t); }
.top-in { max-width: 640px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px 8px; }
.top h1 { font-size: 28px; font-weight: 700; }
.top-r { display: flex; align-items: center; gap: 6px; }
.sync { font-size: 12px; color: var(--muted); }
.sync.off { color: var(--warn); } .sync.wait { color: var(--muted); }
.iconbtn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); cursor: pointer; }
.iconbtn:active { background: var(--surface2); }

main { overflow-x: clip; max-width: 640px; margin: 0 auto; padding: 4px 16px calc(var(--nav-h) + var(--safe-b) + 90px); }

/* navigazione inferiore */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex; justify-content: space-around; background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + var(--safe-b)); }
.tabs button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted); padding: 4px 0; cursor: pointer; min-height: 48px; }
.tabs button.on { color: var(--accent); }
.tabs button.on .ic { stroke-width: 2.2; }
.fab { position: fixed; right: max(16px, calc(50% - 304px)); bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 25; width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; box-shadow: 0 6px 20px rgba(20, 60, 40, .28); cursor: pointer; }
.fab .ic { width: 28px; height: 28px; stroke-width: 2.4; }
.fab:active { transform: scale(.95); }

/* hero: quanto si può spendere */
.hero { background: var(--hero); color: var(--hero-ink); border-radius: 24px; padding: 20px 20px 16px; margin: 6px 0 12px; }
.hero .eyebrow { font-size: 14px; color: var(--hero-muted); }
.hero .big { font-size: 46px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 2px; }
.hero.over .big { color: #f0a296; }
.hero-sub { font-size: 13.5px; color: var(--hero-muted); }
.hero-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .1); }
.hero-row span { display: flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--hero-muted); }
.hero-row .ic { width: 16px; height: 16px; }
.hero-row b { font-size: 20px; font-weight: 650; }
.hero-row b.neg { color: #f0a296 !important; }

/* controlli segmentati e chip */
.seg { display: flex; background: var(--surface2); border-radius: 12px; padding: 3px; margin: 0 0 12px; }
.seg button { flex: 1; border: 0; background: none; padding: 9px 6px; border-radius: 9px; font-size: 14.5px; font-weight: 550; color: var(--muted); cursor: pointer; min-height: 40px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; flex-wrap: wrap; }
main > .chips { flex-wrap: nowrap; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 13px; font-size: 14px; white-space: nowrap; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip i { width: 10px; height: 10px; border-radius: 50%; }

/* card e griglie */
.card { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow); }
.card.list, .list { padding: 4px 0; }
.card.list .muted.pad { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.stat span { display: block; font-size: 12.5px; color: var(--muted); }
.stat b { display: block; font-size: 19px; font-weight: 650; color: var(--ink); margin: 2px 0 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat small { font-size: 12px; color: var(--muted); }
.stat.neg b { color: var(--neg); } .stat.pos b { color: var(--pos); } .stat.warn b { color: var(--warn); }
.sec { font-size: 15px; font-weight: 650; margin: 18px 2px 8px; display: flex; justify-content: space-between; align-items: baseline; }
.sec a { font-size: 14px; font-weight: 500; }
.day { font-size: 13px; color: var(--muted); font-weight: 600; margin: 14px 4px 6px; text-transform: capitalize; }

/* righe movimento */
.row { width: 100%; display: flex; align-items: center; gap: 12px; padding: 11px 16px; border: 0; background: none; text-align: left; cursor: pointer; min-height: 58px; }
.row + .row { border-top: 1px solid var(--line); }
.row:active:not(.static) { background: var(--surface2); }
.row.dim { opacity: .5; }
.dot { width: 34px; height: 34px; border-radius: 11px; flex: none; display: grid; place-items: center; color: #fff; }
.dot .ic { width: 16px; height: 16px; }
.dot.sm { width: 12px; height: 12px; border-radius: 4px; display: inline-block; margin-right: 6px; vertical-align: -1px; }
.rmain { flex: 1; min-width: 0; }
.rmain b { display: block; font-weight: 550; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rmain small { display: block; font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ramt { text-align: right; flex: none; }
.ramt b { display: block; font-weight: 600; color: var(--ink); }
.ramt.in b { color: var(--pos); } .ramt.transfer b { color: var(--muted); }
.badge { display: inline-block; font-style: normal; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; background: var(--surface2); color: var(--muted); margin-top: 2px; }
.badge.due { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--neg-soft); color: var(--neg); }
.badge.salary { background: var(--accent-soft); color: var(--accent); vertical-align: 1px; }

/* conti */
.accs { display: grid; gap: 8px; }
.acc { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 0; border-radius: 16px; padding: 12px 14px; text-align: left; box-shadow: var(--shadow); cursor: pointer; min-height: 56px; }
.acc i { width: 10px; height: 34px; border-radius: 6px; flex: none; }
.acc span { flex: 1; font-weight: 550; color: var(--ink); }
.acc small { display: block; font-weight: 400; font-size: 12.5px; color: var(--muted); }
.acc b { font-size: 17px; font-weight: 650; color: var(--ink); }
.acc.ghost { background: none; box-shadow: none; border: 1px dashed var(--line); color: var(--muted); }
.acc.ghost span { color: var(--muted); font-weight: 500; }

/* consigli e avvisi */
.advice { display: grid; gap: 10px; }
.adv { margin: 0; display: flex; gap: 10px; font-size: 14.5px; line-height: 1.4; }
.adv i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; margin-top: 7px; }
.adv.good i { background: var(--pos); } .adv.warn i { background: var(--warn); } .adv.danger i { background: var(--neg); } .adv.info i { background: var(--accent); }
.card.advice { gap: 12px; }
.alert { background: var(--neg-soft); color: var(--neg); border-radius: 14px; padding: 11px 14px; font-size: 14px; margin-bottom: 10px; font-weight: 500; }
.alert.soft { background: var(--warn-soft); color: var(--warn); margin: 6px 0; }

/* dettaglio budget */
.kv { display: grid; grid-template-columns: 1fr auto; gap: 9px 12px; margin: 10px 0; font-size: 15px; align-items: center; }
.kv span { color: var(--text); display: flex; align-items: center; gap: 6px; }
.kv span .ic { width: 18px; height: 18px; color: var(--muted); }
.kv b { text-align: right; font-weight: 650; color: var(--ink); }
.meter { height: 8px; background: var(--surface2); border-radius: 99px; overflow: hidden; margin: 8px 0; }
.meter span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meter.warn span { background: var(--warn); } .meter.over span { background: var(--neg); }
.minilist { display: grid; gap: 6px; margin-top: 10px; font-size: 14px; }
.minilist div { display: flex; align-items: center; gap: 8px; }
.minilist i { width: 9px; height: 9px; border-radius: 50%; }
.minilist span { flex: 1; } .minilist b { font-weight: 600; }
.goal { margin: 10px 0; } .goal > div { display: flex; justify-content: space-between; font-size: 14.5px; }
.goal span { color: var(--muted); }

/* movimenti */
.monthnav { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; }
.monthnav b { text-transform: capitalize; font-size: 17px; color: var(--ink); }
.search { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; font-size: 16px; }
.totals { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); margin: 2px 4px 10px; flex-wrap: wrap; }
.totals b { display: block; font-size: 16px; color: var(--ink); }
.totals b.pos { color: var(--pos); }

/* calendario */
.cal { padding: 12px; }
.wd, .cgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cd { min-width: 0; }
.wd span { text-align: center; font-size: 12px; color: var(--muted); padding-bottom: 6px; font-weight: 600; }
.cd { aspect-ratio: 1 / 1.05; border: 0; background: none; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; cursor: pointer; font-size: 15px; color: var(--ink); padding: 0; }
.cd.empty { cursor: default; }
.cd.tight { background: var(--warn-soft); }
.cd.today span { background: var(--ink); color: var(--bg); border-radius: 50%; width: 26px; height: 26px; display: grid; place-items: center; font-weight: 650; }
.cd.sel { outline: 2px solid var(--accent); outline-offset: -2px; }
.cd i { display: flex; gap: 3px; height: 6px; }
.cd i b, .legend i { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.d-sal { background: var(--pos); box-shadow: 0 0 0 2px var(--accent-soft); } .d-in { background: var(--pos); } .d-out { background: var(--neg); } .d-paid { background: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.lg { display: inline-flex; align-items: center; gap: 5px; }
.legend i.tightkey { width: 12px; height: 9px; border-radius: 3px; background: var(--warn-soft); border: 1px solid var(--warn); }
.legend i.s-in { background: var(--pos); } .legend i.s-out { background: var(--neg); } .legend i.s-fix { background: #6a7a99; } .legend i.s-var { background: #b0884f; } .legend i.s-fun { background: #9a5f7a; }

/* grafici */
.chart { width: 100%; height: auto; display: block; margin: 6px 0; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { font-size: 10px; fill: var(--muted); }
.chart .s-in { fill: var(--pos); } .chart .s-out { fill: var(--neg); opacity: .85; }
.chart .s-fix { fill: #6a7a99; } .chart .s-var { fill: #b0884f; } .chart .s-fun { fill: #9a5f7a; }
.chart .ln { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; }
.chart .area { fill: var(--accent); opacity: .1; }
.chart .zero { stroke: var(--neg); stroke-dasharray: 3 3; opacity: .6; }
.chart .thr { stroke: var(--warn); stroke-dasharray: 2 4; opacity: .7; }
.chart .neg { fill: var(--neg); }
.donut { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.donut .dl { font-size: 10px; fill: var(--muted); } .donut .dv { font-size: 15px; font-weight: 650; fill: var(--ink); }
.dlist { flex: 1; min-width: 160px; display: grid; gap: 5px; font-size: 13.5px; }
.drow { display: flex; align-items: center; gap: 7px; }
.drow i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.drow span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drow em { font-style: normal; color: var(--muted); width: 34px; text-align: right; }

/* pulsanti */
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 13px; padding: 11px 16px; font-weight: 600; font-size: 15px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px; }
.btn .ic { width: 18px; height: 18px; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--neg); }
.btn.big { width: 100%; min-height: 52px; font-size: 16.5px; }
.btn.block { width: 100%; margin: 4px 0 12px; }
.btn.small { min-height: 34px; padding: 5px 11px; font-size: 13.5px; }
.btnrow { display: flex; gap: 8px; margin-top: 8px; } .btnrow .btn { flex: 1; } .btnrow.wrap { flex-wrap: wrap; } .btnrow.wrap .btn { flex: 1 1 140px; }

/* form */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 5px; font-size: 13.5px; color: var(--muted); font-weight: 500; }
.form input:not([type=checkbox]):not([type=radio]), .form select { width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px 13px; font-size: 16px; color: var(--ink); min-height: 48px; -webkit-appearance: none; appearance: none; }
.form select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.form input:focus, .form select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.form .amount input { font-size: 30px !important; font-weight: 650; padding: 10px 13px !important; letter-spacing: -.01em; }
.form .small-amt { grid-template-columns: 1fr 140px; align-items: center; }
.form .small-amt span { color: var(--ink); font-size: 15px; }
.form .small-amt input { font-size: 18px !important; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form .check { display: flex; gap: 10px; align-items: flex-start; color: var(--text); font-size: 14.5px; }
.form .check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); flex: none; }
.form fieldset { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 12px; display: grid; gap: 10px; margin: 0; }
.form legend { font-size: 13.5px; font-weight: 650; color: var(--ink); padding: 0 4px; }
.fixrow { display: grid; grid-template-columns: 1fr 96px 62px; gap: 6px; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.colors label { display: block; }
.colors input { position: absolute; opacity: 0; }
.colors i { display: block; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; }
.colors input:checked + i { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--ink); }
.err { color: var(--neg); font-size: 14px; margin: 0; min-height: 1em; }
.warns:empty { display: none; }
.paytitle { margin: 0; } .paytitle b { display: block; font-size: 19px; color: var(--ink); } .paytitle span { color: var(--muted); font-size: 14px; }
.steps { display: flex; gap: 6px; } .steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--surface2); font-size: 0; } .steps span.on { background: var(--accent); }
.step { display: grid; gap: 12px; } .step[hidden] { display: none; } .step p { margin: 0; }

/* sheet */
.overlay { position: fixed; inset: 0; background: rgba(10, 15, 12, .38); z-index: 40; animation: fade .2s; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 640px; margin: 0 auto; background: var(--bg); border-radius: 22px 22px 0 0; max-height: calc(100dvh - var(--safe-t) - 20px); display: flex; flex-direction: column; transform: translateY(100%); transition: transform .28s cubic-bezier(.2, .9, .3, 1); }
.sheet.in { transform: none; }
.sh-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 6px 18px; }
.sh-head h2 { font-size: 19px; }
.sh-body { overflow-y: auto; padding: 6px 18px calc(24px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
@keyframes fade { from { opacity: 0; } }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 90px); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-size: 14.5px; font-weight: 550; opacity: 0; pointer-events: none; transition: .25s; z-index: 60; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* accesso */
.auth { max-width: 420px; margin: 0 auto; padding: calc(60px + var(--safe-t)) 20px 40px; }
.brand { text-align: center; margin-bottom: 24px; }
.brand .ic { width: 54px; height: 54px; color: var(--accent); }
.brand h1 { font-size: 30px; margin: 8px 0 4px; }
.empty { text-align: center; padding: 30px 20px; } .empty p { color: var(--muted); }

#print { display: none; }
@media print {
  body { background: #fff; color: #000; }
  #app > *:not(#print) { display: none !important; }
  #print { display: block; font: 12px/1.4 -apple-system, "Helvetica Neue", Arial, sans-serif; color: #000; }
  #print h1 { font-size: 20px; color: #000; } #print h2 { font-size: 14px; margin: 16px 0 6px; color: #000; }
  #print table { width: 100%; border-collapse: collapse; } #print td, #print th { border-bottom: 1px solid #ddd; padding: 4px 6px; text-align: left; }
  #print td:last-child { text-align: right; }
}
@media (min-width: 700px) { .grid2 { grid-template-columns: repeat(4, 1fr); } }
