:root {
  color-scheme: light dark;
  --bg: #f4f3ef; --surface: #ffffff; --surface-2: #f9f8f5; --ink: #1c1c1a; --muted: #6a6964;
  --line: #e2e0d8; --accent: #1f6f5c; --accent-ink: #ffffff; --accent-soft: #e2f0eb;
  --in: #1f7a4d; --out: #b8432f; --move: #4a5fa8; --warn-bg: #fdf0e6;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413; --surface: #1e1e1c; --surface-2: #252523; --ink: #ecebe5; --muted: #a09f98;
    --line: #33322e; --accent: #5cc2a6; --accent-ink: #0f2a23; --accent-soft: #1d3530;
    --in: #6bcf98; --out: #f08a73; --move: #9aa9ea; --warn-bg: #3a2a1e; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
.shell { max-width: 960px; margin: 0 auto; padding: 0 16px 96px; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 0; }
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 17px; text-decoration: none; color: var(--ink); }
.brand span { color: var(--accent); }
.topbar .spacer { flex: 1; }
.who { color: var(--muted); font-size: 14px; }
.nav { display: flex; gap: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 4px; }
.nav a { padding: 6px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-size: 14px; font-weight: 500; }
.nav a.on { background: var(--accent); color: var(--accent-ink); }
.nav a.soon { opacity: .55; }
@media (max-width: 640px) {
  .topbar .nav { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); justify-content: space-around; z-index: 20; box-shadow: 0 6px 24px rgba(0,0,0,.12); }
  .who { display: none; }
}

h1 { font-size: 22px; letter-spacing: -.015em; margin: 8px 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stack > * + * { margin-top: 14px; }
.grid { display: grid; gap: 14px; }
@media (min-width: 760px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.side { grid-template-columns: 340px 1fr; align-items: start; } }

/* ---------- Controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 16px; border-radius: 10px; border: 1px solid transparent; background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--out); border-color: var(--line); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.input, select.input, textarea.input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); outline: none; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; min-height: 18px; }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 8px 6px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on[data-k="expense"] { background: var(--surface); color: var(--out); box-shadow: var(--shadow); }
.seg button.on[data-k="income"] { background: var(--surface); color: var(--in); box-shadow: var(--shadow); }
.seg button.on[data-k="transfer"] { background: var(--surface); color: var(--move); box-shadow: var(--shadow); }
.seg button.on:not([data-k]) { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.amount { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.amount::placeholder { font-size: 15px; font-weight: 400; letter-spacing: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 4px 0 16px; }
.toolbar .input { width: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); padding: 5px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; color: var(--muted); }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

/* ---------- Data ---------- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .k { font-size: 12.5px; color: var(--muted); }
.tile .v { font-size: 19px; font-weight: 700; letter-spacing: -.01em; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { .tiles { grid-template-columns: 1fr 1fr; } .tiles .tile:last-child { grid-column: span 2; } }
.in { color: var(--in); } .out { color: var(--out); } .move { color: var(--move); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .m { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .amt { font-weight: 700; white-space: nowrap; }
.list li.tap { cursor: pointer; border-radius: 8px; }
.list li.tap:hover { background: var(--surface-2); }
.day { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); font-weight: 600; margin: 18px 0 2px; }
.day span:first-child { text-transform: uppercase; letter-spacing: .04em; }
.day:first-child { margin-top: 0; }
.dot { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; font-size: 15px; flex: none; }
.dot.in { background: color-mix(in srgb, var(--in) 14%, transparent); }
.dot.out { background: color-mix(in srgb, var(--out) 14%, transparent); }
.dot.move { background: color-mix(in srgb, var(--move) 14%, transparent); }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; border-radius: 4px; }
.empty { color: var(--muted); text-align: center; padding: 28px 8px; font-size: 14px; }
.total { display: flex; justify-content: space-between; font-weight: 700; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 4px; }
.modcard { display: block; text-decoration: none; color: inherit; }
.modcard .name { font-weight: 700; font-size: 17px; }
.modcard .desc { color: var(--muted); font-size: 14px; margin: 2px 0 10px; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); margin: 2px 4px 2px 0; }
.tag.soon { background: var(--warn-bg); border-color: transparent; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }

/* ---------- Dialog & toast ---------- */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog .body { padding: 20px; }
dialog .foot { display: flex; gap: 8px; justify-content: flex-end; padding: 0 20px 20px; }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--out); color: #fff; }

/* ---------- Clara ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-h { text-align: center; font-size: 11.5px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.cal-d { aspect-ratio: 1 / 1; border: 0; background: transparent; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 14px; padding: 0; }
.cal-d:hover { background: var(--surface-2); }
.cal-d.other { color: var(--muted); opacity: .55; }
.cal-d.today span { color: var(--accent); font-weight: 700; }
.cal-d.sel { background: var(--accent); color: var(--accent-ink); }
.cal-d.sel span { color: var(--accent-ink); }
.cal-d i { display: flex; gap: 2px; height: 5px; }
.cal-d i b, b.legend { width: 5px; height: 5px; border-radius: 50%; background: var(--move); display: inline-block; }
.cal-d i b.ws, b.legend.ws { background: var(--in); }
.cal-d.sel i b { background: var(--accent-ink); }
.list .when { flex: 0 0 52px; font-weight: 600; font-size: 13.5px; line-height: 1.3; }

.clara-grid { display: grid; gap: 14px; grid-template-areas: "cal" "agenda" "set" "msg"; }
@media (min-width: 760px) { .clara-grid { grid-template-columns: 340px 1fr; grid-template-areas: "cal agenda" "set agenda" "msg agenda"; align-items: start; } .clara-grid > [style*="agenda"] { align-self: start; } }
