:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e3e6ea;
  --text: #16191d;
  --muted: #5f6873;
  --brand: #0f766e;
  --brand-ink: #ffffff;
  --brand-soft: #e6f4f2;
  --danger: #c2410c;
  --danger-soft: #fdeee6;
  --warn: #a16207;
  --warn-soft: #fdf6e3;
  --ok: #15803d;
  --ok-soft: #e8f6ec;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 1px 3px rgb(16 24 40 / 0.06);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 0.18);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --surface: #171b1f;
    --surface-2: #1e2328;
    --border: #2a3036;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --brand: #2dd4bf;
    --brand-ink: #062a26;
    --brand-soft: #12302c;
    --danger: #fb923c;
    --danger-soft: #36200f;
    --warn: #facc15;
    --warn-soft: #2f2a10;
    --ok: #4ade80;
    --ok-soft: #12291a;
    --shadow: none;
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.5rem; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.num { font-variant-numeric: tabular-nums; }
.boot { padding: 4rem; text-align: center; color: var(--muted); }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 24px; height: 60px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand img { width: 28px; height: 28px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a {
  color: var(--muted); padding: 6px 12px; border-radius: 8px; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { color: var(--brand); background: var(--brand-soft); }
.top-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
main { max-width: 1080px; margin: 0 auto; padding: 28px 16px 64px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .topbar-inner { gap: 12px; }
  .brand span { display: none; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around;
  }
  .nav a { font-size: 0.8rem; padding: 6px 8px; }
  main { padding-bottom: 96px; }
}

/* ---------- surfaces ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); gap: 12px; }
.stack { display: grid; gap: 20px; }
.grid-2 { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); align-items: start; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 24px; }
.stat { padding: 16px 18px; }
.stat .label { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.stat .value { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; }
.stat .sub { color: var(--muted); font-size: 0.8rem; }
.stat.danger .value { color: var(--danger); }
@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 1.25rem; }
}

/* ---------- bill rows ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: grid; grid-template-columns: 64px 1fr auto auto; align-items: center; gap: 16px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.list > .row:first-child { border-top: 0; }
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: var(--surface-2); }
.datechip {
  text-align: center; border-radius: 10px; padding: 6px 0; background: var(--surface-2);
  line-height: 1.1;
}
.datechip .m { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.datechip .d { font-size: 1.25rem; font-weight: 650; }
.datechip.overdue { background: var(--danger-soft); }
.datechip.overdue .m, .datechip.overdue .d { color: var(--danger); }
.datechip.today { background: var(--warn-soft); }
.datechip.today .m, .datechip.today .d { color: var(--warn); }
.row .title { font-weight: 600; }
.row .meta { color: var(--muted); font-size: 0.85rem; display: flex; gap: 6px 12px; flex-wrap: wrap; align-items: center; }
.row .amount { font-weight: 650; text-align: right; white-space: nowrap; }
.row .actions { display: flex; gap: 6px; justify-content: flex-end; }
.row.future { opacity: 0.6; }
@media (max-width: 640px) {
  .row { grid-template-columns: 52px 1fr auto; gap: 12px; padding: 12px 14px; }
  .row .actions { grid-column: 2 / -1; justify-content: flex-start; }
}

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; font-weight: 600;
  padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.brand { background: var(--brand-soft); color: var(--brand); }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.presets { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }

table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 20px; border-top: 1px solid var(--border); }
.table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; border-top: 0; }
.table td.r, .table th.r { text-align: right; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 0.88rem;
  padding: 8px 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 0.8rem; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.icon-btn { position: relative; padding: 7px; }
.icon-btn svg { width: 20px; height: 20px; display: block; }
.dot {
  position: absolute; top: 2px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 0.68rem; font-weight: 700;
  display: grid; place-items: center;
}

label.field { display: grid; gap: 5px; font-size: 0.85rem; font-weight: 600; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }
input, select, textarea {
  font: inherit; font-size: 0.95rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 9px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent;
}
textarea { resize: vertical; min-height: 70px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 0.92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form { display: grid; gap: 14px; }
.form-row { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .form-row { grid-template-columns: 1fr; } }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: 8px; font-size: 0.88rem; }
.money-input { position: relative; }
.money-input span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 24px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type=search] { width: 220px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { font: inherit; font-size: 0.85rem; font-weight: 600; border: 0; background: var(--surface); color: var(--muted); padding: 7px 12px; cursor: pointer; }
.seg button.on { background: var(--brand-soft); color: var(--brand); }
details summary { cursor: pointer; color: var(--brand); font-weight: 600; font-size: 0.88rem; }
details[open] summary { margin-bottom: 12px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 420px; }
.auth .brand { justify-content: center; font-size: 1.4rem; margin-bottom: 6px; }
.auth .brand img { width: 40px; height: 40px; }
.auth .tag { text-align: center; color: var(--muted); margin-bottom: 24px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; border-bottom: 1px solid var(--border); }
.tabs button { font: inherit; font-weight: 600; padding: 14px; background: none; border: 0; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- modal, popover, toast ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgb(10 14 18 / 0.45);
  display: grid; place-items: center; padding: 16px; animation: fade 0.12s ease-out;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  animation: pop 0.14s ease-out;
}
.modal header { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal .body { padding: 16px 22px 22px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(0.98); } }

.popover {
  position: absolute; right: 0; top: calc(100% + 8px); width: min(360px, calc(100vw - 32px));
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  z-index: 40; overflow: hidden;
}
.popover .head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.popover .items { max-height: 400px; overflow-y: auto; }
.notif { display: block; width: 100%; text-align: left; font: inherit; color: var(--text); background: none; border: 0; border-top: 1px solid var(--border); padding: 12px 16px; cursor: pointer; }
.notif:first-child { border-top: 0; }
.notif:hover { background: var(--surface-2); }
.notif.unread { background: var(--brand-soft); }
.notif .when { color: var(--muted); font-size: 0.78rem; }
.rel { position: relative; }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 14px 10px 16px; border-radius: 10px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 14px; font-size: 0.9rem;
  animation: pop 0.14s ease-out;
}
.toast button { font: inherit; font-weight: 700; background: none; border: 0; color: var(--brand); cursor: pointer; filter: brightness(1.3); }
@media (max-width: 720px) { #toasts { bottom: 84px; } }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.kv dt { color: var(--muted); font-size: 0.88rem; }
.kv dd { margin: 0; font-weight: 500; }
.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; letter-spacing: 0.12em;
  background: var(--surface-2); padding: 6px 12px; border-radius: 8px; font-weight: 600;
}
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.8rem; }
.member { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem; flex: none;
}
.member .grow { flex: 1; min-width: 0; }

/* ---------- utilities (inline styles are blocked by the CSP) ---------- */
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-20 { margin-top: 20px; } .m-0 { margin: 0; }
.mb-6 { margin-bottom: 6px; } .mb-12 { margin-bottom: 12px; } .mb-14 { margin-bottom: 14px; }
.w-240 { max-width: 240px; } .pre { white-space: pre-wrap; }
.divider { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- sign-in & security ---------- */
.auth .brand { color: var(--text); }
.auth-foot { text-align: center; margin-top: 16px; }
.center { text-align: center; justify-self: center; }
.mb-0 { margin-bottom: 0; }
.pad-x { padding: 0 20px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.providers { display: grid; gap: 10px; }
.btn.provider { width: 100%; padding: 10px 14px; font-size: 0.92rem; gap: 10px; }
.btn.provider svg, .provider-inline svg { flex: none; }
.divider-label { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 0.8rem; margin: 18px 0 14px; }
.divider-label::before, .divider-label::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 64px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  font: inherit; font-size: 0.78rem; font-weight: 600; color: var(--muted);
  background: none; border: 0; padding: 4px 8px; border-radius: 6px; cursor: pointer;
}
.pw-toggle:hover { color: var(--text); background: var(--surface-2); }
.meter { height: 4px; border-radius: 2px; background: var(--surface-2); overflow: hidden; }
.meter span { display: block; height: 100%; width: 0; transition: width 0.2s, background 0.2s; }
.meter[data-score="0"] span { width: 8%; background: var(--danger); }
.meter[data-score="1"] span { width: 25%; background: var(--danger); }
.meter[data-score="2"] span { width: 50%; background: var(--warn); }
.meter[data-score="3"] span { width: 75%; background: var(--ok); }
.meter[data-score="4"] span { width: 100%; background: var(--ok); }
.linklike { font: inherit; background: none; border: 0; color: var(--brand); cursor: pointer; padding: 2px; justify-self: center; }
.linklike.muted { color: var(--muted); }
.linklike:hover { text-decoration: underline; }
input.otp { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.4rem; letter-spacing: 0.3em; text-align: center; }
.banner {
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--warn-soft); color: var(--text); font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
}
.subnav { display: flex; gap: 4px; margin: -8px 0 20px; border-bottom: 1px solid var(--border); }
.subnav a { padding: 8px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--brand); border-bottom-color: var(--brand); }
.qr { display: grid; place-items: center; margin: 4px 0 14px; }
.qr svg { width: 200px; height: 200px; border-radius: 8px; border: 1px solid var(--border); }
.steps { padding-left: 20px; margin: 0 0 8px; }
.steps li { margin-bottom: 4px; }
.codes {
  columns: 2; gap: 24px; padding: 14px 14px 14px 36px; margin: 0 0 6px; background: var(--surface-2); border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1rem;
}
.codes li { padding: 2px 0; }
.member .avatar svg { width: 16px; height: 16px; }
.btn:disabled:hover { background: var(--surface); }

/* ---------- notifications prompt ---------- */
.nudge { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.nudge .grow { flex: 1; min-width: 200px; }
.nudge-icon {
  width: 40px; height: 40px; border-radius: 10px; flex: none;
  background: var(--brand-soft); color: var(--brand); display: grid; place-items: center;
}
.nudge-icon svg { width: 20px; height: 20px; }

/* ---------- phones & installed app ---------- */
/* Respect the notch / home indicator when installed to the Home Screen. */
.topbar { padding-top: env(safe-area-inset-top); }
.topbar-inner, main {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.kv dd { overflow-wrap: anywhere; }

@media (max-width: 720px) {
  /* 16px stops iPhone Safari from zooming in when a field is tapped. */
  input, select, textarea, .copy-row input { font-size: 16px; }
  h1 { font-size: 1.3rem; }
  .card-pad { padding: 16px; }
  .card-head { padding: 14px 16px; flex-wrap: wrap; }
  .card-head input[type=search] { max-width: none; flex: 1 1 100%; }
  .table th, .table td { padding: 10px 14px; }
  .hide-sm { display: none; }
  .member { padding: 12px 16px; }
  .pad-x { padding: 0 16px; }
  /* Dialogs become bottom sheets. */
  .overlay { align-items: end; padding: 0; }
  .modal {
    max-width: none; border-radius: 16px 16px 0 0; max-height: 92vh;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .modal .body { padding: 14px 16px 20px; }
  .modal header { padding: 16px 16px 0; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1; }
  .subnav { overflow-x: auto; scrollbar-width: none; }
  .subnav::-webkit-scrollbar { display: none; }
  .subnav a { white-space: nowrap; }
}
