/* ============================================================================
   MAP Design System — Maximize Athletic Performance
   Brand (per Peter 2026-04-28):
     Red       #FF0000
     White     #FFFFFF
     Black     #000000
     Flamingo  #EF4444
   ============================================================================ */

/* ── CSS Custom Properties ─────────────────────────────────────────────── */
:root {
  /* Brand Colors */
  --map-black: #000000;
  --map-red: #FF0000;
  --map-red-hover: #CC0000;
  --map-red-light: rgba(255, 0, 0, 0.10);
  --map-flamingo: #EF4444;
  --map-flamingo-hover: #DC2626;
  --map-flamingo-light: rgba(239, 68, 68, 0.10);
  --map-gold: #C9A84C;
  --map-gold-hover: #B8973D;
  --map-gold-light: rgba(201, 168, 76, 0.15);
  --map-white: #FFFFFF;

  /* Neutral Palette */
  --gray-50: #FAFAFA;
  --gray-100: #F4F4F5;
  --gray-200: #E4E4E7;
  --gray-300: #D4D4D8;
  --gray-400: #A1A1AA;
  --gray-500: #71717A;
  --gray-600: #52525B;
  --gray-700: #3F3F46;
  --gray-800: #27272A;
  --gray-900: #18181B;

  /* Semantic Colors */
  --success: #22C55E;
  --success-bg: rgba(34, 197, 94, 0.1);
  --warning: #F59E0B;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --danger: #EF4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --info: #3B82F6;
  --info-bg: rgba(59, 130, 246, 0.1);

  /* Scoring Tiers */
  --score-above-avg: #22C55E;
  --score-avg: #C9A84C;
  --score-below-avg: #EF4444;

  /* Semantic surface/text tokens — preferred for new code so dark mode works
     automatically. Existing styles using --map-white / --map-black / --gray-*
     are also overridden in [data-theme="dark"] below. */
  --bg-page:       #FAFAFA;
  --bg-card:       #FFFFFF;
  --bg-elevated:   #F4F4F5;
  --text-primary:  #18181B;
  --text-secondary:#52525B;
  --text-muted:    #71717A;
  --border-default:#E4E4E7;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;
  --font-display: 'Inter', var(--font-sans);

  /* Font Sizes */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;

  /* Spacing Scale */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;

  /* Layout */
  --sidebar-width: 260px;
  --header-height: 64px;
  --max-content: 1280px;
  --border-radius: 8px;
  --border-radius-lg: 12px;
  --border-radius-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
  --transition-slow: 350ms ease;
}

/* ── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--gray-900);
  background: var(--gray-50);
}

a { color: var(--map-red); text-decoration: none; }
a:hover { color: var(--map-red-hover); }

img { max-width: 100%; height: auto; display: block; }

/* ── Typography ────────────────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  color: var(--map-black);
}

h1 { font-size: var(--text-4xl); }
h2 { font-size: var(--text-3xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }

.text-gold { color: var(--map-gold); }
.text-red { color: var(--map-red); }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-mono { font-family: var(--font-mono); }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }

/* ── Layout Components ─────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  /* The nav is ALWAYS the brand-black sidebar. The dark theme flips
     --map-black→white / --gray-*→inverted, which would turn this panel white
     and wash out its light text + white-based borders (the "left nav
     disappears in dark mode" bug). Re-pin the tokens it uses to their
     light-mode values so the sidebar renders identically in both themes. */
  --map-black: #000000;
  --map-white: #FFFFFF;
  --gray-50:  #FAFAFA;
  --gray-100: #F4F4F5;
  --gray-300: #D4D4D8;
  --gray-500: #71717A;

  width: var(--sidebar-width);
  background: var(--map-black);
  color: var(--map-white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition-base);
}

.app-sidebar__logo {
  padding: var(--space-6);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.app-sidebar__logo-text {
  font-size: var(--text-xl);
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--map-gold);
}

.app-sidebar__logo-sub {
  font-size: var(--text-xs);
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.app-sidebar__nav {
  flex: 1;
  /* A column flex item defaults to min-height:auto, which lets it grow past the
     fixed sidebar instead of shrinking — the overflow rule below then never
     engages. Pin it to 0 so the nav is genuinely bounded by the viewport. */
  min-height: 0;
  padding: var(--space-4) 0;
  overflow-y: auto;

  /* The nav has outgrown a laptop screen (25 links; ~600px below the fold on a
     900px-tall window). It scrolled, but macOS hides overlay scrollbars until you
     already scroll — so the list simply looked CUT OFF at "All Athletes", and
     Trackman Import / Leaderboard / meal plans appeared not to exist at all.
     Reported 2026-08-16 as "the page is cutoff… looks like all the pages are",
     which is exactly right: it is the shared sidebar, so it was every page.
     Styling the scrollbar opts out of overlay behaviour and keeps it visible. */
  scrollbar-width: thin;                                  /* Firefox */
  scrollbar-color: rgba(255,255,255,0.28) transparent;
}
.app-sidebar__nav::-webkit-scrollbar { width: 8px; }
.app-sidebar__nav::-webkit-scrollbar-track { background: transparent; }
.app-sidebar__nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.28);
  border-radius: 999px;
}
.app-sidebar__nav::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.45); }

