:root {
  /* Dark is the default palette; :root[data-theme="light"] below overrides it. */
  --brand: #1f6feb;
  --brand-dark: #14508f;
  --bg: #0f1420;
  --card: #1a2233;
  --text: #eef1f6;
  --muted: #97a3b8;
  --border: #2a3448;
  --danger: #ff6b6b;
  --warn: #f5c14b;
  --ok: #4ade80;
  /* Material 3-inspired shape scale: rounded squares for surfaces, a true pill for buttons. */
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-pill: 999px;
  --elevation-1: 0 1px 2px rgba(0,0,0,0.4), 0 1px 3px rgba(0,0,0,0.3);
  --elevation-2: 0 4px 8px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1a1f26;
  --muted: #6b7280;
  --border: #e2e5ea;
  --danger: #d64545;
  --warn: #b5860a;
  --ok: #1e8a4c;
}

* { box-sizing: border-box; }

/* The page scrolls at the document level (no inner scroll container), so the scrollbar
   to hide is html's, not a wrapper div's. Scrolling itself stays fully functional -
   only the visible track/thumb are suppressed. */
html {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
html::-webkit-scrollbar { display: none; }

body {
  margin: 0;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--brand); }
a:visited { color: var(--brand); }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  /* Sticky (not fixed) so it keeps taking up its normal spot in the document flow while not
     scrolled - no compensating top-padding needed on .content the way position:fixed would
     require. The top offset matches .status-bar-safe-area's own height (env(safe-area-inset-top))
     so on MAUI the stuck header lands right below that status-bar spacer instead of underneath
     it; on Web there's no such spacer and the env() falls back to 0px, so it just sticks to the
     true top. */
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  /* Below .modal-overlay's z-index (100) - a modal should still cover the sticky header, not sit behind it. */
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.55rem 1rem;
  /* Branded chrome stays dark regardless of the light/dark content theme toggle below it -
     matches how most product headers (and the reference design) keep the bar itself fixed. */
  background: linear-gradient(120deg, #0b0f1a 0%, #13224a 55%, var(--brand-dark) 100%);
  color: white;
  box-shadow: 0 2px 16px rgba(0,0,0,0.35);
}
/* .topbar-row (logo/brand/hamburger) and .topbar-controls (nav/actions) are separate divs
   so the narrow-screen layout can stack them - on wide screens .topbar itself lays them out
   side by side in one row instead. */
.topbar-row { display: flex; align-items: center; gap: 0.75rem; }
.topbar .brand { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.01em; white-space: nowrap; }
.topbar .topnav { display: flex; align-items: center; flex-wrap: wrap; gap: 0.125rem; }
.topbar .topnav a {
  color: white; text-decoration: none; opacity: 0.75;
  display: flex; align-items: center; min-height: 44px; padding: 0 0.5rem;
  font-size: 0.9rem; white-space: nowrap;
  position: relative; transition: opacity 0.15s ease;
}
.topbar .topnav a:hover { opacity: 1; }
.topbar .topnav a.active { opacity: 1; font-weight: 600; }
.topbar .topnav a.active::after {
  content: "";
  position: absolute; left: 0.75rem; right: 0.75rem; bottom: 4px;
  height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--brand) 0%, #7fb8ff 100%);
}
.topbar .spacer { flex: 1; }
.topbar .who { opacity: 0.9; display: flex; align-items: center; white-space: nowrap; }
/* Specificity must beat .link-button (also sets display, and this button carries both
   classes) - a plain .nav-toggle rule loses that tie by source order regardless of which
   class comes first in the HTML. */
.topbar-row .nav-toggle { display: none; font-size: 1.3rem; padding: 0.4rem 0.7rem; }
/* No flex-wrap on .topbar-controls or .topbar-actions, on purpose, at any nesting level:
   align-items:center on .topbar vertically centers the shorter .topbar-row against whichever
   sibling ends up tallest, so ANY of these wrapping into extra sub-lines visually splits the
   brand between them. If nav's own links need to wrap (.topbar .topnav already allows that),
   that's fine - it only grows .topbar-controls's height as a single block, it doesn't
   fragment the row into separately-centered pieces. */
