/* ---------- Temi ----------
   Ogni tema definisce lo stesso set di variabili colore.
   Il tema attivo è deciso da app.js e scritto come attributo data-theme
   sull'elemento <html> (già impostato da uno script in index.html prima
   che la pagina si disegni, per evitare un lampo del tema sbagliato). */

:root, [data-theme="verde"] {
  --ink: #1E1D1B;
  --ink-rgb: 30, 29, 27;
  --muted: #6B6862;
  --faint: #A6A39B;
  --bg: #F6F5F2;
  --surface: #FFFFFF;
  --surface-2: #F6F5F2;
  --border: #E4E2DC;
  --divider: #F0EFEA;
  --accent: #1F6F5C;
  --accent-rgb: 31, 111, 92;
  --accent-ink: #FAFAF8;
  --negative: #B3413A;
  --negative-rgb: 179, 65, 58;
  --warn: #B08900;
  --warn-rgb: 176, 137, 0;
  --warn-ink: #7A5F00;
  --header-bg: var(--accent);
  --header-fg: #FAFAF8;
  --header-fg-rgb: 250, 250, 248;
}

[data-theme="blu"] {
  --ink: #1B2530;
  --ink-rgb: 27, 37, 48;
  --muted: #5C6B7A;
  --faint: #9DA9B5;
  --bg: #F2F5F8;
  --surface: #FFFFFF;
  --surface-2: #F2F5F8;
  --border: #DDE4EB;
  --divider: #E9EEF2;
  --accent: #1A5DA6;
  --accent-rgb: 26, 93, 166;
  --accent-ink: #FAFBFC;
  --negative: #B3413A;
  --negative-rgb: 179, 65, 58;
  --warn: #A6791F;
  --warn-rgb: 166, 121, 31;
  --warn-ink: #6B5115;
  --header-bg: var(--accent);
  --header-fg: #FAFBFC;
  --header-fg-rgb: 250, 251, 252;
}

[data-theme="scuro"] {
  --ink: #F2F1ED;
  --ink-rgb: 242, 241, 237;
  --muted: #A6A29A;
  --faint: #726E66;
  --bg: #16191A;
  --surface: #1F2325;
  --surface-2: #242829;
  --border: #33393B;
  --divider: #2B3032;
  --accent: #33A382;
  --accent-rgb: 51, 163, 130;
  --accent-ink: #0F1613;
  --negative: #E2685B;
  --negative-rgb: 226, 104, 91;
  --warn: #B98424;
  --warn-rgb: 185, 132, 36;
  --warn-ink: #F0D28E;
  --header-bg: #20262A;
  --header-fg: #F2F1ED;
  --header-fg-rgb: 242, 241, 237;
}

[data-theme="minimal"] {
  --ink: #1A1A1A;
  --ink-rgb: 26, 26, 26;
  --muted: #6E6E6E;
  --faint: #A8A8A8;
  --bg: #FAFAF9;
  --surface: #FFFFFF;
  --surface-2: #F3F3F2;
  --border: #E3E2E0;
  --divider: #ECEBE9;
  --accent: #3B5B52;
  --accent-rgb: 59, 91, 82;
  --accent-ink: #FFFFFF;
  /* niente rosso/ambra: in questo tema il segno + / - basta a distinguere entrate e uscite */
  --negative: var(--ink);
  --negative-rgb: 26, 26, 26;
  --warn: var(--ink);
  --warn-rgb: 26, 26, 26;
  --warn-ink: var(--muted);
  --header-bg: var(--surface-2);
  --header-fg: var(--ink);
  --header-fg-rgb: 26, 26, 26;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Public Sans', sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
h1, h2 { font-family: 'Fraunces', serif; margin: 0; }
input, select, button { font-family: 'Public Sans', sans-serif; }
input, select { font-size: 16px; color: var(--ink); background: var(--surface); } /* evita lo zoom automatico su iOS */
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
a { color: var(--accent); }
button { touch-action: manipulation; }

.page {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: 20px 14px calc(64px + env(safe-area-inset-bottom));
  padding-top: calc(20px + env(safe-area-inset-top));
}
.wrap {
  width: 100%;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.section-title { font-size: 18px; font-weight: 600; }
.muted { color: var(--muted); }
.form-box {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 14px;
  background: var(--surface-2);
  border-radius: 12px;
}
.text-input, select.text-input {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 15px;
  background: var(--surface);
  color: var(--ink);
}
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-dark { background: var(--ink); color: var(--bg); }
.btn-ghost { background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); }
.btn-link { background: none; border: none; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; font-size: 12px; }
.icon-btn { background: none; border: none; cursor: pointer; padding: 4px; color: var(--faint); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.list-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--divider); }
.bar-track { flex-grow: 1; height: 10px; background: var(--divider); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; }
.avatar { border-radius: 50%; color: #fff; font-weight: 600; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.badge { font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 20px; }
.grid-fit { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }

/* selettore tema */
.theme-swatch { width: 34px; height: 34px; border-radius: 50%; cursor: pointer; padding: 0; flex-shrink: 0; position: relative; }
.theme-swatch svg { position: absolute; inset: 0; margin: auto; }

/* finestra impostazioni (Aspetto, Backup, Reimposta) */
.settings-link {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  background: none; border: none; cursor: pointer; padding: 10px; margin: 0 auto;
  font-size: 13px; color: var(--muted);
}
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
  padding: 0;
}
.modal-panel {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 88vh;
  overflow-y: auto; border-radius: 18px 18px 0 0; padding: 18px 14px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 18px;
}
@media (min-width: 760px) {
  .modal-backdrop { align-items: center; }
  .modal-panel { border-radius: 18px; max-height: 80vh; }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }

@media print {
  button { display: none !important; }
  body { background: #FFFFFF; color: #1E1D1B; }
}
