:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f172a;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --good: #059669;
  --good-soft: #e3f6ee;
  --warn: #b45309;
  --warn-soft: #fdf1dc;
  --bad: #dc2626;
  --bad-soft: #fde8e8;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.app { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(var(--safe-top) + 10px) 18px 10px;
  background: rgba(245, 246, 248, .92);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin: 0; flex: 1; }
.topbar .sub { color: var(--muted); font-size: 13px; font-weight: 500; display: block; letter-spacing: 0; }
main {
  padding: 4px 16px calc(var(--nav-h) + var(--safe-bottom) + 96px);
  max-width: 760px; margin: 0 auto;
}

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(255, 255, 255, .95);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11.5px; font-weight: 600; position: relative;
}
.nav a svg { width: 25px; height: 25px; }
.nav a.on { color: var(--accent); }
.nav .brand-side, .nav .side-add { display: none; }
.dot-badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
}

.fab {
  position: fixed; z-index: 25;
  left: 16px; right: 16px; bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  max-width: 520px; margin: 0 auto;
  height: 56px; border: 0; border-radius: 16px;
  background: var(--accent); color: #fff; font-size: 17px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 8px 24px rgba(37, 99, 235, .35);
}
.fab svg { width: 22px; height: 22px; }
.fab:active { transform: scale(.98); }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 248px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100dvh; padding: 24px 14px;
    display: flex; flex-direction: column; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); background: #fff;
  }
  .nav .brand-side { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; padding: 0 10px 18px; }
  .nav .brand-side img { width: 34px; height: 34px; border-radius: 9px; }
  .nav .side-add { display: flex; margin: 0 0 14px; height: 50px; border-radius: 14px; border: 0; background: var(--accent); color: #fff; font-weight: 700; align-items: center; justify-content: center; gap: 8px; font-size: 16px; }
  .nav .side-add svg { width: 20px; height: 20px; }
  .nav a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 12px; border-radius: 12px; font-size: 15px; }
  .nav a.on { background: var(--accent-soft); }
  .nav a svg { width: 22px; height: 22px; }
  .dot-badge { position: static; margin-left: auto; border: 0; }
  .fab { display: none; }
  .topbar { padding: 26px 32px 12px; }
  .topbar h1 { font-size: 28px; }
  .wrap { min-width: 0; }
  main { padding: 4px 32px 48px; max-width: 1080px; margin: 0; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
  .grid-2 > .col { display: flex; flex-direction: column; gap: 0; }
}

/* ---------- cards & text ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 15px; font-weight: 650; color: var(--muted); margin: 0 0 10px; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.card h2 .right { margin-left: auto; color: var(--accent); font-size: 14px; font-weight: 600; background: none; border: 0; padding: 6px 0; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 22px 4px 8px; display: flex; align-items: center; }
.section-title button { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: 15px; font-weight: 600; color: var(--accent); background: none; border: 0; padding: 6px 2px; }
.big { font-size: 34px; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.mid { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hero {
  background: linear-gradient(160deg, #0f172a, #1e293b); color: #fff;
  border-radius: 22px; padding: 20px 18px 18px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.hero .label { color: #cbd5e1; font-size: 14px; font-weight: 600; }
.hero .big { color: #fff; margin: 4px 0 2px; font-size: 40px; }
.hero .of { color: #cbd5e1; font-size: 14px; }
.bar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, .16); overflow: hidden; margin: 14px 0 10px; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: #34d399; }
.bar.warn > i { background: #fbbf24; }
.bar.bad > i { background: #f87171; }
.hero .split { display: flex; justify-content: space-between; font-size: 14px; color: #e2e8f0; }
.hero .note { margin-top: 10px; font-size: 13px; color: #cbd5e1; background: rgba(255,255,255,.08); padding: 8px 10px; border-radius: 10px; }

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 13.5px; font-weight: 600; }
.tile .mid { margin-top: 4px; }

/* due monday */
.due { border: 2px solid var(--accent); }
.due .when { font-weight: 700; color: var(--accent); font-size: 14px; }

