:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-2: #f8f6f1;
  --line: #e7e2d8;
  --text: #1c1a17;
  --muted: #77716a;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #d9f0ec;
  --out: #d1495b;
  --out-soft: #fbe4e7;
  --in: #16a34a;
  --in-soft: #dcf5e4;
  --warn: #c2410c;
  --warn-soft: #ffedd5;
  --shadow: 0 1px 2px rgba(40, 30, 10, .05), 0 6px 20px rgba(40, 30, 10, .06);
  --radius: 18px;
  --note-yellow: #fff3bf; --note-green: #d3f9d8; --note-blue: #d0ebff; --note-pink: #ffdeeb;
  --note-purple: #e5dbff; --note-orange: #ffe8cc; --note-gray: #eceae6;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12110f; --surface: #1c1b18; --surface-2: #24221f; --line: #33302b; --text: #f2efe9; --muted: #a29b91;
    --brand: #2dd4bf; --brand-2: #14b8a6; --brand-soft: #123a36; --out: #ff7b8b; --out-soft: #3a1d22;
    --in: #4ade80; --in-soft: #16301f; --warn: #fb923c; --warn-soft: #3a2513;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
    --note-yellow: #3b3519; --note-green: #1c3322; --note-blue: #19293a; --note-pink: #3a1f2b;
    --note-purple: #2a2240; --note-orange: #3b2a17; --note-gray: #2a2825;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12110f; --surface: #1c1b18; --surface-2: #24221f; --line: #33302b; --text: #f2efe9; --muted: #a29b91;
  --brand: #2dd4bf; --brand-2: #14b8a6; --brand-soft: #123a36; --out: #ff7b8b; --out-soft: #3a1d22;
  --in: #4ade80; --in-soft: #16301f; --warn: #fb923c; --warn-soft: #3a2513;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
  --note-yellow: #3b3519; --note-green: #1c3322; --note-blue: #19293a; --note-pink: #3a1f2b;
  --note-purple: #2a2240; --note-orange: #3b2a17; --note-gray: #2a2825;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

.splash { min-height: 100vh; display: grid; place-items: center; }
.logo-dot { width: 54px; height: 54px; border-radius: 16px; background: var(--brand); animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(.85); opacity: .6; } }

/* ---------- layout ---------- */
.shell { max-width: 560px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 12px) 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.topbar h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.topbar .sub { color: var(--muted); font-size: 13px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 22px 2px 10px; }
.section-title h2 { font-size: 16px; margin: 0; }
.section-title .link { color: var(--brand); font-weight: 600; font-size: 14px; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }

/* ---------- hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 24px; padding: 20px 20px 18px; color: #fff;
  background: radial-gradient(120% 140% at 100% 0%, #14b8a6 0%, #0f766e 45%, #134e4a 100%);
  box-shadow: 0 10px 30px rgba(15, 118, 110, .35);
}
.hero::after {
  content: ""; position: absolute; right: -40px; top: -40px; width: 160px; height: 160px; border-radius: 50%;
  border: 26px solid rgba(255,255,255,.08);
}
.hero .label { opacity: .85; font-size: 13px; font-weight: 500; }
.hero .big { font-size: 38px; font-weight: 750; letter-spacing: -.03em; margin: 2px 0 14px; }
.hero .big small { font-size: 18px; font-weight: 600; opacity: .8; margin-left: 4px; }
.hero .stats { display: flex; gap: 10px; }
.hero .stat { flex: 1; background: rgba(255,255,255,.13); border-radius: 14px; padding: 8px 12px; backdrop-filter: blur(4px); }
.hero .stat .k { font-size: 12px; opacity: .85; }
.hero .stat .v { font-weight: 650; }
.hero.alt { background: radial-gradient(120% 140% at 100% 0%, #818cf8 0%, #4f46e5 45%, #312e81 100%); box-shadow: 0 10px 30px rgba(79, 70, 229, .3); }
.hero.warm { background: radial-gradient(120% 140% at 100% 0%, #fbbf24 0%, #d97706 45%, #92400e 100%); box-shadow: 0 10px 30px rgba(217, 119, 6, .3); }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.qbtn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px; border-radius: 16px; font-weight: 650; background: var(--surface); box-shadow: var(--shadow); }
.qbtn .ic { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 18px; font-weight: 700; }
.qbtn.out .ic { background: var(--out-soft); color: var(--out); }
.qbtn.in .ic { background: var(--in-soft); color: var(--in); }
.qbtn:active { transform: scale(.98); }

/* ---------- people strip ---------- */
.people { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.people::-webkit-scrollbar { display: none; }
.person { flex: 0 0 auto; min-width: 110px; padding: 12px; border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); text-align: left; border: 2px solid transparent; }
.person.active { border-color: var(--brand); }
.person .n { font-weight: 600; font-size: 14px; margin-top: 6px; white-space: nowrap; }
.person .a { font-size: 13px; color: var(--out); font-weight: 600; }
.person .a.pos { color: var(--in); }

