:root {
  --bg: #F6F3EE; --card: #FFFFFF; --ink: #1C1B19; --ink2: #4A463F; --muted: #6B665E;
  --line: #ECE6DC; --line2: #E0D9CD; --track: #E9E3D9; --chip: #EDE8DF;
  --blue: #2E6A9E; --blue-d: #22507A; --navy: #1D3550; --sky: #8EC3EC; --sky-t: #C9D8E8; --blue-soft: #EAF1F8; --blue-line: #CFDEEC;
  --warn: #B4532A; --danger: #A8321A; --peach: #FBEFE6; --peach-line: #F0D5C2; --brown: #7A3517;
  --serif: 'Fraunces', Georgia, serif; --sans: 'Manrope', system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; }
a { color: var(--blue); } a:hover { color: var(--blue-d); }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.loading { padding: 120px 24px; text-align: center; color: var(--muted); }
.screen { max-width: 520px; margin: 0 auto; padding: calc(20px + var(--safe-t)) 16px calc(120px + var(--safe-b)); }
.screen.no-nav { padding-bottom: calc(40px + var(--safe-b)); }

/* intestazioni */
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 16px 8px 0; }
.top .kicker { font-size: 13px; color: var(--muted); }
.title { font-family: var(--serif); font-weight: 600; font-size: 28px; margin: 0; line-height: 1.15; }
.hello { font-family: var(--serif); font-weight: 600; font-size: 26px; }
.bar-back { display: flex; align-items: center; gap: 4px; padding: 8px 0 0; }
.bar-back .t { font-size: 16px; font-weight: 700; flex-grow: 1; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line2); background: var(--card); display: inline-flex; align-items: center; justify-content: center; color: var(--ink); text-decoration: none; cursor: pointer; flex-shrink: 0; }
.icon-btn.plain { border: none; background: transparent; }
.sub { font-size: 14px; color: var(--muted); line-height: 1.5; margin: 6px 0 0; }
.pad { padding: 0 8px; }