/* Fade the last few pixels so there is a second, colour-independent cue that the
   list continues past the fold. Sits above the footer, ignores pointer events so
   it can never swallow a click on the link underneath. */
.app-sidebar__nav {
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 34px), transparent 100%);
          mask-image: linear-gradient(to bottom, #000 calc(100% - 34px), transparent 100%);
}
.app-sidebar__nav.is-scroll-end {
  -webkit-mask-image: none;
          mask-image: none;
}

.app-sidebar__section {
  padding: var(--space-2) var(--space-6);
  margin-top: var(--space-4);
}

/* Section headers are real <button>s so the fold is keyboard- and screen-reader
   accessible (aria-expanded / aria-controls). They were <div>s, so every button
   default — background, border, font, alignment — has to be reset back to the
   original look, or they render as chunky grey boxes. */
.app-sidebar__section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  padding: 0;
  background: none;
  border: 0;
  font-family: inherit;
  font-size: var(--text-xs);
  font-weight: inherit;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--gray-500);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: color var(--transition-base);
}
.app-sidebar__section-label:hover { color: var(--map-white); }
.app-sidebar__section-label:focus-visible {
  outline: 2px solid var(--map-red, #FF0000);
  outline-offset: 3px;
  border-radius: 4px;
}

.app-sidebar__section-caret {
  font-size: 12px;
  line-height: 1;
  opacity: 0.85;   /* the only hint that a section folds — too faint and nobody finds it */
  transition: transform var(--transition-base);
}
.app-sidebar__section-label[aria-expanded="false"] .app-sidebar__section-caret {
  transform: rotate(-90deg);
}

/* Collapsed sections are removed from layout entirely — that is the whole point:
   it reclaims the vertical space rather than just hiding the labels. */
.app-sidebar__section-items.is-collapsed { display: none; }

@media (prefers-reduced-motion: reduce) {
  .app-sidebar__section-caret { transition: none; }
}

.app-sidebar__link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  color: var(--gray-300);
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: 0;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.app-sidebar__link:hover {
  color: var(--map-white);
  background: rgba(255,255,255,0.06);
}

.app-sidebar__link--active {
  color: var(--map-gold);
  background: rgba(201, 168, 76, 0.1);
  border-right: 3px solid var(--map-gold);
}

.app-sidebar__link-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.app-sidebar__link--active .app-sidebar__link-icon {
  opacity: 1;
}

.app-sidebar__footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: var(--space-3);
}

.app-sidebar__user {
  padding: var(--space-4) var(--space-3) var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}

.app-sidebar__user-info {
  min-width: 0;
  flex: 1;
}

.app-sidebar__logout {
  flex-shrink: 0;
  width: 44px;                  /* a11y tap target (Evan 7/14) */
  height: 44px;
  border-radius: var(--border-radius);
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  color: var(--gray-500);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.app-sidebar__logout:hover {
  background: rgba(239,68,68,0.15);
  border-color: rgba(239,68,68,0.3);
  color: #EF4444;
}

.app-sidebar__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--map-gold);
  color: var(--map-black);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--text-sm);
  flex-shrink: 0;
}

.app-sidebar__user-name {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--map-white);
}

.app-sidebar__user-role {
  font-size: var(--text-xs);
  color: var(--gray-500);
}

.app-main {
  flex: 1;
  min-width: 0; /* allow the flex child to shrink to viewport instead of growing to its content's min-width (prevents whole-page horizontal scroll on mobile) */
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
}

.app-header {
  height: var(--header-height);
  background: var(--map-white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-header__title {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--map-black);
}

.app-header__actions {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.app-content {
  flex: 1;
  padding: var(--space-8);
  max-width: var(--max-content);
  width: 100%;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--map-white);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card__header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card__title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--map-black);
}

.card__subtitle {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin-top: var(--space-1);
}

.card__body {
  padding: var(--space-6);
}

.card__footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}

/* ── Metric Cards ──────────────────────────────────────────────────────── */
.metric-card {
  background: var(--map-white);
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
  padding: var(--space-5) var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  transition: box-shadow var(--transition-fast);
}

.metric-card:hover {
  box-shadow: var(--shadow-md);
}

.metric-card__label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--gray-500);
  font-weight: 600;
}

.metric-card__value {
  font-size: var(--text-3xl);
  font-weight: 800;
  color: var(--map-black);
  font-family: var(--font-mono);
}

.metric-card__delta {
  font-size: var(--text-sm);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.metric-card__delta--up { color: var(--success); }
.metric-card__delta--down { color: var(--danger); }
.metric-card__delta--neutral { color: var(--gray-500); }

.metric-card__unit {
  font-size: var(--text-sm);
  color: var(--gray-400);
  font-weight: 500;
}

/* ── Score Badge ───────────────────────────────────────────────────────── */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 48px;
  height: 32px;
  padding: 0 var(--space-3);
  border-radius: 999px;
  font-size: var(--text-sm);
  font-weight: 700;
  font-family: var(--font-mono);
}

.score-badge--above { background: var(--success-bg); color: var(--success); }
.score-badge--avg { background: var(--gold-light, rgba(201,168,76,0.15)); color: var(--map-gold-hover); }
.score-badge--below { background: var(--danger-bg); color: var(--danger); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  min-height: 44px;              /* a11y: 44px min tap target (Evan 7/14) */
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--border-radius);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-sans);
  line-height: 1;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--map-red);
  color: var(--map-white);
}
.btn--primary:hover:not(:disabled) { background: var(--map-red-hover); }

