:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #f9f8f4;
  --ink: #1b1d1a;
  --muted: #6a6e66;
  --line: #e4e1d8;
  --brand: #16603f;
  --brand-ink: #ffffff;
  --brand-soft: #e2efe7;
  --in: #1a7f52;
  --out: #c2452f;
  --out-soft: #f8e4df;
  --warn: #9a6400;
  --chat-bg: #efe9df;
  --bubble-me: #d8f3cf;
  --bubble-bot: #ffffff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(20, 25, 20, .05), 0 6px 24px -12px rgba(20, 25, 20, .12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121412; --surface: #1b1e1b; --surface-2: #222622; --ink: #eceee9; --muted: #9ba096; --line: #2e332e;
    --brand: #3fae7c; --brand-ink: #07120c; --brand-soft: #1f3529; --in: #52c48f; --out: #f07b64; --out-soft: #3a2420;
    --warn: #e2b04a; --chat-bg: #161a17; --bubble-me: #1f4a33; --bubble-bot: #232823;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 28px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121412; --surface: #1b1e1b; --surface-2: #222622; --ink: #eceee9; --muted: #9ba096; --line: #2e332e;
  --brand: #3fae7c; --brand-ink: #07120c; --brand-soft: #1f3529; --in: #52c48f; --out: #f07b64; --out-soft: #3a2420;
  --warn: #e2b04a; --chat-bg: #161a17; --bubble-me: #1f4a33; --bubble-bot: #232823;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--brand); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; background: var(--surface-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; word-break: break-all; }
h2, h3 { margin: 0 0 .4rem; letter-spacing: -.01em; }
h3 { font-size: 1rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.muted { color: var(--muted); margin: .2rem 0 .8rem; }
.small-note { font-size: .85rem; }

/* brand */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; font-size: 1.05rem; }
.brand.big { font-size: 1.4rem; margin-bottom: .4rem; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--brand); position: relative; flex: none; }
.logo::before { content: ""; position: absolute; left: 6px; right: 6px; top: 9px; height: 13px; border-radius: 4px; border: 2.5px solid var(--brand-ink); border-top-width: 5px; }
.logo::after { content: ""; position: absolute; right: 9px; top: 14px; width: 5px; height: 5px; border-radius: 50%; background: var(--brand-ink); }
.logo.small { width: 34px; height: 34px; border-radius: 50%; }

/* buttons & inputs */
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 12px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; transition: background .15s, transform .05s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--out); border-color: color-mix(in srgb, var(--out) 40%, var(--line)); }
.btn.small { padding: 6px 12px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: progress; }
.link { background: none; border: 0; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }
.icon-btn { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-size: 1.3rem; line-height: 1; cursor: pointer; }
label { display: grid; gap: 6px; font-weight: 600; font-size: .88rem; margin-bottom: 12px; }
label small { font-weight: 400; color: var(--muted); }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px; border-color: var(--brand); }
.error { color: var(--out); min-height: 1.2em; margin: .6rem 0 0; font-weight: 600; }

/* auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 28px; box-shadow: var(--shadow); }

/* layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px max(16px, calc((100vw - 1040px) / 2)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; }
.tabs button { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: var(--muted); font: inherit; font-weight: 600; padding: 8px 12px; border-radius: 10px; cursor: pointer; }
.tabs button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.active { color: var(--brand); background: var(--brand-soft); }
main { max-width: 1040px; margin: 0 auto; padding: 16px 16px 110px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.month-picker { display: flex; align-items: center; gap: 10px; }
.month-picker strong { min-width: 150px; text-align: center; font-size: 1.05rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.card-head h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid2 > .card { margin-bottom: 0; }
.grid2 + .card { margin-top: 14px; }
.row { display: flex; gap: 8px; }
.row input { flex: 1; }
.row-end { display: flex; align-items: end; margin-bottom: 12px; }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* hero */
.hero { background: var(--brand); color: var(--brand-ink); border: 0; padding: 22px; }
.hero-label { opacity: .85; font-weight: 600; font-size: .9rem; }
.hero-value { font-size: clamp(1.9rem, 6vw, 2.6rem); font-weight: 800; letter-spacing: -.03em; line-height: 1.15; margin: 2px 0 16px; font-variant-numeric: tabular-nums; }
.hero-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hero-split > div { background: color-mix(in srgb, var(--brand-ink) 12%, transparent); border-radius: 12px; padding: 10px 12px; font-size: .82rem; font-weight: 600; display: grid; }
.hero-split .hs-label { display: flex; align-items: center; opacity: .9; }
.hero-split b { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.hero-split small { opacity: .8; font-weight: 500; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.hero .dot.in { background: #9ef0c6; } .hero .dot.out { background: #ffb4a3; }

/* day chart */
.daychart { display: flex; align-items: flex-end; gap: 2px; height: 150px; padding-top: 8px; position: relative; }
.daychart .bar { flex: 1; min-width: 2px; background: var(--out); border-radius: 3px 3px 0 0; opacity: .85; position: relative; cursor: default; }
.daychart .bar.zero { background: var(--line); height: 2px !important; opacity: 1; }
.daychart .bar.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.daychart .bar:hover { opacity: 1; }
.daychart-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .75rem; margin-top: 6px; }
.chart-tip { font-size: .82rem; color: var(--muted); min-height: 1.3em; margin-top: 4px; }

/* category bars */
.catbars { display: grid; gap: 10px; }
.catbar-top { display: flex; justify-content: space-between; gap: 8px; font-size: .88rem; font-weight: 600; }
.catbar-top span:last-child { font-variant-numeric: tabular-nums; }
.catbar-track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 4px; border: 1px solid var(--line); }
.catbar-fill { height: 100%; background: var(--out); border-radius: 99px; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

/* transactions */
.txlist { list-style: none; margin: 0; padding: 0; }
.tx { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 10px 6px; border-radius: 12px; cursor: pointer; }
.tx:hover { background: var(--surface-2); }
.tx + .tx { border-top: 1px solid var(--line); }
.tx-icon { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: .95rem; }
.tx-icon.out { background: var(--out-soft); color: var(--out); }
.tx-icon.in { background: var(--brand-soft); color: var(--in); }
.tx-main { min-width: 0; }
.tx-note { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { color: var(--muted); font-size: .8rem; display: flex; gap: 6px; flex-wrap: wrap; }
.tx-amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx-amt.out { color: var(--out); } .tx-amt.in { color: var(--in); }
.src { font-size: .7rem; font-weight: 700; padding: 0 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); }
.daygroup { margin-bottom: 14px; }
.daygroup-head { display: flex; justify-content: space-between; color: var(--muted); font-size: .82rem; font-weight: 700; padding: 0 6px 6px; text-transform: uppercase; letter-spacing: .03em; }
.daygroup .card { padding: 6px 10px; margin: 0; }
.filters { display: flex; gap: 10px; margin-bottom: 12px; }
.filters input { flex: 1; }
.totals { display: flex; gap: 16px; flex-wrap: wrap; color: var(--muted); font-size: .88rem; margin: 0 4px 12px; }
.totals b { color: var(--ink); font-variant-numeric: tabular-nums; }

/* segmented */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; color: var(--muted); font: inherit; font-weight: 600; font-size: .88rem; padding: 7px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg.wide { display: flex; margin-bottom: 14px; }
.seg.wide button { flex: 1; white-space: normal; padding: 7px 6px; }

/* chat */
.chat { padding: 0; overflow: hidden; display: flex; flex-direction: column; height: min(640px, calc(100dvh - 220px)); min-height: 420px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-head small { display: block; color: var(--muted); font-size: .78rem; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: min(80%, 460px); padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: .92rem; box-shadow: 0 1px 1px rgba(0,0,0,.08); }
.bubble.me { align-self: flex-end; background: var(--bubble-me); border-bottom-right-radius: 4px; }
.bubble.bot { align-self: flex-start; background: var(--bubble-bot); border-bottom-left-radius: 4px; }
.bubble.typing { color: var(--muted); font-style: italic; }
.chips { display: flex; gap: 6px; padding: 10px 12px 0; overflow-x: auto; }
.chips button { flex: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: 99px; padding: 5px 12px; font: inherit; font-size: .82rem; cursor: pointer; }
.chat-input { display: flex; gap: 8px; padding: 10px 12px 12px; align-items: flex-end; }
.chat-input textarea { resize: none; max-height: 140px; border-radius: 20px; padding: 10px 14px; }
.chat-input .btn { border-radius: 20px; }

/* settings */
.paircode { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.paircode code { font-size: 1.15rem; font-weight: 700; padding: 6px 12px; letter-spacing: .04em; }
.senders { list-style: none; padding: 0; margin: 8px 0 0; }
.senders li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.senders li .grow { flex: 1; min-width: 0; }
.senders li small { color: var(--muted); display: block; }
.steps { padding-left: 1.2rem; margin: .2rem 0 1rem; color: var(--muted); }
.steps li { margin-bottom: 4px; }
.steps b, .steps code { color: var(--ink); }
.copyline { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; flex-wrap: wrap; }
.copyline span { font-weight: 600; font-size: .85rem; min-width: 96px; }
.copyline code { flex: 1; min-width: 0; padding: 6px 10px; }
.badge { font-size: .75rem; font-weight: 700; padding: 3px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: var(--brand-soft); color: var(--in); border-color: transparent; }
.badge.warn { color: var(--warn); }

/* fab, dialog, toast */
.fab { position: fixed; right: max(20px, calc((100vw - 1040px) / 2 + 16px)); bottom: 24px; width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--brand); color: var(--brand-ink); box-shadow: 0 10px 24px -8px color-mix(in srgb, var(--brand) 70%, transparent); cursor: pointer; z-index: 15; }
.fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.5; stroke-linecap: round; }
dialog { border: 0; border-radius: 20px; padding: 22px; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 30px 60px -20px rgba(0,0,0,.4); }
dialog::backdrop { background: rgba(10, 14, 10, .45); backdrop-filter: blur(2px); }
dialog input[name="amount"] { font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.dialog-actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.spacer { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: .9rem; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* mobile */
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; backdrop-filter: none; background: var(--bg); }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabs button { flex-direction: column; gap: 2px; font-size: .7rem; padding: 6px 4px; flex: 1; }
  .tabs button svg { width: 22px; height: 22px; }
  .tabs button.active { background: none; }
  .fab { bottom: calc(84px + env(safe-area-inset-bottom)); right: 16px; }
  .toast { bottom: calc(150px + env(safe-area-inset-bottom)); }
  .grid2, .grid-form { grid-template-columns: 1fr; }
  .month-picker strong { min-width: 120px; font-size: 1rem; }
  .filters { flex-direction: column; }
  .chat { height: calc(100dvh - 230px); }
  main { padding-bottom: 150px; }
}
