:root {
  --bg: #F2F3F5; --card: #FFFFFF; --text: #16181D; --muted: #5B6170; --line: #EEF0F3; --tabs: #E3E5E9;
  --paid: #1E8E3E; --paid-bg: #E6F4EA; --paid-text: #0F5223;
  --overdue: #C5221F; --overdue-bg: #FCE8E6; --overdue-text: #8A130C; --overdue-cell: #C5221F;
  --upcoming: #9AA0AA; --upcoming-bg: #E6E8EC; --upcoming-text: #2B2F38;
  --in: #1F6FB2; --in-bg: #E8F1FA; --in-text: #0F3F63;
  --out: #B45309; --out-bg: #FDF0E3; --out-text: #6B3908;
  --taken: #5B2F9E; --taken-bg: #F3EEFB; --taken-text: #48247E;
  --accent: #1F6FB2; --soft: #EEF0F3; --weekend: #A1170F; --chip-on: #16181D; --chip-on-text: #FFFFFF;
}
html.dark {
  --bg: #0F1115; --card: #1A1D23; --text: #ECEEF2; --muted: #A3A9B5; --line: #2A2E36; --tabs: #24282F;
  --paid: #3DBE62; --paid-bg: #173322; --paid-text: #8FE0A8;
  --overdue: #E5534B; --overdue-bg: #3A1A19; --overdue-text: #FFB4AE; --overdue-cell: #A8231C;
  --upcoming: #7D8490; --upcoming-bg: #2A2E36; --upcoming-text: #D5D9E0;
  --in: #5AA6E8; --in-bg: #16283A; --in-text: #A9D1F5;
  --out: #E39A4B; --out-bg: #36240F; --out-text: #F5C898;
  --taken: #A985E6; --taken-bg: #2A2140; --taken-text: #D3BFF7;
  --accent: #5AA6E8; --soft: #2A2E36; --weekend: #FF8A80; --chip-on: #ECEEF2; --chip-on-text: #0F1115;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font-family: inherit; }
[hidden] { display: none !important; }
.app { max-width: 520px; margin: 0 auto; padding: 8px 12px 32px; display: flex; flex-direction: column; gap: 12px; }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 40px; }
.top { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
h1 { margin: 0; font-size: 19px; font-weight: 700; text-align: center; }
h2 { margin: 0 0 4px; font-size: 17px; }
h3 { margin: 0; font-size: 19px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.icon-btn { width: 44px; height: 44px; border: none; border-radius: 12px; background: var(--card); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.icon-btn.soft { background: var(--soft); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; background: var(--tabs); border-radius: 12px; padding: 4px; }
.tabs button { height: 40px; border: none; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.tabs button[aria-current="page"] { background: var(--card); color: var(--text); font-weight: 700; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.chips { display: flex; gap: 8px; }
.chips button { flex: 1 1 0; height: 36px; padding: 0 10px; border-radius: 18px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font-size: 14px; font-weight: 600; cursor: pointer; }
.chips button[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-text); border-color: var(--chip-on); }
.tab { display: flex; flex-direction: column; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.card { background: var(--card); border-radius: 18px; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.summary .big { font-size: 34px; font-weight: 700; letter-spacing: -0.5px; }
.big2 { font-size: 22px; }
.bar { height: 10px; border-radius: 5px; background: var(--upcoming-bg); overflow: hidden; }
.bar-fill { height: 10px; width: 0; background: var(--paid); transition: width .3s; }
.bar-fill.in { background: var(--in); }
.bar-fill.out { background: var(--out); }
.bar.thin, .bar.thin .bar-fill { height: 6px; }
.tiles { display: grid; gap: 8px; }
.tiles.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tiles.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile { border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; font-weight: 600; }
.tile b { font-size: 16px; }
.t-paid { background: var(--paid-bg); color: var(--paid-text); }
.t-overdue { background: var(--overdue-bg); color: var(--overdue-text); }
.t-upcoming { background: var(--upcoming-bg); color: var(--upcoming-text); }
.t-in { background: var(--in-bg); color: var(--in-text); }
.t-out { background: var(--out-bg); color: var(--out-text); }
.t-taken { background: var(--taken-bg); color: var(--taken-text); }
.line { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 14px; }
.line b { white-space: nowrap; }
.line.sub, .line.total { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 700; }
.line.total { font-size: 17px; }
.line.cost { color: var(--muted); }
.pos { color: var(--paid-text); } .neg { color: var(--overdue-text); } .tk { color: var(--taken-text); }
.note-box { border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.taken-box { background: var(--taken-bg); color: var(--taken-text); }
.plain-box { background: var(--soft); }
.dark-card { background: #16181D; color: #FFFFFF; }
html.dark .dark-card { background: #262A33; }
.dark-card .line { color: #D5D9E0; } .dark-card .line b { color: #FFFFFF; }
.dark-card .line.total b { color: #7EE2A0; } .dark-card .line.total b.neg-total { color: #FF9A92; } .dark-card .line.total, .dark-card .line.sub { border-color: #3A3F49; }
.dark-card p { color: #A3A9B5; margin: 0; }
.calendar { padding: 14px 10px 12px; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.weekdays span { text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.weekdays .we { color: var(--weekend); }
.day { height: 58px; border-radius: 12px; border: 2px solid transparent; padding: 5px 2px; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  font-size: 13px; font-weight: 500; color: var(--upcoming-text); background: transparent; }
.day.we { color: var(--weekend); }
.day.today { border-color: var(--accent); }
button.day { cursor: pointer; font-weight: 600; }
.day .sum { font-size: 12px; font-weight: 700; }
.day.st-paid { background: var(--paid-bg); color: var(--paid-text); }
.day.st-overdue { background: var(--overdue-cell); color: #FFFFFF; }
.day.st-upcoming { background: var(--upcoming-bg); color: var(--upcoming-text); }
.day .dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 4px; background: var(--paid); }
.day.st-overdue .dot { background: #FFFFFF; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding: 6px 4px 0; font-size: 12px; color: var(--muted); }
.legend span { display: flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw-paid { background: var(--paid); } .sw-overdue { background: var(--overdue); } .sw-upcoming { background: var(--upcoming); }
.sw-today { border: 2px solid var(--accent); }
.group-title { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 6px; }
.row { display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.row .info { display: flex; flex-direction: column; gap: 2px; flex-grow: 1; min-width: 0; }
.row .name { font-size: 15px; font-weight: 600; }
.row .meta { font-size: 13px; font-weight: 500; color: var(--muted); }
.row .amt { font-size: 15px; font-weight: 700; white-space: nowrap; }
.row .pin { width: 10px; height: 10px; border-radius: 5px; flex-shrink: 0; }
.op-icon { width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.op-in { background: var(--in-bg); color: var(--in-text); }
.op-out { background: var(--out-bg); color: var(--out-text); }
.op-tr { background: var(--taken-bg); color: var(--taken-text); }
.amt.in { color: var(--in); } .amt.tr { color: var(--taken-text); }
.st-text-paid { color: var(--paid-text) !important; } .st-text-overdue { color: var(--overdue-text) !important; }
.pin-paid { background: var(--paid); } .pin-overdue { background: var(--overdue); } .pin-upcoming { background: var(--upcoming); }
.act { height: 40px; min-width: 96px; padding: 0 12px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer;
  border: none; background: var(--paid); color: #FFFFFF; }
html.dark .act:not(.undo) { color: #0B1F12; }
.act.undo { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.act:disabled { opacity: .5; }
.cat { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.obj-head { border: none; background: transparent; color: var(--text); padding: 0; text-align: left; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px; width: 100%; }
.obj-title { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.obj-title b { font-size: 17px; }
.badge { flex-shrink: 0; height: 26px; padding: 0 10px; border-radius: 13px; font-size: 12px; font-weight: 700; display: flex; align-items: center; }
.obj-body { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--line); padding-top: 10px; }
.take-btn { height: 46px; border: none; border-radius: 12px; background: var(--taken); color: #FFFFFF; font-size: 15px; font-weight: 600; cursor: pointer; }
html.dark .take-btn { color: #17112A; }
.chart { display: flex; align-items: flex-end; gap: 6px; height: 130px; }
.chart .col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 4px; justify-content: flex-end; height: 100%; }
.chart .col i { width: 100%; border-radius: 4px 4px 0 0; background: var(--paid); min-height: 2px; }
.chart .col i.neg { background: var(--overdue); }
.chart .col span { font-size: 10px; color: var(--muted); }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; margin: 0; }
.error { margin: 0; padding: 12px 14px; border-radius: 12px; background: var(--overdue-bg); color: var(--overdue-text); font-size: 14px; }
.backdrop { position: fixed; inset: 0; background: rgba(16, 18, 24, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; background: var(--card); border-radius: 22px 22px 0 0; padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 10px; max-height: 85vh; overflow-y: auto; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
#sheet-body { display: flex; flex-direction: column; gap: 10px; }
.sheet .row { border: none; padding: 8px 12px; border-radius: 14px; }
.sheet .row.st-paid { background: var(--paid-bg); } .sheet .row.st-overdue { background: var(--overdue-bg); } .sheet .row.st-upcoming { background: var(--soft); }
.wide-btn { height: 48px; border: none; border-radius: 12px; background: var(--accent); color: #FFFFFF; font-size: 15px; font-weight: 600; cursor: pointer; }
.choice { display: flex; flex-direction: column; gap: 8px; }
.choice button { height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-size: 15px; font-weight: 600; text-align: left; padding: 0 14px; cursor: pointer; }
.choice button[aria-pressed="true"] { border: 2px solid var(--accent); }