.btn--gold {
  background: var(--map-gold);
  color: var(--map-black);
}
.btn--gold:hover:not(:disabled) { background: var(--map-gold-hover); }

.btn--dark {
  background: var(--map-black);
  color: var(--map-white);
}
.btn--dark:hover:not(:disabled) { background: var(--gray-800); }

.btn--outline {
  background: transparent;
  border: 1.5px solid var(--gray-300);
  color: var(--gray-700);
}
.btn--outline:hover:not(:disabled) { border-color: var(--gray-400); background: var(--gray-50); }

.btn--ghost {
  background: transparent;
  color: var(--gray-600);
}
.btn--ghost:hover:not(:disabled) { background: var(--gray-100); }

.btn--sm { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); }
.btn--lg { padding: var(--space-4) var(--space-8); font-size: var(--text-base); }

/* ── Form Elements ─────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-700);
}

.form-input {
  padding: var(--space-3) var(--space-4);
  border: 1.5px solid var(--gray-300);
  border-radius: var(--border-radius);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  color: var(--gray-900);
  background: var(--map-white);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus {
  outline: none;
  border-color: var(--map-gold);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

.form-input::placeholder { color: var(--gray-400); }
.form-input--error { border-color: var(--danger); }

.form-select {
  appearance: none;
  padding-right: var(--space-10);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2371717A' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-helper {
  font-size: var(--text-xs);
  color: var(--gray-500);
}

.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
}

/* ── Grid Layouts ──────────────────────────────────────────────────────── */
.grid { display: grid; gap: var(--space-6); }
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--gray-200);
  border-radius: var(--border-radius-lg);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th {
  padding: var(--space-3) var(--space-4);
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-600);
  text-align: left;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.5px;
}

.table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--gray-100);
  color: var(--gray-700);
}

.table tr:hover td { background: var(--gray-50); }
.table tr:last-child td { border-bottom: none; }

/* ── Tabs ──────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--gray-200);
  gap: var(--space-1);
}

.tab {
  padding: var(--space-3) var(--space-5);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--gray-500);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tab:hover { color: var(--gray-700); }
.tab--active { color: var(--map-red); border-bottom-color: var(--map-red); }

/* ── Tags / Badges ─────────────────────────────────────────────────────── */
.tag {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-3);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 600;
}

.tag--red { background: var(--map-red-light); color: var(--map-red); }
.tag--gold { background: var(--map-gold-light); color: var(--map-gold-hover); }
.tag--success { background: var(--success-bg); color: var(--success); }
.tag--warning { background: var(--warning-bg); color: var(--warning); }
.tag--danger { background: var(--danger-bg); color: var(--danger); }
.tag--info { background: var(--info-bg); color: var(--info); }

/* ── Utility Classes ───────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Loading & Empty States ────────────────────────────────────────────── */
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--map-red);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.spinner--lg { width: 40px; height: 40px; border-width: 4px; }

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.empty-state {
  padding: var(--space-16);
  text-align: center;
  color: var(--gray-400);
}

.empty-state__icon {
  font-size: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: var(--space-2);
}

/* ── Toast Notifications ───────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  /* Clear a fixed top banner (e.g. the Act-As bar) and sit above everything so
     new-message toasts are never occluded (Evan 7/14). */
  top: 64px;
  right: var(--space-6);
  z-index: 100001;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.toast {
  padding: var(--space-4) var(--space-5);
  border-radius: var(--border-radius);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  animation: slideIn 0.3s ease;
  min-width: 300px;
}

.toast--success { background: var(--gray-900); color: var(--map-white); border-left: 4px solid var(--success); }
.toast--error { background: var(--gray-900); color: var(--map-white); border-left: 4px solid var(--danger); }
.toast--warning { background: var(--gray-900); color: var(--map-white); border-left: 4px solid var(--warning); }
.toast--info { background: var(--gray-900); color: var(--map-white); border-left: 4px solid var(--info); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Responsive ────────────────────────────────────────────────────────── */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--gray-700);
  cursor: pointer;
  padding: var(--space-2);
  min-width: 44px;              /* a11y tap target (Evan 7/14) */
  min-height: 44px;
  align-items: center;
  justify-content: center;
}

@media (max-width: 768px) {
  .app-sidebar {
    transform: translateX(-100%);
  }

  .app-sidebar--open {
    transform: translateX(0);
  }

  .app-main {
    margin-left: 0;
  }

  .mobile-menu-toggle {
    display: flex;
  }

  .grid--2, .grid--3, .grid--4 {
    grid-template-columns: 1fr;
  }

  .app-content {
    padding: var(--space-4);
  }
}

@media (max-width: 1024px) {
  .grid--4 { grid-template-columns: repeat(2, 1fr); }
}

