:root {
  --bg: #f2f2f7; --card: #fff; --text: #111; --muted: #6b6b73; --line: rgba(60,60,67,.16);
  --blue: #007aff; --green: #34c759; --orange: #ff9500; --red: #ff3b30; --fill: rgba(120,120,128,.12);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --tabh: 52px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --text: #f2f2f7; --muted: #98989f; --line: rgba(84,84,88,.5); --fill: rgba(120,120,128,.28);
    --blue: #0a84ff; --green: #30d158; --orange: #ff9f0a; --red: #ff453a; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; touch-action: manipulation; cursor: pointer; padding: 0; }
input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

#view { position: fixed; inset: 0; bottom: calc(var(--tabh) + var(--sab)); overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: calc(var(--sat) + 8px) 16px 120px; }
#tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabh) + var(--sab)); padding-bottom: var(--sab);
  display: flex; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: .5px solid var(--line); z-index: 20; }
#tabbar button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--muted); font-size: 10px; min-height: 44px; }
#tabbar button i { font-style: normal; font-size: 20px; filter: grayscale(1); opacity: .7; }
#tabbar button.on { color: var(--blue); font-weight: 600; }
#tabbar button.on i { filter: none; opacity: 1; }

#fab { position: fixed; right: 18px; bottom: calc(var(--tabh) + var(--sab) + 14px); width: 68px; height: 68px; border-radius: 50%;
  background: var(--blue); color: #fff; font-size: 40px; font-weight: 300; line-height: 1; z-index: 25;
  box-shadow: 0 6px 18px rgba(0,122,255,.45); display: grid; place-items: center; transition: transform .12s; }
#fab:active { transform: scale(.92); }
#fab-badge { position: absolute; top: -2px; right: -2px; min-width: 24px; height: 24px; border-radius: 12px; background: var(--orange);
  color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; padding: 0 6px; }

h1 { font-size: 30px; margin: 4px 0 8px; letter-spacing: -.02em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin: 22px 16px 6px; }
.card { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 12px; }
.pad { padding: 14px 16px; }
.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 16px; width: 100%; text-align: left; }
.row + .row, .card > * + .row { border-top: .5px solid var(--line); }
.grow { flex: 1; min-width: 0; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted { color: var(--muted); } .small { font-size: 13px; } .center { text-align: center; }
.pos { color: var(--green); } .neg { color: var(--red); } .warn { color: var(--orange); }
.emo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-size: 20px; flex: none; }

/* period bar */
.pbar { display: flex; align-items: center; gap: 4px; margin: 2px -8px 6px; }
.pbar .nav { width: 44px; height: 44px; font-size: 26px; color: var(--blue); border-radius: 10px; }
.pbar .lbl { flex: 1; text-align: center; font-weight: 600; font-size: 17px; line-height: 1.15; min-height: 44px; display: grid; place-items: center; }
.pbar .lbl small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.pill { background: var(--fill); border-radius: 999px; padding: 6px 12px; font-size: 14px; min-height: 32px; }
.pill.on { background: var(--blue); color: #fff; }

/* dashboard */
.hero { text-align: center; padding: 20px 16px 16px; }
.hero .big { font-size: 46px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.hero .cap { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.triple { display: grid; grid-template-columns: repeat(3, 1fr); border-top: .5px solid var(--line); }
.triple button { padding: 12px 6px; text-align: center; min-height: 64px; }
.triple button + button { border-left: .5px solid var(--line); }
.triple b { display: block; font-size: 17px; margin-top: 2px; }
.bar { height: 8px; border-radius: 4px; background: var(--fill); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--green); transition: width .3s; }
.bar > i.o { background: var(--orange); } .bar > i.r { background: var(--red); }
.banner { background: color-mix(in srgb, var(--orange) 18%, var(--card)); border-radius: 14px; padding: 12px 16px; margin-bottom: 12px; display: flex; gap: 10px; align-items: center; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }
.chart text { fill: var(--muted); font-size: 10px; }
.legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); padding-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* switch */
.sw { position: relative; width: 51px; height: 31px; border-radius: 16px; background: var(--fill); flex: none; transition: background .2s; }
.sw::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.3); transition: transform .2s; }
.sw.on { background: var(--green); } .sw.on::after { transform: translateX(20px); }

