/* style.css — aspetto "Material-like", mobile first, con tema chiaro/scuro automatico */
:root {
  --bg: #f4f6f5; --surface: #ffffff; --text: #1d1f1e; --muted: #5f6b69;
  --primary: #1b5e5a; --primary-text: #ffffff; --accent: #e3f2f0; --border: #d9e0de;
  --danger: #b3261e; --warn-bg: #fff4e5; --warn-border: #f0b36a;
  --c-RIFORNIMENTO: #c0623a; --c-RICARICA: #2e8b7a; --c-MANUTENZIONE: #5c6bc0; --c-ASSICURAZIONE: #8e24aa; --c-BOLLO: #f9a825; --c-ALTRO: #78909c; --c-READING: #90a4ae;
  --radius: 14px; --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121514; --surface: #1c2120; --text: #e8ecea; --muted: #9aa5a2; --primary: #6fc5bb; --primary-text: #0f2b29; --accent: #1f3634; --border: #2e3836; --warn-bg: #3a2c16; --warn-border: #8a6a2e; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { min-height: 100vh; }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
h2 { font-size: 1.35rem; margin: 8px 0 12px; }
h3 { font-size: 1.05rem; margin: 0 0 10px; }
h4 { font-size: 0.95rem; margin: 14px 0 6px; }
p { margin: 6px 0; }
small, .small { font-size: 0.82rem; }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
code { background: var(--accent); padding: 1px 5px; border-radius: 4px; }

.topbar { position: sticky; top: 0; z-index: 5; background: var(--primary); color: var(--primary-text); padding: calc(10px + env(safe-area-inset-top)) 16px 10px; font-weight: 700; letter-spacing: .3px; }
.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--border); z-index: 5; }
.bottomnav button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.75rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; }
.bottomnav button .ico { font-size: 1.3rem; line-height: 1; }
.bottomnav button.on { color: var(--primary); font-weight: 600; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }
.row.wrap { align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .row2 { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 140px; margin-bottom: 10px; }
.field-label { font-size: 0.82rem; color: var(--muted); }
.hint { font-size: 0.76rem; color: var(--muted); }
input, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; min-height: 44px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--primary); border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-bottom: 10px; }
.check input { width: auto; min-height: 0; }
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 10px; padding: 10px 16px; min-height: 44px; cursor: pointer; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.btn.danger { color: var(--danger); border-color: var(--danger); margin-top: 10px; }
.icon { font: inherit; border: 0; background: none; cursor: pointer; font-size: 1.1rem; padding: 8px; color: var(--muted); }
.segmented { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.segmented button { flex: 1; border: 0; background: var(--surface); color: var(--text); font: inherit; padding: 10px; cursor: pointer; }
.segmented button.on { background: var(--primary); color: var(--primary-text); font-weight: 600; }
.segmented button:disabled { opacity: .5; cursor: default; }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 10px; padding: 10px 12px; margin: 6px 0 12px; }
.warn ul { margin: 6px 0 10px 18px; padding: 0; }

.filterbar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.filterbar select, .filterbar input { min-height: 40px; padding: 6px 10px; font-size: 0.92rem; }

.list { list-style: none; margin: 0; padding: 0; }
.list .month { color: var(--muted); font-size: 0.8rem; text-transform: capitalize; margin: 14px 0 6px 4px; }
.item { display: flex; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 6px 10px 12px; margin-bottom: 8px; }
.item.reading { background: transparent; border-style: dashed; }
.item-main { flex: 1; min-width: 0; }
.item-top { display: flex; align-items: center; gap: 8px; }
.item-date { color: var(--muted); font-size: 0.85rem; flex: 1; }
.item-amount { font-weight: 700; white-space: nowrap; }
.item-sub { font-size: 0.85rem; color: var(--muted); margin-top: 3px; }
.item-notes { font-size: 0.85rem; margin-top: 3px; font-style: italic; }
.item-actions { display: flex; flex-direction: column; justify-content: center; }
.badge { font-size: 0.72rem; font-weight: 600; color: #fff; border-radius: 6px; padding: 2px 7px; white-space: nowrap; }
.badge.RIFORNIMENTO { background: var(--c-RIFORNIMENTO); } .badge.RICARICA { background: var(--c-RICARICA); } .badge.MANUTENZIONE { background: var(--c-MANUTENZIONE); }
.badge.ASSICURAZIONE { background: var(--c-ASSICURAZIONE); } .badge.BOLLO { background: var(--c-BOLLO); color: #222; } .badge.ALTRO { background: var(--c-ALTRO); } .badge.READING { background: var(--c-READING); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--accent); border-radius: 10px; padding: 10px 12px; }
.stat-value { font-size: 1.25rem; font-weight: 700; }
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-sub { font-size: 0.74rem; color: var(--muted); margin-top: 2px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr auto; align-items: center; gap: 8px; margin: 6px 0; font-size: 0.9rem; }
.bar { height: 10px; background: var(--accent); border-radius: 5px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--primary); border-radius: 5px; }
.bar-fill.RIFORNIMENTO { background: var(--c-RIFORNIMENTO); } .bar-fill.RICARICA { background: var(--c-RICARICA); } .bar-fill.MANUTENZIONE { background: var(--c-MANUTENZIONE); }
.bar-fill.ASSICURAZIONE { background: var(--c-ASSICURAZIONE); } .bar-fill.BOLLO { background: var(--c-BOLLO); } .bar-fill.ALTRO { background: var(--c-ALTRO); }
.bar-value { white-space: nowrap; font-weight: 600; }
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 10px -14px 0; padding: 0 14px; }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 0.78rem; }
table.dense th, table.dense td { padding: 4px 6px; font-size: 0.8rem; }
details { border-top: 1px solid var(--border); padding: 8px 0; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.result { background: var(--accent); border-radius: 10px; padding: 10px 12px; }
.plain { list-style: none; padding: 0; margin: 0 0 10px; }
.plain li { padding: 8px 0; border-bottom: 1px solid var(--border); }

#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 10; font-size: 0.9rem; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.item.reading .item-amount { white-space: normal; text-align: right; }
