/* Valori da DESIGN.md */
:root {
  color-scheme: light dark;
  --bg: #F6F5F1; --surface: #FFFFFF; --surface-2: #EEEDE7;
  --text: #1C1B19; --text-2: #5E5B55; --border: #E3E0D8; --border-campo: #8E8A80;
  --primary: #0F6B5C; --on-primary: #FFFFFF;
  --ok: #1E7A46; --warn: #8A5300; --bad: #B3261E;
  --ok-fill: #2E9E5B; --warn-fill: #E0A100; --bad-fill: #D93A2F;
  --shadow: 0 4px 16px rgb(0 0 0 / 0.08);

  --fs-hero: 56px; --fs-xl: 28px; --fs-lg: 20px; --fs-md: 17px; --fs-sm: 15px; --fs-xs: 13px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  --r-sm: 8px; --r-md: 14px; --r-pill: 999px;
  --tocco: 48px;
  --larghezza: 560px;
  --nav-h: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121311; --surface: #1C1D1B; --surface-2: #262724;
    --text: #EDEBE6; --text-2: #A9A59C; --border: #2E2F2C; --border-campo: #77736A;
    --primary: #4FC1A6; --on-primary: #0B1F1A;
    --ok: #5BCB8A; --warn: #F2C04B; --bad: #FF7A6E;
    --ok-fill: #5BCB8A; --warn-fill: #F2C04B; --bad-fill: #FF7A6E;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 var(--fs-md)/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
.cifra, .hero-numero, input[inputmode="decimal"] { font-variant-numeric: tabular-nums; }

main {
  max-width: var(--larghezza);
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + var(--s4)) var(--s4) calc(var(--nav-h) + env(safe-area-inset-bottom) + 96px);
}

h1 { font-size: var(--fs-xl); line-height: 1.15; margin: var(--s2) 0 var(--s4); }
h2 { font-size: var(--fs-lg); line-height: 1.25; margin: 0 0 var(--s3); font-weight: 600; }
p { margin: 0 0 var(--s3); }
.sotto { color: var(--text-2); font-size: var(--fs-sm); }
.piccolo { font-size: var(--fs-xs); color: var(--text-2); }

/* Schede e avvisi */
.scheda {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s4);
  margin-bottom: var(--s4);
}
.avviso { border-left: 4px solid var(--warn-fill); }
.avviso.rosso { border-left-color: var(--bad-fill); }
.avviso.info { border-left-color: var(--primary); }
.avviso strong { display: block; margin-bottom: var(--s1); }

/* Numero di oggi */
.hero { padding: var(--s5) var(--s4); }
.hero-etichetta { color: var(--text-2); font-size: var(--fs-sm); margin: 0; }
.hero-numero { font-size: var(--fs-hero); line-height: 1.05; font-weight: 700; margin: var(--s2) 0; letter-spacing: -0.02em; }
.hero-numero.negativo { color: var(--bad); }

details { margin-top: var(--s3); }
summary { color: var(--primary); cursor: pointer; min-height: var(--tocco); display: flex; align-items: center; font-weight: 600; }
.conto-riga { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.conto-riga:last-child { border-bottom: 0; }
.conto-riga.totale { font-weight: 700; font-size: var(--fs-md); }

/* Pulsanti */
button, .pulsante {
  font: inherit;
  min-height: var(--tocco);
  border: 0;
  border-radius: var(--r-md);
  padding: 0 var(--s4);
  cursor: pointer;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  text-decoration: none;
}
button:active, .pulsante:active { opacity: 0.85; }
button:disabled { opacity: 0.4; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid var(--primary); outline-offset: 2px;
}
.primario { background: var(--primary); color: var(--on-primary); min-height: 52px; width: 100%; }
.discreto { background: transparent; color: var(--primary); padding: 0 var(--s2); }
.pericolo { color: var(--bad); }
.riga-azioni { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s3); }
.riga-azioni > * { flex: 1 1 auto; }

/* Campi */
label { display: block; font-size: var(--fs-sm); color: var(--text-2); margin: var(--s3) 0 var(--s1); }
input, select {
  font: inherit; font-size: var(--fs-md);
  width: 100%; min-height: var(--tocco);
  padding: 0 var(--s3);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-campo); border-radius: var(--r-sm);
}
input[type="checkbox"] { width: auto; min-height: auto; }
.campo-importo { font-size: 40px; font-weight: 700; min-height: 72px; text-align: center; }
.errore { color: var(--bad); font-size: var(--fs-sm); margin-top: var(--s2); min-height: 1.3em; }

