:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e2e8f0;
  --brand: #0b5563;
  --brand-ink: #ffffff;
  --pos: #0a7d3c;
  --neg: #b91c1c;
  --warn-bg: #fff7ed;
  --warn-line: #fdba74;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .7rem 1.2rem;
  background: var(--brand); color: var(--brand-ink);
}
.topbar .brand { font-weight: 700; color: var(--brand-ink); text-decoration: none; }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a, .topbar nav button { color: var(--brand-ink); text-decoration: none; opacity: .92; }
.topbar nav a:hover, .topbar nav button:hover { opacity: 1; text-decoration: underline; }
.topbar .user { opacity: .8; font-size: .9em; }
/* Il logout e' un form POST con token CSRF: il pulsante va reso identico agli
   altri link della barra. Niente 'font: inherit', che sovrascriverebbe il peso
   impostato subito sotto. */
.topbar nav button {
  background: none; border: 0; padding: 0; cursor: pointer;
  font-family: inherit; font-size: inherit;
}
.topbar .logout-form { display: contents; }
.topbar .logout { font-weight: 600; }

.container { max-width: 1080px; margin: 1.5rem auto; padding: 0 1.2rem; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; }
.muted, .hint { color: var(--muted); }
code { background: #eef2f5; padding: .05rem .3rem; border-radius: 4px; }

/* Card / form */
.card, form.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 1.2rem; max-width: 520px;
}
label { display: block; margin: .6rem 0; font-weight: 600; }
input, select {
  display: block; width: 100%; margin-top: .3rem;
  padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: 7px; font: inherit; background: #fff;
}
input[type=checkbox] { width: auto; display: inline; }
button, .btn-secondary {
  display: inline-block; margin-top: 1rem; padding: .55rem 1.1rem;
  border: 0; border-radius: 8px; font: inherit; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); cursor: pointer;
  text-decoration: none;
}
.btn-secondary { background: #e5eaee; color: var(--ink); }
.hint { font-size: .88em; margin-top: .8rem; }

/* Flash / errori */
.flash {
  background: var(--warn-bg); border: 1px solid var(--warn-line);
  padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem;
}
.error { background: #fef2f2; border: 1px solid #fecaca; color: var(--neg);
  padding: .6rem .8rem; border-radius: 8px; margin: .6rem 0; }
.badge { background: #eef2f5; border-radius: 20px; padding: .1rem .6rem; font-size: .85em; }

/* Tabelle */
table.grid { width: 100%; border-collapse: collapse; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.grid th, table.grid td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; }
table.grid th { background: #f0f4f6; font-size: .85em; text-transform: uppercase; letter-spacing: .02em; color: var(--muted); }
table.grid td input { margin-top: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
input.wide { min-width: 260px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
tr.da-verificare { background: var(--warn-bg); }
tr.giroconto-riga { color: var(--muted); font-style: italic; }
tr.giroconto-riga .num { opacity: .7; }

.actions { display: flex; gap: .8rem; align-items: center; margin-top: 1rem; }

/* Paginazione */
.paginazione { display: flex; gap: 1rem; align-items: center; margin: 1rem 0; color: var(--muted); }
.paginazione a { color: var(--brand); text-decoration: none; font-weight: 600; }
.paginazione a:hover { text-decoration: underline; }

/* Form inline dentro le tabelle (es. riconciliazione) */
form.inline { display: inline-flex; gap: .4rem; align-items: center; margin: 0; }
form.inline select { width: auto; margin: 0; max-width: 420px; }
form.inline button, form.inline .btn-secondary { margin: 0; padding: .35rem .7rem; }

/* Filtri + totali archivio */
.filtri { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1rem; }
.filtri input { width: auto; }
.filtri label { margin: 0; font-weight: 400; font-size: .9em; color: var(--muted); }
.filtri button, .filtri .btn-secondary { margin-top: 0; }
.totali { display: flex; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.tot { background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem 1.1rem; min-width: 150px; }
.tot span { display: block; color: var(--muted); font-size: .82em; }
.tot strong { font-size: 1.2rem; }
.tot.entrate strong { color: var(--pos); }
.tot.uscite strong { color: var(--neg); }

/* Dashboard */
h2.sez { font-size: 1.15rem; margin: 1.8rem 0 .8rem; padding-bottom: .3rem;
  border-bottom: 1px solid var(--line); }
h2.sez .hint { font-size: .7em; font-weight: 400; }
.chart-box { background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
details.dettaglio { margin-bottom: 1rem; }
details.dettaglio > summary { cursor: pointer; color: var(--brand);
  font-weight: 600; margin-bottom: .6rem; }
.tot.saldo strong { color: var(--brand); }
.export-links { display: flex; gap: .6rem; margin-bottom: .8rem; }
.export-links .btn-secondary { margin-top: 0; padding: .35rem .8rem; font-size: .9em; }
table.grid tfoot .riga-totale td { font-weight: 700; background: #eef4f6;
  border-top: 2px solid var(--line); }

/* Business plan */
.bp-form label { min-width: 140px; }
.bp-form input { width: 100%; }
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .chart-grid { grid-template-columns: 1fr; } }
.scenario-titolo { font-size: 1.05rem; margin: 1.2rem 0 .5rem;
  padding-left: .6rem; border-left: 4px solid var(--brand); }
.scenario-titolo .hint { font-size: .72em; font-weight: 400; }
.scenario-ottimistico { border-left-color: var(--pos); }
.scenario-pessimistico { border-left-color: var(--neg); }

/* Categorie */
.cat-azioni { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap;
  margin-bottom: 1rem; }
.cat-azioni form { margin: 0; }
.cat-azioni button { margin-top: 0; }
.due-colonne { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; align-items: start; }
@media (max-width: 820px) { .due-colonne { grid-template-columns: 1fr; } }
.card.mini { max-width: none; margin-top: 1rem; padding: 1rem; }
.card.mini h3 { margin: 0 0 .4rem; font-size: 1rem; }
.btn-piccolo { margin-top: 0; padding: .25rem .6rem; font-size: .82em; }
table.grid td form.inline select { max-width: 200px; }
.report-categorie { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.2rem;
  align-items: start; }
@media (max-width: 820px) { .report-categorie { grid-template-columns: 1fr; } }

hr.sep { border: 0; border-top: 2px solid var(--line); margin: 2.4rem 0 1.4rem; }

/* Dettaglio fattura */
.dett-testata { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem;
  align-items: start; margin-bottom: 1rem; }
@media (max-width: 760px) { .dett-testata { grid-template-columns: 1fr; } }
table.kv { border-collapse: collapse; width: 100%; }
table.kv th { text-align: left; color: var(--muted); font-weight: 600;
  padding: .3rem .8rem .3rem 0; white-space: nowrap; vertical-align: top; }
table.kv td { padding: .3rem 0; }
.badge.pos { background: #e7f6ee; color: var(--pos); }
.badge.neg { background: #fdeaea; color: var(--neg); }

/* Login */
.login-page { display: grid; place-items: center; min-height: 100vh; }
.login-card { width: 340px; max-width: 92vw; }
.login-card h1 { font-size: 1.25rem; margin-bottom: .2rem; }
.login-card .sub { color: var(--muted); margin-top: 0; }
