/* Gym Manager — admin. Power Core Fitness theme, matched to pcfgym.co.ke:
   white background, #111827 ink, burgundy #800020 accent, Inter + Barlow Condensed.
   The logo is white+red on black, so it always appears as its own dark badge tile
   (exactly how their website header shows it) — never as bare art on the white UI. */

:root {
  --accent: #800020;        /* burgundy, from the site's buttons + active nav */
  --accent-dk: #660019;
  --accent-soft: rgba(128, 0, 32, 0.08);
  --accent-line: rgba(128, 0, 32, 0.30);
  --paper: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F9FAFB;
  --surface-3: #F3F4F6;
  --ink: #111827;
  --line: #E5E7EB;
  --line-2: #D1D5DB;
  --muted: #6B7280;
  --faint: #9CA3AF;
  --ok: #047857;
  --warn: #B45309;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 4px 14px rgba(17, 24, 39, 0.05);
  --display: 'Barlow Condensed', system-ui, sans-serif;
  --body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--body);
  background: var(--paper);
  color: var(--ink);
  min-height: 100dvh;
  font-size: 14px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}

/* ---- login ---- */
#login {
  min-height: 100dvh; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
#login .box { width: 100%; max-width: 360px; }

/* ---- shell ---- */
/* The bar and the nav are ONE sticky block, so the nav can never tuck under the
   bar. --head-h is measured in JS for scroll-margin only, where being a few px
   out is cosmetic rather than an overlap. */
:root { --head-h: 122px; }

#app { display: none; }

.head {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar {
  padding: 12px 18px; padding-top: calc(12px + env(safe-area-inset-top));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--line);
}

/* Wraps, never scrolls sideways. A menu you have to swipe to discover is a menu
   half the owners never find — and a horizontally-scrolling strip inside a page
   that doesn't scroll sideways reads as a rendering bug. Seven items wrap to one
   row on desktop and two on a phone. */
.nav {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 18px;
}
.nav a {
  flex: 0 1 auto; padding: 8px 14px; border-radius: 20px;
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  text-decoration: none; border: 1px solid var(--line); white-space: nowrap;
  transition: color .14s ease, border-color .14s ease, background .14s ease;
}
.nav a:hover { color: var(--ink); border-color: var(--line-2); }
.nav a.on { color: var(--accent); border-color: var(--accent-line); background: var(--accent-soft); }

.wrap { max-width: 900px; margin: 0 auto; padding: 22px 18px; }

section { margin-bottom: 34px; scroll-margin-top: calc(var(--head-h) + 14px); }
h2 {
  font-family: var(--display); font-weight: 800; font-size: 22px;
  margin-bottom: 4px; letter-spacing: .01em; text-transform: uppercase;
}
.sub { color: var(--muted); font-size: 13px; line-height: 1.5; margin-bottom: 16px; }

/* ---- KPIs ---- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
/* Buttons, not divs. They lift on hover, so they must do something on click. */
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; text-align: left; width: 100%; cursor: pointer;
  font-family: var(--body); color: var(--ink); box-shadow: var(--shadow);
  transition: transform .12s ease, border-color .15s ease, box-shadow .15s ease;
}
.kpi:hover { border-color: var(--line-2); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(17,24,39,.09); }
.kpi:active { transform: translateY(0) scale(.99); }
.kpi.hot:hover { border-color: var(--accent); }
.kpi.hot { border-color: var(--accent-line); background: linear-gradient(165deg, #FBEFF1, var(--surface)); }
.kpi-val { font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1; }
.kpi.hot .kpi-val { color: var(--accent); }
.kpi-label {
  font-size: 10.5px; color: var(--muted); margin-top: 8px;
  letter-spacing: .06em; text-transform: uppercase; font-weight: 600;
}

.sec-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.sec-actions .btn { flex: 1 1 auto; }

/* ---- rows ---- */
.rows { display: flex; flex-direction: column; gap: 8px; }
.row {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 15px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow);
}
.row.warn { border-color: rgba(180, 83, 9, 0.4); }
.row.milestone { border-color: rgba(4, 120, 87, 0.4); }
.row.risk { border-color: var(--accent-line); }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 600; font-size: 14px; }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.pill {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .04em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 20px; margin-left: 7px;
  vertical-align: middle;
}
.pill.ok { background: rgba(4, 120, 87, .12); color: var(--ok); }
.pill.warn { background: rgba(180, 83, 9, .14); color: var(--warn); }
.pill.dead { background: var(--accent-soft); color: var(--accent); }