/* Segmenti (Bancomat / Carta) */
.segmenti { display: flex; background: var(--surface-2); border-radius: var(--r-pill); padding: var(--s1); margin: var(--s3) 0; }
.segmenti button { flex: 1; border-radius: var(--r-pill); background: transparent; min-height: 44px; font-size: var(--fs-sm); }
.segmenti button[aria-pressed="true"] { background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border); }

/* Griglia categorie */
.griglia { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2); margin: var(--s3) 0; }
.griglia button { min-height: 64px; background: var(--surface); border: 1px solid var(--border); justify-content: flex-start; text-align: left; line-height: 1.2; padding: var(--s2) var(--s3); }
.pallino { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); flex: 0 0 auto; }

/* Budget */
.budget { padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.budget:last-child { border-bottom: 0; }
.budget-testa { display: flex; justify-content: space-between; gap: var(--s2); font-size: var(--fs-sm); margin-bottom: var(--s2); }
.binario { height: 8px; background: var(--surface-2); border-radius: var(--r-pill); overflow: hidden; }
.riempimento { height: 100%; width: 0; background: var(--ok-fill); border-radius: var(--r-pill); }
.attenzione .riempimento { background: var(--warn-fill); }
.superato .riempimento { background: var(--bad-fill); }
.stato { font-size: var(--fs-xs); font-weight: 600; }
.ok .stato { color: var(--ok); }
.attenzione .stato { color: var(--warn); }
.superato .stato { color: var(--bad); }

/* Elenchi */
.elenco { list-style: none; margin: 0; padding: 0; }
.elenco li { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.elenco li:last-child { border-bottom: 0; }
.elenco .principale { flex: 1; min-width: 0; }
.elenco .principale > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.giorno { font-size: var(--fs-xs); color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; margin: var(--s4) 0 0; }
.badge { font-size: var(--fs-xs); background: var(--surface-2); border-radius: var(--r-pill); padding: 2px var(--s2); color: var(--text-2); }
.importo-positivo { color: var(--ok); }

/* Navigazione */
nav.barra {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: var(--shadow);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex; justify-content: center;
}
nav.barra .voci { display: flex; width: 100%; max-width: var(--larghezza); }
nav.barra a {
  flex: 1; min-height: var(--nav-h); display: flex; align-items: center; justify-content: center;
  color: var(--text-2); text-decoration: none; font-size: var(--fs-xs); font-weight: 600;
}
nav.barra a[aria-current="page"] { color: var(--primary); }
.piu {
  position: fixed; right: max(var(--s4), calc(50% - var(--larghezza) / 2 + var(--s4)));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + var(--s4));
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow);
  font-size: 32px; font-weight: 400; display: flex; align-items: center; justify-content: center; text-decoration: none;
}

/* Toast */
.toast {
  position: fixed; left: var(--s4); right: var(--s4); margin: 0 auto; max-width: calc(var(--larghezza) - 2 * var(--s4));
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 88px);
  background: var(--text); color: var(--bg); border-radius: var(--r-md);
  padding: var(--s3) var(--s4); display: flex; align-items: center; justify-content: space-between; gap: var(--s3);
  font-size: var(--fs-sm);
}
.toast button { background: transparent; color: var(--bg); text-decoration: underline; min-height: 44px; padding: 0 var(--s2); }
.nascosto { display: none !important; }

/* Campo ponte: riceve il focus nel tocco su "+" così iOS apre subito la tastiera */
.ponte { position: fixed; top: 0; left: 0; width: 1px; height: 1px; opacity: 0; font-size: 16px; border: 0; padding: 0; pointer-events: none; }
.conto-riga .cifra { white-space: nowrap; text-align: right; }
.spunta { display: flex; align-items: center; gap: var(--s3); min-height: var(--tocco); color: var(--text); font-size: var(--fs-sm); margin: var(--s2) 0; }
.spunta input { width: 22px; height: 22px; flex: 0 0 auto; }
fieldset { border: 0; padding: 0; margin: var(--s3) 0 0; }
legend { padding: 0; margin-bottom: var(--s1); }
