:root {
  --carta: #f6f2ea;
  --card: #fffdf8;
  --inchiostro: #1d2622;
  --muto: #6b726d;
  --linea: #e4ddcf;
  --bosco: #1f3a34;
  --bosco-chiaro: #2d5249;
  --cotto: #c4572e;
  --cotto-chiaro: #fbe9e1;
  --verde: #2f7a4f;
  --rosso: #b23a2b;
  --ambra: #f4e3b5;
  --r: 14px;
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --carta: #151a18; --card: #1d2421; --inchiostro: #ece7dc; --muto: #9aa29c; --linea: #2f3934;
    --bosco: #a7d3c2; --bosco-chiaro: #8cc2ae; --cotto: #e88a63; --cotto-chiaro: #3a2620;
    --verde: #7fcf9d; --rosso: #f08a7a; --ambra: #3d3420;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--carta); color: var(--inchiostro);
  font: 15px/1.5 var(--sans); padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
a { color: var(--bosco); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; }
h1 { font-size: 1.6rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 1.8rem 0 .6rem; display: flex; align-items: baseline; gap: .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
main { max-width: 860px; margin: 0 auto; padding: 1rem 16px 2rem; }

.top {
  display: flex; justify-content: space-between; align-items: center;
  padding: .8rem 16px; padding-top: calc(.8rem + env(safe-area-inset-top));
  background: var(--bosco); color: #f6f2ea;
}
@media (prefers-color-scheme: dark) { .top { background: #10221d; } }
.marchio { font-family: var(--serif); font-size: 1.25rem; color: inherit; text-decoration: none; }
.utente { display: flex; gap: .8rem; align-items: center; font-size: .9rem; }
.utente a, .utente .link { color: #f6f2ea; opacity: .85; }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around; background: var(--card);
  border-top: 1px solid var(--linea); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; text-align: center; text-decoration: none; color: var(--muto);
  font-size: .7rem; padding: .45rem 0 .5rem; display: flex; flex-direction: column; align-items: center;
}
.tabs a span { font-size: 1.25rem; line-height: 1.3; }
.tabs a.on { color: var(--cotto); font-weight: 600; }
@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .tabs { position: static; justify-content: center; gap: .3rem; border-top: 0; border-bottom: 1px solid var(--linea); }
  .tabs a { flex: 0 0 auto; flex-direction: row; gap: .35rem; font-size: .9rem; padding: .7rem 1rem; }
  .tabs a span { font-size: 1rem; }
  .tabs a.on { box-shadow: inset 0 -2px 0 var(--cotto); }
}

.card {
  background: var(--card); border: 1px solid var(--linea); border-radius: var(--r);
  padding: 1rem; margin-bottom: .8rem;
}
.card.stretta { max-width: 420px; }
details.card > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: .8rem; }

.hero {
  background: var(--bosco); color: #f6f2ea; border-radius: var(--r); padding: 1.2rem;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1rem;
}
@media (prefers-color-scheme: dark) { .hero { background: #1b3730; } }
.hero .label { opacity: .8; font-size: .85rem; }
.big { font-family: var(--serif); font-size: 2.2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.hero .big.neg { color: #ffb4a1; }
.azioni-rapide { display: flex; flex-wrap: wrap; gap: .5rem; }
.hero .btn { background: rgba(255,255,255,.12); color: #f6f2ea; border-color: rgba(255,255,255,.25); }
.hero .btn.primario { background: var(--cotto); border-color: var(--cotto); color: #fff; }

.btn {
  display: inline-block; font: 600 .92rem var(--sans); padding: .6rem 1rem; border-radius: 10px;
  border: 1px solid var(--linea); background: var(--card); color: var(--inchiostro);
  text-decoration: none; cursor: pointer;
}
.btn.primario { background: var(--cotto); color: #fff; border-color: var(--cotto); }
.btn.pericolo { color: var(--rosso); border-color: var(--rosso); background: transparent; }
button.link { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: underline; color: inherit; }
.mini { font: 500 .8rem var(--sans); color: var(--cotto); }

form label { display: block; font-size: .85rem; font-weight: 500; color: var(--muto); margin-bottom: .75rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .25rem; font: 16px var(--sans); color: var(--inchiostro);
  padding: .6rem .7rem; border: 1px solid var(--linea); border-radius: 10px; background: var(--carta);
}
input[type=checkbox], input[type=radio] { display: inline; width: auto; margin: 0 .4rem 0 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--cotto); outline-offset: 0; border-color: transparent; }
fieldset { border: 1px solid var(--linea); border-radius: 10px; margin: 0 0 .75rem; padding: .5rem .8rem .2rem; }
legend { font-size: .85rem; color: var(--muto); padding: 0 .3rem; }
fieldset label { display: inline-flex; align-items: center; margin-right: 1.2rem; color: var(--inchiostro); font-size: .95rem; }
.due { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
@media (max-width: 480px) { .due { grid-template-columns: 1fr; } }

.flash { padding: .7rem 1rem; border-radius: 10px; margin-bottom: .8rem; font-size: .9rem; }
.flash.ok { background: #e3f2e8; color: #1f5a37; }
.flash.errore { background: var(--cotto-chiaro); color: var(--rosso); }
@media (prefers-color-scheme: dark) { .flash.ok { background: #1d3527; color: var(--verde); } }

.muted { color: var(--muto); }
.nota { color: var(--muto); font-size: .85rem; }
.pos { color: var(--verde); }
.neg { color: var(--rosso); }
.chip {
  display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 99px;
  background: var(--carta); border: 1px solid var(--linea); color: var(--muto); margin-right: .3rem;
}

.lista { display: flex; flex-direction: column; gap: .5rem; }
.riga {
  display: flex; align-items: center; gap: .8rem; padding: .75rem .9rem; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--linea); border-radius: 12px; border-left: 4px solid var(--linea);
}
.riga-main { flex: 1; min-width: 0; text-decoration: none; color: inherit; }
.riga-titolo { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.riga-meta { font-size: .8rem; color: var(--muto); margin-top: .15rem; }
.riga-desc { font-size: .85rem; margin-top: .3rem; }
.riga-importo { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mov-spesa { border-left-color: var(--cotto); }
.mov-versamento { border-left-color: var(--verde); }
.mov-rimborso { border-left-color: #6b7fb3; }
.mov-prelievo { border-left-color: #a08a4a; }
.riga.da-pagare { background: var(--ambra); }
.urgente .riga { outline: 2px solid var(--rosso); }

.pareggio { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; padding: .45rem 0; border-bottom: 1px dashed var(--linea); }
.pareggio:last-of-type { border-bottom: 0; }
.pareggio > span:first-child { flex: 1; }
.importo { font-weight: 600; font-variant-numeric: tabular-nums; }
.dettaglio { margin-top: .6rem; }
.dettaglio summary { cursor: pointer; color: var(--muto); font-size: .85rem; }

.tab { width: 100%; border-collapse: collapse; margin: .5rem 0; font-size: .92rem; }
.tab th, .tab td { padding: .4rem .3rem; border-bottom: 1px solid var(--linea); text-align: left; }
.tab th { font-weight: 500; color: var(--muto); font-size: .78rem; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }

.segmenti { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; margin-bottom: .6rem; scrollbar-width: none; }
.segmenti a {
  flex: 0 0 auto; text-decoration: none; font-size: .85rem; padding: .4rem .8rem; border-radius: 99px;
  border: 1px solid var(--linea); color: var(--inchiostro); background: var(--card);
}
.segmenti a.on { background: var(--bosco); color: var(--carta); border-color: var(--bosco); }

.filtri { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .8rem; }
.filtri select, .filtri input { width: auto; margin: 0; padding: .45rem .6rem; font-size: .9rem; }
.titolo-azioni { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.totale { text-align: right; color: var(--muto); font-size: .85rem; }
.indietro { display: inline-block; font-size: .85rem; margin-bottom: .5rem; text-decoration: none; }

.griglia { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.utenza { text-decoration: none; color: inherit; margin: 0; display: block; }
.utenza.spenta { opacity: .55; }
.ut-tipo { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--cotto); }
.ut-forn { font-family: var(--serif); font-size: 1.2rem; margin: .1rem 0; }
.ut-foot { font-size: .8rem; margin-top: .6rem; color: var(--muto); }

.dettaglio-mov h1 { margin: .5rem 0 .3rem; }
.dettaglio-mov .big { margin-bottom: .6rem; }
.stato-da-pagare { display: inline-block; background: var(--ambra); padding: .25rem .7rem; border-radius: 8px; font-weight: 600; font-size: .85rem; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 1rem 0; font-size: .92rem; }
dt { color: var(--muto); }
dd { margin: 0; }

.login { max-width: 360px; margin: 10vh auto 0; text-align: center; }
.login h1 { margin: .6rem 0 .2rem; }
.login form { text-align: left; margin-top: 1.4rem; }
.login .btn { width: 100%; }
