:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e2e0da;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #8a8984;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --income: #2a78d6;      /* series 1 */
  --expense: #eb6834;     /* series 2 */
  --wealth: #1baf7a;
  --good: #0f7b3c;
  --warn: #b26a00;
  --bad: #c42b2b;
  --good-bg: #e3f4e8;
  --warn-bg: #fdf1dc;
  --bad-bg: #fbe4e2;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
  --radius: 14px;
  --nav-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --line: #33332f;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --accent: #3987e5;
    --income: #3987e5;
    --expense: #d95926;
    --wealth: #199e70;
    --good: #5ccf86;
    --warn: #f0b44c;
    --bad: #ff7b72;
    --good-bg: #16301f;
    --warn-bg: #3a2c10;
    --bad-bg: #3d1a18;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110; --surface: #1a1a19; --surface-2: #242422; --line: #33332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86; --accent: #3987e5;
  --income: #3987e5; --expense: #d95926; --wealth: #199e70;
  --good: #5ccf86; --warn: #f0b44c; --bad: #ff7b72;
  --good-bg: #16301f; --warn-bg: #3a2c10; --bad-bg: #3d1a18; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.t2 { color: var(--text-2); }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- layout */
header.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  padding: 10px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--line);
}
header.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
main { max-width: 1100px; margin: 0 auto; padding: 14px 16px 24px; }
.grid { display: grid; gap: 14px; }
@media (min-width: 900px) {
  .grid.two { grid-template-columns: 1fr 1fr; }
  .grid.three { grid-template-columns: repeat(3, 1fr); }
  body { padding-bottom: 0; padding-left: 220px; }
  nav.tabs { top: 0; bottom: 0 !important; left: 0; width: 220px; height: auto !important; flex-direction: column;
             justify-content: flex-start !important; padding: 18px 10px !important; border-top: 0 !important; border-right: 1px solid var(--line); }
  nav.tabs button { flex-direction: row !important; justify-content: flex-start; gap: 12px !important; padding: 10px 14px !important; font-size: 15px !important; border-radius: 10px; flex: none !important; }
  nav.tabs button.active { background: var(--surface-2); }
  nav.tabs .brand { display: block !important; order: -2; }
  nav.tabs .fab-wrap { order: -1; margin: 6px 0 14px; flex: none; }
  nav.tabs { align-items: stretch !important; }
  nav.tabs .fab { width: 100% !important; height: 44px !important; border-radius: 12px !important; transform: none !important; font-size: 15px !important; }
  nav.tabs .fab .lbl { display: inline !important; }
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0;
}
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin: 0 0 10px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .sp { flex: 1; }

/* ---------- bottom nav */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 0 6px env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-around;
}
nav.tabs .brand { display: none; font-weight: 700; font-size: 17px; padding: 4px 14px 14px; }
nav.tabs button {
  background: none; border: 0; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; color: var(--muted); padding: 6px 4px; cursor: pointer; flex: 1;
}
nav.tabs button.active { color: var(--accent); }
nav.tabs svg { width: 22px; height: 22px; }
.fab-wrap { flex: 1; display: flex; justify-content: center; }
nav.tabs .fab {
  width: 54px; height: 54px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink);
  display: flex !important; align-items: center; justify-content: center; gap: 8px;
  transform: translateY(-12px); box-shadow: 0 6px 18px rgba(42,120,214,.35); cursor: pointer; font-weight: 600;
}
.fab svg { width: 26px; height: 26px; }
.fab .lbl { display: none; }

