
/* Layout: una colonna da telefono, un'azione sola in primo piano (il +), niente riquadri dentro riquadri. */
:root {
  --bg: #f2f4f1; --surface: #ffffff; --ink: #17241f; --muted: #5a6963; --line: #d9e0db;
  --accent: #0d6a58; --accent-soft: #dcefe9; --on-accent: #ffffff; --soon: #8a5a06; --danger: #a8322a;
  --display: "Bricolage Grotesque", "Trebuchet MS", sans-serif;
  --body: "Figtree", "Segoe UI", Roboto, sans-serif;
  --gut-l: max(16px, env(safe-area-inset-left, 0px)); --gut-r: max(16px, env(safe-area-inset-right, 0px));
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #101715; --surface: #18211e; --ink: #e8efeb; --muted: #9caaa4; --line: #2b3632;
  --accent: #58c7ab; --accent-soft: #1d3a33; --on-accent: #06211b; --soon: #e0b05a; --danger: #ee8d84; color-scheme: dark } }
:root[data-theme="dark"] {
  --bg: #101715; --surface: #18211e; --ink: #e8efeb; --muted: #9caaa4; --line: #2b3632;
  --accent: #58c7ab; --accent-soft: #1d3a33; --on-accent: #06211b; --soon: #e0b05a; --danger: #ee8d84; color-scheme: dark }
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 400 15px/1.4 var(--body); font-variant-numeric: tabular-nums; overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3, p { margin: 0; }

.app { height: 100%; max-width: 460px; margin: 0 auto; display: flex; flex-direction: column; position: relative; overflow: hidden; background: var(--bg); }
@media (min-width: 520px) { .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); } }


main { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 16px var(--gut-r) 24px var(--gut-l); display: flex; flex-direction: column; gap: 22px; }
.wallet-btn { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 15px; min-height: 32px; }
.wallet-btn svg { width: 14px; height: 14px; }
.big { font: 700 44px/1.05 var(--display); letter-spacing: -.02em; margin-top: 2px; }
.lab { font-size: 13px; color: var(--muted); }
.cap { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.pos { color: var(--accent); }

.month { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.month b { font: 700 18px/1.2 var(--display); }
.month button { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; }
.month button:disabled { opacity: .25; cursor: default; }
.month svg { width: 18px; height: 18px; }

.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.trio b { display: block; font-weight: 600; font-size: 15px; }

.soon { display: flex; flex-direction: column; gap: 6px; }
.soon-row { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.soon-row span:first-child { min-width: 0; }
.soon-row em { font-style: normal; color: var(--soon); font-weight: 600; margin-right: 6px; }

.search { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 0 12px; }
.search::placeholder { color: var(--muted); }

.day { padding: 10px 0 2px; font-size: 13px; font-weight: 600; color: var(--muted); }
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left; padding: 10px 0; border-bottom: 1px solid var(--line); min-height: 56px; }
.row-main { min-width: 0; flex: 1 1 auto; }
.row-t { font-weight: 500; overflow-wrap: anywhere; }
.row-s { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row-v { font-weight: 600; white-space: nowrap; }
.tag { display: inline-flex; vertical-align: -2px; margin-left: 4px; color: var(--muted); }
.tag svg { width: 13px; height: 13px; }
.paused { opacity: .55; }
.empty { padding: 24px 0; color: var(--muted); text-align: center; }

.bars { display: flex; flex-direction: column; gap: 12px; margin-top: 10px; }
.bar-row { display: block; width: 100%; text-align: left; }
.bar-top { display: flex; justify-content: space-between; gap: 12px; }
.track { height: 8px; border-radius: 4px; background: var(--line); margin-top: 5px; overflow: hidden; }
.fill { height: 100%; border-radius: 4px; background: var(--accent); }
.subs { display: flex; flex-direction: column; gap: 3px; margin-top: 7px; padding-left: 12px; font-size: 13px; color: var(--muted); }
.subs div { display: flex; justify-content: space-between; gap: 12px; }

.chart { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.col { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.col.on { color: var(--ink); font-weight: 600; }
.pair { height: 110px; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 3px; border-bottom: 1px solid var(--line); }
.pair i { display: block; width: 38%; max-width: 14px; border-radius: 3px 3px 0 0; min-height: 1px; }
.pair .i-in { background: var(--accent); }
.pair .i-out { background: var(--muted); }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; }

.btn { min-height: 46px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; }
.btn.main { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.del { color: var(--danger); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 130px; }
.code { font: 700 30px/1.1 var(--display); letter-spacing: .08em; margin: 6px 0 10px; }
.note { font-size: 14px; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.line-in { display: flex; gap: 8px; }
.line-in .search { flex: 1 1 auto; min-width: 0; }
.line-in .btn { flex: 0 0 auto; }
.cat-line { padding: 8px 0; border-bottom: 1px solid var(--line); }
.cat-line b { font-weight: 600; }

nav.tabs { flex: 0 0 auto; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); border-top: 1px solid var(--line); background: var(--surface); padding: 4px var(--gut-r) calc(4px + env(safe-area-inset-bottom, 0px)) var(--gut-l); align-items: center; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 0; min-height: 50px; }
.tab svg { width: 22px; height: 22px; }
.tab[aria-current="page"] { color: var(--accent); }
.plus { justify-self: center; width: 54px; height: 54px; border-radius: 16px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; }
.plus svg { width: 26px; height: 26px; }

.scrim { position: absolute; inset: 0; background: var(--bg); z-index: 5; display: flex; flex-direction: column; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(16px); } to { transform: none; } }
@media (prefers-reduced-motion: reduce) { .scrim { animation: none; } }
.sh-head { padding: 14px var(--gut-r) 10px var(--gut-l); text-align: center; }
.sh-head .sh-title { font-size: 14px; font-weight: 600; }
.amount { display: block; width: 100%; text-align: center; font: 700 44px/1.1 var(--display); padding: 2px 0 6px; letter-spacing: -.02em; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }
.rec-box { display: flex; flex-direction: column; gap: 12px; padding: 0 0 4px 32px; }
.more { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 44px; font-weight: 600; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.more svg { width: 18px; height: 18px; transition: transform .15s; }
.more[aria-expanded="true"] svg { transform: rotate(180deg); }
@media (prefers-reduced-motion: reduce) { .more svg { transition: none; } }
.dateline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 36px; }
.dateline .lab { margin-right: 2px; }
.date-chip { min-height: 36px; padding: 0 10px; white-space: nowrap; }
.date-other { margin-left: auto; }
@media (max-width: 389px) { .dateline { gap: 4px; } .dateline .lab { display: none; } .date-chip { padding: 0 8px; } }
.chip.add { border-style: dashed; color: var(--accent); font-weight: 600; }
.line-in.add-in { margin-top: 6px; }
.line-in.add-in .btn { padding: 0 12px; }
.count { width: 90px; flex: 0 0 auto; margin-top: 0; }
.count-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.amount.zero { color: var(--muted); }
.sh-body { flex: 1 1 auto; min-height: 90px; overflow-y: auto; padding: 0 var(--gut-r) 14px var(--gut-l); display: flex; flex-direction: column; gap: 14px; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { min-height: 40px; padding: 0 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 500; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.seg .chip { width: 100%; }
.text { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 0 12px; margin-top: 6px; }
.pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.pad button { height: 44px; border-radius: 8px; font: 500 21px/1 var(--display); background: var(--surface); }
.sh-foot { flex: 0 0 auto; padding: 8px var(--gut-r) calc(10px + env(safe-area-inset-bottom, 0px)) var(--gut-l); display: flex; gap: 8px; }
.sh-foot .main { flex: 1 1 auto; min-height: 52px; font-size: 16px; }
.sh-foot .btn:not(.main) { flex: 0 0 32%; min-height: 52px; }
.sh-foot .main.off { opacity: .45; }
.hint { color: var(--danger); font-size: 13px; font-weight: 600; text-align: center; min-height: 18px; }

.toast { position: absolute; left: 16px; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 11px 14px; border-radius: 10px; display: flex; justify-content: space-between; align-items: center; gap: 12px; z-index: 9; font-size: 14px; }
.toast button { color: inherit; font-weight: 700; text-decoration: underline; min-height: 28px; }

/* ---------- App vera: font locali, accesso, stati ---------- */
@font-face { font-family: "Bricolage Grotesque"; src: url(/fonts/bricolage.woff2) format("woff2"); font-weight: 500 700; font-display: swap; }
@font-face { font-family: "Figtree"; src: url(/fonts/figtree.woff2) format("woff2"); font-weight: 400 700; font-display: swap; }
.top8 { margin-top: 8px; }
.center { text-align: center; }
.title { font: 700 24px/1.2 var(--display); }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1 1 auto; }
.link { font-weight: 600; color: var(--accent); min-height: 36px; padding: 0 4px; }
.link.danger { color: var(--danger); }
.linkbtn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: var(--ink); }
.narrow { align-self: flex-start; }
.stack-lg { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.stats-grid { display: flex; flex-direction: column; gap: 22px; }
.home-grid { display: flex; flex-direction: column; gap: 22px; }
.col-side { display: flex; flex-direction: column; gap: 22px; min-width: 0; }
.col-main { min-width: 0; }
.seg-small { max-width: 240px; }
.seg-small .chip { min-height: 36px; }
.legend .i-in { background: var(--accent); }
.legend .i-out { background: var(--muted); }
.status { flex: 0 0 auto; padding: 7px var(--gut-r) 7px var(--gut-l); font-size: 13px; font-weight: 600; background: var(--accent-soft); color: var(--ink); }
.gate { height: 100%; overflow-y: auto; display: flex; justify-content: center; padding: 32px var(--gut-r) 32px var(--gut-l); background: var(--bg); }
.gate-box { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; }
.gate-box .stack { gap: 12px; }
.brand { font: 700 34px/1.1 var(--display); letter-spacing: -.02em; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input { color: var(--ink); font-weight: 400; font-size: 16px; }
.search, .text { font-size: 16px; }
.hint:empty { display: none; }
.chip-search { margin-bottom: 2px; height: 38px; }
.more-chip { color: var(--muted); font-weight: 600; }
.rec-box.flat { padding-left: 0; }
.tabs .side-brand { display: none; }
.plus span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.dialog { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; background: var(--bg); }
#toast .toast { position: fixed; }
#toast { z-index: 20; }
a.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row-s .link { min-height: 28px; }

/* ---------- Computer: barra laterale, più colonne, finestra al centro ---------- */
@media (min-width: 900px) {
  .app { max-width: none; display: grid; grid-template-columns: 232px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "tabs status" "tabs main"; border: 0; }
  .status { grid-area: status; padding: 8px 32px; }
  main { grid-area: main; padding: 28px 32px 40px; }
  main > * { width: 100%; max-width: 1180px; margin-inline: auto; }
  nav.tabs { grid-area: tabs; display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: 22px 14px; border-top: 0; border-right: 1px solid var(--line); }
  .tabs .side-brand { display: block; font: 700 21px/1.15 var(--display); letter-spacing: -.01em; padding: 0 10px 18px; }
  .tab { flex-direction: row; gap: 12px; font-size: 15px; padding: 0 10px; min-height: 44px; border-radius: 10px; }
  .tab:hover { background: var(--bg); }
  .tab[aria-current="page"] { background: var(--accent-soft); }
  .tab svg { width: 20px; height: 20px; }
  .plus { order: -1; justify-self: auto; width: 100%; height: 46px; border-radius: 10px; display: flex; align-items: center; justify-content: center; gap: 8px; font-weight: 600; margin-bottom: 14px; }
  .side-brand { order: -2; }
  .plus svg { width: 20px; height: 20px; }
  .plus span { position: static; width: auto; height: auto; overflow: visible; clip-path: none; font-size: 15px; }
  .plus:hover { filter: brightness(1.08); }
  .home-grid { display: grid; grid-template-columns: minmax(280px, 340px) minmax(0, 1fr); gap: 40px; align-items: start; }
  .col-side { position: sticky; top: 0; }
  .stats-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 40px; align-items: start; }
  .row:hover { background: var(--surface); }
  .row { padding-inline: 10px; }
  .day { padding-inline: 10px; }
  .big { font-size: 40px; }
  .chip:hover, .btn:hover { border-color: var(--muted); }
  .scrim { background: color-mix(in srgb, var(--ink) 45%, transparent); align-items: center; justify-content: center; padding: 28px; animation: none; }
  .dialog { width: 100%; max-width: 560px; max-height: 100%; flex: 0 1 auto; border-radius: 14px; overflow: hidden; }
  .amount { cursor: default; }
  #toast .toast { left: auto; right: 28px; bottom: 28px; width: 360px; }
}

[hidden] { display: none !important; }
/* Telefono: barra di navigazione in basso, a portata di pollice. */
.status { order: 0; }
main { order: 1; }
nav.tabs { order: 2; }
.duo { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.duo b { display: block; font-weight: 600; font-size: 15px; }
/* Profilo */
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%; background: var(--accent-soft); color: var(--ink); font-size: 13px; font-weight: 700; }
.big-av { width: 48px; height: 48px; font-size: 16px; }
.side-profile { display: none; }
@media (min-width: 900px) {
  .only-phone { display: none; }
  .side-profile { display: flex; order: 9; margin-top: auto; align-items: center; gap: 10px; min-height: 52px; padding: 0 8px; border-radius: 10px; font-weight: 600; text-align: left; }
  .side-profile:hover, .side-profile[aria-current="page"] { background: var(--accent-soft); }
  .side-profile span:last-child { min-width: 0; overflow-wrap: anywhere; }
}
/* Foto */
img.avatar { object-fit: cover; display: block; background: var(--accent-soft); }
.avatar-btn { border-radius: 50%; flex: 0 0 auto; }
.big-av { width: 72px; height: 72px; font-size: 22px; }
.photo-row { display: flex; align-items: center; gap: 16px; }
.photo-row .btn-row { min-width: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
label.btn { cursor: pointer; }
#p-photo:focus-visible + .btn, label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
/* In sospeso */
.due { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.due-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--soon); }
.due-head b { font-size: 16px; }
.due-row { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.due-row:last-child { border-bottom: 0; }
.due-row .row { flex: 1 1 auto; min-width: 0; border-bottom: 0; padding-inline: 0; }
.due-row .avatar { width: 28px; height: 28px; font-size: 11px; }
.btn.paid { flex: 0 0 auto; min-height: 38px; padding: 0 10px; font-size: 13px; color: var(--accent); border-color: var(--accent); }
/* Registro delle modifiche */
.log-row { align-items: flex-start; }
.log-ch { display: block; margin-top: 2px; font-size: 13px; overflow-wrap: anywhere; }
.avatar svg { width: 16px; height: 16px; }
/* Telefono: lo swipe orizzontale lo gestisce l'app, lo scorrimento verticale il browser */
@media (max-width: 899px) { main { touch-action: pan-y pinch-zoom; } }
#swipe-edge { position: fixed; top: 0; right: 0; bottom: 0; width: 72px; background: linear-gradient(to left, var(--danger), transparent); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 5; }
