:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --ink: #1d2626;
  --muted: #66706f;
  --line: #e3dfd8;
  --line-soft: #efece6;
  --brand: #0f5f5c;
  --brand-ink: #0b4643;
  --brand-soft: #e3efed;
  --accent: #d97706;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn-soft: #fff4dc;
  --ok-soft: #e6f4ea;
  --info-soft: #e8f0fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 30, .05), 0 4px 16px rgba(20, 30, 30, .04);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: 0 0 2px; letter-spacing: -.01em; }
h2 { font-size: 1.08rem; margin: 0 0 14px; }
h2 small { font-weight: 400; font-size: .82rem; margin-left: 6px; }
h3 { font-size: 1rem; margin: 8px 0 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.strong { font-weight: 600; }
code { font-size: .82rem; background: var(--line-soft); padding: 1px 6px; border-radius: 5px; }

/* ---------- topbar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 22px; padding: 0 24px; height: 60px;
  background: var(--brand-ink); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 25V13l8-6 8 6v12h-5v-7h-6v7z' fill='%230f5f5c'/%3E%3C/svg%3E") center/80% no-repeat; display: inline-block; }
.logo.big { width: 56px; height: 56px; border-radius: 14px; background-color: var(--brand); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M8 25V13l8-6 8 6v12h-5v-7h-6v7z' fill='white'/%3E%3C/svg%3E"); }
.mainnav { display: flex; gap: 2px; flex: 1; }
.mainnav a, .usermenu a { color: rgba(255,255,255,.82); text-decoration: none; padding: 8px 12px; border-radius: 8px; font-size: .93rem; white-space: nowrap; }
.mainnav a:hover, .usermenu a:hover { background: rgba(255,255,255,.1); color: #fff; }
.mainnav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: 4px; }
.usermenu a { display: flex; align-items: center; gap: 8px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.nav-toggle { display: none; margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }

/* ---------- layout ---------- */
.container { max-width: 1280px; margin: 0 auto; padding: 26px 24px 40px; }
.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 0 26px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid2 .card { margin-bottom: 0; }
.grid2 + p { margin-top: 10px; }
.chart-box { position: relative; height: 270px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpis.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { font-size: .82rem; color: var(--muted); }
.kpi-value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: .85rem; font-weight: 500; color: var(--muted); }
.kpi-sub { font-size: .78rem; color: var(--muted); }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit; font-size: .92rem; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cfc9bf; background: #faf9f6; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1c13; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: #f3c3bd; }
.btn-sm { padding: 4px 10px; font-size: .84rem; }
.btn-block { width: 100%; padding: 11px; }
input, select { font: inherit; color: inherit; padding: 8px 10px; border: 1px solid #d5d0c7; border-radius: 8px; background: #fff; min-width: 0; }
input:focus, select:focus { outline: 2px solid rgba(15, 95, 92, .25); border-color: var(--brand); }
label { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; font-weight: 500; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: 16px; height: 16px; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar-card { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.chip { padding: 5px 11px; border-radius: 99px; border: 1px solid var(--line); font-size: .84rem; text-decoration: none; color: var(--ink); background: #faf9f6; }
.chip:hover { border-color: var(--brand); }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 14px; font: inherit; font-size: .92rem; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--brand); color: #fff; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.form-grid > h2 { grid-column: 1 / -1; margin: 0; }
.form-grid > .alert { grid-column: 1 / -1; margin: 0; }
.form-grid.narrow { max-width: 720px; }
.span2 { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.sticky-actions { position: sticky; bottom: 0; background: rgba(244, 242, 238, .94); backdrop-filter: blur(6px); padding: 14px 0; border-top: 1px solid var(--line); justify-content: space-between; }
.row-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-form input[name=nome] { flex: 1; min-width: 160px; }
.w-small { width: 90px; }
.danger-zone { margin-top: 30px; padding-top: 16px; border-top: 1px dashed var(--line); text-align: right; }

/* ---------- alerts & badges ---------- */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; border: 1px solid transparent; }
.alert-success { background: var(--ok-soft); border-color: #bfe3c9; }
.alert-error { background: var(--danger-soft); border-color: #f3c3bd; color: #7a1a12; }
.alert-warning { background: var(--warn-soft); border-color: #f5dc9f; }
.alert-info { background: var(--info-soft); border-color: #c8d8f3; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; background: var(--line-soft); color: var(--muted); font-weight: 600; }
.role-admin { background: #fde7d0; color: #8a4b05; }
.role-operatore { background: var(--brand-soft); color: var(--brand-ink); }
.role-condomino { background: var(--info-soft); color: #1e40af; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: middle; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #faf9f6; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th a { color: inherit; text-decoration: none; border-bottom: 1px dotted; }
.table th a:hover { color: var(--brand); }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table tbody tr:hover td { background: #fbfaf7; }
.group-row td { background: var(--brand-soft) !important; color: var(--brand-ink); font-weight: 700; font-size: .85rem; padding-top: 7px; padding-bottom: 7px; }
.sum-row td { font-weight: 700; background: #faf6ec !important; border-top: 1px solid var(--line); }
tr.disabled td { opacity: .55; }
td.neg { color: var(--danger); font-weight: 600; }
td.tot, th.tot { background: #f7f5f0; font-weight: 600; }
td.actions { white-space: nowrap; text-align: right; }
td.actions form { display: inline; }
.sheet td.sticky, .sheet th.sticky { position: sticky; left: 0; z-index: 1; background: #fff; min-width: 230px; box-shadow: 1px 0 0 var(--line); }
.sheet th.sticky { background: #faf9f6; }
.sheet .group-row td.sticky { background: var(--brand-soft); }
.sheet .sum-row td.sticky { background: #faf6ec; }
.bar { display: inline-block; width: 70px; height: 7px; background: var(--line-soft); border-radius: 9px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.bar span { display: block; height: 100%; background: var(--brand); border-radius: 9px; }
.generali td { color: #3b4646; }

/* ---------- entry form ---------- */
.entry { table-layout: fixed; min-width: 640px; }
.entry th:nth-child(2) { width: 180px; } .entry th:nth-child(3) { width: 200px; } .entry th:nth-child(4) { width: 150px; }
.entry td:first-child { min-width: 220px; }
.entry td:first-child small { display: block; }
.entry td label { font-weight: 600; font-size: .92rem; display: inline; }
.w-input { width: 190px; }
.num-input { width: 170px; text-align: right; font-variant-numeric: tabular-nums; font-size: 1rem; }
.entry .delta { font-weight: 600; color: var(--brand-ink); min-width: 110px; }
.entry tr.warn td { background: var(--warn-soft) !important; }
.entry tr.warn .delta { color: #9a5b00; }
.entry tr.warn .delta::before { content: "⚠ "; }
.entry tr.err td { background: var(--danger-soft) !important; }
.entry tr.err .delta { color: var(--danger); font-weight: 500; font-size: .82rem; }
.entry tr.err input { border-color: var(--danger); }

/* ---------- login ---------- */
body.guest { background: radial-gradient(1200px 600px at 20% -10%, #d8ebe7 0, transparent 60%), var(--bg); }
.login-wrap { min-height: calc(100vh - 140px); display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; padding: 30px; }
.login-brand { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.login-brand h1 { font-size: 1.5rem; }
.login-brand p { margin: 0; }

/* ---------- spese ---------- */
.bills { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.bill { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: #fcfbf8; display: flex; flex-direction: column; gap: 10px; }
.bill h3 { margin: 0; font-size: .95rem; }
.bill .num-input { width: 100%; }
.bill small { font-weight: 400; }
.mt { margin-top: 20px; }
.gas-tab { margin-top: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; background: #fbfaf6; }
.gas-tab h4 { margin: 0 0 8px; }
.gas-tab p { margin: 8px 0 0; }
textarea { font: inherit; padding: 8px 10px; border: 1px solid #d5d0c7; border-radius: 8px; width: 100%; resize: vertical; }
.altre input:not(.num-input) { width: 100%; min-width: 180px; }
.altre select { min-width: 150px; }
.manuale { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; }
.manuale[hidden] { display: none; }
.num-input.sm { width: 90px; font-size: .9rem; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.credit { color: #15803d !important; }
.total-row td { font-size: 1rem; background: #f3efe4 !important; }
th.hl, td.hl { background: #fff8e6; }
.riparto td:first-child { min-width: 240px; }
.form-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 14px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.chart-box.tall { height: 340px; }
.pad { padding: 16px 22px; }
.card-head.pad { margin: 0; padding-bottom: 6px; }
.crumbs { margin: 0 0 4px; font-size: .85rem; }
.nowrap { white-space: nowrap; }
.w-name { width: 100%; min-width: 200px; display: block; margin-bottom: 4px; }
.muted-input { color: var(--muted); padding: 4px 8px; }
.pct { display: block; font-size: .72rem; }
.note { background: var(--warn-soft); padding: 10px 14px; border-radius: 8px; }
.calc-details { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.calc-details summary { cursor: pointer; font-weight: 600; color: var(--brand); }
.calc-details h4 { margin: 12px 0 6px; }
.grid2.tight { gap: 24px; }
.table.compact td, .table.compact th { padding: 5px 10px; }
ul.plain { padding-left: 18px; margin: 0; line-height: 1.8; }
.kpi-value.credit { color: #15803d; }
.print-only { display: none; }
@media print {
  .topbar, .footer, .no-print, .btn, .calc-details, .danger-zone { display: none !important; }
  .print-only { display: block; }
  body { background: #fff; }
  .card, .kpi { box-shadow: none; border-color: #ccc; }
  .container { padding: 0; max-width: none; }
  .kpis { grid-template-columns: repeat(5, 1fr); }
}

/* ---------- versamenti ---------- */
.debt { color: var(--danger) !important; }
.kpi-value.debt { color: var(--danger); }
a.kpi-link { text-decoration: none; color: inherit; transition: border-color .15s; }
a.kpi-link:hover { border-color: var(--brand); }
a.kpi-link.sel { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.form-grid.five { grid-template-columns: 1.2fr 1fr 1fr 1.4fr 2fr; margin-bottom: 14px; }
.form-grid.five + .form-actions { justify-content: flex-end; }
tr.hl-row td { background: #fff8e6; }
.prospetto th.mese { text-align: center; border-left: 1px solid var(--line); }
.prospetto th.sub { font-size: .7rem; }
.prospetto td.av, .prospetto th.av { border-right: 1px solid var(--line); font-weight: 600; background: #faf8f2; }
.prospetto td { white-space: nowrap; }
tr.mv-versamento td { background: #f6fbf7; }
.card-head.pad .toolbar { margin: 0; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .grid2 { grid-template-columns: 1fr; }
  .bills, .form-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis.five { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .uname { display: none; }
}
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; min-height: 56px; padding: 10px 16px; gap: 8px; }
  .nav-toggle { display: block; }
  .mainnav, .usermenu { display: none; width: 100%; flex-direction: column; }
  body.nav-open .mainnav, body.nav-open .usermenu { display: flex; }
  .usermenu { flex-direction: row; justify-content: space-between; border-top: 1px solid rgba(255,255,255,.15); padding-top: 6px; }
  .uname { display: inline; }
  .container { padding: 18px 16px 30px; }
  .form-grid { grid-template-columns: 1fr; }
  .presets { margin-left: 0; }
  .sheet td.sticky, .sheet th.sticky { min-width: 150px; }
  .num-input { width: 120px; }
  .w-input { width: 130px; }
  .entry td:first-child { min-width: 140px; }
  .entry th:nth-child(2) { width: 110px; } .entry th:nth-child(3) { width: 140px; } .entry th:nth-child(4) { width: 90px; }
}
@media (max-width: 640px) {
  .entry { min-width: 0; table-layout: auto; }
  .entry thead { display: none; }
  .entry, .entry tbody, .entry tfoot { display: block; }
  .entry tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
  .entry td { display: block; border: 0; padding: 0 4px; min-width: 0 !important; }
  .entry td:first-child { grid-column: 1 / -1; }
  .entry td:nth-child(2) { text-align: left !important; }
  .entry td:nth-child(2)::before { content: "Prec.: "; }
  .entry td:nth-child(3) { grid-row: 2 / 4; grid-column: 2; align-self: center; }
  .entry td.delta { text-align: left !important; min-width: 0; }
  .entry td.delta:not(:empty)::before { content: "Consumo: "; font-weight: 400; color: var(--muted); }
  .entry tfoot td:nth-child(2)::before { content: "Prec.: "; }
  .entry tfoot td:nth-child(3) { grid-row: auto; }
  .num-input { width: 130px; }
}
@media (max-width: 480px) {
  .bills, .form-grid.four { grid-template-columns: 1fr; }
  .kpis.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form-grid.five { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
}

/* =====================================================================
   VERSIONE TELEFONO (≤ 640px) — layout lineare, una colonna
   ===================================================================== */
.mobile-only, .bottomnav, .menu-sheet, .gas-mini { display: none; }
.conta { margin-left: 10px; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line-soft); color: var(--muted); vertical-align: 2px; }
.conta.ok { background: var(--ok-soft); color: #166534; }
.conta.warn { background: var(--warn-soft); color: #9a5b00; }
.conta:empty { display: none; }
@media print {
  .desk-only { display: block !important; }
  .show-desk, .bottomnav, .menu-sheet { display: none !important; }
}

@media (max-width: 640px) {
  html { scroll-padding-bottom: 150px; scroll-padding-top: 64px; }
  body.logged { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .mobile-only { display: block; }
  .desk-only:not(.show) { display: none !important; }
  .footer { display: none; }

  /* barra superiore: solo il nome */
  .topbar { height: 52px; min-height: 52px; padding: 0 16px; flex-wrap: nowrap; }
  .nav-toggle, .topbar .mainnav, .topbar .usermenu { display: none !important; }
  .brand { font-size: 1rem; }

  /* barra di navigazione in basso */
  .bottomnav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 12px rgba(0,0,0,.06); }
  .bottomnav a, .bottomnav button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px 9px; font: inherit; font-size: .7rem;
    color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; }
  .bottomnav .ico { font-size: 1.25rem; line-height: 1.2; filter: grayscale(1); opacity: .75; }
  .bottomnav .active { color: var(--brand); font-weight: 700; }
  .bottomnav .active .ico { filter: none; opacity: 1; }
  .menu-sheet { position: fixed; inset: 0; z-index: 35; background: rgba(15, 30, 30, .35); align-items: flex-end; }
  body.sheet-open .menu-sheet { display: flex; }
  .sheet-panel { width: 100%; background: #fff; border-radius: 16px 16px 0 0; padding: 10px 0 calc(72px + env(safe-area-inset-bottom)); }
  .sheet-panel a { display: block; padding: 14px 22px; color: var(--ink); text-decoration: none; font-size: 1rem; border-top: 1px solid var(--line-soft); }
  .sheet-panel a.active { color: var(--brand); font-weight: 700; }
  .sheet-panel a.danger { color: var(--danger); }
  .sheet-user { display: flex; align-items: center; gap: 10px; padding: 12px 22px 14px; }

  /* struttura */
  .container { padding: 14px 12px 24px; }
  .card { padding: 14px; margin-bottom: 14px; border-radius: 12px; }
  .card.flush { padding: 0; }
  .card-head { margin-bottom: 8px; }
  .card-head.pad { padding: 12px 14px 4px; }
  h1 { font-size: 1.3rem; }
  h2 { font-size: 1rem; margin-bottom: 10px; }
  h2 small { display: block; margin: 2px 0 0; }
  .page-head { margin-bottom: 12px; gap: 10px; }
  .page-head p { font-size: .88rem; }
  .page-head > .toolbar, .page-head > form.toolbar, .page-head > .btn { width: 100%; }
  .actions-main { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .actions-main .btn, .page-head > .btn { width: 100%; padding: 11px; }
  .btn-block { margin-bottom: 14px; }
  .alert { padding: 10px 12px; font-size: .9rem; }
  .toolbar-card { gap: 10px; }
  .presets { flex-wrap: nowrap; overflow-x: auto; width: 100%; padding-bottom: 2px; -webkit-overflow-scrolling: touch; }
  .chip { white-space: nowrap; }
  .grid2 { gap: 14px; }
  .form-grid, .form-grid.five, .form-grid.four { grid-template-columns: 1fr; gap: 12px; }
  input, select, textarea { font-size: 16px; } /* evita lo zoom automatico su iPhone */

  /* riquadri numerici -> lista compatta */
  .kpis, .kpis.five { display: block; background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
  .card .kpis, .card .kpis.five { border: 0; border-radius: 0; margin: 0 -14px -14px !important; border-top: 1px solid var(--line-soft); }
  .kpi { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line-soft);
    border-radius: 0; box-shadow: none; }
  .kpi:last-child { border-bottom: 0; }
  .kpi-label { font-size: .9rem; color: var(--ink); grid-row: 1 / span 2; }
  .kpi-value { font-size: 1.05rem; text-align: right; }
  .kpi-value small { font-size: .75rem; }
  .kpi-sub { text-align: right; font-size: .72rem; }
  .kpi-sub:empty { display: none; }
  a.kpi-link.sel { box-shadow: none; background: #fff8e6; }

  /* tabelle -> schede */
  .table.cards, .table.cards tbody, .table.cards tfoot { display: block; width: 100%; }
  .table.cards thead { display: none; }
  .table.cards tr { display: flex; flex-direction: column; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); }
  .table.cards td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 2px 0; border: 0;
    text-align: right !important; white-space: normal; min-width: 0 !important; background: none !important; }
  .table.cards td::before { content: attr(data-label); color: var(--muted); font-size: .76rem; font-weight: 500; text-align: left; flex: 0 0 auto; text-transform: none; }
  .table.cards td.c-empty { display: none; }
  .table.cards td.c-title, .table.cards tr:not(:has(.c-title)) > td:first-child { order: -1; display: block; text-align: left !important; font-weight: 600; font-size: .98rem; padding-bottom: 4px; }
  .table.cards td.c-title::before, .table.cards tr:not(:has(.c-title)) > td:first-child::before { content: none; }
  .table.cards td.actions { justify-content: flex-end; padding-top: 6px; }
  .table.cards td.actions::before { content: none; }
  .table.cards tr.group-row { padding: 8px 14px; background: var(--brand-soft); }
  .table.cards tr.group-row td::before { content: none; }
  .table.cards tr.sum-row, .table.cards tr.total-row { background: #faf6ec; }
  .table.cards tr.mv-versamento { background: #f6fbf7; }
  .table.cards tr:hover td { background: none !important; }
  .table.cards .bar { width: 50px; }
  .table.cards td:has(input, select, textarea) { display: block; text-align: left !important; }
  .table.cards td:has(input, select, textarea)::before { display: block; margin-bottom: 4px; }
  .table.cards td input:not([type=checkbox]), .table.cards td select { width: 100%; }
  .card:not(.flush) > .table-wrap > .table.cards, .card:not(.flush) > .table.cards { margin: 0 -14px; width: calc(100% + 28px); }

  .table.cards.grid2c tr { display: grid; grid-template-columns: 1fr 1fr; column-gap: 18px; }
  .table.cards.grid2c td.c-title, .table.cards.grid2c tr:not(:has(.c-title)) > td:first-child,
  .table.cards.grid2c td.actions, .table.cards.grid2c tr.group-row td { grid-column: 1 / -1; }
  .table.cards.limitata tr.oltre { display: none; }
  .table.cards td.c-hide-m { display: none; }
  /* estratto conto: una riga compatta per movimento */
  .table.cards.ledger tr { display: grid; grid-template-columns: auto 1fr auto; column-gap: 12px; position: relative; padding-right: 44px; }
  .table.cards.ledger td.c-title { grid-column: 1 / -1; font-size: .92rem; font-weight: 600; }
  .table.cards.ledger td::before { content: none; }
  .table.cards.ledger td.l-date { grid-column: 1; font-size: .8rem; color: var(--muted); text-align: left !important; }
  .table.cards.ledger td.l-dare, .table.cards.ledger td.l-avere { grid-column: 2; justify-content: flex-end; font-weight: 600; }
  .table.cards.ledger td.l-saldo { grid-column: 3; font-size: .8rem; }
  .table.cards.ledger td.l-saldo::before { content: "saldo"; font-weight: 400; margin-right: 4px; }
  .table.cards.ledger td.actions { position: absolute; right: 10px; top: 8px; padding: 0; }
  .table.cards.ledger td.actions form { display: block; }
  .mostra-tutto { margin: 10px 14px 14px; width: calc(100% - 28px); }
  .form-grid .num-input { width: 100%; }

  /* foglio letture: resta scorrevole, colonna fissa più stretta */
  .sheet td.sticky, .sheet th.sticky { min-width: 120px; max-width: 150px; white-space: normal; }

  /* ---- inserimento letture ---- */
  .entry-form section.card[data-sezione] > h2 { display: flex; align-items: center; cursor: pointer; margin: 0; }
  .entry-form section.card[data-sezione] > .table-wrap { margin-top: 10px; }
  .chev { display: inline-block !important; margin-left: 8px; transition: transform .15s; color: var(--muted); }
  .conta { margin-left: auto; }
  section.chiusa > .table-wrap { display: none; }
  section.chiusa .chev { transform: rotate(-90deg); }
  .entry { min-width: 0 !important; }
  .entry tbody tr { display: grid; grid-template-columns: 1fr 132px; grid-template-rows: auto auto; column-gap: 12px; row-gap: 0; padding: 9px 0;
    border-bottom: 1px solid var(--line-soft); align-items: center; }
  .entry tbody td { padding: 0 !important; }
  .entry tbody td:first-child { grid-column: 1; grid-row: 1; }
  .entry tbody td:first-child label { font-size: .92rem; }
  .entry tbody td:first-child small { display: inline; margin-left: 4px; }
  .entry tbody td:nth-child(2) { grid-column: 1; grid-row: 2; text-align: left !important; font-size: .78rem; }
  .entry tbody td:nth-child(2)::before { content: "prec. "; }
  .entry tbody td:nth-child(2) br { display: none; }
  .entry tbody td:nth-child(2) small::before { content: " del "; }
  .entry tbody td:nth-child(3) { grid-column: 2; grid-row: 1; }
  .entry tbody td.delta { grid-column: 2; grid-row: 2; text-align: right !important; font-size: .78rem; min-width: 0; }
  .entry tbody td.delta:not(:empty)::before { content: "consumo "; font-weight: 400; color: var(--muted); }
  .entry .num-input { width: 100%; padding: 9px 10px; }
  .entry tfoot tr { display: flex; justify-content: space-between; gap: 10px; padding: 8px 10px; flex-wrap: wrap; }
  .entry tfoot td { padding: 0 !important; background: none !important; }
  .entry tfoot td.sum-prev { display: none; }
  .entry tfoot td.sum-delta:not(:empty)::before { content: "consumo "; font-weight: 400; color: var(--muted); }
  .sticky-actions { position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); margin: 0 -12px; padding: 10px 12px; z-index: 20; }
  .sticky-actions > .muted, .sticky-actions > span.small { display: none; }
  .sticky-actions .btn-primary, .sticky-actions > span { flex: 1; }
  .sticky-actions > span { display: flex; gap: 8px; }
  .sticky-actions .btn { flex: 1; padding: 12px; }
  .bills { grid-template-columns: 1fr; gap: 10px; }
  .bill { padding: 12px; gap: 8px; }
  .gas-tab table, .gas-tab .gas-note, .gas-tab h4 small { display: none; }
  .gas-tab .gas-mini { display: block; margin: 0; }
  .gas-tab h4 { font-size: .9rem; margin-bottom: 6px; }
  .manuale { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
  .manuale label.inline { justify-content: space-between; }
  .manuale .num-input.sm { width: 90px; }
  .danger-zone { text-align: center; }

  /* dashboard: grafici a schede */
  .chart-tabs.mobile-only { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; }
  .chart-tabs button { flex: 1; padding: 8px 6px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font: inherit; font-size: .8rem; white-space: nowrap; cursor: pointer; }
  .chart-tabs button.on { background: var(--brand); border-color: var(--brand); color: #fff; }
  .charts[data-active="0"] > .card:not(:nth-child(1)), .charts[data-active="1"] > .card:not(:nth-child(2)),
  .charts[data-active="2"] > .card:not(:nth-child(3)), .charts[data-active="3"] > .card:not(:nth-child(4)) { display: none; }
  .chart-box { height: 230px; }
  .chart-box.tall { height: 260px; }

  /* login */
  .login-card { padding: 22px; }
}
