:root {
  --bg: #F5F1EA;
  --card: #FFFFFF;
  --card-2: #FBF8F3;
  --ink: #1D1A17;
  --ink-2: #5E5750;
  --ink-3: #958C82;
  --line: #E7E0D5;
  --accent: #A12A22;
  --accent-ink: #FFFFFF;
  --accent-soft: #F6E3DF;
  --gold: #B8862F;
  --ok: #2E7D4F;
  --ok-soft: #E2F1E7;
  --warn: #B26A00;
  --warn-soft: #FBEBD2;
  --bad: #B3261E;
  --bad-soft: #F9E0DD;
  --shadow: 0 1px 2px rgba(40, 28, 16, .05), 0 6px 20px rgba(40, 28, 16, .06);
  --r: 18px;
  --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: #151312;
    --card: #211E1C;
    --card-2: #1B1917;
    --ink: #F3EEE8;
    --ink-2: #BDB4AA;
    --ink-3: #847B72;
    --line: #34302C;
    --accent: #E0574B;
    --accent-ink: #1A0B09;
    --accent-soft: #3A1E1A;
    --gold: #D9A84E;
    --ok: #5CC28A;
    --ok-soft: #1D3326;
    --warn: #F0A43A;
    --warn-soft: #3A2C17;
    --bad: #F2766B;
    --bad-soft: #3D1F1C;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- layout ---------- */
.shell { max-width: 560px; margin: 0 auto; padding: calc(var(--safe-t) + 14px) 16px calc(var(--nav-h) + var(--safe-b) + 28px); }
.topbar { display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 16px; }
.topbar h1 { font-size: 28px; line-height: 1.1; margin: 0; letter-spacing: -.02em; font-weight: 750; }
.topbar .sub { font-size: 14px; color: var(--ink-2); margin-top: 3px; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 15px; }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 26px 4px 10px; }
.section-title h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 0; font-weight: 650; }
.section-title .link { font-size: 14px; color: var(--accent); font-weight: 600; }

.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.pad { padding: 16px; }

/* ---------- hero ---------- */
.hero { padding: 20px 20px 18px; position: relative; overflow: hidden; }
.hero .label { font-size: 14px; color: var(--ink-2); font-weight: 550; }
.hero .big { font-size: 64px; font-weight: 760; line-height: 1; margin: 6px 0 4px; letter-spacing: -.035em; }
.hero .big small { font-size: 20px; font-weight: 600; color: var(--ink-3); margin-left: 6px; letter-spacing: 0; }
.hero .meta { font-size: 14px; color: var(--ink-2); }

