:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --p1: #2a78d6;
  --p2: #eb6834;
  --seq: #2a78d6;
  --good: #1a7f3c;
  --bad: #c43b3a;
  --grid: #e8e7e3;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #3987e5; --p1: #3987e5; --p2: #d95926; --seq: #3987e5;
    --good: #4cbb6f; --bad: #e66767; --grid: #2a2a28;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2f2f2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --p1: #3987e5; --p2: #d95926; --seq: #3987e5;
  --good: #4cbb6f; --bad: #e66767; --grid: #2a2a28;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; text-align: center; color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: 980px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { text-decoration: none; color: var(--text-2); padding: 7px 12px; border-radius: 999px; font-size: 15px; white-space: nowrap; }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.user-menu { display: flex; align-items: center; gap: 8px; }
main { max-width: 980px; margin: 0 auto; padding: 16px 16px 100px; }
h1 { font-size: 22px; margin: 4px 0 14px; }
h2 { font-size: 17px; margin: 0 0 12px; }
@media (max-width: 720px) {
  .topbar { backdrop-filter: none; background: var(--bg); }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; justify-content: space-around; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 20; }
  .nav a { display: flex; flex-direction: column; align-items: center; font-size: 12px; padding: 4px 10px; gap: 1px; }
  .nav a .ico { font-size: 20px; }
  .user-menu { margin-left: auto; }
  .user-menu .who { display: none; }
}
@media (min-width: 721px) { .nav a .ico { display: none; } }

/* Cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.section { margin-bottom: 14px; }

/* Forms */
label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
.field { margin-bottom: 12px; }
input[type=text], input[type=password], input[type=date], input[type=month], input[inputmode], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); min-height: 44px;
}
textarea { min-height: 60px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 140px; }
.amount-input { font-size: 26px !important; font-weight: 700; text-align: right; }
.btn { border: 1px solid var(--border); background: var(--surface); padding: 10px 16px; border-radius: 10px; cursor: pointer; min-height: 44px; font-weight: 600; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 6px 10px; min-height: 34px; font-size: 14px; }
.btn-block { width: 100%; }
.error { color: var(--bad); font-size: 14px; margin: 8px 0; }

.seg { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--surface); padding: 10px 8px; cursor: pointer; min-height: 44px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); font-weight: 700; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.dot.p1 { background: var(--p1); } .dot.p2 { background: var(--p2); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 14px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* Month switcher */
.month-switch { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.month-switch .label { font-size: 20px; font-weight: 700; text-align: center; flex: 1; }
.month-switch .btn { min-width: 44px; padding: 8px 12px; }

/* Expense list */
.day { font-size: 13px; color: var(--text-3); font-weight: 600; margin: 14px 2px 6px; text-transform: capitalize; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.item + .item { border-top: 1px solid var(--border); }
.item:hover { background: var(--surface-2); }
.item .icon { width: 38px; height: 38px; border-radius: 10px; background: var(--surface-2); display: grid; place-items: center; font-size: 19px; flex: none; }
.item .main { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 13px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.item .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.item.settlement .icon { background: transparent; border: 1px dashed var(--border); }
.empty { text-align: center; color: var(--text-3); padding: 30px 10px; }

.fab { position: fixed; right: 18px; bottom: 84px; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 30px; box-shadow: 0 6px 20px rgba(0,0,0,.2); cursor: pointer; z-index: 15; }
@media (min-width: 721px) { .fab { bottom: 28px; right: 28px; } }

/* Stat tiles */
.tile .k { font-size: 13px; color: var(--text-2); }
.tile .v { font-size: 26px; font-weight: 700; margin-top: 2px; }
.tile .s { font-size: 13px; color: var(--text-3); }
.person-head { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 8px; }
.kv { display: flex; justify-content: space-between; padding: 4px 0; font-size: 15px; }
.kv + .kv { border-top: 1px dashed var(--border); }
.pos { color: var(--good); } .neg { color: var(--bad); }

.verdict { text-align: center; padding: 22px 16px; }
.verdict .big { font-size: 30px; font-weight: 800; margin: 6px 0; }
.verdict .who { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 18px; font-weight: 600; flex-wrap: wrap; }
.verdict .arrow { color: var(--text-3); }

/* Charts */
.chart { width: 100%; overflow: visible; }
.chart text { fill: var(--text-2); font-size: 12px; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + g rect, .chart g.bar:hover rect { opacity: .85; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--text-2); margin-bottom: 8px; flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: 14px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 14px; display: flex; gap: 2px; }
.hbar .seg-fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .val { font-weight: 600; text-align: right; min-width: 74px; }
.split-bar { display: flex; height: 14px; gap: 2px; margin: 8px 0 4px; }
.split-bar div { height: 100%; }
.split-bar div:first-child { border-radius: 4px 0 0 4px; } .split-bar div:last-child { border-radius: 0 4px 4px 0; }
.bg-p1 { background: var(--p1); } .bg-p2 { background: var(--p2); } .bg-seq { background: var(--seq); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--border); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--text-2); font-weight: 600; }
details summary { cursor: pointer; color: var(--text-2); font-size: 14px; margin-top: 8px; }

.tooltip { position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--bg); padding: 8px 10px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 240px; }
.tooltip .t { font-weight: 700; margin-bottom: 2px; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
@media (min-width: 600px) { .modal-back { align-items: center; } .modal { border-radius: 18px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.modal-head h2 { margin: 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .spacer { flex: 1; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login .logo { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-bottom: 18px; }
.login .logo img { width: 56px; height: 56px; }
.login .logo h1 { margin: 0; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 120; font-size: 14px; }

.badge { display: inline-block; font-size: 11px; font-weight: 600; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; margin-left: 6px; vertical-align: 2px; }
.item.paused { opacity: .55; }
label.check { display: flex; align-items: center; gap: 8px; font-size: 15px; color: var(--text); margin: 4px 0 10px; }
label.check input { width: 20px; height: 20px; }
@media (max-width: 380px) { .nav a { padding: 4px 6px; } }
