:root {
  --bg: #0D0F12;
  --card: #171A1F;
  --card2: #1F232A;
  --well: #0D0F12;
  --line: #22262D;
  --line2: #333943;
  --text: #EEF0F3;
  --soft: #C9CED6;
  --muted: #98A1AD;
  --struck: #808894;
  --paid: #4CC6A6;
  --pending: #F2B24C;
  --pending-text: #F5C06A;
  --pending-bg: #2A2213;
  --danger: #FF8A80;
  --primary: #EEF0F3;
  --on-primary: #0D0F12;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }
a { color: var(--text); }
.wrap { max-width: 520px; margin: 0 auto; padding-bottom: calc(96px + var(--bottom)); }
.wrap.bare { padding-bottom: calc(32px + var(--bottom)); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

/* header */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  padding: calc(var(--top) + 20px) 20px 16px; }
.head-l { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.title-row { display: flex; align-items: center; gap: 2px; margin-left: -12px; }
.h1 { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.h1.sm { font-size: 28px; }
.sub { font-size: 14px; color: var(--muted); }
.icon-btn { width: 44px; height: 44px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 0; color: var(--muted); border-radius: 22px; padding: 0; }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.link-btn { background: none; border: 0; padding: 4px 0; color: var(--muted); font-size: 14px; text-align: left;
  text-decoration: underline; text-decoration-color: #4a515c; text-underline-offset: 3px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 18px;
  border-radius: 22px; border: 1px solid var(--line2); background: transparent; color: var(--text);
  font-weight: 700; font-size: 15px; text-decoration: none; white-space: nowrap; }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.big { min-height: 54px; border-radius: 27px; font-size: 16px; font-weight: 800; width: 100%; }
.btn.danger { color: var(--danger); border-color: #5a3330; }
.btn:disabled { opacity: 0.5; }

/* cards */
.card { margin: 0 16px; padding: 20px; border-radius: 24px; background: var(--card); display: flex; flex-direction: column; gap: 14px; }
.card + .card, .card + .tiles, .tiles + .group, .group + .group, .card + .group { margin-top: 12px; }
.label { font-size: 14px; font-weight: 600; color: var(--muted); }
.hero-num { font-size: 52px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.hero-num.neg { color: var(--danger); }
.line { font-size: 15px; color: var(--soft); }
.line strong { color: var(--text); }
.bar { height: 6px; border-radius: 3px; background: #262B33; overflow: hidden; }
.bar > span { display: block; height: 6px; background: var(--paid); border-radius: 3px; }
.small { font-size: 13px; color: var(--muted); line-height: 1.5; }
.split { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.divided { padding-top: 14px; border-top: 1px solid #262B33; }
.stack { display: flex; flex-direction: column; gap: 2px; }
.bal { font-size: 20px; font-weight: 700; }
.tiny { font-size: 12px; color: var(--muted); }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px 16px 0; }
.tile { padding: 14px 12px; border-radius: 18px; background: var(--card); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-paid { color: var(--paid); }
.c-pending { color: var(--pending); }

/* groups & rows */
.group { margin: 20px 16px 0; border-radius: 20px; background: var(--card); overflow: hidden; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; padding: 16px 16px 10px; gap: 8px; }
.group-head h2 { font-size: 17px; font-weight: 800; }
.group-head h2 span { font-weight: 600; color: var(--muted); }
.group-head .sum { font-size: 14px; font-weight: 700; color: var(--soft); }
.row { display: flex; align-items: center; gap: 4px; min-height: 60px; padding: 0 6px; border-top: 1px solid var(--line); }
.tog { width: 44px; height: 44px; flex: none; background: none; border: 0; padding: 0; display: flex; align-items: center; justify-content: center; }
.dot-paid { width: 26px; height: 26px; border-radius: 13px; background: var(--paid); display: flex; align-items: center; justify-content: center; }
.dot-pending { width: 24px; height: 24px; border-radius: 12px; border: 2px solid var(--pending); }
.dot-removed { color: var(--muted); display: flex; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 9px 4px; background: none; border: 0; text-align: left; }
.row-main .nm { font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main .meta { font-size: 12px; color: var(--muted); }
.amt { font-size: 15px; font-weight: 700; padding: 0 8px; white-space: nowrap; }
.row.removed .nm, .row.removed .amt { color: var(--struck); text-decoration: line-through; font-weight: 500; }
.row .x { margin-left: -6px; }
.empty { padding: 4px 16px 18px; font-size: 14px; color: var(--muted); }

.cta { margin: 20px 16px 0; padding: 18px 20px; border-radius: 20px; background: var(--card2);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 0; width: calc(100% - 32px); text-align: left; }
.cta b { font-size: 16px; }

/* tab bar */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: rgba(17, 19, 23, 0.94);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + var(--bottom)); }
.tabs-in { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tab { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0; font-size: 11px; font-weight: 600;
  color: var(--muted); background: none; border: 0; }
.tab[aria-current="page"] { color: var(--text); font-weight: 700; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.input { height: 52px; padding: 0 16px; border-radius: 14px; background: var(--well); border: 1px solid var(--line2);
  color: var(--text); font-size: 16px; width: 100%; min-width: 0; }
.input:focus { border-color: var(--text); outline: none; }
.input.huge { height: 72px; font-size: 32px; font-weight: 800; }
.input.code { font-size: 24px; letter-spacing: 0.3em; text-align: center; font-weight: 700; height: 64px; }
.money { display: flex; align-items: center; gap: 4px; height: 72px; padding: 0 18px; border-radius: 18px;
  background: var(--well); border: 2px solid var(--text); }
.money em { font-style: normal; font-size: 32px; font-weight: 800; color: var(--muted); }
.money input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; font-size: 32px; font-weight: 800; color: var(--text); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--well); }
.seg button { height: 40px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 700; }
.seg button[aria-pressed="true"] { background: #2A2F37; color: var(--text); }
.check { display: flex; align-items: center; gap: 12px; min-height: 48px; font-size: 14px; color: var(--soft); }
.check input { width: 20px; height: 20px; accent-color: var(--paid); margin: 0; flex: none; }
.note { padding: 14px 16px; border-radius: 16px; background: var(--card2); font-size: 13px; color: var(--soft); line-height: 1.5; }
.note strong { color: var(--text); }
.err { color: var(--danger); font-size: 14px; min-height: 0; }
.err:empty { display: none; }
.preview { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 18px; background: var(--card2); font-size: 14px; }
.preview .split > span:first-child { color: var(--muted); }
.preview .total { padding-top: 10px; border-top: 1px solid var(--line2); font-weight: 800; font-size: 16px; }
.preview .total > span:first-child { color: var(--text); }

/* list rows (recurring, history, settings) */
.list { margin: 0 16px; border-radius: 20px; background: var(--card); overflow: hidden; }
.list + .list, .list + .section-title { margin-top: 20px; }
.li { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 10px 16px; border-top: 1px solid var(--line);
  background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; color: var(--text); }
.li:first-child { border-top: 0; }
.li .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.li .grow b { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li.off b { color: var(--struck); }
.section-title { margin: 20px 20px 8px; font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.pad { padding: 16px; }
.carry .check { padding: 0 16px; border-top: 1px solid var(--line); }
.codes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 16px; }
.codes span { padding: 10px; border-radius: 10px; background: var(--well); text-align: center; }
.qr { align-self: center; background: #fff; padding: 12px; border-radius: 16px; line-height: 0; }
.secret { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 15px; word-break: break-all; padding: 12px; border-radius: 12px; background: var(--well); user-select: all; }

/* auth screens */
.auth { max-width: 440px; margin: 0 auto; padding: calc(var(--top) + 72px) 24px calc(40px + var(--bottom));
  min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; gap: 32px; }
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 16px; }
.brand p { font-size: 15px; color: var(--muted); line-height: 1.5; }
.foot { margin-top: auto; font-size: 12px; color: var(--muted); text-align: center; }

/* sheet */
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.6); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 520px; max-height: calc(100dvh - var(--top) - 24px); overflow: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 28px 28px 0 0; padding: 10px 20px calc(28px + var(--bottom));
  display: flex; flex-direction: column; gap: 16px; animation: up 0.18s ease-out; }
.grip { width: 40px; height: 5px; border-radius: 3px; background: #3A404A; align-self: center; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 20px; font-weight: 800; }
.sheet-head button { background: none; border: 0; color: var(--muted); font-size: 15px; font-weight: 600; min-height: 44px; padding: 0 0 0 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--bottom)); z-index: 60;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4); }
.loading { padding: 40vh 0; text-align: center; color: var(--muted); }

@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
@media (min-width: 700px) { .sheet-back { align-items: center; } .sheet { border-radius: 28px; } }

[hidden] { display: none !important; }
.li { text-decoration: none; }