/* ── Login Page ────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  background: var(--map-black);
}

.login-page__brand {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-16);
  background: linear-gradient(135deg, #000000 0%, #1a1a1a 50%, #000000 100%);
  position: relative;
  overflow: hidden;
}

.login-page__brand::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle, rgba(255, 0, 0, 0.05) 0%, transparent 50%);
  animation: pulse-glow 8s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.8; }
}

.login-page__brand-logo {
  font-size: 72px;
  font-weight: 900;
  letter-spacing: 8px;
  color: var(--map-gold);
  position: relative;
  z-index: 1;
}

.login-page__brand-tagline {
  font-size: var(--text-lg);
  color: var(--gray-400);
  margin-top: var(--space-4);
  text-transform: uppercase;
  letter-spacing: 4px;
  position: relative;
  z-index: 1;
}

.login-page__form-panel {
  width: 480px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-16);
  background: var(--map-white);
}

.login-page__form-title {
  font-size: var(--text-2xl);
  font-weight: 800;
  color: var(--map-black);
  margin-bottom: var(--space-2);
}

.login-page__form-subtitle {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin-bottom: var(--space-8);
}

@media (max-width: 768px) {
  .login-page { flex-direction: column; }
  .login-page__brand { padding: var(--space-8); min-height: 200px; }
  .login-page__brand-logo { font-size: 48px; }
  .login-page__form-panel { width: 100%; padding: var(--space-8); }
}

/* ============================================================================
   LAYOUT ALIASES — pages use these names; aliased to design system classes
   ============================================================================ */

/* main-content = app-main (the flex column that sits right of the sidebar) */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* content-area = app-content (padded scrolling region inside main-content) */
.content-area {
  flex: 1;
  padding: var(--space-8);
  width: 100%;
  max-width: var(--max-content);
}

/* ── card flat-name aliases (pages use card-header vs BEM card__header) ── */
.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--map-black);
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--gray-500);
  margin-top: var(--space-1);
}

.card-body {
  padding: var(--space-6);
}

.card-footer {
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--gray-100);
  background: var(--gray-50);
}

/* ── app-header sub-element aliases ──────────────────────────────────────── */
.app-header__left {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.app-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-4);
}

.app-header__breadcrumb {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--gray-500);
}

.app-header__breadcrumb-item {
  color: var(--gray-400);
}

.app-header__breadcrumb-sep {
  color: var(--gray-300);
}

.app-header__breadcrumb-current {
  font-weight: 600;
  color: var(--map-black);
}

/* ── Responsive overrides for aliased layout ─────────────────────────────── */
@media (max-width: 768px) {
  .main-content {
    margin-left: 0;
  }
  .content-area {
    padding: var(--space-4);
  }
}

/* ============================================================================
   Mobile UX baseline (Peter v2 spec, Feature 2)
   Breakpoints: phone <576px, tablet 576-992px, desktop >992px.
   Goals: no horizontal scroll, 44pt touch targets, iOS-safe forms, drawer
   sidebar with click-out backdrop, charts/cards reflow, header doesn't break.
   ============================================================================ */

/* iOS safe-area awareness — applies to bottom-fixed UI like Coach APE launcher
   and any future bottom tab bar. */
@supports (padding: max(0px)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* Generic horizontal-scroll wrapper for any wide table or strip.
   Use: <div class="table-wrap"><table>…</table></div>. */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

/* Backdrop for the mobile sidebar drawer. Toggled by sidebar.js via
   body.has-sidebar-open. Click → closes the drawer. */
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
}
body.has-sidebar-open .sidebar-backdrop {
  opacity: 1;
  pointer-events: auto;
}
body.has-sidebar-open { overflow: hidden; } /* lock scroll while drawer open */

/* Tablet — collapse 4-col grids to 2 col. */
@media (max-width: 992px) {
  .grid--4 { grid-template-columns: repeat(2, 1fr) !important; }
  /* Guard against any single wide element forcing a whole-page horizontal scroll
     on phones/tablets — wide tables keep their own local overflow-x scroll. */
  html, body { max-width: 100%; overflow-x: hidden; }
}

/* ── Phones (≤576px) ─────────────────────────────────────────────────────── */
@media (max-width: 576px) {
  /* Sidebar becomes overlay drawer at narrow phone width too */
  .app-sidebar { transform: translateX(-100%); width: min(280px, 86vw); }
  .app-sidebar--open { transform: translateX(0); box-shadow: 0 8px 30px rgba(0,0,0,0.35); }

  .app-main, .main-content { margin-left: 0; }
  .content-area, .app-content { padding: var(--space-3); }

  /* Header — stacks if it can't fit on one line */
  .app-header {
    padding: var(--space-3) var(--space-4);
    gap: var(--space-2);
  }
  .app-header__title,
  .app-header__breadcrumb-current {
    font-size: var(--text-base);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .app-header__actions,
  .app-header__right { gap: var(--space-2); }

  /* Touch targets — min 44pt height on anything tappable */
  .btn,
  .toggle-btn,
  .filter-select,
  .app-sidebar__link,
  select, input[type="text"], input[type="email"],
  input[type="password"], input[type="number"], input[type="search"],
  input[type="tel"], input[type="date"], textarea {
    min-height: 44px;
  }
  /* Avoid iOS auto-zoom on input focus (16px is the threshold) */
  input, select, textarea { font-size: 16px !important; }

  /* Buttons grow comfortably + don't crowd */
  .btn { padding: var(--space-3) var(--space-4); font-size: var(--text-sm); }
  .btn--sm { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); min-height: 44px; }  /* a11y tap target (Evan 7/14) */

  /* Any 2/3/4-col grid auto-collapses to 1 col */
  .grid--2, .grid--3, .grid--4,
  .kpi-grid {
    grid-template-columns: 1fr !important;
  }

  /* Cards — slightly tighter, full bleed inside content-area */
  .card { padding: var(--space-4); }
  .card-header { flex-wrap: wrap; gap: var(--space-2); }
  .card-title { font-size: var(--text-base); }

  /* Chart containers — fluid height */
  .chart-container,
  .chart-container--responsive {
    height: clamp(220px, 55vw, 320px) !important;
  }

  /* Tables get auto horizontal scroll if not wrapped */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table thead, table tbody, table tr, table td, table th { white-space: nowrap; }

  /* Modal/dialog → full-bleed on phone */
  .modal, .dialog, .sheet {
    width: 100vw !important;
    max-width: 100vw !important;
    height: auto;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
    margin: auto 0 0;
  }

  /* Coach APE launcher — respect safe area */
  .ape-launcher,
  #ape-launcher {
    bottom: max(20px, env(safe-area-inset-bottom)) !important;
    right: 16px !important;
    width: 56px !important; height: 56px !important;
  }
  .ape-panel,
  #ape-panel {
    right: 8px !important;
    left: 8px !important;
    bottom: 84px !important;
    width: auto !important;
    max-width: none !important;
  }
}

