/* Spese Ufficio — aspetto preso da HomeKeeper (tasti grandi «fisici», pastelli).
   Due temi scelti da ognuno: chiaro con scritte nere, scuro con scritte bianche.
   Campi editabili sempre >= 16px (sotto, iPhone ingrandisce la pagina al tocco). */

:root, :root[data-theme="chiaro"] {
  --bg: #f4f6fb; --card: #ffffff; --text: #111111; --muted: #4b5563; --border: #dfe3ec;
  --danger: #d4473b; --plus: #1f8a4c; --field: #ffffff;
  color-scheme: light;
}
:root[data-theme="scuro"] {
  --bg: #1c2029; --card: #272c37; --text: #ffffff; --muted: #c9ced8; --border: #3a414f;
  --danger: #ff8a7d; --plus: #6fe0a0; --field: #1f232c;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.loading { padding: 3rem; text-align: center; color: var(--muted); }

#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); background: var(--bg);
}
.top h1 { flex: 1; margin: 0; font-size: 1.2rem; text-align: center; line-height: 1.2; }
.top .nav { min-width: 96px; display: flex; gap: 8px; }
.top.home .nav { min-width: 52px; }   /* in home a sinistra non c'è niente: più spazio al titolo */
.top .nav.r { justify-content: flex-end; }
main {
  flex: 1; display: flex; flex-direction: column; width: 100%; max-width: 640px; margin: 0 auto;
  padding: 6px 16px calc(96px + env(safe-area-inset-bottom, 0px));
}

/* ---- tasti ---- */
.btn, .key { --kb: var(--card); --ks: var(--border); --ki: var(--text); }
.c-giallo  { --kb: #FFD84D; --ks: #D4A91A; --ki: #2a2100; }
.c-verde   { --kb: #7BE0A0; --ks: #3FB56E; --ki: #06301a; }
.c-corallo { --kb: #FF9B8A; --ks: #E0664F; --ki: #3d0f06; }
.c-azzurro { --kb: #7CCBFF; --ks: #3E9BDB; --ki: #062a45; }
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; min-height: 58px;
  margin: 6px 0 14px; padding: 12px 18px; border: 1px solid var(--ks); border-radius: 18px;
  font: inherit; font-size: 1.2rem; font-weight: 700; line-height: 1.2; text-align: center; text-decoration: none; cursor: pointer;
  background: var(--kb); color: var(--ki); box-shadow: 0 5px 0 var(--ks); transition: transform .06s, box-shadow .06s;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ks); }
.btn:disabled { opacity: .5; }
.btn.big { min-height: 70px; font-size: 1.35rem; margin-top: 20px; }
.btn.small { width: auto; min-height: 44px; margin: 0; padding: 8px 14px; font-size: 1rem; border-radius: 13px; box-shadow: 0 4px 0 var(--ks); }
.btn.danger { color: var(--danger); margin-top: 24px; }
.keys { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 6px 0 16px; }
.key {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 120px;
  border-radius: 26px; text-decoration: none; font-size: 1.2rem; font-weight: 800; text-align: center;
  background: var(--kb); color: var(--ki); box-shadow: 0 8px 0 var(--ks); -webkit-tap-highlight-color: transparent;
}
.key .ic { font-size: 2.4rem; line-height: 1; }
.key:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--ks); }