.alert { display: flex; gap: 12px; align-items: center; margin-top: 16px; padding: 12px 14px; border-radius: 14px; font-size: 14px; }
.alert .ic { flex: none; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; }
.alert b { font-weight: 700; }
.alert.ok { background: var(--ok-soft); } .alert.ok .ic { background: var(--ok); color: #fff; }
.alert.warn { background: var(--warn-soft); } .alert.warn .ic { background: var(--warn); color: #fff; }
.alert.bad { background: var(--bad-soft); } .alert.bad .ic { background: var(--bad); color: #fff; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.action { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 14px 16px; border-radius: var(--r); background: var(--card); box-shadow: var(--shadow); text-align: left; transition: transform .1s; }
.action:active { transform: scale(.98); }
.action .ic { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; }
.action .t { font-weight: 700; font-size: 15px; }
.action .s { font-size: 12.5px; color: var(--ink-2); margin-top: -6px; }
.action.primary .ic { background: var(--accent); color: var(--accent-ink); }
.action.secondary .ic { background: var(--ink); color: var(--bg); }

/* ---------- packets ---------- */
.list { display: flex; flex-direction: column; gap: 10px; }
.packet { display: flex; gap: 14px; align-items: center; padding: 14px; width: 100%; text-align: left; }
.datebox { flex: none; width: 52px; height: 56px; border-radius: 13px; background: var(--card-2); border: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.datebox .d { font-size: 22px; font-weight: 750; line-height: 1; }
.datebox .m { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin-top: 3px; font-weight: 600; }
.packet .body { flex: 1; min-width: 0; }
.packet .title { font-weight: 650; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.packet .exp { font-size: 13px; color: var(--ink-2); margin-top: 1px; }
.bar { height: 6px; border-radius: 6px; background: var(--line); margin-top: 9px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.bad > i { background: var(--bad); }
.bar.fut > i { background: var(--gold); }
.packet .rem { flex: none; text-align: right; }
.packet .rem .v { font-size: 20px; font-weight: 750; }
.packet .rem .of { font-size: 12px; color: var(--ink-3); }
.packet.dim { opacity: .62; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 999px; letter-spacing: .01em; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--card-2); color: var(--ink-2); border: 1px solid var(--line); }

.empty { text-align: center; padding: 34px 22px; }
.empty .ic { width: 64px; height: 64px; border-radius: 20px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h3 { margin: 0 0 6px; font-size: 18px; }
.empty p { margin: 0 0 16px; color: var(--ink-2); font-size: 14.5px; }

.toggle-row { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-weight: 600; font-size: 15px; color: var(--ink-2); }
.chev { transition: transform .2s; }
.open .chev { transform: rotate(180deg); }

/* ---------- movimenti ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 8px 14px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-size: 14px; font-weight: 600; color: var(--ink-2); }
.chip.on { background: var(--ink); color: var(--bg); }

.group-h { display: flex; justify-content: space-between; margin: 20px 6px 8px; font-size: 13px; font-weight: 650; color: var(--ink-2); text-transform: capitalize; }
.mov { display: flex; gap: 12px; padding: 13px 14px; width: 100%; text-align: left; align-items: flex-start; }
.mov + .mov { border-top: 1px solid var(--line); }
.mov .ic { flex: none; width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; margin-top: 1px; }
.mov.in .ic { background: var(--ok-soft); color: var(--ok); }
.mov.out .ic { background: var(--accent-soft); color: var(--accent); }
.mov .body { flex: 1; min-width: 0; }
.mov .t { font-weight: 650; font-size: 15px; }
.mov .d { font-size: 13px; color: var(--ink-2); margin-top: 1px; }
.mov .x { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.mov .v { flex: none; font-weight: 750; font-size: 16px; }
.mov.in .v { color: var(--ok); }
.mov.out .v { color: var(--accent); }

/* ---------- archivio ---------- */
.yearsel { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 4px 0 14px; }
.yearsel .y { font-size: 22px; font-weight: 750; min-width: 70px; text-align: center; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--card); box-shadow: var(--shadow); color: var(--ink); }
.iconbtn:disabled { opacity: .35; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { padding: 14px 16px; }
.tile .k { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.tile .v { font-size: 28px; font-weight: 760; margin-top: 4px; letter-spacing: -.02em; }
.tile .v.accent { color: var(--accent); }
.tile .h { font-size: 12px; color: var(--ink-3); margin-top: 1px; }

.chart { padding: 18px 12px 12px; }
.chart .cols { display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px; align-items: end; height: 150px; }
.chart .col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.chart .col .n { font-size: 11.5px; font-weight: 700; color: var(--ink-2); }
.chart .col .b { width: 100%; max-width: 26px; border-radius: 6px 6px 3px 3px; background: var(--accent); min-height: 3px; transition: height .3s; }
.chart .col .b.zero { background: var(--line); }
.chart .col.cur .b { background: var(--gold); }
.chart .labels { display: grid; grid-template-columns: repeat(12, 1fr); gap: 5px; margin-top: 6px; }
.chart .labels span { text-align: center; font-size: 11px; color: var(--ink-3); text-transform: uppercase; font-weight: 600; }

.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: right; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 650; padding: 12px 6px 8px; }
.table th:first-child, .table td:first-child { text-align: left; padding-left: 14px; }
.table th:last-child, .table td:last-child { padding-right: 14px; }
.table td { text-align: right; padding: 11px 6px; border-top: 1px solid var(--line); }
.table td:first-child { text-transform: capitalize; font-weight: 600; }
.table tr.zero td { color: var(--ink-3); }
.table tr.total td { font-weight: 750; border-top: 2px solid var(--line); }
.table tr.clk { cursor: pointer; }
.table tr.detail td { text-align: left; padding: 4px 16px 12px; border-top: 0; font-size: 13px; color: var(--ink-2); text-transform: none; font-weight: 400; }

/* ---------- forms ---------- */
.field { margin-bottom: 16px; }
.field > label, .lbl { display: block; font-size: 13px; font-weight: 650; color: var(--ink-2); margin: 0 2px 7px; }
.input { width: 100%; height: 50px; padding: 0 14px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--card-2); outline: none; font-size: 16px; -webkit-appearance: none; appearance: none; }
.input:focus { border-color: var(--accent); background: var(--card); }
textarea.input { height: 76px; padding: 12px 14px; resize: none; }
input[type=date].input, input[type=time].input { display: flex; align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hint { font-size: 12.5px; color: var(--ink-3); margin: 6px 2px 0; }
.hint.warn { color: var(--warn); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 52px; padding: 0 22px; border-radius: 15px; font-weight: 700; font-size: 16px; transition: transform .1s, opacity .2s; }
.btn:active { transform: scale(.98); }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--ink); color: var(--bg); }
.btn.ghost { background: var(--card-2); color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn.sm { height: 40px; padding: 0 14px; font-size: 14px; border-radius: 12px; }
.btnrow { display: flex; gap: 10px; }
.btnrow > * { flex: 1; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card-2); border: 1.5px solid var(--line); border-radius: 14px; padding: 3px; gap: 3px; }
.seg button { height: 40px; border-radius: 11px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
@media (prefers-color-scheme: dark) { .seg button.on { background: #35302C; } }

.stepper { display: flex; align-items: center; justify-content: space-between; background: var(--card-2); border: 1.5px solid var(--line); border-radius: 16px; padding: 6px; }
.stepper button { width: 52px; height: 52px; border-radius: 12px; background: var(--card); box-shadow: var(--shadow); font-size: 26px; font-weight: 500; display: grid; place-items: center; }
.stepper button:disabled { opacity: .35; }
.stepper .val { font-size: 34px; font-weight: 760; letter-spacing: -.02em; }
.quick { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.quick button { padding: 7px 12px; border-radius: 999px; font-size: 13.5px; font-weight: 650; background: var(--card-2); border: 1.5px solid var(--line); color: var(--ink-2); }
.quick button.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.preview { border-radius: 16px; padding: 14px 16px; background: var(--card-2); border: 1.5px dashed var(--line); margin-bottom: 16px; }
.preview .main { font-size: 15.5px; font-weight: 650; }
.preview .main b { color: var(--accent); }
.preview .sub { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.preview.err { border-color: var(--bad); background: var(--bad-soft); }
.preview.err .main { color: var(--bad); }

.timeline { position: relative; height: 34px; border-radius: 10px; background: var(--line); margin: 12px 0 4px; overflow: hidden; }
.timeline .perm { position: absolute; top: 0; bottom: 0; background: var(--accent); border-radius: 8px; display: grid; place-items: center; color: var(--accent-ink); font-size: 12px; font-weight: 700; transition: left .2s, width .2s; }
.timeline-l { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-3); font-weight: 600; }

/* ---------- sheet ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(15, 10, 6, .42); z-index: 50; opacity: 0; transition: opacity .2s; }
.sheet-bg.show { opacity: 1; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--card); border-radius: 24px 24px 0 0; padding: 8px 18px calc(var(--safe-b) + 20px); transform: translateY(100%); transition: transform .28s cubic-bezier(.2,.8,.2,1); max-width: 560px; margin: 0 auto; }
.sheet.show { transform: translateY(0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-h h3 { margin: 0; font-size: 21px; letter-spacing: -.01em; }
.close { width: 34px; height: 34px; border-radius: 50%; background: var(--card-2); display: grid; place-items: center; color: var(--ink-2); }

.kv { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line); font-size: 15px; gap: 12px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--ink-2); }
.kv .v { font-weight: 650; text-align: right; }

/* ---------- nav ---------- */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: saturate(1.6) blur(18px); -webkit-backdrop-filter: saturate(1.6) blur(18px); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.nav-in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--nav-h); }
.nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 650; color: var(--ink-3); }
.nav button.on { color: var(--accent); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; max-width: 420px; margin: 0 auto; padding: calc(var(--safe-t) + 24px) 22px calc(var(--safe-b) + 24px); }
.brand { display: flex; flex-direction: column; align-items: center; margin-bottom: 26px; text-align: center; }
.brand .logo { width: 76px; height: 76px; border-radius: 22px; margin-bottom: 14px; box-shadow: var(--shadow); }
.brand h1 { margin: 0; font-size: 30px; letter-spacing: -.02em; }
.brand p { margin: 6px 0 0; color: var(--ink-2); font-size: 15px; }
.err-msg { background: var(--bad-soft); color: var(--bad); padding: 11px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 14px; font-weight: 550; }

/* ---------- settings ---------- */
.menu { overflow: hidden; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 14px 16px; text-align: left; font-size: 15.5px; font-weight: 550; }
.menu-item + .menu-item { border-top: 1px solid var(--line); }
.menu-item .ic { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--card-2); color: var(--ink-2); flex: none; }
.menu-item .sp { flex: 1; }
.menu-item.red { color: var(--bad); }
.menu-item.red .ic { background: var(--bad-soft); color: var(--bad); }
.rules p { margin: 0 0 8px; font-size: 14.5px; color: var(--ink-2); }
.rules p:last-child { margin: 0; }
.rules b { color: var(--ink); }
.user-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.user-row + .user-row { border-top: 1px solid var(--line); }
.user-row .body { flex: 1; min-width: 0; }
.user-row .n { font-weight: 650; }
.user-row .e { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); transform: translate(-50%, 20px); background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: 14px; font-size: 14.5px; font-weight: 600; opacity: 0; pointer-events: none; transition: all .25s; z-index: 60; max-width: calc(100% - 40px); text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--bad); color: #fff; }

.offline { background: var(--warn-soft); color: var(--warn); font-size: 13px; font-weight: 600; text-align: center; padding: 8px; border-radius: 12px; margin-bottom: 12px; }

.beta { display: inline-block; font-size: 10.5px; font-weight: 800; letter-spacing: .08em; padding: 2px 7px; border-radius: 6px; background: var(--gold); color: #fff; vertical-align: middle; position: relative; top: -1px; }
.brand h1 .beta { font-size: 12px; top: -4px; }
.feat { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; color: var(--ink-2); margin-bottom: 12px; }
.feat svg { flex: none; color: var(--accent); margin-top: 1px; }
.feat b { color: var(--ink); }
.check { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; color: var(--ink-2); margin: 4px 2px 18px; cursor: pointer; }
.check input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.linkbtn { color: var(--accent); font-weight: 650; text-decoration: underline; text-underline-offset: 2px; }
.legal h4 { margin: 18px 0 6px; font-size: 15px; }
.legal h4:first-child { margin-top: 0; }
.legal p { margin: 0 0 9px; font-size: 14.5px; color: var(--ink-2); line-height: 1.5; }
.legal b { color: var(--ink); }
.legal a { color: var(--accent); }
.backup-tip { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 13px 14px; margin-top: 12px; font-size: 14.5px; }
.backup-tip > span:nth-child(2) { flex: 1; }
.backup-tip .ic { width: 34px; height: 34px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; flex: none; }
.avatar svg { display: block; }

.brand-title { text-transform: uppercase; font-size: 25px !important; letter-spacing: .04em !important; line-height: 1.15; }
.brand-beta { margin-top: 8px; }
.notice { display: flex; gap: 12px; align-items: flex-start; font-size: 14.5px; line-height: 1.45; color: var(--ink-2); background: var(--card-2); border: 1.5px solid var(--line); border-radius: 14px; padding: 13px 14px; margin-bottom: 16px; }
.notice svg { flex: none; color: var(--gold); margin-top: 1px; }
.notice b { color: var(--ink); }