/* ── Tablet (577-992px) — keep desktop chrome but tighten ─────────────────── */
@media (min-width: 577px) and (max-width: 992px) {
  .grid--3 { grid-template-columns: repeat(2, 1fr) !important; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .content-area, .app-content { padding: var(--space-5); }
}

/* ── Glossary tooltip — (i) icon with hover/tap popover (Peter v2 spec, F5) ── */
.gloss {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin-left: 2px;
  padding: 6px;                 /* larger tap area around the inline info dot (Evan 7/14) */
  min-width: 32px;
  min-height: 32px;
  cursor: help;
  outline: none;
}
.gloss__icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--gray-200); color: var(--gray-600);
  font-size: 10px; font-weight: 800; font-family: var(--font-mono);
  font-style: italic;
  transition: background 150ms ease, color 150ms ease;
}
.gloss:hover .gloss__icon,
.gloss:focus .gloss__icon,
.gloss.is-open .gloss__icon {
  background: var(--map-red);
  color: var(--map-white);
}
.gloss-pop {
  position: absolute;
  bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  width: 280px; max-width: 80vw;
  padding: 12px 14px;
  /* Always a dark popover with white text — its body text is hardcoded white, so
     the bg must stay dark in BOTH themes. var(--map-black) flipped to white in dark
     mode → white-on-white blank box (Peter 6/25 "test description color is off"). */
  background: #1a1a1a;
  color: #FFFFFF;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  font-size: 12.5px; line-height: 1.5; text-align: left;
  z-index: 50;
  opacity: 0; visibility: hidden;
  transition: opacity 150ms ease, visibility 150ms;
  pointer-events: none;
}
.gloss-pop::after {
  content: '';
  position: absolute;
  top: 100%; left: 50%; transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1a1a1a;
}
.gloss:hover .gloss-pop,
.gloss:focus .gloss-pop,
.gloss.is-open .gloss-pop {
  opacity: 1; visibility: visible; pointer-events: auto;
}
.gloss-pop__term { font-weight: 800; font-size: 13px; margin-bottom: 6px; color: var(--map-gold); }
.gloss-pop__def  { font-size: 12.5px; margin-bottom: 8px; color: rgba(255,255,255,0.95); }
.gloss-pop__hdr  { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: 1px; color: rgba(255,255,255,0.55); margin-top: 8px; margin-bottom: 3px; }
.gloss-pop__body { font-size: 12px; color: rgba(255,255,255,0.85); }

/* Mobile — popover anchors to the right edge of the screen if it would clip */
@media (max-width: 576px) {
  .gloss-pop { width: min(280px, 80vw); }
}

/* ── Best/Average segmented control (Peter v2 spec, F5) ─────────────────── */
.seg-control {
  display: inline-flex; align-items: center;
  background: var(--gray-100);
  border-radius: 8px; padding: 3px;
}
.seg-control__btn {
  padding: 6px 14px; font-size: 12px; font-weight: 700;
  letter-spacing: 0.5px; text-transform: uppercase;
  background: transparent; color: var(--gray-500);
  border: none; border-radius: 6px; cursor: pointer;
  transition: all 150ms ease;
  min-height: 32px;
}
.seg-control__btn.is-active {
  background: var(--map-white);
  color: var(--map-black);
  box-shadow: var(--shadow-sm);
}

/* Page-specific inline grids that don't have classes — phone overrides.
   Each entry corresponds to an `id` set directly on a grid container.
   !important is required because the grids use inline style=. */
@media (max-width: 576px) {
  /* athlete-profile.html — strengths/weaknesses, body vitals, plan cells */
  #sw-grid,
  #body-comp-content {
    grid-template-columns: 1fr !important;
  }
  #body-vitals {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* Reduce-motion friendly — respects user accessibility prefs */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================================
   Mobile UX — Phase 2 (full-site sweep, 2026-05-11)
   Catches the inline-style grids that don't carry a class so the global
   .grid--N rules can't reach them. Uses attribute selectors to bite at
   inline style strings. Limit to phone width so desktop layouts are untouched.
   ============================================================================ */

