:root {
  --bg: #f3f3ef;
  --surface: #ffffff;
  --surface-2: #ecece6;
  --line: #dcdcd4;
  --text: #15161a;
  --muted: #6b6d73;
  --accent: #b5e61d;
  --accent-ink: #10120a;
  --accent-strong: #6f9400;
  --ok: #14a44d;
  --warn: #e8a317;
  --bad: #e03a3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.06);
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1012;
    --surface: #18191d;
    --surface-2: #222328;
    --line: #2c2d33;
    --text: #f2f2ee;
    --muted: #9a9ca3;
    --accent: #c6f432;
    --accent-strong: #c6f432;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; -webkit-text-size-adjust: 100%; }
body { min-height: 100dvh; }
[hidden] { display: none !important; }
a { color: var(--accent-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--display); letter-spacing: .01em; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.opt { color: var(--muted); font-weight: 400; }

/* ---------- Buttons & inputs ---------- */
.btn { appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text); padding: .7rem 1rem; border-radius: 12px; font-weight: 600; cursor: pointer; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; text-decoration: none; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-danger { background: transparent; color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn-ghost { background: transparent; }
.btn-wa { background: #25d366; color: #06210f; border-color: transparent; }
.btn-block { width: 100%; }
.btn-lg { min-height: 56px; font-size: 1.1rem; }
.btn-sm { min-height: 34px; padding: .35rem .7rem; font-size: .875rem; border-radius: 10px; }
.icon-btn { appearance: none; border: 0; background: transparent; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); }

label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .85rem; }
input, select, textarea { display: block; width: 100%; margin-top: .35rem; padding: .75rem .85rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 1rem; min-height: 48px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea { min-height: 80px; resize: vertical; }
.form-error { color: var(--bad); font-weight: 600; margin: .75rem 0 0; }
.row { display: flex; gap: .6rem; }
.row > * { flex: 1; }

/* ---------- Login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow); text-align: left; }
.login-title { font-size: 2rem; margin-top: 14px; }
.brand-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 1.8rem; }
.brand-mark.sm { width: 34px; height: 34px; font-size: 1.2rem; border-radius: 10px; }

/* ---------- Layout ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; padding: calc(10px + env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.gym-name { font-family: var(--display); font-weight: 700; font-size: 1.2rem; line-height: 1.1; }
.who { font-size: .8rem; color: var(--muted); }
.net-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.net-dot.off { background: var(--bad); }
main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 25; display: flex; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar button { flex: 1; appearance: none; border: 0; background: none; padding: 8px 2px 9px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: .72rem; font-weight: 600; color: var(--muted); cursor: pointer; min-width: 0; }
.tabbar svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.on { color: var(--text); }
.tabbar button.on svg { stroke: var(--accent-strong); }
@media (min-width: 900px) { main { padding-bottom: 100px; } }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.h2 { font-size: 1.6rem; margin-bottom: 4px; }
.section-title { font-size: 1.15rem; margin: 22px 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.loading, .empty { color: var(--muted); padding: 18px 4px; text-align: center; list-style: none; }

/* ---------- Scan ---------- */
.scan-wrap { position: relative; background: #000; border-radius: 18px; overflow: hidden; aspect-ratio: 4 / 3; max-height: 52vh; width: 100%; }
.reader { width: 100%; height: 100%; }
.reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.reader img[alt="Info icon"], .reader img[alt="Camera based scan"] { display: none; }
.scan-hint { position: absolute; left: 0; right: 0; bottom: 0; padding: 10px 12px; font-size: .9rem; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.7)); text-align: center; pointer-events: none; }
.scan-controls { display: flex; gap: 10px; margin: 12px 0; }
.scan-controls .btn { flex: 1; }
.manual { display: flex; gap: 10px; }
.manual input { margin: 0; flex: 1; }

.scan-result { position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 20px calc(24px + env(safe-area-inset-bottom)); text-align: center; color: #fff; }
.scan-result.ok { background: #0f8a3e; }
.scan-result.repeat { background: #1d6fb8; }
.scan-result.bad { background: #c42727; }
.scan-result.unknown { background: #3a3b40; }
.sr-icon { font-family: var(--display); font-size: 1.6rem; letter-spacing: .08em; text-transform: uppercase; opacity: .9; }
.sr-big { font-family: var(--display); font-size: clamp(2.6rem, 11vw, 4.5rem); line-height: 1; margin: 6px 0 16px; text-transform: uppercase; }
.sr-photo { width: 150px; height: 150px; border-radius: 22px; object-fit: cover; border: 4px solid rgba(255,255,255,.85); background: rgba(255,255,255,.15); display: grid; place-items: center; font-family: var(--display); font-size: 3.5rem; margin-bottom: 14px; }
.sr-name { font-size: 1.7rem; font-weight: 700; }
.sr-meta { font-size: 1.05rem; opacity: .92; margin-top: 6px; }
.sr-actions { display: flex; gap: 10px; margin-top: 26px; flex-wrap: wrap; justify-content: center; }
.sr-actions .btn { background: rgba(255,255,255,.95); color: #111; border: 0; min-width: 130px; }
.sr-actions .btn-primary { background: var(--accent); color: var(--accent-ink); }
.sr-tap { position: absolute; bottom: calc(16px + env(safe-area-inset-bottom)); font-size: .85rem; opacity: .75; }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; cursor: pointer; min-height: 64px; }
.item:active { background: var(--surface-2); }
.avatar { width: 46px; height: 46px; flex: none; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 1.2rem; object-fit: cover; color: var(--muted); }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-end { text-align: right; flex: none; font-size: .85rem; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
.pill.active, .pill.allowed { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.expiring, .pill.repeat { background: color-mix(in srgb, var(--warn) 22%, transparent); color: #b07a00; }
.pill.expired, .pill.unknown, .pill.void { background: color-mix(in srgb, var(--bad) 16%, transparent); color: var(--bad); }
.pill.never, .pill.guest { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) { .pill.expiring, .pill.repeat { color: var(--warn); } }

.toolbar { display: flex; gap: 10px; margin-bottom: 10px; }
.toolbar input { margin: 0; flex: 1; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { appearance: none; flex: none; border: 1px solid var(--line); background: var(--surface); padding: .45rem .9rem; border-radius: 999px; font-weight: 600; font-size: .9rem; cursor: pointer; min-height: 36px; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }

/* ---------- Payment method picker ---------- */
.method-pick { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
.method-pick button { appearance: none; border: 1.5px solid var(--line); background: var(--surface); padding: .7rem .5rem; border-radius: 12px; font-weight: 600; cursor: pointer; min-height: 48px; }
.method-pick button.on { border-color: var(--accent-strong); background: color-mix(in srgb, var(--accent) 22%, var(--surface)); }
.price-line { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 2px; border-top: 1px dashed var(--line); margin-top: 4px; margin-bottom: 12px; }
.price-line strong { font-family: var(--display); font-size: 2rem; }
.dp-found { background: color-mix(in srgb, var(--accent) 18%, var(--surface)); border-radius: 12px; padding: 10px 12px; margin: -4px 0 14px; font-size: .92rem; }

/* ---------- Sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 92dvh; overflow-y: auto; background: var(--bg); border-radius: 22px 22px 0 0; padding: 10px 16px calc(24px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; box-shadow: 0 -10px 40px rgba(0,0,0,.25); animation: up .22s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-grab { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 8px; }
.sheet-close { position: absolute; top: 10px; right: 10px; font-size: 1.1rem; }
.sheet-body { padding-top: 6px; }
.sheet h2 { font-size: 1.7rem; margin: 6px 40px 12px 0; }

.profile-head { display: flex; gap: 14px; align-items: center; margin: 8px 0 14px; }
.profile-head .avatar { width: 76px; height: 76px; border-radius: 18px; font-size: 2rem; }
.profile-head h2 { margin: 0; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.stat b { display: block; font-family: var(--display); font-size: 1.35rem; }
.stat span { font-size: .78rem; color: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.actions .wide { grid-column: 1 / -1; }
.history { list-style: none; padding: 0; margin: 0; }
.history li { display: flex; justify-content: space-between; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: .92rem; gap: 10px; }
.history li:last-child { border-bottom: 0; }

.photo-pick { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.photo-pick .avatar { width: 72px; height: 72px; border-radius: 16px; }

.card-preview { width: 100%; border-radius: 16px; display: block; margin: 4px 0 14px; box-shadow: var(--shadow); }

/* ---------- Dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(3, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.kpi .lab { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi .val { font-family: var(--display); font-size: 1.9rem; font-weight: 700; line-height: 1.1; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi.hero { grid-column: 1 / -1; background: linear-gradient(135deg, #20240f, #121316 70%); color: #fff; border: 1px solid rgba(198, 244, 50, .35); }
.kpi.hero .lab, .kpi.hero .sub { color: rgba(255, 255, 255, .72); }
.kpi.hero .val { font-size: 2.6rem; color: #c6f432; }
.up { color: var(--ok); } .down { color: var(--bad); }
.kpi.hero .up { color: #7be39f; } .kpi.hero .down { color: #ff8f8f; }

.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 9px; font-family: var(--font); }
.chart .bar { fill: var(--accent-strong); }
.chart .bar.dim { fill: color-mix(in srgb, var(--accent-strong) 45%, transparent); }
.chart .bar.wk { fill: #4f8fd6; }
.chart .bar.dp { fill: #e8a317; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th, .tbl td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); }
.tbl th { font-size: .78rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl input { margin: 0; min-height: 40px; padding: .45rem .6rem; }

.money-total { font-family: var(--display); font-size: 2.6rem; font-weight: 700; line-height: 1; }
.drawer { display: flex; justify-content: space-between; align-items: center; background: color-mix(in srgb, var(--accent) 20%, var(--surface)); border-radius: 12px; padding: 12px 14px; margin-top: 12px; }
.drawer { gap: 12px; }
.drawer span { flex: 1; }
.drawer strong { font-family: var(--display); font-size: 1.6rem; white-space: nowrap; }
.void-row { opacity: .55; text-decoration: line-through; }

.banner { background: color-mix(in srgb, var(--warn) 22%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 50%, transparent); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; font-size: .92rem; }
.banner b { display: block; margin-bottom: 2px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 70; background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 32px); box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.toast.err { background: var(--bad); color: #fff; }

/* ---------- Plan editor ---------- */
.plan-row { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.plan-row input.pName { margin: 0 0 8px; }
.plan-row .plan-meta { display: flex; align-items: center; gap: 10px; }
.plan-row .plan-meta .len { flex: 1; color: var(--muted); font-size: .88rem; }
.plan-row .pPrice { margin: 0; width: 130px; text-align: right; }
.plan-row .on-toggle { display: flex; align-items: center; gap: 6px; margin: 0; font-size: .85rem; }
.plan-row .on-toggle input { width: 22px; min-height: 22px; margin: 0; }

/* Owner clean-up: select & delete members */
.btn-danger-solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.select-bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid color-mix(in srgb, var(--bad) 40%, var(--line)); border-radius: 12px; padding: 8px 10px; margin-bottom: 10px; }
.select-bar span { flex: 1; font-weight: 600; font-size: .9rem; }
.selecting .item { position: relative; padding-left: 44px; }
.selecting .item::before { content: ''; position: absolute; left: 12px; top: 50%; width: 22px; height: 22px; margin-top: -11px; border-radius: 6px; border: 2px solid var(--line); background: var(--surface); }
.selecting .item.picked { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.selecting .item.picked::before { content: '✓'; color: #fff; background: var(--bad); border-color: var(--bad); font-weight: 700; font-size: 15px; line-height: 18px; text-align: center; }
.banner.danger { background: color-mix(in srgb, var(--bad) 12%, var(--surface)); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
