/* Lo standard delle app finanziarie, fatto bene: iOS nativo, liste raggruppate, caratteri di sistema.
   Un accento blu solo per cio' che si tocca. Un solo rosso: saldi e totali negativi, stato "In rosso", errori. */

:root {
  --sfondo: #f2f2f7;
  --cella: #ffffff;
  --cella-premuta: #e5e5ea;
  --separatore: #d8d8dc;
  --testo: #000000;
  --secondario: #6c6c70;
  --terziario: #8e8e93;
  --accento: #0060d0;
  --accento-tenue: #e5efff;
  --accento-pieno: #0060d0;   /* fondo dei pulsanti pieni: testo bianco almeno 4,5:1 */
  --rosso: #d70015;
  --rosso-tenue: #ffe5e7;
  --neutro-tenue: #e9e9ee;
  --traccia: #e5e5ea;
  --barra-schede: rgb(249 249 249 / .94);
  --f: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --f-titolo: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --raggio: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sfondo: #000000; --cella: #1c1c1e; --cella-premuta: #2c2c2e; --separatore: #38383a;
    --testo: #ffffff; --secondario: #a1a1a8; --terziario: #8e8e93;
    --accento: #3b95ff; --accento-tenue: #0c2747; --accento-pieno: #1667d9; --rosso: #ff5c52; --rosso-tenue: #3b1512;
    --neutro-tenue: #2c2c2e; --traccia: #2c2c2e; --barra-schede: rgb(22 22 24 / .94);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --sfondo: #000000; --cella: #1c1c1e; --cella-premuta: #2c2c2e; --separatore: #38383a;
  --testo: #ffffff; --secondario: #a1a1a8; --terziario: #8e8e93;
  --accento: #3b95ff; --accento-tenue: #0c2747; --accento-pieno: #1667d9; --rosso: #ff5c52; --rosso-tenue: #3b1512;
  --neutro-tenue: #2c2c2e; --traccia: #2c2c2e; --barra-schede: rgb(22 22 24 / .94);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--sfondo);
  color: var(--testo);
  font: 400 17px/1.35 var(--f);
  font-variant-numeric: tabular-nums;
  caret-color: var(--accento);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
::selection { background: color-mix(in srgb, var(--accento) 25%, transparent); }
* { scrollbar-width: thin; scrollbar-color: var(--separatore) transparent; }
:focus-visible { outline: 2px solid var(--accento); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.visivo-nascosto { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
p { margin: 0; }
.secondario { color: var(--secondario); font-size: 15px; }
.piccolo { font-size: 13px; }
.accento { color: var(--accento); }
.negativo, .neg { color: var(--rosso); }
.errore { margin-top: 12px; color: var(--rosso); font-size: 15px; min-height: 1.3em; }

.app {
  max-width: 640px; margin: 0 auto;
  padding: env(safe-area-inset-top) 16px calc(96px + env(safe-area-inset-bottom));
}

/* Titolo grande, come nelle app di sistema */
.titolo-grande { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 20px 4px 8px; }
.titolo-grande + .gruppo, .titolo-grande + .filtri { margin-top: 20px; }
.titolo-grande h1 { margin: 0; font: 700 34px/1.1 var(--f-titolo); letter-spacing: -.02em; }

/* Il numero in evidenza */
.saldo { padding: 12px 4px 24px; }
.saldo-riga { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 4px 0 8px; }
.saldo-cifra { font: 600 52px/1.05 var(--f-titolo); letter-spacing: -.03em; }
.saldo-cifra .decimali { font-size: .5em; letter-spacing: -.01em; color: inherit; }
.saldo .secondario + .secondario { margin-top: 2px; }
.capsula {
  display: inline-flex; align-items: center; height: 26px; padding: 0 10px; border-radius: 13px;
  font-size: 13px; font-weight: 600; color: var(--secondario); background: var(--neutro-tenue);
}
.capsula[data-stato="rosso"] { color: var(--rosso); background: var(--rosso-tenue); }
.capsula[data-stato="regola"] { color: var(--accento); background: var(--accento-tenue); }

/* Liste raggruppate */
.gruppo { margin: 0 0 28px; }
.gruppo-titolo { margin: 0 0 6px; padding: 0 16px; font-size: 13px; font-weight: 400; color: var(--secondario); }
.gruppo-nota { margin: 6px 0 0; padding: 0 16px; font-size: 13px; color: var(--secondario); }
.lista { list-style: none; margin: 0; padding: 0; background: var(--cella); border-radius: var(--raggio); overflow: hidden; }
.lista > li { position: relative; }
.lista > li + li::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; height: 1px;
  background: var(--separatore); transform: scaleY(.5); transform-origin: top;
}
.riga {
  display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 44px; padding: 11px 16px; margin: 0; border: 0;
  background: transparent; color: inherit; font: inherit; text-align: left; text-decoration: none;
}
.collegamento { cursor: pointer; }
.collegamento:active, .voce:active { background: var(--cella-premuta); }
@media (hover: hover) { .collegamento:hover, .voce:hover { background: color-mix(in srgb, var(--cella-premuta) 55%, var(--cella)); } }
.riga-testo { flex: 1; min-width: 0; display: grid; gap: 1px; }
.riga-titolo { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.riga-sotto { font-size: 13px; color: var(--secondario); }
/* nei movimenti una riga sola, con i puntini: il nome intero e' nella rettifica */
.voce .riga-titolo, .voce .riga-sotto { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riga-valore { flex: none; text-align: right; white-space: nowrap; }
.riga-valore.forte, .riga.totale .riga-valore { font-weight: 600; }
.riga.totale .riga-titolo { font-weight: 600; }
.freccia { flex: none; width: 16px; height: 16px; fill: none; stroke: var(--terziario); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.lista .vuoto { padding: 12px 16px; color: var(--secondario); font-size: 15px; }

/* Spese per categoria: la quota come barra sottile sotto la riga */
.voce-categoria { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 11px 16px 12px; cursor: pointer; }
.voce-categoria .traccia { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--traccia); overflow: hidden; }
.voce-categoria .pieno { display: block; height: 100%; border-radius: 2px; background: var(--accento); }

/* Tabella mese per mese: densa, in una cella */
.tabella-contenitore { background: var(--cella); border-radius: var(--raggio); overflow: hidden; }
.tabella { width: 100%; border-collapse: collapse; font-size: 15px; table-layout: fixed; }
.tabella th { padding: 10px 16px 6px; font-size: 13px; font-weight: 400; color: var(--secondario); text-align: right; }
.tabella td { padding: 10px 16px; text-align: right; white-space: nowrap; border-top: .5px solid var(--separatore); }
.tabella th:first-child, .tabella td:first-child { text-align: left; }
.tabella td:first-child { text-transform: capitalize; }
.tabella .vuoto { text-align: left; color: var(--secondario); }

/* Avvisi */
#note .riga { align-items: flex-start; }
#note .riga-testo { gap: 3px; }
#note .riga-titolo { white-space: normal; font-weight: 600; }
#note .riga-sotto { white-space: normal; font-size: 15px; }
#note .pulsante { margin-top: 8px; justify-self: start; }

/* Movimenti: raggruppati per giorno */
.filtri { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 20px; }
select {
  width: 100%; min-height: 36px; padding: 6px 30px 6px 12px; border: 0; border-radius: 10px;
  font: 500 15px var(--f); color: var(--testo); background-color: var(--cella);
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--secondario) 50%), linear-gradient(135deg, var(--secondario) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
.registro .giorno { margin: 0 0 24px; }
.registro .giorno-titolo { margin: 0 0 6px; padding: 0 16px; font-size: 13px; font-weight: 400; color: var(--secondario); }
.giorno-titolo::first-letter { text-transform: uppercase; }
.voce { cursor: pointer; }
.voce .riga-valore { font-weight: 500; }
.voce.giroconto .riga-titolo, .voce.giroconto .riga-valore { color: var(--secondario); }
.voce[aria-expanded="true"] { background: var(--cella-premuta); }

/* Rettifica: si apre sotto la riga */
.rettifica {
  display: grid; gap: 12px; padding: 12px 16px 16px; background: var(--cella);
  border-top: .5px solid var(--separatore);
  animation: piega 200ms cubic-bezier(.16, 1, .3, 1);
}
@keyframes piega { from { clip-path: inset(0 0 100% 0); } to { clip-path: inset(0); } }
@media (prefers-reduced-motion: reduce) { .rettifica { animation: none; } }
.rettifica-nome { overflow-wrap: anywhere; }
.rettifica:focus { outline: none; }
.rettifica select { background-color: var(--sfondo); }
.campo { display: grid; gap: 4px; }
.interruttore { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: 15px; cursor: pointer; }
.interruttore input {
  flex: none; appearance: none; -webkit-appearance: none; margin: 0; position: relative;
  width: 51px; height: 31px; border-radius: 16px; background: var(--traccia); cursor: pointer;
  transition: background-color .2s;
}
.interruttore input::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgb(0 0 0 / .15), 0 1px 1px rgb(0 0 0 / .16);
  transition: transform .2s cubic-bezier(.16, 1, .3, 1);
}
.interruttore input:checked { background: var(--accento-pieno); }
.interruttore input:checked::after { transform: translateX(20px); }
@media (prefers-reduced-motion: reduce) { .interruttore input, .interruttore input::after { transition: none; } }
.azioni { display: flex; justify-content: flex-end; gap: 8px; }

.pulsante {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 18px; border: 0; border-radius: 12px;
  font: 600 16px var(--f); cursor: pointer;
}
.pulsante.primario { background: var(--accento-pieno); color: #fff; }
.pulsante.secondario-pulsante { background: var(--accento-tenue); color: var(--accento); }
.pulsante:disabled { opacity: .5; cursor: progress; }
#altri { width: 100%; margin-top: 4px; }

.avviso-rete {
  margin: 12px 0 0; padding: 10px 14px; border-radius: var(--raggio);
  background: var(--cella); color: var(--secondario); font-size: 15px;
}

/* Accesso */
.accesso { display: grid; gap: 14px; max-width: 360px; margin: 0 auto; padding-top: 18vh; text-align: center; }
.accesso-icona { justify-self: center; border-radius: 16px; }
.accesso h1 { margin: 0; font: 700 28px/1.1 var(--f-titolo); }
.accesso input[type="password"] {
  width: 100%; min-height: 48px; padding: 0 14px; border: 0; border-radius: 12px;
  font: 400 17px var(--f); color: var(--testo); background: var(--cella);
}

/* Titolo compatto: compare quando il titolo grande esce dallo schermo, come nelle app di iOS */
.barra-compatta {
  position: fixed; top: 0; left: 0; right: 0; z-index: 9;
  display: grid; place-items: center; height: calc(44px + env(safe-area-inset-top)); padding-top: env(safe-area-inset-top);
  font-size: 17px; font-weight: 600;
  background: var(--barra-schede);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--separatore);
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.barra-compatta.visibile { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .barra-compatta { transition: none; } }

/* Schermata interna: il ritorno in alto a sinistra, come nelle app di iOS */
.indietro { display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 12px 0 0; color: var(--accento); text-decoration: none; font-size: 17px; }
.indietro svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* Grafico del saldo previsto */
.grafico-contenitore { background: var(--cella); border-radius: var(--raggio); padding: 12px 8px 8px; }
.grafico { display: block; width: 100%; height: 180px; overflow: visible; }
.grafico .linea { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.grafico .sopra { stroke: var(--accento); }
.grafico .sotto { stroke: var(--rosso); }
.grafico .zero { stroke: var(--separatore); stroke-width: 1; stroke-dasharray: 3 3; }
.grafico .tacca { stroke: var(--separatore); stroke-width: 1; }
.grafico text { font: 11px var(--f); fill: var(--secondario); }
.giorno-titolo { display: flex; justify-content: space-between; gap: 12px; }
.giorno-titolo .saldo-giorno { font-variant-numeric: tabular-nums; }
.riga.interruttore { cursor: pointer; }
.riga.interruttore input { margin-left: auto; }

/* Controllo a segmenti, come in iOS */
.segmenti { display: grid; grid-auto-columns: 1fr; grid-auto-flow: column; gap: 2px; margin: 4px 0 20px; padding: 2px;
  background: var(--neutro-tenue); border-radius: 9px; }
.segmenti button { min-height: 32px; border: 0; border-radius: 7px; background: transparent; color: var(--testo);
  font: 500 14px var(--f); cursor: pointer; }
.segmenti button[aria-selected="true"], .segmenti button[aria-checked="true"] {
  background: var(--cella); font-weight: 600; box-shadow: 0 3px 8px rgb(0 0 0 / .12), 0 1px 1px rgb(0 0 0 / .04); }
.segmenti.piccoli { margin-top: 0; }
.spazio-sopra { margin-top: 8px; }
.grafico .barra { fill: var(--accento); }
.grafico .barra.parziale { fill: var(--traccia); }
.grafico .media { stroke: var(--secondario); stroke-width: 1; stroke-dasharray: 4 3; }

/* Barra delle schede */
.schede {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px max(8px, calc((100% - 640px) / 2)) env(safe-area-inset-bottom);
  background: var(--barra-schede);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--separatore);
}
.schede a {
  position: relative; display: grid; justify-items: center; gap: 2px;
  min-height: 49px; padding: 2px 0 4px; text-decoration: none;
  font-size: 11px; font-weight: 500; color: var(--secondario);
}
.schede svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.schede a[aria-current="page"] { color: var(--accento); }
.contatore {
  position: absolute; top: 0; left: calc(50% + 6px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  font-size: 12px; font-weight: 600; line-height: 18px; text-align: center; color: #fff; background: var(--rosso);
}