/* card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; margin-top: 12px; }
.card.dark { background: var(--navy); color: var(--bg); border: none; }
.card.dark .muted { color: var(--sky-t); }
.card.peach { background: var(--peach); border-color: var(--peach-line); }
.card.soft { background: var(--blue-soft); border-color: var(--blue-line); }
.card.flush { padding: 0; overflow: hidden; }
.muted { color: var(--muted); }
.small { font-size: 12px; } .s13 { font-size: 13px; } .s14 { font-size: 14px; }
.big { font-family: var(--serif); font-weight: 600; font-size: 40px; line-height: 1; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.grow { flex-grow: 1; min-width: 0; }
.h2 { font-size: 17px; font-weight: 700; margin: 0; }
.section { margin-top: 22px; padding: 0 8px; }
.label-up { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.link-row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 16px; border-top: 1px solid #EFEAE2; text-decoration: none; color: var(--ink); background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; cursor: pointer; }
.link-row:first-child { border-top: 0; }
.link-row .v { font-size: 13px; color: var(--muted); }
.link-row.danger { color: var(--danger); }
.banner { display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: 16px; margin-top: 12px; text-decoration: none; color: var(--ink); font-size: 14px; }
.banner.peach { background: var(--peach); border: 1px solid var(--peach-line); }
.banner.soft { background: var(--blue-soft); border: 1px solid var(--blue-line); }
.banner.danger { background: #FBE9E4; border: 1px solid #F0C9B6; }

/* barre */
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--blue); }
.bar.on-dark { background: rgba(255,255,255,.15); } .bar.on-dark > i { background: var(--sky); }
.bar > i.warn { background: var(--warn); } .bar > i.over { background: var(--danger); } .bar > i.fixed { background: var(--muted); }
.budget-row { display: flex; flex-direction: column; gap: 6px; text-decoration: none; color: var(--ink); }
.budget-row .hd { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.budget-row .hd b { font-weight: 600; }

/* cockpit */
.rings { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.ring { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.ring .r { position: relative; width: 72px; height: 72px; }
.ring svg { transform: rotate(-90deg); }
.ring .pct { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; }
.ring .nm { font-size: 13px; font-weight: 700; }
.ring .nt { font-size: 11px; font-weight: 600; color: var(--muted); }
.ring .nt.over { color: var(--danger); } .ring .nt.ok { color: var(--blue); }

/* pulsanti */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 54px; padding: 0 18px; border-radius: 16px; border: none; background: var(--blue); color: #fff; font-size: 16px; font-weight: 700; text-decoration: none; cursor: pointer; width: 100%; }
.btn:hover { background: var(--blue-d); color: #fff; }
.btn.secondary { background: var(--card); border: 1px solid #D5CCBE; color: var(--ink); }
.btn.secondary:hover { background: #fbfaf7; }
.btn.small { min-height: 44px; font-size: 14px; border-radius: 12px; width: auto; }
.btn.light { background: var(--sky); color: #102338; }
.btn.ghost-dark { background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff; }
.btn.danger { background: var(--danger); }
.btn[disabled] { opacity: .55; cursor: default; }
.text-btn { background: none; border: none; color: var(--blue); font-weight: 700; font-size: 14px; min-height: 44px; cursor: pointer; padding: 0 4px; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.text-btn.danger { color: var(--danger); }
.sticky-cta { position: sticky; bottom: calc(12px + var(--safe-b)); margin-top: 24px; }

/* form */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .lbl { font-size: 13px; font-weight: 700; color: var(--ink2); }
.field .hint { font-size: 12px; color: var(--muted); line-height: 1.5; }
.input, select.input, textarea.input { min-height: 48px; border-radius: 12px; border: 1px solid var(--line2); background: var(--card); padding: 0 14px; font-size: 16px; font-weight: 500; width: 100%; }
textarea.input { padding: 12px 14px; min-height: 80px; }
.input:focus, .btn:focus-visible, .chip-btn:focus-visible, .seg button:focus-visible, .link-row:focus-visible, a:focus-visible { outline: 3px solid rgba(46,106,158,.35); outline-offset: 2px; }
.amount-input { width: 100%; border: none; background: transparent; text-align: center; font-family: var(--serif); font-size: 52px; font-weight: 600; padding: 0; }
.amount-input:focus { outline: none; }
.seg { padding: 4px; border-radius: 14px; background: #ECE6DC; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; }
.seg button { min-height: 40px; border: none; border-radius: 10px; background: transparent; font-weight: 600; font-size: 14px; color: var(--ink2); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--ink); font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line2); background: var(--card); font-weight: 600; font-size: 13px; cursor: pointer; }
.chip-btn.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.chip-btn.pill { border-radius: 22px; }
.tag { display: inline-block; padding: 3px 9px; border-radius: 9px; font-size: 11px; font-weight: 700; background: var(--chip); color: var(--ink2); }
.tag.dark { background: var(--navy); color: #fff; }
.tag.warn { background: #FBE9E4; color: var(--danger); }
.check { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; color: var(--ink2); line-height: 1.5; min-height: 44px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--blue); flex-shrink: 0; }
.err { color: var(--danger); font-size: 13px; font-weight: 600; min-height: 0; }
.sr { position: absolute; left: -9999px; }

/* liste movimenti */
.tx { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid #EFEAE2; text-decoration: none; color: var(--ink); }
.tx .av { width: 40px; height: 40px; border-radius: 12px; background: var(--chip); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: var(--ink2); flex-shrink: 0; }
.tx .av.inc { background: var(--blue-soft); color: var(--blue); }
.tx .nm { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .mt { font-size: 12px; color: var(--muted); }
.tx .am { font-size: 15px; font-weight: 600; white-space: nowrap; }
.tx .am.inc { color: var(--blue); }
.day { padding: 16px 0 4px; }

/* navigazione */
.nav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid #E6E0D6; display: flex; justify-content: space-around; align-items: flex-start; padding: 10px 0 calc(10px + var(--safe-b)); z-index: 10; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; min-height: 44px; text-decoration: none; font-size: 11px; font-weight: 600; color: var(--muted); }
.nav a.on { color: var(--blue); }
.nav a.fab { width: 56px; height: 56px; min-width: 0; margin-top: -26px; border-radius: 28px; background: var(--blue); color: #fff; justify-content: center; box-shadow: 0 6px 16px rgba(46,106,158,.35); }

/* grafici */
.chart { height: 150px; display: flex; align-items: flex-end; gap: 12px; position: relative; border-bottom: 1px solid var(--line2); margin-top: 12px; }
.chart .col { flex: 1; border-radius: 6px 6px 0 0; background: #A8C3DC; min-height: 2px; }
.chart .col.over { background: var(--warn); } .chart .col.cur { background: var(--blue); }
.chart .line { position: absolute; left: 0; right: 0; border-top: 1px dashed #9A948A; }
.chart-x { display: flex; gap: 12px; font-size: 11px; color: var(--muted); margin-top: 6px; }
.chart-x span { flex: 1; text-align: center; }
.legend-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.legend-row .sw { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }

/* checklist */
.todo { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 16px; border-top: 1px solid #EFEAE2; text-decoration: none; color: var(--ink); }
.todo .c { width: 28px; height: 28px; border-radius: 14px; border: 2px solid #C9C0B2; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; color: var(--ink2); flex-shrink: 0; }
.todo.done .c { background: var(--blue); border-color: var(--blue); color: #fff; }
.todo.done .tt { text-decoration: line-through; color: var(--muted); }

/* guida */
.step { display: flex; gap: 14px; }
.step .n { width: 32px; height: 32px; border-radius: 16px; background: var(--blue); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--bg); border-radius: 10px; padding: 10px 12px; word-break: break-all; }
.card.dark .code { background: rgba(0,0,0,.25); color: #fff; }
.path { padding: 10px 12px; border-radius: 10px; background: var(--blue-soft); font-size: 13px; font-weight: 600; color: var(--navy); line-height: 1.6; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; }
.kv b { font-family: ui-monospace, Menlo, monospace; font-weight: 600; }
ol.plain { margin: 0; padding-left: 20px; font-size: 14px; color: var(--ink2); line-height: 1.6; }
ol.plain li + li { margin-top: 4px; }

/* hero benvenuto */
.hero { background: var(--navy); color: var(--bg); padding: calc(64px + var(--safe-t)) 24px 28px; border-radius: 0 0 32px 32px; }
.hero .title { font-size: 34px; }
.hero ul { list-style: none; padding: 0; margin: 16px 0 0; display: flex; flex-direction: column; gap: 10px; color: #DDE7F2; font-size: 15px; }
.hero li { display: flex; gap: 10px; align-items: center; }
.logo { width: 56px; height: 56px; border-radius: 16px; background: var(--navy); display: flex; align-items: center; justify-content: center; }
.hero .logo { background: rgba(142,195,236,.18); }

#toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 30; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

.modal-bg { position: fixed; inset: 0; background: rgba(28,27,25,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 40; }
.modal { background: var(--bg); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 20px 16px calc(20px + var(--safe-b)); max-height: 90vh; overflow: auto; }
@media (min-width: 600px) { .modal-bg { align-items: center; } .modal { border-radius: 22px; } }
