:root {
  --bg: #f5f6f8; --card: #ffffff; --card-2: #f9fafb; --text: #111827; --muted: #6b7280; --border: #e5e7eb;
  --accent: #1d4ed8; --accent-2: #2563eb; --accent-soft: #dbeafe; --on-accent: #ffffff;
  --green: #15803d; --green-bg: #dcfce7;
  --amber: #b45309; --amber-bg: #fef3c7;
  --red: #b91c1c; --red-bg: #fee2e2;
  --blue: #1d4ed8; --blue-bg: #dbeafe;
  --gray-bg: #f3f4f6;
  --wa: #16a34a;
  --shadow: 0 1px 2px #0000000d, 0 4px 16px #0000000a;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13; --card: #171a20; --card-2: #1d2128; --text: #e8eaed; --muted: #9aa0a6; --border: #2a2f38;
    --accent: #3b82f6; --accent-2: #60a5fa; --accent-soft: #1e3a8a66; --on-accent: #ffffff;
    --green: #4ade80; --green-bg: #14532d66;
    --amber: #fbbf24; --amber-bg: #78350f66;
    --red: #f87171; --red-bg: #7f1d1d66;
    --blue: #93c5fd; --blue-bg: #1e3a8a66;
    --gray-bg: #232830;
    --wa: #22c55e;
    --shadow: 0 1px 2px #0006;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; min-height: 100dvh; }
a { color: var(--accent-2); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
.wrap { max-width: 980px; margin: 0 auto; padding: 0 16px; }
.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- splash / auth ---------- */
.splash { min-height: 100dvh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: min(400px, 100%); background: var(--card); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); display: grid; gap: 14px; animation: rise .35s ease; }
.auth-logo { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; background: var(--accent); color: #fff; margin: 0 auto; }
.auth-logo .i { width: 30px; height: 30px; }
.auth-card h1 { text-align: center; font-size: 20px; }
.auth-card p { text-align: center; margin: -6px 0 4px; }

/* ---------- header & nav ---------- */
.top { position: sticky; top: 0; z-index: 10; background: color-mix(in srgb, var(--card) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.bar { display: flex; align-items: center; gap: 12px; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; min-width: 0; flex: 1; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topnav { display: none; gap: 2px; }
.topnav a, .bottomnav a { color: var(--muted); text-decoration: none; display: flex; align-items: center; gap: 6px; }
.topnav a { padding: 8px 12px; border-radius: 10px; font-weight: 500; }
.topnav a.on { color: var(--accent-2); background: var(--accent-soft); }
.topnav a:hover:not(.on) { background: var(--gray-bg); color: var(--text); }
.btn.add-desktop { display: none; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav a { flex: 1; flex-direction: column; justify-content: center; gap: 2px; height: var(--nav-h); font-size: 11px; font-weight: 500; position: relative; }
.bottomnav a.on { color: var(--accent-2); }
.bottomnav a.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent-2); }
.badge-dot { position: absolute; top: 9px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px; background: var(--red); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }
.topnav .badge-dot { position: static; }

.fab { position: fixed; right: 18px; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); z-index: 11; width: 58px; height: 58px; border-radius: 18px; border: none; background: var(--accent); color: #fff; box-shadow: 0 8px 24px #1d4ed855; display: grid; place-items: center; cursor: pointer; transition: transform .15s; }
.fab:active { transform: scale(.92); }
.fab .i { width: 26px; height: 26px; stroke-width: 2.5; }

main { padding: 16px 0 calc(var(--nav-h) + 96px + env(safe-area-inset-bottom)); animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

@media (min-width: 820px) {
  .topnav, .btn.add-desktop { display: flex; }
  .bottomnav, .fab { display: none; }
  main { padding-bottom: 48px; }
}

/* ---------- page heading ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.page-head h1 { font-size: 22px; }
.greet { font-size: 13px; color: var(--muted); margin-bottom: 2px; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; transition: transform .1s, background .15s; min-height: 40px; }
.btn:active { transform: scale(.96); }
.btn:hover { background: var(--gray-bg); }
.btn:disabled { opacity: .55; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.wa { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; min-height: 34px; border-radius: 9px; }
.btn.sm .i { width: 16px; height: 16px; }
.btn.block { width: 100%; }
.icon-btn { border: none; background: none; color: var(--muted); padding: 8px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--gray-bg); color: var(--text); }

label { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
input, select, textarea { font: inherit; font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); color: var(--text); width: 100%; min-height: 44px; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 64px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pw { position: relative; }
.pw input { padding-right: 64px; }
.pw button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); border: none; background: none; color: var(--accent-2); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px; }

/* ---------- stat tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
@media (min-width: 640px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; cursor: pointer; text-align: left; font: inherit; color: inherit; box-shadow: var(--shadow); transition: transform .12s, border-color .15s; position: relative; overflow: hidden; }
.tile:active { transform: scale(.97); }
.tile:hover { border-color: var(--accent-2); }
.tile .n { font-size: 30px; font-weight: 750; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--muted); font-size: 13px; font-weight: 500; }
.tile::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--tone, var(--border)); }
.tile.green { --tone: var(--green); } .tile.amber { --tone: var(--amber); } .tile.red { --tone: var(--red); } .tile.blue { --tone: var(--blue); }
.tile.green .n { color: var(--green); } .tile.amber .n { color: var(--amber); } .tile.red .n { color: var(--red); } .tile.blue .n { color: var(--blue); }
.money { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.money .n { font-size: 24px; }

/* ---------- cards & lists ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; box-shadow: var(--shadow); overflow: hidden; animation: rise .25s ease both; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; display: flex; align-items: center; gap: 8px; }
.card-head .sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.count { background: var(--gray-bg); color: var(--muted); font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.card-body { padding: 14px; display: grid; gap: 12px; }
.empty { padding: 22px 14px; color: var(--muted); text-align: center; font-size: 14px; }
.empty .big { font-size: 28px; display: block; margin-bottom: 4px; }

.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background .12s; }
.row:last-child { border-bottom: none; }
.row:hover { background: var(--card-2); }
.row:active { background: var(--gray-bg); }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; background: var(--gray-bg); color: var(--muted); }
.avatar.active { background: var(--green-bg); color: var(--green); }
.avatar.expiring { background: var(--amber-bg); color: var(--amber); }
.avatar.expired { background: var(--red-bg); color: var(--red); }
.avatar.lead { background: var(--blue-bg); color: var(--blue); }
.avatar.lg { width: 56px; height: 56px; border-radius: 16px; font-size: 19px; }
.who { flex: 1; min-width: 0; }
.who b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-end { display: flex; align-items: center; gap: 6px; flex: none; }
@media (max-width: 520px) { .row .pill.hide-sm { display: none; } .row .avatar { width: 36px; height: 36px; } }

.pill { font-size: 12px; padding: 3px 9px; border-radius: 99px; font-weight: 600; white-space: nowrap; display: inline-block; }
.pill.active, .pill.sent { background: var(--green-bg); color: var(--green); }
.pill.expiring, .pill.pending { background: var(--amber-bg); color: var(--amber); }
.pill.expired, .pill.failed { background: var(--red-bg); color: var(--red); }
.pill.lead { background: var(--blue-bg); color: var(--blue); }
.pill.skipped { background: var(--gray-bg); color: var(--muted); }

/* ---------- toolbar / chips ---------- */
.search { position: relative; margin-bottom: 10px; }
.search .i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 40px; border-radius: 12px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--border); background: var(--card); color: var(--text); padding: 7px 12px; border-radius: 99px; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; display: flex; gap: 6px; align-items: center; transition: all .15s; }
.chip b { font-weight: 600; color: var(--muted); }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip.on b { color: inherit; opacity: .7; }

/* ---------- sheet (dialog) ---------- */
.sheet { border: none; padding: 0; background: var(--card); color: var(--text); width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; border-radius: 22px 22px 0 0; box-shadow: 0 -10px 40px #0003; overflow: auto; overscroll-behavior: contain; }
.sheet[open] { animation: slide-up .28s cubic-bezier(.2, .9, .3, 1); }
.sheet::backdrop { background: #0007; animation: fade .2s ease; }
@keyframes slide-up { from { transform: translateY(100%); } }
@media (min-width: 640px) {
  .sheet { width: min(520px, calc(100vw - 32px)); margin: auto; border-radius: 20px; }
  .sheet[open] { animation: pop .2s ease; }
  @keyframes pop { from { opacity: 0; transform: scale(.96); } }
}
.sheet-body { padding: 8px 18px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 14px; }
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 10px auto 4px; }
.sheet-title { display: flex; justify-content: space-between; align-items: center; }
.sheet-title h3 { font-size: 18px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.actions .btn { flex: 1; }
@media (min-width: 640px) { .actions .btn { flex: none; } }
.hint { font-size: 13px; color: var(--muted); background: var(--card-2); border: 1px dashed var(--border); border-radius: 10px; padding: 9px 12px; }
.hint.ok { color: var(--green); background: var(--green-bg); border-color: transparent; font-weight: 500; }
.paybox { display: grid; gap: 10px; padding: 12px; border-radius: 12px; background: var(--card-2); border: 1px solid var(--border); animation: rise .2s ease; }

.mhead { display: flex; align-items: center; gap: 14px; }
.mhead h3 { font-size: 20px; margin-bottom: 4px; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick .btn { flex-direction: column; gap: 4px; padding: 10px 4px; font-size: 12px; min-height: 64px; }
.quick .btn .i { width: 22px; height: 22px; }
.facts { display: grid; gap: 0; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
.facts div:last-child { border-bottom: none; }
.facts span:first-child { color: var(--muted); }
.facts span:last-child { text-align: right; font-weight: 500; overflow-wrap: anywhere; }
.timeline { display: grid; gap: 0; }
.timeline .t { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.timeline .t:last-child { border-bottom: none; }
.section-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }

/* ---------- payments ---------- */
.months { display: grid; gap: 10px; padding: 14px; }
.month { display: grid; grid-template-columns: 76px 1fr auto; align-items: center; gap: 10px; font-size: 14px; }
.month .track { height: 10px; border-radius: 5px; background: var(--gray-bg); overflow: hidden; }
.month .fill { height: 100%; border-radius: 5px; background: var(--accent-2); transform-origin: left; animation: grow .6s cubic-bezier(.2, .9, .3, 1) both; }
@keyframes grow { from { transform: scaleX(0); } }
.month b { font-variant-numeric: tabular-nums; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom)); z-index: 100; display: grid; gap: 8px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
@media (min-width: 820px) { #toasts { bottom: 24px; } }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; box-shadow: 0 8px 24px #0004; animation: rise .25s ease; transition: opacity .3s, transform .3s; }
.toast.error { background: var(--red); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- skeleton ---------- */
.skel { height: 64px; border-radius: var(--radius); margin-bottom: 12px; background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- automated messages ---------- */
.pill.queued { background: var(--blue-bg); color: var(--blue); }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); cursor: pointer; }
.check input { width: 20px; height: 20px; min-height: 0; accent-color: var(--wa); flex: none; }
.switch { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 46px; height: 28px; border-radius: 14px; background: var(--border); position: relative; flex: none; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px #0003; transition: transform .2s; }
.switch input:checked + .track { background: var(--wa); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--accent-soft); }
.wrap-chips { flex-wrap: wrap; padding: 6px 0 0; }
.wrap-chips .chip { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; padding: 5px 10px; }
.wa-chat { background: #efeae2; border-radius: 12px; padding: 14px; }
.bubble { background: #d9fdd3; color: #111b21; border-radius: 10px 0 10px 10px; padding: 8px 10px 6px; margin-left: auto; max-width: 88%; width: fit-content; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px 1px #0000001a; animation: rise .2s ease; }
.bubble .time { display: block; text-align: right; font-size: 11px; color: #667781; margin-top: 2px; }
@media (prefers-color-scheme: dark) {
  .wa-chat { background: #0b141a; }
  .bubble { background: #005c4b; color: #e9edef; }
  .bubble .time { color: #8fb3aa; }
}
.chars.bad { background: var(--red-bg); color: var(--red); }
.section-label .count { text-transform: none; letter-spacing: 0; margin-left: 6px; }

/* ---------- sign-up link ---------- */
.auth-alt { text-align: center; font-size: 14px; color: var(--muted); }
.link { border: none; background: none; padding: 0; font: inherit; font-weight: 600; color: var(--accent-2); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* ---------- role picker ---------- */
.role-pick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role-opt { display: grid; gap: 4px; text-align: left; padding: 12px; border-radius: 12px; border: 1.5px solid var(--border); background: var(--card); color: var(--text); font: inherit; cursor: pointer; transition: border-color .15s, background .15s; }
.role-opt span { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.role-opt:hover:not(:disabled) { border-color: var(--accent-2); }
.role-opt.on { border-color: var(--accent-2); background: var(--accent-soft); cursor: default; }
.role-opt.on b::after { content: " ✓"; color: var(--accent-2); }
.mhead .pill { margin-left: 6px; }
.grid-gap { display: grid; gap: 10px; }

/* ---------- create-your-gym sign-up ---------- */
.steps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.steps span { padding-top: 8px; border-top: 3px solid var(--border); transition: border-color .2s, color .2s; }
.steps span.on { border-color: var(--accent-2); color: var(--accent-2); }
.step { display: grid; gap: 14px; animation: rise .25s ease; }
.money-input { position: relative; }
.money-input span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.money-input input { padding-left: 28px; }