.topbar-controls { display: flex; align-items: center; gap: 1rem; flex: 1; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.link-button {
  background: none; border: 1px solid rgba(255,255,255,0.6); color: white;
  border-radius: var(--radius-pill); padding: 0.3rem 0.7rem; cursor: pointer;
  transition: background-color 0.15s ease;
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap;
}
.link-button:hover { background: rgba(255,255,255,0.15); }
.lang-select {
  background: rgba(255,255,255,0.15); color: white; border: 1px solid rgba(255,255,255,0.4);
  border-radius: var(--radius-pill); padding: 0.25rem 0.6rem; font-size: 0.85rem;
  width: auto; flex: 0 0 auto; min-height: 44px;
}
.lang-select option { color: var(--text); }

/* Below this width (small tablets in portrait and narrower), the nav row and its trailing
   controls no longer fit on one line - collapse them behind the hamburger toggle instead. */
@media (max-width: 768px) {
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar-row .nav-toggle { display: inline-flex; }
  .topbar-controls {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    margin-top: 0.5rem;
  }
  .topbar-controls.nav-open { display: flex; }
  .topbar .topnav { display: flex; flex-direction: column; }
  .topbar .topnav a { padding: 0.6rem 0.4rem; }
  .topbar-actions { justify-content: space-between; }
}

.content { padding: 1rem; max-width: 900px; margin: 0 auto; width: 100%; position: relative; }

.pull-indicator {
  height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center;
  transition: height 0.2s ease; color: var(--brand);
}
.pull-spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--brand) 25%, transparent);
  border-top-color: var(--brand);
}
.pull-indicator.ready .pull-spinner { border-top-color: var(--brand-dark); }
.pull-indicator.spinning .pull-spinner { animation: pull-spin 0.7s linear infinite; }
@keyframes pull-spin { to { transform: rotate(360deg); } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--elevation-1);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

h1 { font-size: 1.4rem; margin-top: 0; }
h2 { font-size: 1.1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
th { color: var(--muted); font-weight: 600; }

button, .btn {
  background: var(--brand);
  color: white;
  border: none;
  border-radius: var(--radius-pill);
  padding: 0.55rem 1.25rem;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 44px;
  transition: background-color 0.15s ease, box-shadow 0.15s ease;
}
button:hover, .btn:hover { background: var(--brand-dark); box-shadow: var(--elevation-1); }
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }
button.secondary { background: var(--card); color: var(--brand); border: 1px solid var(--brand); }
button.danger { background: var(--danger); }

input:not([type]), input[type=text], input[type=password], input[type=email], input[type=tel], input[type=date], input[type=number], select {
  background: var(--card);
  color: var(--text);
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  width: 100%;
  min-height: 44px;
  transition: border-color 0.15s ease;
}
input:not([type]):focus, input[type=text]:focus, input[type=password]:focus, input[type=email]:focus, input[type=tel]:focus, input[type=date]:focus, input[type=number]:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 25%, transparent);
}

label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.2rem; margin-top: 0.6rem; }

.badge { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; }
.badge-qr { background: rgba(31, 111, 235, 0.18); color: var(--brand); }
.badge-manual { background: rgba(151, 163, 184, 0.18); color: var(--muted); }
.badge-warn { background: rgba(245, 193, 75, 0.18); color: var(--warn); }
.badge-ok { background: rgba(74, 222, 128, 0.18); color: var(--ok); }
.badge-danger { background: rgba(255, 107, 107, 0.18); color: var(--danger); }

.error-text { color: var(--danger); font-size: 0.9rem; }
.error-boundary { text-align: center; }
.error-boundary p { margin-top: 0; }
.muted { color: var(--muted); font-size: 0.9rem; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem; z-index: 100;
}
.modal-panel {
  background: var(--card); border-radius: var(--radius-lg); padding: 1.5rem;
  max-width: 480px; width: 100%; max-height: 85vh; overflow-y: auto;
  border: 1px solid var(--border); box-shadow: var(--elevation-2);
}
.modal-panel-lg { max-width: 560px; }
@media (max-width: 600px) {
  .modal-panel { max-width: 100%; }
}

.table-wrap { overflow-x: auto; }
@media (max-width: 768px) {
  .table-wrap table { font-size: 0.85rem; }
  .table-wrap th, .table-wrap td { padding: 0.4rem; }
}

.checkin-list { list-style: none; margin: 0; padding: 0; }
.checkin-list li {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.4rem 0; border-bottom: 1px solid var(--border);
}
.checkin-list li .name { flex: 1; }

.qr-box { text-align: center; }
.qr-box img { max-width: 280px; width: 100%; border: 1px solid var(--border); border-radius: var(--radius-md); background: white; padding: 8px; }
.qr-shortcode { font-size: 2rem; letter-spacing: 0.3rem; font-weight: 700; margin: 0.5rem 0; }

