:root {
  --bg: #f4f6fa; --card: #ffffff; --text: #1d2433; --muted: #6b7385; --line: #e3e7ef;
  --brand: #1f2a44; --accent: #2f6fde; --accent-soft: #e6eefc;
  --pos: #2e7d32; --pos-soft: #e8f5e9; --neg: #c62828; --neg-soft: #fdecea; --warn: #b26a00; --warn-soft: #fff4e0;
  --radius: 14px; --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 1px 3px rgb(16 24 40 / .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141f; --card: #182030; --text: #e8ecf4; --muted: #98a2b6; --line: #2a3446;
    --brand: #0b1220; --accent: #6c9cff; --accent-soft: #1f2d4a;
    --pos: #6fcf75; --pos-soft: #183324; --neg: #ff7b72; --neg-soft: #3a1d1d; --warn: #f0b45a; --warn-soft: #3a2c14;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141f; --card: #182030; --text: #e8ecf4; --muted: #98a2b6; --line: #2a3446;
  --brand: #0b1220; --accent: #6c9cff; --accent-soft: #1f2d4a;
  --pos: #6fcf75; --pos-soft: #183324; --neg: #ff7b72; --neg-soft: #3a1d1d; --warn: #f0b45a; --warn-soft: #3a2c14;
  --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  background: var(--brand); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
.logo { font-weight: 700; letter-spacing: .3px; }
main { max-width: 860px; margin: 0 auto; padding: 14px 16px 24px; }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.hero { padding: 16px; margin-bottom: 12px; }
.hero .label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.hero .big { font-size: 32px; font-weight: 700; margin: 2px 0 6px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { padding: 12px; }
.tile .label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.tile .val { font-size: 19px; font-weight: 650; margin-top: 2px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.badge.ok { background: var(--pos-soft); color: var(--pos); }
.badge.ko { background: var(--neg-soft); color: var(--neg); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

.list { overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-bottom: 1px solid var(--line);
  background: transparent; width: 100%; text-align: left; color: inherit; font: inherit; border-left: 0; border-right: 0; border-top: 0;
}
.row:last-child { border-bottom: 0; }
button.row, a.row { cursor: pointer; text-decoration: none; }
button.row:active, a.row:active { background: var(--accent-soft); }
.row .main { flex: 1; min-width: 0; }
.row .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.paid { background: var(--pos-soft); }
.row.entrata { background: var(--pos-soft); }
.row.rimborso { background: var(--warn-soft); }
.row.overdue { background: var(--neg-soft); }
.row.next { background: var(--warn-soft); }
.row.total { font-weight: 650; }
.check { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); background: var(--card); display: grid; place-items: center; flex: none; cursor: pointer; }
.check.on { background: var(--pos); border-color: var(--pos); color: #fff; }
.check svg { width: 16px; height: 16px; fill: currentColor; }

.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer; min-height: 42px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--neg); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 13.5px; }
.btn:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.add { margin: 8px 0 0; width: 100%; border-style: dashed; color: var(--accent); }

.monthbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.monthbar h1 { margin: 0; text-align: center; flex: 1; }
.monthbar .btn { min-width: 44px; }

label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 120px; }
input[type="checkbox"] { width: auto; min-height: 0; }
.inline { display: flex; gap: 8px; align-items: center; }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; }

dialog {
  border: 0; padding: 0; width: min(560px, 100%); max-height: 92vh; border-radius: 18px 18px 0 0;
  margin: auto auto 0; background: var(--card); color: var(--text);
}
@media (min-width: 640px) { dialog { border-radius: 18px; margin: auto; } }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog form { padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); overflow: auto; max-height: 92vh; }
dialog h3 { margin: 0 0 6px; font-size: 18px; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; color: var(--muted); text-decoration: none; font-size: 11px; }
.tabs a svg { width: 24px; height: 24px; fill: currentColor; }
.tabs a.on { color: var(--accent); font-weight: 600; }

.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.catrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.catrow:last-child { border-bottom: 0; }
.catrow .bar { grid-column: 1 / -1; height: 6px; }

.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
tr.click { cursor: pointer; }
tr.click:active { background: var(--accent-soft); }

.tx { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.tx:last-child { border-bottom: 0; }
.tx .head { display: flex; justify-content: space-between; gap: 10px; }
.tx .desc { font-weight: 600; overflow-wrap: anywhere; }
.tx .prop { margin-top: 6px; font-size: 13.5px; }
.tx .actions { margin: 8px 0 0; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2 { display: inline-block; }
details > summary h2::after { content: " ▸"; }
details[open] > summary h2::after { content: " ▾"; }

.login { max-width: 380px; margin: 8vh auto 0; padding: 22px; }
.err { color: var(--neg); font-size: 14px; min-height: 20px; }
#avviso {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px);
}
.empty { padding: 16px; text-align: center; color: var(--muted); }

a.btn { text-decoration: none; display: inline-grid; place-items: center; }

/* intestazione con logo */
.top .logo { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; }
.top .logo img { border-radius: 7px; }
.top .chi { font-size: 12.5px; opacity: .75; }
/* spesa veloce */
.fab {
  position: fixed; right: 16px; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 7; width: 56px; height: 56px;
  border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 28px; line-height: 1;
  box-shadow: 0 4px 14px rgb(0 0 0 / .25); cursor: pointer;
}
.grande { font-size: 30px; font-weight: 700; text-align: center; min-height: 64px; margin: 6px 0 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 7px 12px; border-radius: 999px; border: 1px solid var(--line); font-size: 13.5px; cursor: pointer; background: var(--bg); }
.chip input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
/* foto */
.foto { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.foto .th { position: relative; }
.foto img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.foto .x { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--neg); color: #fff; font-size: 14px; line-height: 22px; padding: 0; cursor: pointer; }
/* grafici */
.grafico { margin: 0; padding: 10px 10px 8px; }
.grafico svg { width: 100%; height: auto; display: block; }
.grafico .gx { font-size: 10px; fill: var(--muted); }
.grafico .gz { stroke: var(--line); stroke-width: 1; }
.grafico .gb { cursor: pointer; }
.grafico .gb.sel rect:nth-child(2) { stroke: var(--text); stroke-width: 1.5; }
.grafico figcaption { margin-top: 4px; }
/* guida */
.guida h2 { margin-top: 26px; }
.guida p, .guida li { line-height: 1.55; }
.guida ol, .guida ul { padding-left: 20px; }
.guida .card { padding: 4px 16px; }
