:root {
  --bg: #f4f5f3;
  --card: #ffffff;
  --text: #1c1f1d;
  --muted: #6b716d;
  --line: #dfe3df;
  --accent: #1d5c3a;
  --accent-soft: #e3efe7;
  --danger: #b3261e;
  --row-alt: #f7f8f7;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121413;
    --card: #1c1f1d;
    --text: #e8ebe9;
    --muted: #9aa19c;
    --line: #2e332f;
    --accent: #5fbf86;
    --accent-soft: #23362a;
    --danger: #ef8a80;
    --row-alt: #202421;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
h1 { margin: 0 0 4px; font-size: 26px; }
h2 { margin: 0 0 12px; font-size: 16px; }

.screen { max-width: 720px; margin: 0 auto; padding: 0 16px 40px; }

/* Accesso */
.auth-box { max-width: 380px; margin: 12vh auto 0; background: var(--card); padding: 24px; border-radius: 14px; border: 1px solid var(--line); }
.msg { min-height: 1.2em; font-size: 13px; color: var(--muted); }
.msg.err { color: var(--danger); }

/* Barra superiore */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; padding: 12px 0 8px; background: var(--bg); }
.topbar select { flex: 1; min-width: 0; font-weight: 600; }
.icon { width: 42px; flex: none; padding: 0; font-size: 18px; background: var(--card); border: 1px solid var(--line); color: var(--text); }

.tabs { display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); font-weight: 600; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }

/* Form */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 12px; }
label, .field { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.lbl { display: block; margin-bottom: 4px; }
input, select, button { font: inherit; border-radius: 8px; height: 42px; }
input, select {
  display: block; width: 100%; margin-top: 4px; padding: 0 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
input[type=file] { height: auto; padding: 10px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
.check input { width: 18px; height: 18px; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; gap: 0; } }

button { cursor: pointer; padding: 0 16px; border: 1px solid transparent; }
.primary { background: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .primary { color: #0d1a12; } }
.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.link { background: none; border: 0; color: var(--accent); padding: 0; height: auto; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 6px; }
.auth-box .row-btns { justify-content: space-between; margin-top: 12px; }
.auth-box .primary { width: 100%; margin-top: 6px; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.seg button { height: 36px; padding: 0 12px; background: var(--bg); border: 1px solid var(--line); color: var(--text); font-size: 13px; }
.seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .seg button.on { color: #0d1a12; } }

/* Liste */
.totbar { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 13px; color: var(--muted); margin: 4px 2px 10px; }
.totbar b { color: var(--text); }
.day { margin-bottom: 12px; }
.day-h { display: flex; justify-content: space-between; font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; padding: 0 4px 4px; }
.item { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); padding: 10px 12px; cursor: pointer; }
.item + .item { border-top: 0; }
.day .item:first-of-type { border-radius: 10px 10px 0 0; }
.day .item:last-of-type { border-radius: 0 0 10px 10px; }
.day .item:only-of-type { border-radius: 10px; }
.item:hover { background: var(--row-alt); }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .s { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-right: 4px; }
.empty { text-align: center; padding: 40px 0; color: var(--muted); }

table.tot { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.tot td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.tot td:last-child { text-align: right; font-weight: 600; }
table.tot tr.grand td { border-top: 2px solid var(--text); border-bottom: 0; font-weight: 700; font-size: 16px; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); }