@media (max-width: 576px) {

  /* 1) Generic inline-grid auto-collapse — anything written inline with
        repeat(N, 1fr) or "1fr 1fr" / "1fr 1fr 1fr" collapses to single col. */
  [style*="grid-template-columns:repeat(2"],
  [style*="grid-template-columns: repeat(2"],
  [style*="grid-template-columns:repeat(3"],
  [style*="grid-template-columns: repeat(3"],
  [style*="grid-template-columns:repeat(4"],
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns:repeat(5"],
  [style*="grid-template-columns: repeat(5"],
  [style*="grid-template-columns:1fr 1fr"],
  [style*="grid-template-columns: 1fr 1fr"],
  [style*="grid-template-columns:2fr 1fr"],
  [style*="grid-template-columns: 2fr 1fr"],
  [style*="grid-template-columns:1fr 2fr"],
  [style*="grid-template-columns: 1fr 2fr"] {
    grid-template-columns: 1fr !important;
  }

  /* 2) auto-fit/auto-fill grids w/ wide minmax — only intervene when the
        minmax floor is too wide to fit phone width. Smaller floors (160-240px)
        self-collapse to 2 cols on 375px which reads better than forced 1 col. */
  [style*="minmax(280px"],
  [style*="minmax(300px"],
  [style*="minmax(360px"] {
    grid-template-columns: 1fr !important;
  }

  /* 2b) Metric-row-item style fixed-pixel 4-col grids — stack on phone */
  [style*="160px 100px"] {
    grid-template-columns: 1fr !important;
    gap: 6px !important;
  }

  /* 2c) Table-like grids with many fixed columns (leaderboard, history) —
        keep columns but allow horizontal scroll so labels stay readable */
  [style*="1fr 100px 80px 90px 90px"],
  [style*="1fr 90px 90px 110px 90px"],
  [style*="1fr auto auto auto auto"] {
    overflow-x: auto;
    min-width: 0;
  }

  /* 3) Flex rows that include big fixed-width children — wrap them */
  .app-header,
  .app-header__right,
  .app-header__left,
  .app-header__actions,
  .card-header,
  .card__header {
    flex-wrap: wrap !important;
  }

  /* 4) Hero score scaling — the 96pt composite on athlete-profile, 64pt on
        athlete-dashboard, and any other oversized monospace number. */
  #hero-composite { font-size: 64px !important; line-height: 0.95 !important; }
  #hero-score     { font-size: 48px !important; line-height: 1 !important; }
  #header-composite { font-size: 24px !important; }
  .hero-composite__score { font-size: 48px !important; }
  .cmj-composite__score  { font-size: 40px !important; }
  .reveal-num            { font-size: 44px !important; }
  .hero-avatar { width: 72px !important; height: 72px !important; font-size: 24px !important; }

  /* 5) Hero blocks should stack their score under the avatar/name */
  .profile-hero,
  .dashboard-hero,
  .admin-hero,
  .coach-hero { flex-direction: column !important; align-items: flex-start !important; }
  .profile-hero > *, .dashboard-hero > * { width: 100% !important; }
  .dashboard-hero__right { justify-content: flex-start !important; }
  #hero-score-block { align-items: flex-start !important; text-align: left !important; min-width: 0 !important; }
  #header-score-block { margin-left: 0 !important; }

  /* 6) Page-header action bars on mobile — stack to a row beneath the title */
  .app-header { row-gap: var(--space-2); padding-top: var(--space-3); padding-bottom: var(--space-3); }
  .app-header__right { justify-content: flex-start !important; width: 100%; }

  /* 7) Card padding tightens on phones */
  .card { padding: var(--space-3) !important; }
  .card-header,
  .card__header { padding: 0 !important; margin-bottom: var(--space-3) !important; }
  .card-title,
  .card__title { font-size: 15px !important; }
  .card-subtitle,
  .card__subtitle { font-size: 11.5px !important; }
  .card-body,
  .card__body { padding: 0 !important; }

  /* 8) Long titles in headers truncate gracefully */
  .app-header__title,
  .app-header__breadcrumb-current { max-width: calc(100vw - 80px); }

  /* 9) Make any unwrapped table scrollable horizontally without breaking layout */
  table:not(.history-table) { display: block; overflow-x: auto; }
  .history-table { font-size: 12px; }
  .history-table th, .history-table td { padding: 8px !important; white-space: nowrap; }

  /* 10) Coach APE chat panel — already mobile-aware but verify launcher */
  .ape-launcher, #ape-launcher { z-index: 250; }

  /* 11) <details> summaries get a comfortable hit area */
  details.map-collapse > summary { padding: var(--space-4) !important; min-height: 48px; }

  /* 12) KPI cards — keep numbers legible, hide noisy delta-secondary if cramped */
  .kpi-card { padding: var(--space-3) !important; }
  .kpi-card__value { font-size: 28px !important; }
  .kpi-card__label { font-size: 11px !important; }

  /* 13) Filter/select widgets stay full-width when wrapped */
  .filter-select { width: 100% !important; max-width: 100% !important; }
  .search-input  { width: 100% !important; }

  /* 14) Anything fixed-width > 240px takes 100% width on phones */
  [style*="min-width: 280px"],
  [style*="min-width:280px"],
  [style*="min-width: 300px"],
  [style*="min-width:300px"],
  [style*="min-width: 360px"],
  [style*="min-width:360px"],
  [style*="min-width: 480px"],
  [style*="min-width:480px"] {
    min-width: 100% !important;
  }

  /* 15) Side-by-side strengths/weaknesses, share modal recent views, edit
        modal form rows — collapse stacked column safely. */
  #sw-grid, #body-comp-content, #ef-name-row { grid-template-columns: 1fr !important; }
}

/* ── Tablet (577-768px) — narrow tablets stack heavy 2-col rows ──────────── */
@media (min-width: 577px) and (max-width: 768px) {
  [style*="grid-template-columns:repeat(4"],
  [style*="grid-template-columns: repeat(4"],
  [style*="grid-template-columns:repeat(5"],
  [style*="grid-template-columns: repeat(5"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  #hero-composite { font-size: 80px !important; }
  .reveal-num     { font-size: 48px !important; }
}

/* ============================================================================
   Mobile polish pass (Peter feedback 2026-05-16)
   ============================================================================ */

/* ── Header: kill fixed height on phones so wrapped action row doesn't bleed
      under the cards below it. Sticky header still works — it just grows. ── */
@media (max-width: 768px) {
  .app-header {
    height: auto !important;
    min-height: var(--header-height);
    align-items: flex-start !important;
  }
  .app-header__breadcrumb {
    flex-wrap: wrap;
    row-gap: 2px;
  }
  .app-header__breadcrumb-current {
    display: inline-block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Action buttons in header — tighten + uniform size so 3-4 buttons fit one row */
  .app-header__right .btn,
  .app-header__right .btn--sm {
    padding: 6px 10px !important;
    font-size: 12px !important;
    flex: 0 1 auto;
  }
  #header-score-block {
    width: 100%;
    justify-content: space-between !important;
    margin-top: var(--space-2);
  }
  #header-composite { font-size: 22px !important; }
}

/* ── Tooltip popover: never overflow the viewport on phones. Anchor the
      popover to a horizontal strip the full viewport width, with comfortable
      inset margins. Arrow centering is dropped to avoid misalignment. ── */
@media (max-width: 576px) {
  /* Bottom-sheet pattern: popover slides up from bottom of viewport,
     spanning full width. Avoids any positioning math near the icon. */
  .gloss-pop {
    position: fixed !important;
    left: 12px !important;
    right: 12px !important;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
    top: auto !important;
    transform: none !important;
    width: auto !important;
    max-width: none !important;
    z-index: 1000 !important;
  }
  .gloss-pop::after { display: none !important; }
}

/* ── Cards: when an empty-state message lives at top of a card, give it
      breathing room and prevent it from being hidden by the sticky header. ── */
@media (max-width: 576px) {
  .card { scroll-margin-top: 100px; }
}

/* ── Fractional inline grids the existing rules miss (Peter audit 2026-05) ── */
@media (max-width: 576px) {
  [style*="1.2fr 1.2fr 1.6fr"],
  [style*="1.2fr 1.6fr"],
  [style*="1.1fr 1.4fr"],
  [style*="1.4fr 1.1fr"],
  [style*="2fr 1.5fr"],
  [style*="1.5fr 2fr"],
  [style*="1.1fr 0.9fr"],
  [style*="1.6fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Inline 6/7-col layouts (e.g. calendar weeks) */
  [style*="repeat(7,"],
  [style*="repeat(7, "],
  [style*="repeat(6,"],
  [style*="repeat(6, "] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
}

/* ── Modals & overlays: never overflow viewport on phones. Cover the common
      hard-coded max-widths in athlete-profile.html and settings.html. ── */
@media (max-width: 576px) {
  [style*="max-width:540px"],
  [style*="max-width: 540px"],
  [style*="max-width:560px"],
  [style*="max-width: 560px"],
  [style*="max-width:520px"],
  [style*="max-width: 520px"],
  [style*="max-width:480px"],
  [style*="max-width: 480px"],
  [style*="max-width:420px"],
  [style*="max-width: 420px"] {
    max-width: calc(100vw - 24px) !important;
  }
}

/* ── audit-log.html: 5-column audit-row → stacked card on mobile ─────────── */
@media (max-width: 576px) {
  .audit-row {
    grid-template-columns: 1fr !important;
    padding: var(--space-3) !important;
    gap: var(--space-2) !important;
    font-size: 12.5px !important;
    border-bottom: 1px solid var(--gray-200) !important;
  }
  .audit-row--header { display: none !important; }
  .audit-time::before  { content: "When: "    ; font-weight: 700; color: var(--gray-400); }
  .audit-actor::before { content: "Who: "     ; font-weight: 700; color: var(--gray-400); }
  .audit-action::before{ content: "Action: "  ; font-weight: 700; color: var(--gray-400); }
  .audit-entity::before{ content: "Entity: "  ; font-weight: 700; color: var(--gray-400); }
  .audit-details, .audit-link { padding-left: 0; }
}

/* ── admin-content.html: 480px-wide slide drawer → near-full on phones ───── */
@media (max-width: 576px) {
  .slide-panel {
    width: calc(100vw - 16px) !important;
    max-width: 100vw !important;
  }
}

/* ── Toasts / floating bottom UI — respect iOS home indicator (safe-area)
      Pattern matches anything position:fixed with bottom set inline. ── */
@media (max-width: 768px) {
  [style*="position: fixed"][style*="bottom:"],
  [style*="position:fixed"][style*="bottom:"] {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* ── teams-manage.html: grid card minmax(320px) is tight on 375px phones ── */
@media (max-width: 576px) {
  .teams-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ============================================================================
   Dark theme (toggled via <html data-theme="dark"> or [data-theme="dark"] body)
   Overrides the brand/gray tokens so existing components flip without code
   changes. Pages that use the semantic --bg-* / --text-* tokens get it for
   free; pages using --map-white / --gray-* also flip via the swaps below.
   ============================================================================ */
[data-theme="dark"] {
  --bg-page:        #0A0A0B;
  --bg-card:        #18181B;
  --bg-elevated:    #27272A;
  --text-primary:   #FAFAFA;
  --text-secondary: #D4D4D8;
  --text-muted:     #A1A1AA;
  --border-default: #3F3F46;

  /* Flip the brand whites/blacks so var(--map-white)/var(--map-black) usages
     still read as "page surface" / "primary text" respectively. */
  --map-white: #18181B;
  --map-black: #FAFAFA;

  /* Inverted gray ramp — light/airy → deep/elevated reverses.
     gray-50→300 stay deep (used for backgrounds/borders); gray-400/500 are bumped
     lighter so SECONDARY TEXT is readable on dark surfaces (Peter 6/22: "change gray
     writing to white in dark mode"). */
  --gray-50:  #18181B;
  --gray-100: #27272A;
  --gray-200: #3F3F46;
  --gray-300: #52525B;
  --gray-400: #9CA3AF;
  --gray-500: #C4C7CF;
  --gray-600: #D4D4D8;
  --gray-700: #E4E4E7;
  --gray-800: #F4F4F5;
  --gray-900: #FAFAFA;

  /* Slightly brighter accents read better on dark */
  --map-red-light:      rgba(255, 0, 0, 0.20);
  --map-gold-light:     rgba(201, 168, 76, 0.18);
  --map-flamingo-light: rgba(239, 68, 68, 0.18);

  color-scheme: dark;
}
[data-theme="dark"] body { background: var(--bg-page); color: var(--text-primary); }

/* Smooth color transitions when flipping */
html { transition: background-color 200ms ease; }
body, .card, .app-sidebar, .app-header { transition: background-color 200ms ease, color 200ms ease, border-color 200ms ease; }

/* ============================================================================
   Mobile readiness pass 3 (Peter audit 2026-05-20)
   ============================================================================ */

/* ── iOS input-zoom prevention: anything < 16px causes Safari to zoom in on
      focus. Force 16px for all interactive controls on phones. ──────────── */
@media (max-width: 768px) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
  select,
  textarea {
    font-size: max(16px, 1rem) !important;
  }
}

/* ── Viewport units: any modal/dialog using vh for max-height breaks when
      iOS keyboard appears. Promote to dynamic viewport (dvh) where supported,
      with graceful fallback. Catches inline styles like max-height:90vh too. ─ */
@supports (height: 100dvh) {
  [style*="max-height:90vh"],
  [style*="max-height: 90vh"],
  [style*="max-height:92vh"],
  [style*="max-height: 92vh"],
  [style*="max-height:80vh"],
  [style*="max-height: 80vh"],
  [style*="max-height:85vh"],
  [style*="max-height: 85vh"] {
    max-height: 90dvh !important;
  }
}

/* ── Touch targets — anything that's clickable + sub-44pt needs a min-height
      bump on phones. Catches the inline pill/badge/chip patterns. ────────── */
@media (max-width: 576px) {
  .readiness-pill,
  .status-badge,
  .alert-reason,
  .saved-chip,
  .badge,
  [class*="badge--"],
  [class*="-pill"],
  [class*="-chip"] {
    min-height: 32px;
    display: inline-flex !important;
    align-items: center;
    padding-left: 10px !important;
    padding-right: 10px !important;
  }
  /* Buttons & links — Apple HIG 44pt minimum hit area (Evan 7/14) */
  button:not(.gloss):not(.app-sidebar__link),
  .btn,
  a.btn {
    min-height: 44px;
  }
  /* Icon-only buttons explicit hit target */
  button[title]:not([class*="link"]):empty,
  button[aria-label]:not([class*="link"]) {
    min-width: 44px;
  }
}

/* ── Adult vs athlete client view ───────────────────────────────────────────
   Peter 2026-09-01: adults "don't need all the sports athlete parts". Mark a
   sport-only block `data-client="athlete"` (or an adult-only one `data-client="adult"`)
   and js/lib/client-view.js flips <html data-client-type>. The rule is CSS, and
   !important, because these cards set their own inline display as data loads —
   an inline style would otherwise undo the view. Staff get data-reveal-athlete="1"
   from the "Show athlete sections" toggle, which drops the rule and lets the
   page's own inline styles govern again (so empty cards stay hidden). */
html[data-client-type="adult"]:not([data-reveal-athlete="1"]) [data-client="athlete"] { display: none !important; }
html:not([data-client-type="adult"]) [data-client="adult"] { display: none !important; }
