:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2230; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --green: #15803d; --red: #b91c1c; --amber: #b45309;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111318; --card: #1b1e25; --text: #e6e8ee; --muted: #9aa1ad; --line: #2b2f38; --primary: #60a5fa; --green: #4ade80; --red: #f87171; --amber: #fbbf24; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
header { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
header nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
header nav a { padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
header nav a.active { background: var(--primary); color: #fff; }
main { max-width: 1200px; margin: 0 auto; padding: 20px; }
h2 { margin: 0 0 12px; font-size: 1.3rem; }
h3 { margin: 0 0 10px; font-size: 1.05rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.tile .lbl { color: var(--muted); font-size: .85rem; }
.tile .val { font-size: 1.4rem; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: .8rem; margin-top: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 800px) { .grid2 { grid-template-columns: 1fr; } }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: .82rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.unpaid td { opacity: .75; }
.table-wrap { overflow-x: auto; }
.pos { color: var(--green); } .neg { color: var(--red); } .warn { color: var(--amber); } .muted { color: var(--muted); }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 4px; min-width: 80px; }
.bar > span { display: block; height: 100%; background: var(--primary); }
.bar > span.over { background: var(--red); }
.badge { display: inline-block; font-size: .75rem; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.ok { color: var(--green); border-color: currentColor; } .badge.no { color: var(--amber); border-color: currentColor; }
button, input, select { font: inherit; color: inherit; }
input, select { padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
button { padding: 7px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); cursor: pointer; }
button.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
button.danger { color: var(--red); }
button.link { border: none; background: none; color: var(--primary); padding: 4px; }
button.small { padding: 3px 8px; font-size: .82rem; }
.paid-toggle { cursor: pointer; background: none; border: none; padding: 0; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
label > input, label > select { color: var(--text); }
label.inline { flex-direction: row; align-items: center; gap: 6px; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--card); color: var(--text); width: min(520px, 94vw); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
#dlg-form { padding: 18px; display: grid; gap: 12px; }
#dlg-form .actions { display: flex; justify-content: flex-end; gap: 8px; }
.fields2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { font-size: .8rem; color: var(--muted); }
.error { color: var(--red); min-height: 1em; }
.login { min-height: 100vh; display: grid; place-items: center; }
.login form { width: min(340px, 92vw); display: grid; gap: 12px; }
.login h1 { font-size: 1.3rem; margin: 0; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