.empty { color: var(--faint); font-size: 13px; padding: 16px; text-align: center; }

/* ---- controls ---- */
.btn {
  font-family: var(--display); font-weight: 700; font-size: 13.5px;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 9px;
  padding: 9px 14px; cursor: pointer;
  transition: transform .1s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn.red { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.red:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn.ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn.wide { width: 100%; padding: 15px; font-size: 15px; }
.btn[disabled] { opacity: .5; cursor: default; }

.field { margin-bottom: 13px; text-align: left; }
label { display: block; font-size: 11.5px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
input, select, textarea {
  width: 100%; padding: 13px 15px; font-family: var(--body); font-size: 15px;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 11px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--faint); }
select { appearance: none; background-image: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

.err { color: var(--accent); font-size: 13px; margin-top: 12px; min-height: 18px; line-height: 1.5; }

/* ---- logo ---- */
/* The logo is white+red on black, so on this white UI it shows as its own dark
   badge tile — same as the pcfgym.co.ke header. logo-badge-mark.png (topbar) is
   the monogram on black; logo-src.jpg (login/checkin) is the full square. */
.logo { display: block; width: 92px; height: 92px; border-radius: 20px; object-fit: cover; margin: 0 auto; box-shadow: var(--shadow); }
.logo.sm { width: 42px; height: 42px; border-radius: 11px; margin: 0; }

/* ---- door QR ---- */
.qr-card {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px; box-shadow: var(--shadow);
}
.qr-img {
  width: 168px; height: 168px; flex: 0 0 auto;
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 9px;
}
.qr-side { flex: 1 1 240px; min-width: 0; }
.qr-link {
  background: var(--surface-3); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; font-size: 13px; color: var(--accent);
  word-break: break-all; margin-bottom: 12px; font-weight: 500;
}
.qr-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.qr-btns .btn { flex: 1; min-width: 120px; }
.qr-note { font-size: 12.5px; color: var(--faint); line-height: 1.55; margin-top: 12px; }

/* ---- help guide ---- */
.guide {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 8px; overflow: hidden; box-shadow: var(--shadow);
}
.guide summary {
  display: block; cursor: pointer; list-style: none;
  padding: 15px 17px; font-family: var(--display); font-weight: 700;
  font-size: 16px; letter-spacing: .01em; position: relative; padding-right: 44px; text-transform: uppercase;
}
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after {
  content: "+"; position: absolute; right: 17px; top: 50%;
  transform: translateY(-50%); color: var(--accent); font-size: 20px; font-weight: 400;
}
.guide[open] summary::after { content: "\2212"; }
.guide summary:hover { background: var(--surface-3); }
.guide p, .guide ol { padding: 0 17px 15px; font-size: 13.5px; color: var(--muted); line-height: 1.6; }
.guide ol { padding-left: 36px; }
.guide li { margin-bottom: 7px; }
.guide b { color: var(--ink); font-weight: 600; }

/* ---- plan / branch editors ---- */
.editor { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.editor:empty { display: none; }
.erow { display: flex; gap: 8px; align-items: center; }
.erow input { padding: 11px 13px; font-size: 14px; }
.erow .e-name { flex: 2 1 0; min-width: 0; }
.erow .e-price, .erow .e-months { flex: 1 1 0; min-width: 0; }
.erow .e-del {
  flex: 0 0 auto; width: 40px; padding: 11px 0; text-align: center;
  background: transparent; border: 1px solid var(--line-2); border-radius: 10px;
  color: var(--muted); font-size: 16px; cursor: pointer; line-height: 1;
}
.erow .e-del:hover { color: var(--accent); border-color: var(--accent); }
.ehead {
  display: flex; gap: 8px; font-size: 10.5px; color: var(--faint);
  text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding: 0 2px;
}
.ehead .e-name { flex: 2 1 0; }
.ehead .e-price, .ehead .e-months { flex: 1 1 0; }
.ehead .e-del { flex: 0 0 40px; }

/* ---- payment-on-add ---- */
.paid-box {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 14px;
}
.check { display: flex; align-items: center; gap: 10px; margin: 0; cursor: pointer; }
.check input { width: auto; flex: 0 0 auto; margin: 0; }
.check span { font-size: 13.5px; font-weight: 600; color: var(--ink); }
#paidFields { margin-top: 14px; }
.paid-note { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.5; }
.paid-note b { color: var(--ink); font-weight: 600; }

/* The native date input renders in the device's locale, which we can't control.
   Echo the chosen date back in dd/mm/yyyy so there's no doubt what was picked. */
.date-echo { font-size: 12px; color: var(--muted); margin-top: 7px; min-height: 16px; }
.date-echo b { color: var(--ink); font-weight: 600; }

/* ---- quick date chips ---- */
.quick { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.chip {
  flex: 1; min-width: 68px; padding: 9px 8px; font-size: 12px; font-weight: 500;
  color: var(--muted); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: 9px; cursor: pointer;
  transition: color .14s ease, border-color .14s ease, background .14s ease;
}
.chip:hover { color: var(--ink); border-color: var(--line-2); }
.chip.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* Tapping anywhere on a date field should open the calendar, not just the icon.
   A gym owner on a phone will not hunt for a 12px glyph. */
input[type="date"] { cursor: pointer; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }

/* ---- modal ---- */
/* Native confirm/alert/prompt die inside WhatsApp and Instagram webviews, and
   that's exactly where a gym owner opens their admin. Always use these. */
.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(17, 24, 39, .45); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px; width: 100%; max-width: 420px;
  max-height: 88dvh; overflow-y: auto; box-shadow: 0 20px 60px rgba(17,24,39,.25);
}
.modal-card.wide { max-width: 520px; }
.modal-card h3 { font-family: var(--display); font-weight: 800; font-size: 22px; margin-bottom: 16px; text-transform: uppercase; }
#listBody { max-height: 56dvh; overflow-y: auto; }
#listSub { margin-top: -10px; margin-bottom: 14px; }
.modal-actions { display: flex; gap: 9px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

/* ---- toast ---- */
#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 24px);
  background: var(--ink); color: #fff; border-radius: 11px;
  padding: 13px 20px; font-size: 13.5px; z-index: 90;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease;
  max-width: calc(100vw - 40px); text-align: center; box-shadow: 0 10px 30px rgba(17,24,39,.25);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- suspended banner ---- */
#suspended {
  display: none; background: var(--accent-soft);
  border-bottom: 1px solid var(--accent); padding: 14px 18px;
  font-size: 13px; line-height: 1.5; color: var(--accent-dk);
}

/* ---- WhatsApp stepper ---- */
/* Phone-first: the desktop "open 20 tabs" trick dies on a phone, because the
   first wa.me link backgrounds the browser and the loop never resumes. */
.stepper {
  display: none; background: var(--surface); border: 1px solid var(--accent-line);
  border-radius: 14px; padding: 18px; margin-top: 12px; box-shadow: var(--shadow);
}
.stepper.open { display: block; }
.step-count { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.step-name { font-family: var(--display); font-weight: 800; font-size: 22px; margin: 6px 0 14px; text-transform: uppercase; }
.step-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.step-actions .btn { flex: 1; min-width: 92px; }
.step-note {
  background: rgba(180, 83, 9, .08); border: 1px solid rgba(180, 83, 9, .3);
  border-radius: 10px; padding: 12px 14px; font-size: 12.5px;
  color: #92400E; line-height: 1.55; margin-bottom: 14px;
}

/* ---- mobile ---- */
/* The owner runs this from a phone. Everything below is about a 360-390px
   viewport, one thumb, and no horizontal scroll anywhere. */
@media (max-width: 620px) {
  body { font-size: 14px; }

  /* The header is frozen, so every pixel it takes is a pixel of the gym the owner
     can't see. Two nav rows earn their space; slack padding doesn't. */
  .topbar { padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .logo.sm { width: 38px; height: 38px; }
  /* Thumb targets. Nothing tappable drops below 40px tall on a phone — the
     top-bar buttons were coming out at 31px, which is a miss waiting to happen. */
  .btn { min-height: 42px; }
  .topbar .btn { padding: 8px 11px; font-size: 12px; min-height: 40px; }
  .nav a { min-height: 36px; display: flex; align-items: center; }
  .e-del { min-height: 42px; }
  .chip { min-height: 40px; }

  /* Two tidy rows. The pills grow to share each row's width instead of leaving a
     ragged gap at the end. */
  .nav { padding: 8px 14px 9px; gap: 5px; }
  .nav a { flex: 1 1 auto; justify-content: center; padding: 6px 10px; font-size: 11.5px; min-height: 34px; }

  .wrap { padding: 18px 14px; }
  section { margin-bottom: 28px; }
  h2 { font-size: 20px; }

  /* Two KPIs across, never one long column of huge numbers. */
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 13px; }
  .kpi-val { font-size: 28px; }
  .kpi-label { font-size: 9.5px; letter-spacing: .04em; }

  /* Name on top, actions as a full-width row underneath. Side-by-side buttons
     squeeze the name to nothing on a narrow screen. */
  .row { flex-wrap: wrap; padding: 12px 13px; }
  .row-actions { width: 100%; }
  .row-actions .btn { flex: 1; padding: 10px 8px; }
  .row-name { font-size: 13.5px; }
  .row-sub { font-size: 11.5px; }
  .pill { font-size: 9px; padding: 2px 6px; margin-left: 5px; }

  .grid2 { grid-template-columns: 1fr; }

  /* QR stacks and centres; the code stays big enough to actually scan. */
  .qr-card { flex-direction: column; align-items: center; padding: 15px; }
  .qr-img { width: 200px; height: 200px; }
  .qr-side { width: 100%; }
  .qr-btns .btn { flex: 1 1 100%; }

  .erow { flex-wrap: wrap; }
  .erow .e-name { flex: 1 1 100%; }
  .erow .e-price, .erow .e-months { flex: 1 1 0; }
  .ehead { display: none; }

  .chip { min-width: 0; font-size: 11.5px; padding: 9px 4px; }

  .modal { padding: 12px; align-items: flex-end; }
  .modal-card { padding: 20px 18px; max-height: 92dvh; border-radius: 18px 18px 12px 12px; }
  .modal-actions { flex-direction: column-reverse; }

  .guide summary { font-size: 15px; padding: 13px 15px; padding-right: 40px; }
  .guide p, .guide ol { font-size: 13px; padding: 0 15px 13px; }
  .guide ol { padding-left: 32px; }

  .step-actions .btn { flex: 1 1 calc(50% - 4px); min-width: 0; }
}

/* Very narrow phones. Nothing may overflow sideways. */
@media (max-width: 360px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi-val { font-size: 25px; }
  .logo.sm { width: 36px; height: 36px; }
  .topbar .btn { padding: 7px 8px; font-size: 11px; }
  .qr-img { width: 168px; height: 168px; }
}
