/* ShvIA Money — the web page (ADR-019). No build step, no external assets. */

:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --ink: #16201b;
  --muted: #5d6a63;
  --line: #e1e5e0;
  --accent: #0f6b45;
  --accent-ink: #ffffff;
  --accent-soft: #e4f1ea;
  --warn: #9a5b00;
  --warn-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --income: #0f6b45;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #18201c;
    --ink: #e7ede9;
    --muted: #9aa8a0;
    --line: #2a3530;
    --accent: #3fbf86;
    --accent-ink: #0b1a13;
    --accent-soft: #1b3328;
    --warn: #f5b041;
    --warn-soft: #3a2c12;
    --danger: #f47c72;
    --danger-soft: #3d1d1a;
    --income: #3fbf86;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}

[hidden] { display: none !important; }

h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 0.8rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); margin: 24px 0 8px; }

button, input, select { font: inherit; color: inherit; }

button { cursor: pointer; border-radius: 10px; border: 1px solid transparent; padding: 10px 16px; font-weight: 600; }
button:disabled { opacity: 0.55; cursor: progress; }
button.primary { background: var(--accent); color: var(--accent-ink); }
button.secondary { background: var(--surface); border-color: var(--line); }
button.link { background: none; padding: 6px 8px; color: var(--muted); font-weight: 500; }
button.icon { background: var(--surface); border-color: var(--line); width: 40px; height: 40px; padding: 0; font-size: 1.3rem; }
button.small { padding: 6px 12px; font-size: 0.85rem; }
button.wide { width: 100%; margin-top: 12px; }

input, select {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); }
label.inline { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }

.brand { margin: 0; font-weight: 500; letter-spacing: -0.01em; }
.brand b { color: var(--accent); font-weight: 750; }

.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 0.9rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.soft { background: var(--accent-soft); border-color: transparent; margin-top: 12px; font-size: 0.92rem; }

.boot { text-align: center; color: var(--muted); margin-top: 30vh; }

/* Sign in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; padding: 24px; }
.login-card .brand { font-size: 1.5rem; text-align: center; margin-bottom: 4px; }

/* Frame */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar select { min-height: 38px; padding: 6px 10px; max-width: 260px; justify-self: end; }

main { max-width: 720px; margin: 0 auto; padding: 16px 16px 120px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { background: none; border-radius: 0; padding: 14px 8px; color: var(--muted); font-weight: 600; }
.tabs button[aria-current="page"] { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }

@media (min-width: 720px) {
  .tabs { position: sticky; top: 59px; bottom: auto; max-width: 720px; margin: 0 auto; border: 0; background: none; padding: 0 16px; grid-template-columns: repeat(3, max-content); gap: 4px; }
  .tabs button { box-shadow: none; border-radius: 999px; padding: 8px 16px; }
  .tabs button[aria-current="page"] { background: var(--accent-soft); box-shadow: none; }
  main { padding-bottom: 48px; }
}

/* Month */
.monthbar { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; margin-bottom: 14px; }
.monthbar h1 { text-align: center; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat .label { font-size: 0.78rem; color: var(--muted); }
.stat .value { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }
.stat .hint { font-size: 0.75rem; color: var(--muted); }
.stat.expense .value { color: var(--ink); }
.stat.income .value { color: var(--income); }
.stat.negative .value { color: var(--danger); }
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:first-child { grid-column: 1 / -1; }
}

.banner { margin: 12px 0 0; padding: 12px 14px; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); font-weight: 600; font-size: 0.92rem; }

.centers, .ledger, .receipts, .agenda { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.centers:empty, .ledger:empty, .receipts:empty, .agenda:empty { display: none; }
.centers li, .ledger li, .receipts li, .agenda li { border-top: 1px solid var(--line); }
.centers > li:first-child, .ledger > li:first-child, .receipts > li:first-child, .agenda > li:first-child { border-top: 0; }

.empty { color: var(--muted); padding: 16px; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); margin: 0; }