.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; flex: 0 0 auto; font-size: 15px; }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--surface); border-radius: 14px; padding: 0 12px; box-shadow: var(--shadow); min-width: 0; }
.search input { border: 0; outline: 0; background: none; padding: 11px 0; width: 100%; min-width: 0; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 11px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg.full { display: flex; width: 100%; }
.seg.full button { flex: 1; }

/* ---------- lists ---------- */
.day { font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 16px 4px 6px; display: flex; justify-content: space-between; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.row:active { background: var(--surface-2); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .s { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { font-weight: 700; text-align: right; white-space: nowrap; }
.row .amt.out { color: var(--out); }
.row .amt.in { color: var(--in); }
.row .bal { font-size: 11px; color: var(--muted); font-weight: 500; text-align: right; }
.icon-badge { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; flex: 0 0 auto; background: var(--surface-2); }
.icon-badge.ok { background: var(--in-soft); color: var(--in); }
.icon-badge.late { background: var(--out-soft); color: var(--out); }
.icon-badge.wait { background: var(--warn-soft); color: var(--warn); }
.pill { display: inline-block; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.pill.cash { background: var(--brand-soft); color: var(--brand); }
.pill.late { background: var(--out-soft); color: var(--out); }
.btn-pay { background: var(--brand); color: #fff; font-weight: 650; font-size: 13px; padding: 8px 12px; border-radius: 10px; white-space: nowrap; }

.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.empty .e { font-size: 34px; margin-bottom: 6px; }

/* ---------- month switcher ---------- */
.month { display: flex; align-items: center; justify-content: space-between; background: var(--surface); border-radius: 16px; padding: 6px; box-shadow: var(--shadow); margin-bottom: 12px; }
.month button { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; color: var(--brand); }
.month button:active { background: var(--surface-2); }
.month .m { font-weight: 700; text-transform: capitalize; }

.progress { height: 8px; background: rgba(255,255,255,.22); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress > i { display: block; height: 100%; background: #fff; border-radius: 99px; }

/* ---------- notes ---------- */
.notes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.note { text-align: left; border-radius: 18px; padding: 14px; min-height: 110px; display: flex; flex-direction: column; gap: 6px; position: relative; box-shadow: var(--shadow); }
.note .nt { font-weight: 650; padding-right: 22px; word-break: break-word; }
.note .na { font-size: 20px; font-weight: 750; letter-spacing: -.02em; }
.note .nb { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; word-break: break-word; }
.note .pin { position: absolute; top: 12px; right: 12px; font-size: 13px; }
.note.done { opacity: .55; }
.note.done .nt, .note.done .na { text-decoration: line-through; }
.note .check { margin-top: auto; align-self: flex-start; font-size: 12px; font-weight: 650; padding: 4px 10px; border-radius: 99px; background: rgba(0,0,0,.06); }
.c-yellow { background: var(--note-yellow); } .c-green { background: var(--note-green); } .c-blue { background: var(--note-blue); }
.c-pink { background: var(--note-pink); } .c-purple { background: var(--note-purple); } .c-orange { background: var(--note-orange); }
.c-gray { background: var(--note-gray); }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav .in { max-width: 560px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); }
.nav button { padding: 9px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); position: relative; }
.nav button svg { width: 24px; height: 24px; }
.nav button.on { color: var(--brand); }
.nav .badge { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--out); color: #fff; font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }

.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 21;
  width: 58px; height: 58px; border-radius: 20px; background: var(--brand); color: #fff; font-size: 30px; font-weight: 400;
  display: grid; place-items: center; box-shadow: 0 8px 24px rgba(15,118,110,.4);
}
.fab:active { transform: scale(.95); }

/* ---------- sheet (modal) ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; animation: fade .2s; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; background: var(--bg); border-radius: 24px 24px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .25s cubic-bezier(.2,.9,.3,1);
}
@media (min-width: 600px) { .backdrop { align-items: center; } .sheet { border-radius: 24px; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet h3 { margin: 4px 0 14px; font-size: 20px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 2px 5px; }
.input, .field input, .field select, .field textarea {
  width: 100%; background: var(--surface); border: 1.5px solid var(--line); border-radius: 14px; padding: 12px 14px; outline: 0;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); }
.field textarea { min-height: 80px; resize: vertical; }
.amount-input { font-size: 30px !important; font-weight: 700; text-align: center; letter-spacing: -.02em; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 7px 12px; border-radius: 99px; background: var(--surface); border: 1.5px solid var(--line); font-size: 13px; font-weight: 600; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }
.swatches { display: flex; gap: 8px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); }
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg) inset; }
.check-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface); border-radius: 14px; border: 1.5px solid var(--line); margin-bottom: 12px; font-weight: 600; }
.check-row input { width: 20px; height: 20px; accent-color: var(--brand); }

.btn { display: block; width: 100%; padding: 14px; border-radius: 14px; font-weight: 700; text-align: center; background: var(--brand); color: #fff; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1.5px solid var(--line); }
.btn.danger { background: transparent; color: var(--out); }
.btn:disabled { opacity: .6; }
.actions { display: grid; gap: 8px; margin-top: 16px; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; max-width: 420px; margin: 0 auto; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.brand img { width: 56px; height: 56px; border-radius: 16px; box-shadow: var(--shadow); }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.brand p { margin: 0; color: var(--muted); font-size: 14px; }
.err { background: var(--out-soft); color: var(--out); padding: 10px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 12px; font-weight: 600; }

/* ---------- account ---------- */
.kv { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; gap: 12px; width: 100%; text-align: left; }
.kv + .kv { border-top: 1px solid var(--line); }
.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 22px; font-weight: 700; letter-spacing: .15em; color: var(--brand); }

#toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