/* ---------- controls */
.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 14px;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: 550; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 6px; border-radius: 50%; }
.btn svg { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.spacer { flex: 1; }

input[type=text], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
label.f { display: block; font-size: 12px; color: var(--text-2); margin: 10px 0 4px; font-weight: 550; }

.monthpick { display: flex; align-items: center; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.monthpick button { background: none; border: 0; padding: 6px 8px; cursor: pointer; border-radius: 999px; display: flex; }
.monthpick button:hover { background: var(--surface-2); }
.monthpick span { min-width: 112px; text-align: center; font-weight: 600; font-size: 14px; }
.monthpick svg { width: 18px; height: 18px; }

.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; overflow-x: auto; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 10px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--text-2); white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 11px; cursor: pointer;
  font-size: 13px; display: inline-flex; align-items: center; gap: 6px; font-weight: 500;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip.on .dot { box-shadow: 0 0 0 2px var(--accent-ink); }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- KPI */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .l { font-size: 12px; color: var(--text-2); font-weight: 550; display: flex; align-items: center; gap: 6px; }
.kpi .v { font-size: 21px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .d { font-size: 12px; color: var(--muted); margin-top: 2px; }
@media (max-width: 520px) { .kpi .v { font-size: 17px; } .kpi { padding: 10px; } }

/* ---------- lists */
.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.li:last-child { border-bottom: 0; }
.li .main { flex: 1; min-width: 0; }
.li .title { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li .amt { font-weight: 650; white-space: nowrap; }
.li.click { cursor: pointer; }
.li.click:hover { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.ico { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex: none; background: var(--surface-2); color: var(--text-2); }
.ico svg { width: 18px; height: 18px; }
.dayhead { font-size: 12px; font-weight: 650; color: var(--text-2); padding: 14px 0 2px; display: flex; justify-content: space-between; text-transform: capitalize; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-weight: 600; white-space: nowrap; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.good { background: var(--good-bg); color: var(--good); }

/* ---------- budget bars */
.bud { padding: 8px 0; }
.bud .top { display: flex; gap: 8px; align-items: baseline; font-size: 14px; }
.bud .top .n { flex: 1; font-weight: 550; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; position: relative; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 4px; background: var(--accent); }
.bar > i.warn { background: var(--warn); }
.bar > i.over { background: var(--bad); }
.bar > b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text-2); opacity: .5; }

/* ---------- category bars */
.cbar { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; gap: 10px; align-items: center; padding: 5px 0; font-size: 14px; cursor: default; }
.cbar .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.cbar .track { height: 14px; position: relative; }
.cbar .track i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--expense); border-radius: 0 4px 4px 0; min-width: 2px; }
.cbar .track b { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--text-2); opacity: .55; }
.cbar .v { text-align: right; font-weight: 600; white-space: nowrap; font-size: 13.5px; }
.cbar .v small { display: block; font-weight: 500; font-size: 11.5px; }