.cal { width: 100%; max-width: 480px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.cal-nav button { padding: 0.3rem 0.7rem; }
.cal-weekdays, .cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-weekdays span { text-align: center; font-size: 0.75rem; color: var(--muted); padding-bottom: 0.25rem; }
.cal-day {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md); background: var(--bg); font-size: 0.85rem; position: relative;
}
.cal-day-empty { background: transparent; }
.cal-day-highlight { background: var(--brand); color: white; font-weight: 600; }
.cal-day-hasdata { box-shadow: inset 0 0 0 2px var(--brand); }
.cal-day-clickable { cursor: pointer; }
.cal-day-clickable:hover { box-shadow: inset 0 0 0 2px var(--brand-dark); }
.cal-day-badge {
  position: absolute; bottom: 2px; right: 2px; background: var(--brand-dark); color: white;
  border-radius: 999px; font-size: 0.6rem; min-width: 14px; height: 14px; line-height: 14px; text-align: center; padding: 0 2px;
}

.search-wrap { position: relative; max-width: 320px; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-md); margin-top: 0.25rem;
  max-height: 220px; overflow-y: auto; z-index: 20; box-shadow: var(--elevation-2);
}
.search-results button {
  display: block; width: 100%; text-align: left; background: none; color: var(--text);
  border: none; border-radius: 0; padding: 0.5rem 0.75rem; font-size: 0.9rem;
}
.search-results button:hover { background: var(--bg); }
.selected-chip {
  display: inline-flex; align-items: center; gap: 0.4rem; background: var(--brand);
  color: white; border-radius: 999px; padding: 0.3rem 0.5rem 0.3rem 0.8rem; font-size: 0.85rem;
}
.selected-chip button { background: none; border: none; color: white; padding: 0 0.2rem; cursor: pointer; font-size: 1rem; line-height: 1; }

/* Full-screen QR pages (public lobby display and admin QR-only screen) */
.bare-shell { min-height: 100vh; background: var(--bg); color: var(--text); }
.qr-fullscreen {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.75rem; padding: 1rem; text-align: center; position: relative;
}
.qr-fullscreen-back { position: absolute; top: 1rem; left: 1rem; }
.qr-fullscreen-header h1 { margin: 0; font-size: clamp(1.5rem, 4vw, 2.5rem); }
.qr-fullscreen-logo { max-height: 72px; border-radius: 8px; margin-bottom: 0.5rem; }
.qr-fullscreen-code img {
  width: min(80vw, 60vh, 560px); height: auto; background: white; padding: 12px;
  border-radius: var(--radius-md); border: 4px solid var(--brand);
}
.qr-fullscreen-short { font-size: clamp(2rem, 6vw, 4rem); }

.impersonation-banner {
  display: flex; gap: 0.75rem; align-items: center; justify-content: center; flex-wrap: wrap;
  padding: 0.5rem 1rem; background: #b45309; color: white; font-weight: 600; text-align: center;
}
.impersonation-banner button { background: white; color: #b45309; padding: 0.25rem 0.75rem; }

/* Platform payment reminder for gym admins - deliberately has no close button */
.billing-banner {
  display: flex; gap: 0.6rem; align-items: flex-start; justify-content: center;
  padding: 0.6rem 1rem; background: #b91c1c; color: #fff; font-weight: 600; line-height: 1.35;
}

.ok-text { color: var(--ok); font-size: 0.9rem; }

/* Classes & reservations */
.check-row { display: flex; gap: 0.5rem; align-items: flex-start; color: var(--text); }
.check-row input { width: auto; margin-top: 0.25rem; }
.card-head { display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 0.5rem; }
.card-head h2 { margin: 0; }
.row-actions { display: flex; gap: 0.4rem; justify-content: flex-end; flex-wrap: wrap; }
.row-actions button { padding: 0.2rem 0.6rem; font-size: 0.85rem; }

.capacity-warnings { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 10%, var(--card)); }
.capacity-warnings-head { display: flex; gap: 0.75rem; align-items: center; justify-content: space-between; }
.capacity-warnings-head h2 { margin: 0; color: var(--warn); }
.capacity-warnings ul { margin: 0.75rem 0 0.5rem; padding-left: 1.2rem; }
.capacity-warnings li { margin-bottom: 0.35rem; }

.day-picker { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.day-chip {
  display: inline-flex; align-items: center; padding: 0.3rem 0.7rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--border); color: var(--text); font-size: 0.85rem; user-select: none;
}
.day-chip input { position: absolute; opacity: 0; pointer-events: none; width: 0; }
.day-chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.day-chip:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }

.roster-class { border-top: 1px solid var(--border); padding: 0.75rem 0; }
.roster-class:first-of-type { border-top: none; }
.roster-head { display: flex; gap: 0.5rem; align-items: center; justify-content: space-between; }
.roster-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.roster-list li { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; padding: 0.2rem 0; }

.qr-class-label { font-size: 1.15rem; font-weight: 700; margin: 0.25rem 0 0.5rem; }

/* Gym (or Gym Register) logo next to the name: keeps its aspect ratio, softly rounded like an app tile. */
.brand-logo { width: auto; border-radius: 22%; flex-shrink: 0; object-fit: contain; }
