:root {
  color-scheme: light;
  --bg: #f9f9f7;
  --surface: #ffffff;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6b6a66;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #1c5cab;
  --on-accent: #ffffff;
  /* Entrate verdi, uscite rosse: riempimenti (barre, pulsanti) e testo hanno toni separati per il contrasto. */
  --inc: #008300;
  --inc-text: #006300;
  --inc-tint: #e4f3e4;
  --exp: #e34948;
  --exp-strong: #d03b3b;
  --exp-text: #c22f2f;
  --exp-tint: #fde8e8;
  --warn: #fab219;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 4px 16px rgba(11, 11, 11, .04);
  /* Serie per categoria (tavolozza categorica validata per daltonismo, ordine fisso) + grigio per «Altre». */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s-other: #a9a8a0;
  --tab-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
/* Tema scuro: data-theme è impostato da index.html e js/theme.js (Automatico segue il dispositivo). */
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #a09f98;
  --line: #2c2c2a;
  --axis: #383835;
  --accent: #6da7ec;
  --on-accent: #0b0b0b;
  --inc: #0ca30c;
  --inc-text: #3ecf5a;
  --inc-tint: #12301a;
  --exp: #e66767;
  --exp-strong: #d03b3b;
  --exp-text: #f08080;
  --exp-tint: #3a1b1b;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s-other: #5d5c57;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }

#topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#topbar h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
#topbar .icon-btn { margin-left: -10px; }
#topbar .sync-btn { position: relative; margin: 0 -10px 0 auto; color: var(--accent); }
.sync-btn.spin svg { animation: spin .9s linear infinite; }
.sync-btn.err::after { content: ''; position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--exp); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .sync-btn.spin svg { animation: pulse 1.2s ease-in-out infinite; } }

#main { padding: 4px 16px calc(var(--tab-h) + var(--safe-b) + 24px); }
.view { display: grid; gap: 16px; }
.view > section { display: grid; gap: 8px; min-width: 0; }

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: flex; justify-content: center;
  padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
#tabbar a {
  flex: 1; max-width: 112px; height: var(--tab-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 500; min-width: 0;
}
#tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
#tabbar a[aria-current] { color: var(--accent); font-weight: 700; }
#tabbar .brand { display: none; }

/* ---------- Elementi comuni ---------- */

.card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.pad, .card.empty, section.card { padding: 16px; }
.card.empty { display: grid; gap: 12px; justify-items: center; text-align: center; padding: 28px 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.num, .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt { font-weight: 600; }
.amt.income { color: var(--inc-text); }
.amt.expense { color: var(--exp-text); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.dot.income { background: var(--inc); }
.dot.expense { background: var(--exp); }

.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 4px; }
.sec-head h2, h2.group { font-size: 15px; font-weight: 700; }
.sec-head a { font-size: 14px; font-weight: 600; }
h2.group { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; padding: 4px 4px 0; margin-bottom: -8px; }

.icon-btn {
  width: 44px; height: 44px; display: inline-grid; place-items: center; flex: none;
  background: none; border: 0; border-radius: 50%; font-size: 26px; line-height: 1; color: var(--text);
}
.icon-btn:active { background: var(--line); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font-weight: 600;
}
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--on-accent); }
.btn.danger { background: var(--exp-strong); border-color: transparent; color: #fff; }
.btn.danger.ghost { background: none; color: var(--exp-text); border-color: var(--line); }
.btn:active { opacity: .8; }

.list > * + * { border-top: 1px solid var(--line); }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; min-height: 54px; padding: 8px 16px;
  background: none; border: 0; text-align: left; color: var(--text);
}
.row small { display: block; color: var(--muted); font-size: 13px; font-weight: 400; margin-top: 2px; }
.row select { border: 0; background: none; color: var(--accent); font-weight: 600; text-align: right; max-width: 55%; padding: 8px 0; }
.chev { color: var(--muted); font-size: 22px; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.meter { display: block; height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; }
.meter.thin { height: 6px; }
.meter > span { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.meter > .warn { background: var(--warn); }
.meter > .over, .meter > .expense { background: var(--exp); }
.meter > .income { background: var(--inc); }

.seg { display: flex; padding: 3px; gap: 3px; border-radius: 12px; background: var(--line); }
.seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--text-2); }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button.income[aria-pressed=true] { color: var(--inc-text); }
.seg button.expense[aria-pressed=true] { color: var(--exp-text); }