/* sheets */
#layer { position: fixed; inset: 0; pointer-events: none; z-index: 50; }
.scrim { position: absolute; inset: 0; background: rgba(0,0,0,.4); pointer-events: auto; animation: fade .2s; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: calc(100% - var(--sat) - 12px); background: var(--bg); border-radius: 18px 18px 0 0;
  pointer-events: auto; display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2,.8,.2,1); padding-bottom: var(--sab); }
.sheet.full { height: calc(100% - var(--sat) - 8px); }
.sheet header { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px; min-height: 52px; gap: 8px; }
.sheet header h3 { margin: 0; font-size: 17px; flex: 1; text-align: center; }
.sheet header .btn { min-width: 44px; min-height: 44px; padding: 0 10px; color: var(--blue); font-weight: 600; }
.sheet .body { overflow-y: auto; padding: 4px 16px 16px; flex: 1; -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(100%); } } @keyframes fade { from { opacity: 0; } }

.field { display: flex; align-items: center; gap: 12px; padding: 0 16px; min-height: 48px; background: var(--card); }
.field + .field { border-top: .5px solid var(--line); }
.field label { color: var(--muted); width: 90px; flex: none; font-size: 15px; }
.field input, .field select { flex: 1; min-width: 0; border: 0; background: transparent; text-align: right; min-height: 44px; outline: none; font-size: 17px; }
.btn-primary, .btn-danger, .btn-plain { display: block; width: 100%; min-height: 50px; border-radius: 13px; font-weight: 600; margin-top: 12px; }
.btn-primary { background: var(--blue); color: #fff; } .btn-danger { background: var(--card); color: var(--red); } .btn-plain { background: var(--card); color: var(--blue); }
.btn-primary:disabled { opacity: .4; }
.seg { display: flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.seg button { flex: 1; min-height: 34px; border-radius: 7px; font-size: 14px; font-weight: 500; padding: 0 12px; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.2); font-weight: 600; }

/* entry sheet */
.entry { display: flex; flex-direction: column; height: 100%; }
.entry .disp { text-align: center; padding: 4px 16px 0; }
.entry .amt { font-size: 56px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; min-height: 62px; }
.entry .amt.dim { color: var(--muted); }
.entry .total { font-size: 15px; color: var(--muted); }
.entry .total b { color: var(--text); font-size: 28px; margin-left: 6px; }
.cartlist { flex: 1; min-height: 44px; overflow-y: auto; padding: 4px 12px; display: flex; flex-wrap: wrap; gap: 6px; align-content: flex-start; }
.cartlist .it { background: var(--card); border-radius: 999px; padding: 0 6px 0 14px; min-height: 40px; display: flex; align-items: center; gap: 4px; font-weight: 600; }
.cartlist .it button { width: 40px; height: 40px; color: var(--red); font-size: 20px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; flex: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 48px; padding: 0 16px; border-radius: 14px; background: var(--card); font-weight: 500; display: flex; align-items: center; gap: 6px; border: 2px solid transparent; white-space: nowrap; }
.chip.on { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 14%, var(--card)); font-weight: 700; }
.meta { display: flex; gap: 8px; padding: 0 12px 8px; flex: none; }
.meta input { flex: 1; min-width: 0; min-height: 44px; border-radius: 12px; border: 0; background: var(--card); padding: 0 12px; outline: none; }
.meta input[type=date] { flex: none; width: 150px; }
.pad-keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 12px; flex: none; }
.pad-keys button { min-height: 58px; border-radius: 14px; background: var(--card); font-size: 28px; font-weight: 500; user-select: none; -webkit-user-select: none; }
.pad-keys button:active { background: var(--fill); }
.actions { display: flex; gap: 8px; padding: 8px 12px 8px; flex: none; }
.actions button { flex: 1; min-height: 58px; border-radius: 14px; font-size: 19px; font-weight: 700; color: #fff; }
.actions .add { background: var(--blue); flex: .8; } .actions .ok { background: var(--green); } .actions button:disabled { opacity: .35; }

/* toast & flash */
#toast { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabh) + var(--sab) + 96px); z-index: 80; background: #2c2c2e; color: #fff; border-radius: 14px;
  padding: 0 6px 0 16px; min-height: 52px; display: flex; align-items: center; gap: 8px; animation: pop .25s; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
#toast span { flex: 1; font-size: 15px; } #toast button { color: #64b5ff; font-weight: 700; min-width: 64px; min-height: 44px; }
@keyframes pop { from { transform: translateY(20px); opacity: 0; } }
.flash { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; pointer-events: none; }
.flash i { width: 110px; height: 110px; border-radius: 50%; background: var(--green); color: #fff; font-style: normal; font-size: 64px; display: grid; place-items: center; animation: flash .7s forwards; }
@keyframes flash { 0% { transform: scale(.4); opacity: 0; } 25% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.1); opacity: 0; } }
.hap { position: fixed; opacity: 0; pointer-events: none; left: -100px; }

