:root {
  --bg: #0d0f14; --surface: #151923; --raised: #1c2130; --line: #262c3d;
  --text: #e8eaf0; --muted: #8a92a6; --mint: #5eead4; --violet: #a78bfa;
  --warn: #fbbf24; --over: #fb7185; --ink: #0d0f14;
  --sans: "Space Grotesk", system-ui, sans-serif; --mono: "Space Mono", ui-monospace, monospace;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f4f5f8; --surface: #ffffff; --raised: #eef0f5; --line: #dde1ea;
  --text: #151923; --muted: #5d6579; --mint: #0f9f8c; --violet: #6d4fd6;
  --warn: #b7791f; --over: #d6336c; --ink: #ffffff;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--sans); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--mint); }
h1, h2, h3 { margin: 0; font-weight: 600; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* header */
header { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.bar { max-width: 1040px; margin: 0 auto; padding: 10px 16px 0; }
.brand { font-weight: 700; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { color: var(--mint); }
.search { flex: 1; min-width: 0; max-width: 300px; margin-left: auto; }
.themes { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.themes button { border: 0; background: none; border-radius: 999px; width: 30px; height: 26px; cursor: pointer; color: var(--muted); }
.themes button[aria-pressed="true"] { background: var(--raised); color: var(--text); }
nav { display: flex; gap: 2px; overflow-x: auto; margin-top: 8px; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
nav a { padding: 8px 12px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; }
nav a.on { color: var(--text); border-color: var(--mint); }
nav a .badge { margin-left: 6px; }

main { max-width: 1040px; margin: 0 auto; padding: 18px 16px 90px; }
section + section, .stack > * + * { margin-top: 16px; }

/* controls */
input[type="text"], input[type="email"], input[type="password"], input[type="date"], input[type="number"],
input[type="search"], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0; width: 100%; }
textarea { min-height: 120px; font-family: var(--mono); font-size: 12px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: 2px solid var(--violet); outline-offset: 1px; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; color: var(--text); }
.btn { border: 1px solid var(--line); background: var(--raised); border-radius: 9px; padding: 8px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--mint); border-color: var(--mint); color: var(--ink); font-weight: 600; }
.btn.quiet { background: none; }
.btn.danger { color: var(--over); }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 13px; background: none; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--violet); border-color: var(--violet); color: var(--ink); font-weight: 600; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px; background: var(--raised); color: var(--muted); white-space: nowrap; }
.badge.mint { background: color-mix(in srgb, var(--mint) 18%, transparent); color: var(--mint); }
.badge.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.badge.over { background: color-mix(in srgb, var(--over) 18%, transparent); color: var(--over); }
.badge.violet { background: color-mix(in srgb, var(--violet) 20%, transparent); color: var(--violet); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 5px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat .v { font: 700 24px/1.2 var(--mono); margin-top: 4px; }
.stat .v.good { color: var(--mint); } .stat .v.bad { color: var(--over); }
.stat .n { font-size: 12px; color: var(--muted); margin-top: 2px; }
.period { display: flex; align-items: center; gap: 8px; }
.period h2 { font-size: 18px; }
.block-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 18px 2px 8px; display: flex; justify-content: space-between; }

.budget { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; overflow: hidden; }
.budget.drop { border-color: var(--mint); box-shadow: 0 0 0 2px color-mix(in srgb, var(--mint) 30%, transparent); }
.budget > button { all: unset; box-sizing: border-box; width: 100%; cursor: pointer; padding: 11px 14px; display: block; }
.budget .top { display: flex; align-items: baseline; gap: 8px; }
.budget .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.budget .amt { margin-left: auto; font-family: var(--mono); font-size: 14px; white-space: nowrap; }
.budget .amt .of { color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--raised); margin-top: 8px; position: relative; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; background: var(--mint); border-radius: 3px; }
.meter.close i { background: var(--warn); } .meter.over i { background: var(--over); }
.meter b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); opacity: 0.6; }
.items { border-top: 1px solid var(--line); }
.item { display: flex; align-items: center; gap: 10px; padding: 9px 14px; cursor: pointer; border-top: 1px solid var(--line); }
.items .item:first-child { border-top: 0; }
.item:hover { background: var(--raised); }
.item .d { color: var(--muted); font-size: 12px; width: 44px; flex: none; font-family: var(--mono); }
.item .t { min-width: 0; flex: 1; }
.item .t .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .t .s { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 1px; }
.item .a { font-family: var(--mono); font-size: 14px; white-space: nowrap; }
.item.out .n, .item.out .a { text-decoration: line-through; color: var(--muted); }
.item.dragging { opacity: 0.4; }
.empty { color: var(--muted); padding: 22px 8px; text-align: center; }

details.fold { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
details.fold > summary { cursor: pointer; padding: 12px 14px; font-weight: 600; list-style: none; display: flex; align-items: center; gap: 8px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: "›"; color: var(--muted); transition: transform 0.15s; display: inline-block; }
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > summary .right { margin-left: auto; font-weight: 400; }
details.fold > .body { border-top: 1px solid var(--line); padding: 12px 14px; }
details.fold > .body.flush { padding: 0; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 500; color: var(--muted); padding: 6px 8px; white-space: nowrap; }
td { padding: 7px 8px; border-top: 1px solid var(--line); vertical-align: middle; }
td.r, th.r { text-align: right; }
.scroll-x { overflow-x: auto; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.code { font-family: var(--mono); font-size: 13px; background: var(--raised); border-radius: 8px; padding: 8px 10px; overflow-wrap: anywhere; user-select: all; }
ol.steps { margin: 8px 0 0; padding-left: 20px; } ol.steps li { margin-top: 6px; }
pre.body { white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.5 var(--mono); max-height: 50vh; overflow: auto; background: var(--raised); border-radius: 8px; padding: 10px; margin: 0; }

/* sign in */
.auth { max-width: 380px; margin: 9vh auto 0; padding: 0 16px; }
.auth h1 { font-size: 28px; letter-spacing: -0.02em; } .auth h1 span { color: var(--mint); }
.auth form { margin-top: 18px; display: grid; gap: 12px; }
.error { color: var(--over); font-size: 13px; min-height: 18px; }

/* sheet */
dialog { border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 16px; padding: 18px;
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; }
dialog::backdrop { background: rgba(5, 7, 12, 0.6); }
dialog h3 { font-size: 17px; overflow-wrap: anywhere; }
dialog .form { display: grid; gap: 12px; margin-top: 14px; }
dialog .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
dialog .actions .spacer { flex: 1; }

#toast { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 20; display: none;
  background: var(--text); color: var(--bg); border-radius: 12px; padding: 10px 14px; gap: 10px; align-items: center;
  max-width: calc(100vw - 24px); box-shadow: 0 8px 30px rgba(0,0,0,0.35); }
#toast.show { display: flex; }
#toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; cursor: pointer; padding: 2px 4px; white-space: nowrap; }

@media (max-width: 560px) {
  .brand { max-width: 46vw; }
  .item .d { width: 38px; }
  .stat .v { font-size: 20px; }
  dialog { margin-bottom: 12px; }
}

main > * + * { margin-top: 14px; }
.row > select, .row > input[type="checkbox"], td select { width: auto; }
td input[type="text"] { min-width: 90px; }
.item select.pick { width: auto; max-width: 42%; flex: none; }
label.row { color: var(--text); font-size: 14px; }
label.row > input { margin-top: 0; }