.pnav { display: flex; align-items: center; justify-content: space-between; }
.pnav-label { font-weight: 700; font-size: 17px; text-align: center; }

/* ---------- Home ---------- */

.summary { padding: 18px 16px 16px; display: grid; gap: 4px; }
.hero { font-size: 38px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.hero.neg { color: var(--exp-text); }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.totals > div, .stats > div { display: grid; gap: 2px; min-width: 0; }
.lbl { color: var(--muted); font-size: 13px; }
.totals b { font-size: 17px; }

.big-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.big {
  display: grid; justify-items: center; gap: 2px; min-height: 112px; padding: 14px 8px;
  border: 0; border-radius: 20px; color: #fff; font-size: 18px; font-weight: 700;
  box-shadow: var(--shadow);
}
.big .sign { font-size: 44px; line-height: 1; font-weight: 400; }
.big.income { background: #008300; }
.big.expense { background: #d03b3b; }
.big:active { transform: scale(.97); }

.budget { display: grid; gap: 6px; width: 100%; padding: 12px 16px; background: none; border: 0; text-align: left; }
.budget-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.budget-head .num { font-weight: 400; color: var(--text-2); font-size: 14px; }
.budget-foot { font-size: 13px; color: var(--muted); }
.budget-foot.over { color: var(--exp-text); font-weight: 600; }

/* ---------- Movimenti ---------- */

.ci {
  width: 40px; height: 40px; flex: none; display: inline-grid; place-items: center;
  border-radius: 12px; font-size: 20px; line-height: 1;
}
.ci.income { background: var(--inc-tint); }
.ci.expense { background: var(--exp-tint); }

.tx-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 16px; background: none; border: 0; text-align: left; }
.tx-row:active, .row:active, .budget:active { background: color-mix(in srgb, var(--line) 50%, transparent); }
.tx-main { flex: 1; min-width: 0; display: grid; }
.tx-cat { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx-note { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.month { display: grid; gap: 8px; }
.month + .month { margin-top: 12px; }
.month-head {
  display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 2px 12px;
  padding: 14px 16px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow);
}
.month-head h2 { font-size: 19px; }
.month-bal { font-weight: 700; font-size: 17px; }
.month-head .totals { grid-column: 1 / -1; margin-top: 6px; }
.month-head .totals b { font-size: 15px; }
.day-head { display: flex; justify-content: space-between; gap: 12px; padding: 6px 4px 0; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---------- Categorie ---------- */

.cat-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.cat-body { flex: 1; min-width: 0; display: grid; gap: 6px; }
.cat-line { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.cat-line > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-row.empty .cat-line { font-weight: 400; color: var(--text-2); }
.pct { width: 38px; text-align: right; color: var(--muted); font-size: 13px; }
section.card > .list { margin: 0 -16px; }

.sortable li { display: flex; align-items: center; background: var(--surface); }
.sortable li:first-child { border-radius: 16px 16px 0 0; }
.sortable li:last-child { border-radius: 0 0 16px 16px; }
.sortable .row { justify-content: flex-start; flex: 1; min-width: 0; font-weight: 600; }
.drag {
  width: 56px; align-self: stretch; display: grid; place-items: center; flex: none;
  font-size: 24px; color: var(--muted); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.sortable li.dragging { position: relative; z-index: 2; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); border-radius: 12px; transform: scale(1.02); }
.rule { justify-content: flex-start; }
.rule .tx-cat, .rule .tx-note { white-space: normal; }

/* ---------- Grafici ---------- */

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats b { font-size: 15px; }
.chart-title { font-size: 15px; font-weight: 700; }
.legend { display: flex; gap: 16px; margin: 6px 0 4px; font-size: 13px; color: var(--text-2); }
.chart { display: block; width: 100%; height: auto; margin-top: 4px; touch-action: manipulation; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.chart .tick.on { fill: var(--text); font-weight: 700; }
.chart .bar.income { fill: var(--inc); }
.chart .bar.expense { fill: var(--exp); }
.chart .sel { fill: var(--line); opacity: .7; }
.chart .stk.income { fill: var(--inc); }
.chart .stk.expense { fill: var(--exp); }
.s1 { --c: var(--s1); } .s2 { --c: var(--s2); } .s3 { --c: var(--s3); } .s4 { --c: var(--s4); } .s5 { --c: var(--s5); } .s-other { --c: var(--s-other); }
.chart .stk[class*=" s"] { fill: var(--c); }
.dot[class*=" s"] { background: var(--c); }
.legend.wrap { flex-wrap: wrap; gap: 6px 14px; }
.detail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.detail-list li { display: flex; justify-content: space-between; gap: 12px; }
.table-scroll { overflow-x: auto; }
.table-scroll table { min-width: max-content; }
.rank-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.rank { list-style: none; margin: 0 -8px; padding: 0; }
.rank button { display: grid; gap: 6px; width: 100%; padding: 8px; border: 0; border-radius: 10px; background: none; text-align: left; color: var(--text); }
.rank button:active { background: var(--bg); }
.rank-line { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.rank-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.rank-line small { color: var(--muted); font-size: 12px; margin-left: 4px; }
.rank-track { display: block; height: 10px; }
.rank-bar { display: block; height: 100%; min-width: 2px; border-radius: 0 4px 4px 0; }
.rank-bar.expense { background: var(--exp); }
.rank-bar.income { background: var(--inc); }
.rank.has-sel button[aria-pressed=false] .rank-bar { background: var(--s-other); }
.rank.has-sel button[aria-pressed=false] { color: var(--text-2); }
.rank button[aria-pressed=true] { background: var(--bg); }
.chart .hit { fill: transparent; cursor: pointer; }
.detail { display: grid; gap: 10px; margin-top: 8px; padding: 12px; border-radius: 12px; background: var(--bg); }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
h3.sub { font-size: 13px; color: var(--text-2); margin: 12px 0 0; }
.table-view { margin-top: 12px; font-size: 14px; }
.table-view summary { color: var(--accent); font-weight: 600; padding: 8px 0; cursor: pointer; }
.table-view table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: right; font-weight: 400; }
.table-view th:first-child { text-align: left; }
.table-view thead th { color: var(--muted); font-size: 12px; border-top: 0; }

/* ---------- Pannelli e moduli ---------- */

.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); animation: fade .15s; }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  padding: 8px 16px calc(16px + var(--safe-b));
  background: var(--surface); border-radius: 20px 20px 0 0; animation: rise .2s ease-out;
}
.sheet.confirm { padding-top: 24px; display: grid; gap: 12px; }
.confirm-msg { font-size: 17px; font-weight: 600; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { animation: none; } }

.sheet form { display: grid; gap: 14px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: -8px; z-index: 1; background: var(--surface); margin: 0 -4px; padding: 4px; }
.sheet-head h2 { font-size: 19px; }
form[data-type=income] { --type: var(--inc-text); --type-fill: #008300; }
form[data-type=expense] { --type: var(--exp-text); --type-fill: #d03b3b; }
form[data-type] .sheet-head h2 { color: var(--type); }
.btn.typed { background: var(--type-fill, var(--accent)); color: #fff; }

.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field small { font-weight: 400; color: var(--muted); }
.field input, .field select {
  width: 100%; min-height: 48px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); font-size: 16px;
  -webkit-appearance: none; appearance: none;
}
.field.amount input { min-height: 64px; font-size: 32px; font-weight: 700; text-align: right; color: var(--type, var(--text)); font-variant-numeric: tabular-nums; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; font-weight: 600; }
.recurring-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.cat-pick {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--text); text-align: left;
}
.cat-pick-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-pick-change { color: var(--accent); font-size: 14px; font-weight: 600; flex: none; }
.picker[data-type=income] { --type: var(--inc-text); }
.picker[data-type=expense] { --type: var(--exp-text); }
.picker .chips { margin-top: 8px; }
.chips { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.chip {
  display: grid; justify-items: center; gap: 4px; padding: 8px 4px; min-width: 0;
  border: 2px solid transparent; border-radius: 14px; background: var(--bg); font-size: 12px; font-weight: 500;
}
.chip span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip[aria-pressed=true] { border-color: var(--type, var(--accent)); background: var(--surface); font-weight: 700; }

.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 196px; overflow-y: auto; padding: 2px; }
.icon-grid button { height: 44px; border: 2px solid transparent; border-radius: 12px; background: var(--bg); font-size: 22px; padding: 0; }
.icon-grid button[aria-pressed=true] { border-color: var(--type, var(--accent)); }

.loc { display: grid; gap: 8px; padding: 12px; border-radius: 12px; background: var(--bg); font-size: 14px; }
.loc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.error { color: var(--exp-text); font-weight: 600; font-size: 14px; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }
.actions .btn.ghost { flex: 0 1 auto; }

.install-app { display: flex; align-items: center; gap: 14px; margin: 4px 0 16px; }
.install-app img { flex: none; border-radius: 13px; box-shadow: var(--shadow); }
.install-steps { display: grid; gap: 12px; margin: 0 0 16px; padding: 0; list-style: none; counter-reset: step; }
.install-steps li { display: flex; align-items: center; gap: 12px; counter-increment: step; }
.install-steps li::before {
  content: counter(step); flex: none; display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: 50%; background: var(--accent); color: var(--on-accent); font-size: 14px; font-weight: 700;
}
.sheet.install > .muted { margin: -4px 0 16px; }
.inline-ico { vertical-align: -3px; color: var(--accent); }
.install-card { display: grid; gap: 12px; justify-items: start; }

.cloud-body, .sheet.cloud form { display: grid; gap: 14px; }
.link-btn { justify-self: start; padding: 4px 0; border: 0; background: none; color: var(--accent); font-weight: 600; }
.recovery-code { padding: 16px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); text-align: center; font: 700 22px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .06em; user-select: all; }
.year-sum { display: grid; gap: 4px; }
.year-sum .month-bal { font-size: 26px; }
.hide-empty { padding: 0 4px; font-weight: 500; color: var(--text-2); }
.legal { display: grid; gap: 10px; font-size: 15px; line-height: 1.5; }
.legal h3 { font-size: 16px; margin: 8px 0 -4px; }
.legal p, .legal ul { margin: 0; }
.legal ul { padding-left: 20px; display: grid; gap: 4px; }
.legal a { color: var(--accent); }
.note { padding: 0 4px; margin-top: -6px; }
.cloud-row > span:first-child { font-weight: 600; }
.danger-link { color: var(--exp-text); justify-self: center; margin-top: 4px; }
.cloud-delete { display: grid; gap: 12px; }
.cloud-delete h3 { font-size: 17px; }
.cloud-delete p { margin: 0; }
.cloud-last { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.btn:disabled { opacity: .5; }
.btn.ghost { background: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; transition: .2s;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mouse: evidenziazione al passaggio ---------- */

@media (hover: hover) and (pointer: fine) {
  .row:hover, .tx-row:hover, .budget:hover, .rank button:hover { background: color-mix(in srgb, var(--line) 45%, transparent); }
  a.row, button.row, .tx-row, .budget, .big, .chip, .cat-pick, .seg button, .icon-grid button { cursor: pointer; }
  .btn:hover { filter: brightness(.96); }
  :root[data-theme=dark] .btn:hover { filter: brightness(1.15); }
  .big:hover { filter: brightness(1.06); }
  .icon-btn:hover { background: var(--line); }
  .seg button:not([aria-pressed=true]):hover { color: var(--text); }
  .chip:hover { background: color-mix(in srgb, var(--line) 60%, var(--bg)); }
}

/* ---------- Schermi grandi (PC, tablet in orizzontale) ---------- */
/* Barra laterale al posto delle schede in basso, contenuto più largo, pannelli come finestre centrate.
   Le pagine usano la classe view-<pagina> (js/app.js) per disporre le sezioni su due colonne. */

@media (min-width: 900px) {
  :root { --side: 232px; }
  #app { max-width: none; margin: 0 0 0 var(--side); }
  #topbar, #main { max-width: 1120px; margin: 0 auto; padding-left: 32px; padding-right: 32px; }
  #topbar { padding-top: 22px; padding-bottom: 14px; }
  #topbar h1 { font-size: 26px; }
  #main { padding-bottom: 48px; }
  .view { gap: 20px; }

  #tabbar {
    top: 0; right: auto; width: var(--side);
    flex-direction: column; justify-content: flex-start; gap: 4px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  #tabbar .brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; font-size: 18px; font-weight: 700; color: var(--text); }
  #tabbar .brand img { border-radius: 8px; }
  #tabbar a {
    flex: none; max-width: none; height: 44px; padding: 0 12px;
    flex-direction: row; justify-content: flex-start; gap: 12px;
    border-radius: 10px; font-size: 15px;
  }
  #tabbar a[aria-current] { background: color-mix(in srgb, var(--accent) 12%, transparent); }
  #tabbar a:not([aria-current]):hover { background: color-mix(in srgb, var(--line) 50%, transparent); color: var(--text); }

  #toast { bottom: 28px; left: calc(50% + var(--side) / 2); }

  /* Pannelli: finestra centrata invece del foglio che sale dal basso. */
  .sheet-wrap { align-items: center; padding: 24px; }
  .sheet { max-height: 88dvh; border-radius: 20px; padding: 12px 24px 24px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
  .sheet.confirm { max-width: 440px; padding-top: 24px; }

  /* Home: riepilogo e pulsanti in alto, budget e ultimi movimenti affiancati. */
  .view-home { grid-template-columns: 1fr 1fr; align-items: start; }
  .view-home > .big-actions { align-self: stretch; }
  .view-home .big { min-height: 0; height: 100%; font-size: 20px; }
  .view-home > section:only-of-type { grid-column: 1 / -1; }

  /* Movimenti e Impostazioni: elenchi, meglio una colonna non troppo larga. */
  .view-tx, .view-settings { max-width: 760px; }

  /* Categorie: entrate e uscite affiancate. */
  .view-cat { grid-template-columns: 1fr 1fr; align-items: start; }
  .view-cat > :not(section) { grid-column: 1 / -1; }
  .view-cat > section:only-of-type { grid-column: 1 / -1; }

  /* Grafici: i due selettori sulla stessa riga; nella vista per categoria grafico e classifica affiancati. */
  .view-charts { grid-template-columns: 1fr 1fr; align-items: start; }
  .view-charts > * { grid-column: 1 / -1; }
  .view-charts > [data-seg=view] { grid-column: 1; }
  .view-charts > [data-seg=mode] { grid-column: 2; }
  .view-charts > .trend { grid-column: 1; }
  .view-charts > .trend + section { grid-column: 2; }
}

/* ---------- Presentazione alla prima apertura (js/onboarding.js) ---------- */

.onboarding {
  position: fixed; inset: 0; z-index: 40; overflow: hidden;
  display: flex; flex-direction: column; color: #fff;
  background: radial-gradient(120% 70% at 50% 30%, #3a2a12 0%, #1a1a19 55%, #0d0d0d 100%);
  padding: env(safe-area-inset-top, 0px) 0 calc(24px + var(--safe-b));
  animation: fade .2s;
}
.onboarding.out { opacity: 0; transition: opacity .25s; }
.onb-skip { align-self: flex-end; margin: 12px 16px 0; padding: 8px 12px; border: 0; background: none; color: #c3c2b7; font-weight: 600; font-size: 15px; }
.onb-track { flex: 1; display: flex; transition: transform .35s ease; }
.onb-slide {
  flex: 0 0 100%; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 0 32px; text-align: center;
}
.onb-slide h2 { font-size: 28px; line-height: 1.2; letter-spacing: -.01em; max-width: 14em; }
.onb-slide p { font-size: 18px; line-height: 1.5; color: #d8d7cf; max-width: 22em; }
.onb-logo { width: 132px; height: 132px; border-radius: 30px; box-shadow: 0 12px 50px rgba(254, 153, 0, .35); margin-bottom: 8px; }
.onb-list { list-style: none; display: grid; gap: 16px; width: 100%; max-width: 360px; text-align: left; margin-top: 6px; }
.onb-list li { display: flex; align-items: center; gap: 14px; font-size: 17px; line-height: 1.4; color: #e8e7e0; }
.onb-ico { flex: none; width: 52px; height: 52px; display: grid; place-items: center; font-size: 26px; border-radius: 16px; background: rgba(255, 255, 255, .08); }
.onb-dots { display: flex; justify-content: center; gap: 8px; margin: 8px 0 20px; }
.onb-dots i { width: 8px; height: 8px; border-radius: 50%; background: rgba(255, 255, 255, .3); transition: .2s; }
.onb-dots i.on { width: 22px; border-radius: 4px; background: #fe9900; }
.onb-next {
  margin: 0 24px; min-height: 56px; border: 0; border-radius: 18px; font-size: 18px; font-weight: 700;
  background: linear-gradient(180deg, #ffb84d, #fe9900); color: #1a1a19;
}
.onb-next:active { transform: scale(.98); }
.onb-next:focus-visible, .onb-skip:focus-visible { outline: 2px solid #fff; outline-offset: 3px; }
@media (min-width: 900px) { .onb-next { width: 360px; align-self: center; } }
@media (prefers-reduced-motion: reduce) { .onb-track { transition: none; } }
