:root {
  --bg: #f7f6f3; --panel: #fff; --ink: #1d1d1f; --muted: #6e6e73; --line: #e3e1dc; --grid: #ecebe7;
  --accent: #c2410c; --accent-ink: #fff; --good: #15803d; --bad: #b91c1c; --warn: #b45309;
  --row-hover: #fbfaf7; --focus: #2563eb;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #161616; --panel: #1f1f1f; --ink: #ececec; --muted: #9a9a9f; --line: #333; --grid: #2a2a2a;
    --accent: #f97316; --accent-ink: #111; --good: #4ade80; --bad: #f87171; --warn: #fbbf24; --row-hover: #242424; --focus: #60a5fa; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif; background: var(--bg); color: var(--ink); padding: 20px 24px 48px; }
input, select, button { font: inherit; color: inherit; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.event { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.event label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.event input, .event select { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 5px 8px; }
#ev-budget { width: 110px; }
.ev-name { font-size: 22px !important; font-weight: 650; border-color: transparent !important; background: transparent !important; padding: 2px 4px !important; width: 260px; }
.ev-name:hover, .ev-name:focus { border-color: var(--line) !important; }
.actions { display: flex; gap: 8px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 7px 12px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:disabled { opacity: .5; cursor: default; }
.sync-status { min-height: 20px; margin: 8px 0 14px; color: var(--muted); font-size: 13px; }
.sync-status.ok { color: var(--good); } .sync-status.err { color: var(--bad); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.tile span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.tile b { font-size: 22px; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); font-size: 12px; }
.over { color: var(--bad) !important; } .under { color: var(--good); }
.meter { height: 6px; background: var(--grid); border-radius: 3px; margin: 12px 0 20px; overflow: hidden; }
#meter-fill { height: 100%; background: var(--accent); transition: width .2s; }
#meter-fill.over { background: var(--bad); }

.toolbar { display: flex; gap: 8px; margin-bottom: 8px; }
.toolbar input, .toolbar select { border: 1px solid var(--line); background: var(--panel); border-radius: 7px; padding: 6px 10px; }
.toolbar input { flex: 0 1 240px; }
.toolbar .btn { margin-left: auto; }

.sheet-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.sheet { border-collapse: collapse; width: 100%; min-width: 1180px; }
.sheet th { position: sticky; top: 0; background: var(--panel); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--line); }
.sheet td { border-bottom: 1px solid var(--grid); border-right: 1px solid var(--grid); padding: 0; height: 34px; }
.sheet td:last-child, .sheet th:last-child { border-right: 0; }
.sheet tbody tr:hover { background: var(--row-hover); }
.sheet input, .sheet select { width: 100%; height: 34px; border: 0; background: transparent; padding: 0 8px; outline: none; }
.sheet .num input { text-align: right; }
.sheet input:focus, .sheet select:focus { box-shadow: inset 0 0 0 2px var(--focus); border-radius: 2px; }
.sheet .c-n { width: 34px; text-align: center; color: var(--muted); font-size: 12px; }
.sheet .c-task { width: 90px; padding: 0 8px; font-size: 12px; white-space: nowrap; }
.sheet .c-task a { color: var(--good); text-decoration: none; }
.sheet .c-x { width: 32px; text-align: center; }
.sheet td.diff { padding: 0 8px; font-size: 13px; width: 80px; }
.del { border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; opacity: 0; }
tr:hover .del, .del:focus { opacity: 1; } .del:hover { color: var(--bad); }
.status[data-s="Paid"] { color: var(--good); font-weight: 600; }
.status[data-s="Booked"] { color: var(--warn); font-weight: 600; }
tr.paid [data-f="item"] { color: var(--muted); }
tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
tr.overdue [data-f="due_date"] { color: var(--bad); font-weight: 600; }
.sheet tfoot td { font-weight: 650; padding: 0 8px; border-bottom: 0; font-variant-numeric: tabular-nums; }
.empty td { text-align: center; color: var(--muted); padding: 28px; height: auto; }

.by-cat { margin-top: 24px; max-width: 640px; }
.by-cat h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
.cat { display: grid; grid-template-columns: 120px 1fr 90px 44px; gap: 10px; align-items: center; padding: 4px 0; }
.bar { height: 10px; background: var(--grid); border-radius: 5px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
/* column widths */
.sheet td:nth-child(3) { min-width: 140px; }
.sheet td:nth-child(10) { min-width: 104px; }
.sheet td:nth-child(5), .sheet td:nth-child(6) { width: 110px; }
/* sign-in */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 0; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: min(340px, 90vw); display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; font-size: 20px; } .login-card p { margin: 0; }
.login-card input { border: 1px solid var(--line); background: var(--bg); border-radius: 7px; padding: 9px 10px; }