/* categories */
.cat-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 10px 0; }
.cat-row .cbar { grid-column: 1 / -1; height: 8px; background: #eef2f7; border-radius: 5px; overflow: hidden; }
.cat-row .cbar i { display: block; height: 100%; border-radius: 5px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1.5px solid var(--line); background: #fff; border-radius: 999px;
  padding: 9px 14px; font-size: 15px; font-weight: 600; color: var(--ink-2); min-height: 42px;
}
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.seg { display: inline-flex; background: #eef2f7; border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* lists */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 14px; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px; min-height: 62px;
  width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: 0; }
.item:active { background: #f8fafc; }
.item .ic {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 15px; color: #fff;
}
.item .grow { flex: 1; min-width: 0; }
.item .t { font-weight: 600; font-size: 16px; }
.item .s { color: var(--muted); font-size: 13.5px; }
.item .amt { font-weight: 700; font-size: 16px; white-space: nowrap; }
.empty { padding: 24px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.pill.draft { background: #eef2f7; color: var(--ink-2); }
.pill.sent { background: var(--warn-soft); color: var(--warn); }
.pill.paid { background: var(--accent-soft); color: var(--accent); }
.pill.received { background: var(--good-soft); color: var(--good); }
.pill.paused { background: #eef2f7; color: var(--muted); }
.pill.auto { background: #f1f5f9; color: var(--muted); font-weight: 600; }

/* invoices */
.inv { padding: 16px; }
.inv + .inv { border-top: 1px solid var(--line); }
.inv .top { display: flex; align-items: flex-start; gap: 10px; }
.inv .period { font-weight: 700; font-size: 17px; }
.inv .who { color: var(--muted); font-size: 13px; margin-top: 6px; }
.inv .actions { display: flex; gap: 8px; margin-top: 12px; }
.steps { display: flex; gap: 4px; margin-top: 12px; }
.steps span { flex: 1; height: 5px; border-radius: 3px; background: #e2e8f0; }
.steps span.on { background: var(--good); }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px; border-radius: 14px; border: 0;
  font-weight: 700; font-size: 16px; background: var(--accent); color: #fff; text-decoration: none;
}
.btn.block { width: 100%; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: #eef2f7; color: var(--ink); }
.btn.good { background: var(--good); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.wa { background: #25d366; color: #fff; }
.btn:disabled { opacity: .5; }
.btn svg { width: 20px; height: 20px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 8px 0; font-size: 15px; }

/* forms */
.field { margin-bottom: 16px; }
.field > label, .field > .label { display: block; font-size: 14px; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 52px; padding: 12px 14px; border-radius: 14px;
  border: 1.5px solid var(--line); background: #fff; font-size: 17px; outline: none;
  -webkit-appearance: none; appearance: none;
}
textarea.input { min-height: 96px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.money-input { position: relative; }
.money-input span { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 26px; font-weight: 700; color: var(--muted); }
.money-input input { font-size: 30px; font-weight: 750; padding-left: 38px; min-height: 64px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-pick {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 56px;
  border: 1.5px dashed #cbd5e1; border-radius: 14px; background: #fafbfc; color: var(--ink-2); font-weight: 600;
}
.file-pick input { display: none; }
.file-pick svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.toggle { position: relative; width: 52px; height: 32px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle i { position: absolute; inset: 0; background: #cbd5e1; border-radius: 20px; transition: .2s; }
.toggle i::after { content: ""; position: absolute; width: 26px; height: 26px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle input:checked + i { background: var(--good); }
.toggle input:checked + i::after { transform: translateX(20px); }

/* sheet */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .42); z-index: 50; opacity: 0; transition: opacity .2s; }
.scrim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  max-height: calc(100dvh - var(--safe-top) - 24px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 22px 22px 0 0;
  padding: 8px 18px calc(var(--safe-bottom) + 20px);
  transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}
.sheet.show { transform: translateY(0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: #cbd5e1; margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; position: sticky; top: -8px; background: var(--bg); padding: 6px 0; z-index: 2; }
.sheet-head h3 { flex: 1; margin: 0; font-size: 20px; font-weight: 700; }
.sheet-head .x { width: 40px; height: 40px; border-radius: 20px; border: 0; background: #e2e8f0; font-size: 20px; line-height: 1; color: var(--ink-2); }
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 560px; border-radius: 22px; transform: translate(-50%, -46%); opacity: 0; transition: transform .2s, opacity .2s; padding-bottom: 22px; }
  .sheet.show { transform: translate(-50%, -50%); opacity: 1; }
  .sheet .grab { display: none; }
}

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.tl li:last-child { border-bottom: 0; }
.tl .av { width: 32px; height: 32px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff; background: #94a3b8; }
.tl .what { font-size: 15px; }
.tl .when { font-size: 12.5px; color: var(--muted); }

/* updates */
.upd { padding: 14px 16px; border-bottom: 1px solid var(--line); position: relative; }
.upd:last-child { border-bottom: 0; }
.upd.unread { background: #f5f8ff; }
.upd.unread::before { content: ""; position: absolute; left: 6px; top: 22px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.upd .t { font-weight: 700; }
.upd .b { white-space: pre-wrap; color: var(--ink-2); margin-top: 4px; font-size: 15px; }
.upd .m { color: var(--muted); font-size: 12.5px; margin-top: 6px; display: flex; gap: 10px; align-items: center; }
.upd .m button { margin-left: auto; }

/* login */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: calc(var(--safe-top) + 24px) 22px calc(var(--safe-bottom) + 24px); max-width: 440px; margin: 0 auto; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; box-shadow: var(--shadow); }
.login h1 { font-size: 30px; letter-spacing: -.02em; margin: 18px 0 4px; }
.login .who { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 22px 0 16px; }
.login .who button { min-height: 64px; border-radius: 16px; border: 2px solid var(--line); background: #fff; font-size: 18px; font-weight: 700; }
.login .who button.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.err { color: var(--bad); font-size: 14.5px; margin: 8px 0; min-height: 1em; }

/* toast + banners */
.toast {
  position: fixed; left: 50%; z-index: 60; transform: translate(-50%, 20px); opacity: 0;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 84px);
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600; font-size: 15px;
  transition: .2s; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2); pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { .toast { bottom: 32px; } }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 14px; font-size: 14px; font-weight: 600; margin-bottom: 12px; }
.install-tip { background: var(--accent-soft); color: #1e3a8a; border-radius: 14px; padding: 12px 14px; font-size: 14.5px; margin-bottom: 14px; display: flex; gap: 10px; align-items: flex-start; }
.install-tip button { margin-left: auto; background: none; border: 0; color: #1e3a8a; font-size: 18px; padding: 0 4px; }

.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .chip { flex: none; min-height: 38px; padding: 7px 13px; font-size: 14px; }
.month-head { display: flex; justify-content: space-between; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 4px 8px; }

/* icons */
.meta-ic { display: inline-flex; align-items: center; gap: 3px; vertical-align: -2px; }
.sheet-head .x, .install-tip button { display: inline-flex; align-items: center; justify-content: center; }
.tl .av svg { color: #fff; }

/* account security */
.sec-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line, #e5e7eb); }
.sec-row > div { flex: 1; min-width: 0; }
.sec-row .btn { flex: none; min-width: 110px; }
.qr { display: flex; justify-content: center; margin: 8px 0 12px; }
.qr svg { width: 210px; height: 210px; background: #fff; border-radius: 12px; }