.center { padding: 12px 16px; display: grid; gap: 6px; }
.center .row { display: flex; justify-content: space-between; gap: 12px; }
.center .name { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.center .amount { font-weight: 650; white-space: nowrap; }
.center .budget { font-size: 0.8rem; color: var(--muted); }
.center.over .budget { color: var(--danger); font-weight: 600; }
.center.child { padding-left: 32px; background: color-mix(in srgb, var(--bg) 45%, var(--surface)); }
.center.child .name { font-weight: 500; }
.bar { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.center.over .bar span { background: var(--danger); }

.txn { width: 100%; text-align: left; background: none; border: 0; border-radius: 0; padding: 12px 16px; display: grid; grid-template-columns: 52px 1fr auto; gap: 2px 12px; align-items: baseline; font-weight: 400; }
.txn .day { color: var(--muted); font-size: 0.85rem; }
.txn .desc { font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.txn .amount { font-weight: 650; white-space: nowrap; }
.txn .amount.income { color: var(--income); }
.txn .sub { grid-column: 2 / -1; font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }
.detail { padding: 0 16px 14px 80px; display: grid; gap: 8px; font-size: 0.88rem; }
.detail .split { display: flex; justify-content: space-between; gap: 12px; }
.detail .reason { color: var(--warn); }
@media (max-width: 420px) { .detail { padding-left: 16px; } }

.pill { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--muted); vertical-align: middle; white-space: nowrap; }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }

/* Receipts */
.upload { display: grid; gap: 12px; }
.file { position: relative; display: block; text-align: center; padding: 22px 16px; border: 2px dashed var(--accent); border-radius: var(--radius); color: var(--accent); font-weight: 700; font-size: 1rem; cursor: pointer; background: var(--accent-soft); }
.file input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.file:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.upload p { margin: 0; font-size: 0.9rem; }

.receipt { display: grid; grid-template-columns: 56px 1fr auto; gap: 4px 12px; padding: 12px 16px; align-items: start; }
.receipt img { width: 56px; height: 72px; object-fit: cover; border-radius: 6px; background: var(--line); grid-row: span 3; }
.receipt .title { font-weight: 600; overflow-wrap: anywhere; }
.receipt .amount { font-weight: 650; white-space: nowrap; }
.receipt .sub { grid-column: 2 / -1; font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }
.receipt .items { grid-column: 2 / -1; margin: 6px 0 0; padding: 0; list-style: none; font-size: 0.85rem; display: grid; gap: 4px; }
.receipt .items li { display: flex; justify-content: space-between; gap: 12px; border: 0; }
.receipt .items .cc { color: var(--muted); font-size: 0.78rem; }

/* Bills */
.bill { display: grid; grid-template-columns: 52px 1fr auto; gap: 4px 12px; padding: 12px 16px; align-items: center; }
.bill .day { color: var(--muted); font-size: 0.85rem; }
.bill .desc { font-weight: 600; overflow-wrap: anywhere; }
.bill .amount { font-weight: 650; white-space: nowrap; }
.bill .sub { grid-column: 2 / -1; font-size: 0.82rem; color: var(--muted); overflow-wrap: anywhere; }
.bill .buttons { grid-column: 2 / -1; display: flex; gap: 6px; margin-top: 4px; }
.bill.overdue .day { color: var(--danger); font-weight: 700; }
.bill.done { opacity: 0.65; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); width: min(420px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog form { display: grid; gap: 14px; }
dialog h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 1.1rem; color: var(--ink); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.actions button { flex: 1 1 auto; }

.toast { position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20; margin: 0; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 10px; background: var(--ink); color: var(--bg); font-size: 0.92rem; box-shadow: 0 6px 24px rgb(0 0 0 / 0.2); }
.toast.error { background: var(--danger); color: #fff; }
@media (min-width: 720px) { .toast { bottom: 24px; } }