/* ---- blocchi ---- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 14px 16px; margin-bottom: 12px; }
.h0 { font-size: 1.05rem; font-weight: 800; margin-bottom: 8px; }
.nm { font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.sub { font-size: .92rem; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.soft { font-weight: 400; color: var(--muted); font-size: .9em; }
.warn { color: var(--danger); font-weight: 700; }
.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 1.05rem; }
.hint { font-size: .95rem; color: var(--muted); margin: 8px 2px; }
.row-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: 1.1rem; font-weight: 700; }
.row-top b { font-size: 1.5rem; }
.fund.low { border: 2px solid var(--danger); }
.fund { cursor: pointer; }

.acc > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; min-height: 30px; font-weight: 800; }
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after { content: '▾'; margin-left: auto; color: var(--muted); transition: transform .15s; }
.acc[open] > summary::after { transform: rotate(180deg); }
.acc[open] > summary { margin-bottom: 8px; }

.person { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.person:first-of-type { border-top: 0; }
.person .bd { flex: 1; min-width: 0; }
.dot { flex: none; display: inline-block; width: 14px; height: 14px; border-radius: 50%; background: var(--uc, #999); }
.diff { flex: none; font-size: 1.15rem; font-weight: 800; white-space: nowrap; }
.plus { color: var(--plus); }
.minus { color: var(--danger); }

.even { border: 2px solid #D4A91A; }
.evsub { margin: 10px 2px 4px; }
.evrow { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-size: 1.02rem; }
.evrow .bd { flex: 1; min-width: 0; }

.pend { border: 2px solid #3E9BDB; }
.pendrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.pendrow:first-of-type { border-top: 0; }
.pendrow .bd { flex: 1; min-width: 0; }
.pendrow .acts { display: flex; gap: 8px; flex: none; }

.monthbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.monthbar select { flex: 1; min-width: 0; }
.monthtot { flex: none; font-weight: 700; color: var(--muted); }
.mbal { background: var(--bg); border-radius: 14px; padding: 10px 12px; margin: 4px 0 12px; }
.mbal-h, .mbal-r { display: grid; grid-template-columns: minmax(0, 1fr) 6em 7em; gap: 6px; align-items: center; }
.mbal-h { font-size: .8rem; color: var(--muted); font-weight: 700; text-align: right; }
.mbal-r { margin-top: 8px; }
/* il nome si accorcia coi puntini: prima i nomi lunghi spingevano gli importi fuori dal riquadro sul telefono */
.mbal-r .n { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.mbal-r .n .dot { margin-right: 6px; vertical-align: -1px; }
.mbal-r .diff { text-align: right; font-size: 1rem; }
.mbal-d { margin: 0 0 0 20px; font-size: .8rem; }
.mbal-fund { border-top: 1px solid var(--border); padding-top: 8px; }

/* ---- righe dei movimenti ---- */
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border);
  border-left: 5px solid var(--uc, var(--border)); border-radius: 14px; background: var(--card); color: var(--text); text-decoration: none;
}
a.item:active, .rowlink:active { opacity: .7; }
.item .ic { flex: none; width: 1.6rem; font-size: 1.2rem; line-height: 1.5rem; text-align: center; }
.item .main { flex: 1; min-width: 0; }
.item .line { display: flex; align-items: baseline; gap: 8px; }
.item .tit { flex: 1; min-width: 0; font-weight: 700; line-height: 1.3; overflow-wrap: break-word; }
.item .amt { flex: none; font-weight: 800; white-space: nowrap; }
.amt.out { color: var(--danger); }
.amt.in { color: var(--plus); }
.meta { font-size: .82rem; line-height: 1.35; color: var(--muted); margin-top: 2px; overflow-wrap: break-word; }
.withdel { padding: 0; align-items: stretch; gap: 0; }
.withdel .rowlink { flex: 1; min-width: 0; display: flex; align-items: flex-start; gap: 10px; padding: 10px 4px 10px 12px; color: inherit; text-decoration: none; }
.trash { flex: none; align-self: center; min-width: 40px; min-height: 40px; margin-right: 4px; border: 0; border-radius: 10px; background: none; font: inherit; font-size: 1.05rem; cursor: pointer; color: var(--text); }
.trash.armed { background: var(--danger); color: #fff; min-width: 64px; font-size: .8rem; font-weight: 800; }

/* ---- moduli ---- */
form { display: flex; flex-direction: column; }
.label { font-weight: 700; margin: 14px 2px 6px; }
input[type=text], input[type=date], input[type=password], input[type=number], select {
  width: 100%; font: inherit; font-size: 18px; padding: 12px 14px; border-radius: 14px;
  border: 2px solid var(--border); background: var(--field); color: var(--text);
}
input:focus, select:focus { outline: none; border-color: #3E9BDB; }
.amount { font-size: 28px !important; font-weight: 800; text-align: center; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border-radius: 999px; border: 2px solid var(--border); background: var(--card); color: var(--text);
  font: inherit; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.chip.on { background: #FFD84D; border-color: #D4A91A; color: #2a2100; }
.chip .dot { margin-right: 6px; vertical-align: -1px; }
.check { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 2px solid var(--border); border-radius: 14px; background: var(--card); font-weight: 700; cursor: pointer; }
.check input { width: 24px; height: 24px; margin: 0; accent-color: #3FB56E; }
.split-note { margin-top: 8px; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--bg); border-top: 1px solid var(--border);
}
.savebar .btn { max-width: 608px; margin: 0 auto; }

/* ---- accesso ---- */
.login { max-width: 420px; margin: 0 auto; width: 100%; padding-top: 10vh; }
.login h1 { text-align: center; font-size: 1.6rem; }
.login .logo { display: block; width: 72px; height: 72px; margin: 0 auto 10px; }
.pin { letter-spacing: .35em; text-align: center; font-size: 26px !important; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%) translateY(20px);
  background: #111; color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 700; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 50; max-width: 90vw; text-align: center;
}
:root[data-theme="scuro"] .toast { background: #fff; color: #111; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.menu-row { display: flex; align-items: center; gap: 12px; padding: 14px 4px; border-top: 1px solid var(--border); color: var(--text); text-decoration: none; }
.menu-row:first-of-type { border-top: 0; }
.menu-row .bd { flex: 1; }
.theme2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.theme-opt { padding: 18px 10px; border-radius: 16px; border: 3px solid var(--border); font: inherit; font-weight: 800; font-size: 1.1rem; cursor: pointer; }
.theme-opt.t-chiaro { background: #fff; color: #111; }
.theme-opt.t-scuro { background: #1c2029; color: #fff; }
/* «scritte nere/bianche» del colore del tasto, non del tema attivo (prima: grigio chiaro su bianco nel tema scuro) */
.theme-opt .soft { color: inherit; opacity: .8; }
.theme-opt.on { border-color: #3FB56E; box-shadow: 0 0 0 3px #7BE0A0; }

/* sola lettura: chi non l'ha registrata (e non è l'amministratore) vede ma non modifica */
.ro { border: 2px dashed var(--border); }
input:disabled, select:disabled, .chip:disabled, .check input:disabled { opacity: .75; cursor: default; }

/* casse con scadenza settimanale (0.1.3): obiettivo, a chi tocca, tasto per versare */
.goal { margin-top: 8px; font-size: .98rem; line-height: 1.4; }
.goal-btn { margin-top: 10px !important; }
.evrow.wrap { flex-wrap: wrap; }
.fundbtns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

/* fatture e documenti (0.1.3) */
.files .frow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 8px 0; border-top: 1px solid var(--border); }
.files .frow:first-child { border-top: 0; }
.files .frow .sub { flex-basis: 100%; }
.files .fname { flex: 1; min-width: 0; font-weight: 700; color: var(--text); overflow-wrap: anywhere; }
.files .flink { flex-basis: 100%; font-weight: 700; color: var(--text); }
.files .up { display: inline-flex; margin-top: 10px; }
.files.busy { opacity: .6; pointer-events: none; }
.inv { color: var(--text); font-weight: 700; }
.alert { border: 2px solid var(--danger); }
.acts2 { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.chip.big { font-size: 1.2rem; padding: 12px 20px; }
.quick { margin-top: 10px; }
.rulebox { margin: 8px 0; }
.rule { margin-bottom: 8px; }
textarea.code { width: 100%; margin-top: 10px; font: 16px/1.4 ui-monospace, Menlo, monospace; padding: 10px; border-radius: 12px;
  border: 2px solid var(--border); background: var(--field); color: var(--text); }
.tok { font-family: ui-monospace, Menlo, monospace; overflow-wrap: anywhere; color: var(--text); }

/* scontrini letti (0.1.4) */
.rcp .up { display: inline-flex; width: auto; }
.rcp.busy { opacity: .7; pointer-events: none; }
.rcp-body > .nm { margin-top: 12px; }
.rline { padding: 10px 0; border-top: 1px solid var(--border); }
.rline .bd { display: flex; align-items: baseline; gap: 10px; }
.rline .tit { flex: 1; min-width: 0; font-weight: 700; overflow-wrap: anywhere; }
.rline .amt { flex: none; font-weight: 800; white-space: nowrap; }
.rline .chips { margin-top: 8px; }
.chip.on.mine { background: #7CCBFF; border-color: #3E9BDB; color: #062a45; }
.ro-line .tit { font-weight: 600; }
.rsum { margin: 12px 0 6px; font-size: 1.05rem; }