/* ---------- tables */
.tablewrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.t { border-collapse: collapse; width: 100%; font-size: 13px; }
table.t th, table.t td { padding: 7px 8px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
table.t th:first-child, table.t td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.t thead th { color: var(--text-2); font-weight: 600; font-size: 12px; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: var(--surface-2); }
table.t td.z { color: var(--muted); }

/* ---------- charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .zero { stroke: var(--text-2); stroke-width: 1; opacity: .5; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.tip {
  position: absolute; pointer-events: none; z-index: 5; background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(0,0,0,.14); min-width: 140px;
  transform: translate(-50%, -100%); white-space: nowrap;
}
.tip .h { font-weight: 650; margin-bottom: 4px; }
.tip .r { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tip .r span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); }

/* ---------- sheet (modal) */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.38); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 94vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  animation: up .2s ease-out;
}
@media (min-width: 700px) { .backdrop { align-items: center; } .sheet { border-radius: 20px; max-height: 90vh; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 0 0 10px; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.sheet .foot { display: flex; gap: 8px; margin-top: 16px; position: sticky; bottom: 0; background: var(--surface); padding-top: 8px; }
.sheet .foot .btn { flex: 1; justify-content: center; padding: 12px; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.amount-in { display: flex; align-items: baseline; gap: 6px; border-bottom: 2px solid var(--line); padding: 6px 2px; margin: 8px 0 4px; }
.amount-in:focus-within { border-color: var(--accent); }
.amount-in input { border: 0 !important; outline: 0 !important; background: none; font-size: 34px; font-weight: 700; padding: 0; width: 100%; }
.amount-in .cur { font-size: 26px; color: var(--muted); font-weight: 600; }
.amount-calc { font-size: 12.5px; color: var(--muted); min-height: 18px; }

.sugg { display: flex; gap: 6px; overflow-x: auto; margin-top: 6px; scrollbar-width: none; }
.sugg button { flex: none; border: 1px dashed var(--line); background: var(--surface-2); border-radius: 10px; padding: 6px 10px; font-size: 12.5px; cursor: pointer; text-align: left; }
.sugg button b { display: block; font-weight: 600; font-size: 13px; }

.toggle { display: flex; align-items: center; gap: 10px; margin-top: 12px; cursor: pointer; font-size: 14px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 20px); transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: up .2s; max-width: calc(100vw - 32px); display: flex; gap: 12px; align-items: center; }
.toast button { background: none; border: 0; color: var(--bg); font-weight: 700; text-decoration: underline; cursor: pointer; padding: 0; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 14px; }
.login { max-width: 360px; margin: 18vh auto 0; padding: 0 16px; }
.login h1 { font-size: 22px; }
.pending { border-color: color-mix(in srgb, var(--warn) 45%, var(--line)); }
.pending .li .amt input { width: 92px; text-align: right; padding: 6px 8px; }
.settings-tabs { margin-bottom: 12px; }
.editrow { display: grid; gap: 8px; grid-template-columns: 1fr 110px auto; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.editrow:last-child { border-bottom: 0; }
.editrow.arch { opacity: .55; }

.plan-head { display: flex; gap: 16px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-bottom: 6px; }
.plan-head .big { font-size: 26px; font-weight: 750; line-height: 1.15; }
.plan-stats { display: grid; grid-template-columns: auto auto; gap: 2px 14px; }
.plan-stats > div { display: contents; }
.plan-stats b { text-align: right; }
.plan-row .ico { width: 30px; height: 30px; border-radius: 8px; }
.plan-row.done .title { color: var(--text-2); }
.plan-row .title .badge { margin-left: 4px; vertical-align: 1px; }
details.plan-done { margin-top: 6px; }
details.plan-done summary { cursor: pointer; padding: 6px 0; font-weight: 600; }
.plan-row .ico { font-weight: 700; font-size: 13px; }
.plan-row .ico.late { background: var(--warn-bg); color: var(--warn); }
.plan-row .amt input { width: 84px; }
.plan-row .btn.icon { padding: 7px; }
.plan-row .btn.icon.sk { padding: 5px; border-color: transparent; color: var(--muted); }
@media (max-width: 420px) { .plan-row { gap: 6px; } .plan-row .amt input { width: 70px; } .plan-row .main { margin-right: 4px; } }
select.accsel { width: auto; min-width: max-content; padding: 1px 18px 1px 6px; background-position: right 2px center; font-size: 12.5px; border-radius: 6px; color: var(--text-2); background-color: var(--surface-2); border-color: transparent; cursor: pointer; }
select.accsel:hover { border-color: var(--line); }
select.accsel.missing { color: var(--bad); background-color: var(--bad-bg); }
.plan-row .sub { overflow: visible; }
label.ck { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
label.ck input { width: 15px; height: 15px; margin: 0 4px 0 0; accent-color: var(--accent); cursor: pointer; }
table.t tr.sel td { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
table.t tr.selsum td { color: var(--accent); font-weight: 700; border-top: 2px solid var(--line); background: color-mix(in srgb, var(--accent) 6%, var(--surface)); }
.fc-hero .big { font-size: 34px; font-weight: 750; line-height: 1.15; margin: 2px 0 4px; }
.fc-grid { display: grid; grid-template-columns: 1fr auto; gap: 3px 16px; font-size: 13px; max-width: 420px; }
.fc-grid b { text-align: right; font-variant-numeric: tabular-nums; }
.fc-table tr.fc-det td { background: var(--surface-2); text-align: left; white-space: normal; position: static; }
.fc-table tr.fc-det td .fc-grid span { color: var(--text-2); }
input[type=month] { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; width: 100%; }
.fc-table th:first-child, .fc-table td:first-child { position: static; }
@media (max-width: 520px) { .fc-table .hs { display: none; } .fc-table th, .fc-table td { padding: 7px 5px; font-size: 12.5px; } }
