/* Gym Manager — admin. Echelon Tactical & Fitness theme, taken from their logo
   (instagram.com/echelon_tactical_fitness): white background, deep teal #00423C
   accent, gold #E0B534 highlight, Inter + Barlow Condensed.

   Their logo has two brand colours and they do different jobs here. The deep
   teal of the "ECHELON" wordmark is the accent: it's what buttons, the active
   nav pill and links are painted with, because it holds up on white at any size.
   The gold of "TACTICAL & FITNESS" is a highlight, never a background for text —
   #E0B534 on white is about 2:1, so anything set in it has to be big (a KPI
   number) or darkened (--gold-ink) first.

   The logo was drawn FOR a white page, so it sits on this UI as bare art. No
   badge tile, no recolouring. */

:root {
  --accent: #00423C;        /* straight off the "ECHELON" wordmark */
  --accent-dk: #002E2A;
  --accent-soft: rgba(0, 66, 60, 0.09);
  --accent-line: rgba(0, 66, 60, 0.42);
  --gold: #E0B534;          /* the logo gold. Big display type and fills only. */
  --gold-ink: #8A6B0F;      /* the same gold, dark enough to set small text in */
  --gold-soft: #FBF3DC;
  --gold-line: rgba(184, 144, 31, 0.45);
  --paper: #FFFFFF;
  --surface: #FFFFFF;
  --surface-2: #F7FAF9;
  --surface-3: #EDF3F1;
  --ink: #0F1F1B;
  --line: #D3DCD9;
  --line-2: #BECBC7;
  --muted: #3A534D;
  --faint: #4E6660;
  --ok: #047857;
  --warn: #B45309;
  --shadow: 0 1px 2px rgba(15, 31, 27, 0.05), 0 4px 14px rgba(15, 31, 27, 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(--gold-ink); }
.kpi.hot { border-color: var(--gold-line); background: linear-gradient(165deg, var(--gold-soft), var(--surface)); }
.kpi-val { font-family: var(--display); font-weight: 800; font-size: 34px; line-height: 1; }
/* --gold-ink, not raw --gold: #E0B534 on the pale gold tile behind it is thin
   even at 34px, and this number is the one the owner is meant to act on. */
.kpi.hot .kpi-val { color: var(--gold-ink); }
.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; }

/* ---- leaderboard ---- */
.board-month-label { align-self: center; font-size: 12.5px; color: var(--muted); }
.board-month {
  flex: 1 1 auto; padding: 11px 13px; font-family: inherit; font-size: 14px;
  color: var(--ink); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; outline: none;
}
.board-rank { display: inline-block; min-width: 22px; font-weight: 800; }

/* ---- spreadsheet import ---- */
input[type="file"] {
  width: 100%; font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; cursor: pointer;
}
input[type="file"]::file-selector-button {
  font-family: inherit; font-weight: 600; font-size: 13px; color: var(--ink);
  background: var(--surface-3); border: 1px solid var(--line); border-radius: 7px;
  padding: 8px 12px; margin-right: 12px; cursor: pointer;
}
.import-counts { font-size: 13.5px; color: var(--muted); margin-bottom: 12px; }
.import-counts b { color: var(--ink); }
.import-preview { max-height: 46vh; overflow: auto; border: 1px solid var(--line);
  border-radius: 10px; margin-top: 6px; }
.imp-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.imp-table th, .imp-table td { text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--line); white-space: nowrap; }
.imp-table th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted);
  font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }
.imp-table tr:last-child td { border-bottom: 0; }
.imp-table tr.bad td { background: var(--accent-soft); color: var(--muted); }

/* ---- rows ---- */
.rows { display: flex; flex-direction: column; gap: 8px; }
/* Long lists scroll inside a box so a full roster doesn't stretch the page into a
   mile of scrolling. Only kicks in when the list is actually taller than the cap. */
.rows.scroll {
  max-height: 60vh; overflow-y: auto; overscroll-behavior: contain;
  padding-right: 6px; margin-right: -6px;
}
.rows.scroll::-webkit-scrollbar { width: 8px; }
.rows.scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; }
.rows.scroll::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.rows.scroll::-webkit-scrollbar-track { background: transparent; }
.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-main.tap { cursor: pointer; }
.row-main.tap:hover .row-name { color: var(--accent); }
.row-name { font-weight: 600; font-size: 14px; transition: color .14s ease; }
.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 ---- */
/* Bare art, no tile: this logo was drawn for a white page. Sized by HEIGHT, not
   width — the full lockup is nearly square once the tagline is included, and
   sizing it by width made the frozen top bar taller than the buttons in it.
   logo-light.png is the full lockup (login, check-in, poster); logo-mark.png is
   the hexagon on its own, which is all that survives at top-bar size. */
.logo { display: block; height: 104px; width: auto; margin: 0 auto; }

/* Top bar: the hexagon plus the name set in type. The lockup's own wordmark and
   tagline turn to mush at header size, and the hexagon alone doesn't say which
   gym this is — the owner opening a bookmark should see his gym's name. */
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand img { height: 34px; width: auto; display: block; }
.brand span {
  font-family: var(--display); font-weight: 800; font-size: 19px;
  letter-spacing: .02em; text-transform: uppercase; line-height: 1;
}
.brand b { color: var(--accent); font-weight: 800; margin-left: 5px; }

/* ---- 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)); }
  .brand img { height: 30px; }
  .brand span { font-size: 17px; }
  /* 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; }

  /* The pills grow to share each row's width instead of leaving a ragged gap at
     the end. Eight items land on three rows at 360px, and the header is frozen,
     so every pixel of padding here is a pixel of the gym the owner can't see.
     Nothing is shortened or hidden though: a menu item he can't find is worse
     than a row of pixels, and Door QR / How it works / Settings are exactly the
     three he needs without phoning us. */
  .nav { padding: 7px 12px 8px; gap: 4px; }
  /* 34px is the floor for anything tappable, and the nav is tapped constantly.
     Shaving it to 32 saved 6px of frozen header and cost a missed tap. Don't. */
  .nav a { flex: 1 1 auto; justify-content: center; padding: 5px 9px; 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; }
  .brand img { height: 27px; }
  .brand span { font-size: 15.5px; }
  .brand { gap: 7px; }
  .topbar .btn { padding: 7px 8px; font-size: 11px; }
  .qr-img { width: 168px; height: 168px; }
}