.handle { width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); touch-action: none; font-size: 22px; }
.dragging { opacity: .6; background: var(--fill); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 12px 16px; background: var(--card); }
.swatches button { width: 44px; height: 44px; border-radius: 50%; border: 3px solid transparent; }
.swatches button.on { border-color: var(--text); }
[hidden] { display: none !important; }

/* v1.1: home di benvenuto, frecce indietro, prospetto */
.welcome h1 { margin: 0 0 2px; font-size: 32px; }
.welcome .small { text-transform: capitalize; margin-top: 4px; }
.hero-card { background: linear-gradient(135deg, #0a84ff 0%, #5e5ce6 100%); color: #fff; box-shadow: 0 10px 24px rgba(10,132,255,.25); }
.hero-card .cap { color: rgba(255,255,255,.8); }
.hero-card .triple { border-top-color: rgba(255,255,255,.25); background: rgba(255,255,255,.08); }
.hero-card .triple button + button { border-left-color: rgba(255,255,255,.25); }
.hero-card .triple .small { opacity: .8; }
.hero-card .big { font-size: 48px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 4px; }
.tile { background: var(--card); border-radius: 16px; padding: 12px 14px; text-align: left; min-height: 92px; display: flex; flex-direction: column; gap: 1px; justify-content: center; }
.tile:active { transform: scale(.97); } .tile .ti { font-size: 26px; margin-bottom: 2px; }
.onboard { background: color-mix(in srgb, var(--blue) 10%, var(--card)); }
.step { padding: 6px 0; min-height: 52px; } .row.step + .row.step { border-top: .5px solid var(--line); }
.stepn { width: 28px; height: 28px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.btn.back { display: flex; align-items: center; gap: 2px; padding: 0 8px 0 2px !important; font-weight: 500 !important; font-size: 17px; }
.btn.back .chev { font-size: 38px; line-height: 1; font-weight: 300; margin-top: -4px; }
.cap-row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.forecast { display: flex; justify-content: space-between; align-items: baseline; margin-top: 12px; padding-top: 12px; border-top: .5px solid var(--line); font-weight: 600; }
.forecast b { font-size: 22px; }
.row .tot, .row b.tot { font-size: 19px; }
.addrow { color: var(--blue); font-weight: 600; }
.chips.wrap { flex-wrap: wrap; overflow: visible; padding: 12px 0 0; }
.row.hist.now { background: color-mix(in srgb, var(--blue) 10%, var(--card)); }
.cap-row > span { margin-right: 8px; }
.cap-row { gap: 8px; }

/* v1.2: schermata iniziale, privacy */
#eye { position: fixed; top: calc(var(--sat) + 6px); right: 10px; width: 44px; height: 44px; border-radius: 50%; z-index: 45; font-size: 22px;
  background: color-mix(in srgb, var(--card) 85%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 1px 6px rgba(0,0,0,.12); }
#cover { position: fixed; inset: 0; z-index: 200; background: linear-gradient(160deg, #0a84ff, #5e5ce6); display: grid; place-items: center; }
.logo { width: 76px; height: 76px; border-radius: 22px; background: rgba(255,255,255,.2); color: #fff; font-weight: 800; font-size: 26px; display: grid; place-items: center; letter-spacing: -.02em; }
#gate { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; animation: fade .25s;
  padding: calc(var(--sat) + 10px) 18px calc(var(--sab) + 18px); background-image: radial-gradient(120% 60% at 50% -10%, color-mix(in srgb, var(--blue) 22%, transparent), transparent); }
#gate.out { opacity: 0; transform: scale(1.03); transition: .25s; }
.gate-in { min-height: 100%; display: flex; flex-direction: column; max-width: 480px; margin: 0 auto; }
.gate-top { display: flex; align-items: center; gap: 10px; min-height: 48px; }
.gate-top .logo { width: 38px; height: 38px; border-radius: 11px; font-size: 14px; background: linear-gradient(135deg, #0a84ff, #5e5ce6); }
.gate-name { font-weight: 700; font-size: 18px; }
.gate-hello { margin: 18px 0 14px; } .gate-hello h1 { font-size: 36px; margin: 0; }
.gate-sum { display: flex; justify-content: space-between; align-items: center; background: linear-gradient(135deg, #0a84ff, #5e5ce6); color: #fff; border-radius: 18px; padding: 14px 18px; margin-bottom: 16px; }
.gate-bal { font-size: 30px; font-weight: 700; letter-spacing: -.02em; }
.gate-actions { display: flex; flex-direction: column; gap: 12px; }
.gate-card { display: flex; align-items: center; gap: 14px; background: var(--card); border-radius: 20px; padding: 16px; min-height: 86px; text-align: left; box-shadow: 0 2px 10px rgba(0,0,0,.05); border-left: 6px solid var(--blue); }
.gate-card:active { transform: scale(.98); }
.gate-card .gi { font-size: 34px; width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px; background: var(--fill); flex: none; }
.gate-card b { display: block; font-size: 19px; } .gate-card .small { color: var(--muted); }
.gate-card .chev2 { font-size: 28px; color: var(--muted); }
.g-in { border-left-color: var(--green); } .g-out { border-left-color: var(--red); } .g-set { border-left-color: var(--orange); } .g-cart { border-left-color: var(--blue); }
.gate-go { margin-top: 18px; min-height: 54px; border-radius: 16px; background: var(--fill); font-weight: 600; font-size: 17px; }
.gate-off { margin-top: 6px; min-height: 44px; color: var(--muted); font-size: 14px; }
.duo { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pbar-wrap { margin: 0 -8px; }
#eye { color: var(--text); display: grid; place-items: center; padding: 0; }

/* v1.3: chip a griglia, carta di credito */
.sheet .body { padding-bottom: 28px; }
.chips.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; overflow: visible; padding: 12px 0 0; }
.chips.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.chips.grid .chip { width: 100%; min-width: 0; justify-content: flex-start; padding: 0 12px; }
.chips.grid.c3 .chip { justify-content: center; }
.chip .ce { width: 1.5em; text-align: center; flex: none; }
.cardrow { margin-top: 12px; }
.cr-toggle { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 6px 16px; background: var(--card); border-radius: 14px; text-align: left; }
.cr-toggle .grow b { display: block; font-weight: 600; }
.cardrow .seg { margin-top: 8px; }
.cardrow .seg button { min-height: 42px; font-size: 16px; }
.cardrow.compact { display: flex; gap: 8px; align-items: center; margin: 0; padding: 0 12px 8px; }
.cardrow.compact .cr-toggle { flex: none; width: auto; min-height: 44px; padding: 0 12px; border-radius: 12px; gap: 8px; }
.cardrow.compact .cr-toggle .sw { transform: scale(.8); margin: 0 -6px 0 0; }
.cardrow.compact .seg { flex: 1; margin: 0; }
.ic { display: inline-grid; place-items: center; flex: none; }
.cardtag { display: flex; align-items: center; gap: 4px; color: var(--blue); } .cardtag .ic svg { width: 14px; height: 14px; }
.row.sub { min-height: 40px; padding-left: 56px; border-top: 0 !important; }
.chips.grid .chip { white-space: normal; text-align: left; line-height: 1.15; min-height: 52px; }
.chips.grid.c3 .chip { text-align: center; }

img.logo { object-fit: cover; background: none; }
.gate-top img.logo { width: 40px; height: 40px; border-radius: 11px; }
#cover .big-logo { width: 120px; height: 120px; border-radius: 28px; box-shadow: 0 12px 32px rgba(0,0,0,.25); }

/* v1.4: spese fisse con data */
.row.fx { padding-right: 4px; }
.fxmain { text-align: left; min-height: 52px; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.swbtn { width: 66px; min-height: 52px; display: grid; place-items: center; flex: none; }
