/* Gym Manager — admin. Jays Fitness Systems theme (jfs.co.ke). */

:root {
  --red: #EC3642;
  --red-dk: #CF2E2E;
  --red-soft: rgba(236, 54, 66, 0.12);
  --ink: #0A0A0A;
  --ink-2: #141414;
  --ink-3: #1C1C1C;
  --line: rgba(255, 255, 255, 0.10);
  --line-2: rgba(255, 255, 255, 0.18);
  --paper: #FFFFFF;
  --muted: rgba(255, 255, 255, 0.58);
  --faint: rgba(255, 255, 255, 0.34);
  --ok: #35C77B;
  --warn: #F2B33D;
  --display: 'Montserrat', system-ui, sans-serif;
  --body: 'Poppins', system-ui, sans-serif;
}

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

body {
  font-family: var(--body);
  background: var(--ink);
  color: var(--paper);
  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(10, 10, 10, 0.94); 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(--paper); border-color: var(--line-2); }
.nav a.on { color: var(--red); border-color: var(--red); background: var(--red-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: 17px;
  margin-bottom: 4px; letter-spacing: .01em;
}
.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(--ink-2); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; text-align: left; width: 100%; cursor: pointer;
  font-family: var(--body); color: var(--paper);
  transition: transform .12s ease, border-color .15s ease, background .15s ease;
}
.kpi:hover { border-color: var(--line-2); background: var(--ink-3); transform: translateY(-2px); }
.kpi:active { transform: translateY(0) scale(.99); }
.kpi.hot:hover { border-color: var(--red); }
.kpi.hot { border-color: rgba(236, 54, 66, 0.45); background: linear-gradient(165deg, #1B0F11, var(--ink-2)); }
.kpi-val { font-family: var(--display); font-weight: 900; font-size: 28px; line-height: 1; }
.kpi.hot .kpi-val { color: var(--red); }
.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(--ink-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 15px; display: flex; align-items: center; gap: 12px;
}
.row.warn { border-color: rgba(242, 179, 61, 0.4); }
.row.risk { border-color: rgba(236, 54, 66, 0.4); }
.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(53, 199, 123, .16); color: var(--ok); }
.pill.warn { background: rgba(242, 179, 61, .16); color: var(--warn); }
.pill.dead { background: rgba(236, 54, 66, .16); color: var(--red); }

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

/* ---- controls ---- */
.btn {
  font-family: var(--display); font-weight: 800; font-size: 12px;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--paper); background: var(--ink-3);
  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: #262626; }
.btn:active { transform: scale(.97); }
.btn.red { background: var(--red); border-color: var(--red); }
.btn.red:hover { background: var(--red-dk); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; padding: 15px; font-size: 13.5px; }
.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(--paper); background: var(--ink-2);
  border: 1px solid var(--line); border-radius: 11px; outline: none;
  transition: border-color .15s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); }
input::placeholder { color: rgba(255, 255, 255, 0.26); }
select { appearance: none; background-image: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

.err { color: #FF8A93; font-size: 13px; margin-top: 12px; min-height: 18px; line-height: 1.5; }

/* ---- logo ---- */
/* logo-dark.png is the client's wordmark with its grey text lifted to white, so
   it reads on the near-black UI. The original webp's grey vanishes on black. */
.logo { display: block; width: 190px; max-width: 60%; height: auto; margin: 0 auto; }
.logo.sm { width: 132px; margin: 0; }

/* ---- door QR ---- */
.qr-card {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start;
  background: var(--ink-2); border: 1px solid var(--line);
  border-radius: 16px; padding: 18px;
}
.qr-img {
  width: 168px; height: 168px; flex: 0 0 auto;
  background: #fff; border-radius: 12px; padding: 9px;
}
.qr-side { flex: 1 1 240px; min-width: 0; }
.qr-link {
  background: var(--ink); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; font-size: 13px; color: var(--red);
  word-break: break-all; margin-bottom: 12px;
}
.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(--ink-2); border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 8px; overflow: hidden;
}
.guide summary {
  display: block; cursor: pointer; list-style: none;
  padding: 15px 17px; font-family: var(--display); font-weight: 800;
  font-size: 13.5px; position: relative; padding-right: 44px;
}
.guide summary::-webkit-details-marker { display: none; }
.guide summary::after {
  content: "+"; position: absolute; right: 17px; top: 50%;
  transform: translateY(-50%); color: var(--red); font-size: 20px; font-weight: 400;
}
.guide[open] summary::after { content: "\2212"; }
.guide summary:hover { background: var(--ink-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(--paper); 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); border-radius: 10px;
  color: var(--muted); font-size: 16px; cursor: pointer; line-height: 1;
}
.erow .e-del:hover { color: var(--red); border-color: var(--red); }
.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(--ink); 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(--paper); }
#paidFields { margin-top: 14px; }
.paid-note { font-size: 12px; color: var(--muted); margin-top: 10px; line-height: 1.5; }
.paid-note b { color: var(--paper); 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(--paper); 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: transparent;
  border: 1px solid var(--line); border-radius: 9px; cursor: pointer;
  transition: color .14s ease, border-color .14s ease;
}
.chip:hover { color: var(--paper); border-color: var(--line-2); }
.chip.on { color: var(--red); border-color: var(--red); background: var(--red-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 {
  filter: invert(1); opacity: .55; 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(0, 0, 0, .72); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal.open { display: flex; }
.modal-card {
  background: var(--ink-2); border: 1px solid var(--line-2); border-radius: 18px;
  padding: 24px; width: 100%; max-width: 420px;
  max-height: 88dvh; overflow-y: auto;
}
.modal-card.wide { max-width: 520px; }
.modal-card h3 { font-family: var(--display); font-weight: 800; font-size: 18px; margin-bottom: 16px; }
#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-3); border: 1px solid var(--line-2); 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;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---- suspended banner ---- */
#suspended {
  display: none; background: rgba(236, 54, 66, .12);
  border-bottom: 1px solid var(--red); padding: 14px 18px;
  font-size: 13px; line-height: 1.5; color: #FFC9CD;
}

/* ---- 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(--ink-2); border: 1px solid var(--red);
  border-radius: 14px; padding: 18px; margin-top: 12px;
}
.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: 18px; margin: 6px 0 14px; }
.step-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.step-actions .btn { flex: 1; min-width: 92px; }
.step-note {
  background: rgba(242, 179, 61, .1); border: 1px solid rgba(242, 179, 61, .35);
  border-radius: 10px; padding: 12px 14px; font-size: 12.5px;
  color: #F7DCA6; 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: 96px; }
  /* 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: 10.5px; 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: 16px; }

  /* 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: 23px; }
  .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: 12.5px; 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: 20px; }
  .logo.sm { width: 88px; }
  .topbar .btn { padding: 7px 8px; font-size: 10px; }
  .qr-img { width: 168px; height: 168px; }
}
