/* ============================================================
   DP Coaches Dashboard — mobile layer (loads LAST)
   Single source of truth for ≤720px. Overrides the conflicting
   mobile rules in the inline styles, dashboard-redesign.css and
   the premium pass. Desktop (>720px) is untouched.
   ============================================================ */

/* Safe-area support for installed PWA (requires viewport-fit=cover) */
:root {
  --dp-hdr-h: 56px;
  --dp-tab-h: 44px;
  --dp-safe-top: env(safe-area-inset-top, 0px);
  --dp-safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (max-width: 720px) {

  /* ── 1. Header: one compact sticky row ─────────────────── */
  header,
  body[data-theme="light"] header {
    position: sticky;
    top: 0;
    z-index: 120;
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: var(--dp-hdr-h);
    height: auto;
    padding: 6px 12px;
    padding-top: calc(6px + var(--dp-safe-top));
    background: rgba(8, 16, 25, .96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }

  .logo-block {
    width: auto;
    flex: 0 0 auto;
    gap: 8px;
    align-items: center;
  }
  .logo-mark, .logo-mark-sm { height: 28px; width: auto; }
  .logo-wordmark { display: none; }
  .logo-kicker { font-size: 14px; letter-spacing: .05em; white-space: nowrap; }
  .logo-role, .coach-pill, .updated { display: none; }

  .h-right {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    width: auto;
    flex: 1 1 auto;
    min-width: 0;
    gap: 6px;
  }

  .coach-select {
    width: auto;
    max-width: 118px;
    min-height: 34px;
    font-size: 10px;
    padding: 6px 8px;
  }

  /* Manage + Refresh as icon buttons (premium pass hid manage entirely) */
  #manage-athletes-btn,
  #gen-btn { display: inline-flex !important; }
  #gen-btn[style*="display:none"], #gen-btn[style*="display: none"] { display: none !important; }
  #manage-athletes-btn, .refresh-btn {
    width: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 0;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
  }
  #manage-athletes-btn::before { content: '\2699'; font-size: 15px; }
  .refresh-btn::before { content: '\21BB'; font-size: 15px; }
  #manage-athletes-btn::before, .refresh-btn::before { line-height: 1; }

  /* Compact theme toggle, never full-width */
  .theme-toggle {
    display: flex;
    width: auto;
    min-height: 34px;
    flex: 0 0 auto;
    grid-column: auto;
    padding: 2px;
  }
  .theme-btn {
    flex: 0 0 auto;
    min-width: 0;
    height: 28px;
    padding: 0 9px;
    font-size: 9px;
  }

  /* ── 2. Tab bar: sticky directly under the header ──────── */
  .tab-bar,
  body[data-theme="light"] .tab-bar {
    position: sticky;
    top: calc(var(--dp-hdr-h) + var(--dp-safe-top));
    z-index: 110;
    display: flex;
    align-items: stretch;
    gap: 2px;
    padding: 0 8px !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: rgba(8, 16, 25, .96);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
  }
  .tab-bar::-webkit-scrollbar { display: none; }
  .tab {
    flex: 0 0 auto;
    min-height: var(--dp-tab-h);
    padding: 12px 12px 10px;
    font-size: 12px;
    white-space: nowrap;
    scroll-snap-align: start;
  }

  /* Filter card is content, never sticky (kills the 3rd sticky layer) */
  .filter-bar,
  body[data-theme="light"] .filter-bar {
    position: relative;
    top: auto;
    z-index: 10;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 9px;
    margin: 10px 10px 0;
    padding: 11px;
    border-radius: 16px;
  }
  /* Full-width rows by default */
  .filter-bar > .search-input,
  .filter-bar > .sort-select,
  .filter-bar > .sf-group:first-of-type { flex: 1 1 100%; }
  .search-input { min-width: 0; min-height: 42px; font-size: 14px; border-radius: 10px; }
  .sort-select { min-height: 40px; border-radius: 10px; font-size: 12.5px; }
  .filter-label, .filter-divider { display: none; }

  /* Status pills: snug scroll row with snap + a right-edge fade cue */
  .filter-bar > .sf-group:first-of-type,
  .filter-bar .sf-group:not(#dash-week-controls):not(:has(#view-cards-btn)) {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-snap-type: x proximity;
    gap: 6px;
    margin: 0 -2px;
    padding: 2px 14px 2px 2px;
    -webkit-mask-image: linear-gradient(90deg, #000 82%, transparent);
    mask-image: linear-gradient(90deg, #000 82%, transparent);
  }
  .filter-bar .sf-group::-webkit-scrollbar { display: none; }
  .filter-bar > .sf-group:first-of-type .sf { scroll-snap-align: start; }
  .sf {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 7px 14px;
    font-size: 11.5px;
    white-space: nowrap;
  }

  /* ── Week nav → compact segmented control ─────────────────── */
  #dash-week-controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0;
    overflow: visible;
    margin: 0;
    padding: 3px;
    background: var(--surface2, #131a22);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 11px;
    -webkit-mask-image: none;
    mask-image: none;
  }
  #dash-week-controls .sf {
    flex: 1;
    min-height: 36px;
    padding: 0 4px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font-size: 10px;
    letter-spacing: 0;
    justify-content: center;
    text-align: center;
  }
  #dash-week-controls .sf:disabled { opacity: .38; }
  #dash-week-controls .sf:not(:disabled):active { background: rgba(121,195,232,.12); }

  /* ── Cards / Table → segmented toggle (portal-style) ──────── */
  .filter-bar .sf-group:has(#view-cards-btn) {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    overflow: visible;
    margin: 0;
    padding: 3px;
    background: var(--surface2, #131a22);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 11px;
    -webkit-mask-image: none;
    mask-image: none;
  }
  .filter-bar .sf-group:has(#view-cards-btn) .sf {
    flex: 1;
    min-height: 38px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted, #8fa3b5);
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
  }
  .filter-bar .sf-group:has(#view-cards-btn) .sf.active {
    background: var(--brand, #79c3e8);
    color: #06101a;
    border: 0;
  }

  /* Put week-nav and view-toggle side by side to save vertical space */
  #dash-week-controls { order: 4; flex: 1 1 calc(58% - 5px); }
  .filter-bar .sf-group:has(#view-cards-btn) { order: 5; flex: 1 1 calc(42% - 5px); }

  /* ── 3. Page intro: fix the giant headline ─────────────── */
  .dp-page-intro { display: block; margin: 2px 0 14px; }
  .dp-page-title {
    font-size: clamp(22px, 6.5vw, 28px);
    line-height: 1.05;
    letter-spacing: 0;
    overflow-wrap: anywhere;
  }
  .dp-eyebrow { font-size: 9px; }
  .dp-page-subtitle { font-size: 12.5px; line-height: 1.5; margin-top: 6px; max-width: none; }
  .dp-intro-date { display: inline-block; margin-top: 8px; font-size: 9px; }

  /* ── 4. Week nav + view toggle: tight rows ──────────────── */
  .dash-week-nav { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px; }
  .dwn-controls {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 100%;
  }
  .dwn-btn { min-height: 38px; padding: 6px 4px; font-size: 9px; white-space: nowrap; }

  /* ── 5. Priority score cards ────────────────────────────── */
  .cc-hero { padding: 14px; }
  .cc-title { font-size: 21px; }
  .cc-score { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; width: 100%; }
  .cc-score-card { padding: 10px 6px; min-width: 0; }
  .cc-score-num { font-size: 21px; }

  .summary-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .sum-card { padding: 12px; }
  .sum-num { font-size: 24px; }

  /* ── 6b. Athlete full-page: stat CARDS, not sideways slide ──
     The hero metrics / scores / bottom stats were flex rows set to
     overflow-x:auto (a horizontal swipe). On mobile we turn them into
     wrapping card grids so every stat is visible in one view. */

  /* 6-metric hero row → 2×3 card grid */
  #fp-overlay .pcard-metrics,
  .pcard-metrics {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    padding: 11px 12px;
    overflow: visible !important;
  }
  .pcard-metrics .pm {
    border-right: 0 !important;
    padding: 10px 5px;
    background: var(--surface2, #131a22);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 10px;
  }
  .pcard-metrics .pm-lbl { margin-bottom: 5px; }
  .pcard-metrics .pm-val { font-size: 19px; }

  /* Weekly check-in scores row → card grid */
  #fp-overlay .scores,
  .scores {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    padding: 10px 12px;
    overflow: visible !important;
  }
  .scores .sc {
    border-right: 0 !important;
    padding: 9px 5px;
    background: var(--surface2, #131a22);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 10px;
  }
  .scores .sc-lbl { margin-bottom: 4px; }
  .scores .sc-val { font-size: 16px; }

  /* Bottom stats strip → wrapping cards (overrides inline column count) */
  #fp-overlay .pcard-stats,
  .pcard-stats {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)) !important;
    gap: 7px;
    padding: 10px 12px;
    overflow: visible !important;
  }
  .pcard-stats .pstat {
    border-right: 0 !important;
    padding: 10px 6px;
    background: var(--bg, #060b11);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 10px;
  }

  /* Coaches-tab score row (same pattern) */
  .coach-scores {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    padding: 10px 12px;
    overflow: visible !important;
  }
  .coach-scores .sc {
    border-right: 0 !important;
    background: var(--surface2, #131a22);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 10px;
  }

  /* Body block: weight + its metric chips stack cleanly */
  #fp-overlay .body-grid, .body-grid {
    flex-direction: column;
    gap: 12px;
  }
  .bmet {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 7px;
    width: 100%;
  }
  .bmet .bm {
    background: var(--surface2, #131a22);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 10px;
    padding: 9px 5px;
  }

  /* Training split stays 2-up but tighter; feels like paired cards */
  #fp-overlay .pcard-training { grid-template-columns: 1fr 1fr !important; gap: 7px; padding: 10px 12px; }
  .pcard-training .ptrain {
    border-right: 0 !important;
    background: var(--surface2, #131a22);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 10px;
    padding: 10px;
  }

  /* Tighter hero + section padding so it reads as one screen */
  #fp-overlay .fpc-hero { padding: 18px 16px 16px; border-radius: 16px; margin-bottom: 14px; }
  #fp-overlay .sec { padding: 10px 12px; }
  #fp-overlay .fp-body { padding-left: 10px; padding-right: 10px; }

  /* ── 6. Athlete TABLE → per-athlete cards (no sideways scroll) ──
     13 columns can't live in a horizontal-scroll table on a phone.
     We collapse each row into a card: name/meta header, then the
     metrics as small labelled stat cells. Labels come from data-label
     stamped by dashboard-mobilenav.js. */
  #grid.table-mode .dash-table-wrap { overflow-x: visible; }
  #grid.table-mode .dash-table {
    display: block;
    min-width: 0 !important;
    table-layout: auto;
    border-collapse: separate;
  }
  #grid.table-mode .dash-table colgroup,
  #grid.table-mode .dash-table thead { display: none; }
  #grid.table-mode .dash-table tbody { display: block; }

  #grid.table-mode .dash-trow {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 9px 6px;
    padding: 13px 13px 14px;
    margin-bottom: 9px;
    background: var(--surface, #0f151d);
    border: 1px solid var(--border, rgba(255,255,255,.08));
    border-radius: 14px;
  }
  #grid.table-mode .dash-trow.trow-red   { border-left: 3px solid rgba(240,130,130,.7); }
  #grid.table-mode .dash-trow.trow-amber { border-left: 3px solid rgba(242,183,102,.7); }

  #grid.table-mode .dash-trow td {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    padding: 0 !important;
    text-align: left !important;
    overflow: visible;
    min-width: 0;
  }
  /* metric label above each value */
  #grid.table-mode .dash-trow td:not(:first-child)::before {
    content: attr(data-label);
    font-family: var(--mono, monospace);
    font-size: 7px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--dim, #6b7d8c);
  }
  /* name cell = full-width card header */
  #grid.table-mode .dash-trow td:first-child {
    grid-column: 1 / -1;
    padding-bottom: 9px !important;
    margin-bottom: 3px;
    border-bottom: 1px solid var(--border, rgba(255,255,255,.07));
  }
  #grid.table-mode .dash-trow td:first-child::before { display: none; }
  #grid.table-mode .tname { font-family: var(--cond, sans-serif); font-size: 18px; font-weight: 900; letter-spacing: .03em; }
  #grid.table-mode .tmeta { font-size: 10px; margin-top: 2px; }
  /* status cell spans full width at the foot of the card */
  #grid.table-mode .dash-trow td:last-child { grid-column: 1 / -1; }
  /* drop empty metric cells so cards stay tight */
  #grid.table-mode .dash-trow td:not(:first-child):not(:last-child):has(> .tdim:only-child) { display: none; }

  /* expanded detail: full-width single column */
  #grid.table-mode .trow-expand { display: none; }
  #grid.table-mode .trow-expand td { display: block; padding: 0 !important; border: 0; }
  .texp-panel { grid-template-columns: 1fr !important; }
  .texp-left { border-right: 0 !important; border-bottom: 1px solid var(--border); }

  /* ── This Week's Plan rows: no date/badge overlap ─────────── */
  .sched-session-row {
    display: grid !important;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    column-gap: 8px;
    row-gap: 5px;
    padding: 10px 0;
  }
  .sched-session-row .sched-date { grid-row: 1; grid-column: 1; min-width: 0; font-size: 10px; padding-top: 0; }
  .sched-session-row > .sbadge { grid-row: 1; grid-column: 2; justify-self: start; }
  .sched-session-row .sched-status-icon,
  .sched-session-row .po-edit-icon { grid-row: 1; grid-column: 3; justify-self: end; }
  .sched-session-row .sched-session-name { grid-row: 2; grid-column: 1 / -1; font-size: 13px; }

  /* Week detail day-by-day rows stack cleanly too */
  .wd-row { grid-template-columns: 1fr !important; row-gap: 8px; padding: 12px 14px; }
  .wd-date { width: auto; padding-top: 0; }

  /* ── 7. Content padding + safe areas ────────────────────── */
  .main, .plan-section, .coaches-section, .sched-section {
    padding: 14px 10px calc(48px + var(--dp-safe-bottom));
  }

  /* Full-page overlays respect the notch too */
  #fp-overlay .fp-topbar, #wh-overlay .wh-topbar {
    padding-top: calc(10px + var(--dp-safe-top));
  }
  .fp-hint { display: none; }

  /* Comfortable tap targets everywhere */
  button, select { touch-action: manipulation; }
}

/* ============================================================
   BOTTOM NAV — athlete-portal architecture
   Fixed thumb-reachable bar replaces the horizontal top tabs on
   mobile. Top tab bar is hidden ≤720px; desktop is unchanged.
   ============================================================ */
.dp-mobilenav { display: none; }
.dp-sheet, .dp-sheet-backdrop { display: none; }

@media (max-width: 720px) {

  /* Hide the top tab bar entirely — bottom nav is the navigation now.
     This also removes the sticky offset that was causing overlap. */
  .tab-bar { display: none !important; }

  /* Room so content never hides behind the fixed bar */
  .main, .plan-section, .coaches-section, .sched-section {
    padding-bottom: calc(78px + var(--dp-safe-bottom)) !important;
  }

  .dp-mobilenav {
    display: flex;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 140;
    justify-content: space-around;
    align-items: stretch;
    gap: 2px;
    padding: 6px 6px calc(6px + var(--dp-safe-bottom));
    background: rgba(10, 14, 18, .93);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border-top: 1px solid rgba(121, 195, 232, .12);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, .38);
  }

  .dp-mnav-item {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 5px 2px 3px;
    background: none;
    border: 0;
    border-radius: 12px;
    color: rgba(240, 237, 232, .52);
    cursor: pointer;
    transition: color .15s ease, background .15s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .dp-mnav-item:active { background: rgba(121, 195, 232, .07); }
  .dp-mnav-item.active { color: var(--brand, #79c3e8); }

  .dp-mnav-ic {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
  }
  .dp-mnav-ic svg { width: 23px; height: 23px; }

  /* Active pill glow behind the icon, portal-style */
  .dp-mnav-item.active .dp-mnav-ic::before {
    content: '';
    position: absolute;
    inset: -5px -10px;
    border-radius: 999px;
    background: rgba(121, 195, 232, .14);
    z-index: -1;
  }

  .dp-mnav-lbl {
    font-family: var(--mono, monospace);
    font-size: 9px;
    font-weight: 600;
    letter-spacing: .04em;
    line-height: 1;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Count badges mirrored from the top bar */
  .dp-mnav-badge {
    position: absolute;
    top: -3px; right: -7px;
    min-width: 15px;
    height: 15px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--brand, #79c3e8);
    color: #06101a;
    font-family: var(--mono, monospace);
    font-size: 9px;
    font-weight: 700;
    line-height: 15px;
    text-align: center;
  }
  .dp-mnav-badge.dot {
    min-width: 8px; width: 8px; height: 8px;
    padding: 0; top: 0; right: -2px;
  }

  /* ── More sheet ─────────────────────────────────────────── */
  .dp-sheet-backdrop {
    display: block;
    position: fixed; inset: 0;
    z-index: 145;
    background: rgba(4, 8, 12, 0);
    pointer-events: none;
    transition: background .2s ease;
  }
  .dp-sheet-backdrop.open {
    background: rgba(4, 8, 12, .55);
    pointer-events: auto;
    backdrop-filter: blur(2px);
  }

  .dp-sheet {
    display: block;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 150;
    transform: translateY(110%);
    transition: transform .26s cubic-bezier(.22, 1, .36, 1);
    background: #10151b;
    border-top: 1px solid rgba(121, 195, 232, .16);
    border-radius: 20px 20px 0 0;
    padding: 8px 16px calc(20px + var(--dp-safe-bottom));
    box-shadow: 0 -18px 50px rgba(0, 0, 0, .5);
  }
  .dp-sheet.open { transform: translateY(0); }

  .dp-sheet-grip {
    width: 38px; height: 4px;
    margin: 4px auto 12px;
    border-radius: 999px;
    background: rgba(240, 237, 232, .22);
  }
  .dp-sheet-title {
    font-family: var(--cond, sans-serif);
    font-size: 16px;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #f0ede8;
    margin: 0 2px 14px;
  }
  .dp-sheet-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }
  .dp-sheet-cell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 14px 6px;
    background: rgba(255, 255, 255, .03);
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 14px;
    color: rgba(240, 237, 232, .82);
    font-family: var(--mono, monospace);
    font-size: 10px;
    letter-spacing: .03em;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .dp-sheet-cell:active { background: rgba(121, 195, 232, .09); }
  .dp-sheet-cell.active {
    border-color: rgba(121, 195, 232, .4);
    color: var(--brand, #79c3e8);
  }
  .dp-sheet-ic {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    width: 28px; height: 28px;
  }
  .dp-sheet-ic svg { width: 24px; height: 24px; }

  /* Hide the redundant in-header refresh/gear duplicates? No — keep them.
     But drop the now-unused bottom padding guard on overlays. */
  #fp-overlay, #wh-overlay { padding-bottom: 0; }
}

/* Light theme surfaces for the nav */
body[data-theme="light"] .dp-mobilenav {
  background: rgba(255, 255, 255, .94);
  border-top-color: rgba(0, 0, 0, .08);
}
body[data-theme="light"] .dp-mnav-item { color: rgba(20, 30, 40, .55); }
body[data-theme="light"] .dp-sheet { background: #fff; }
body[data-theme="light"] .dp-sheet-cell {
  background: rgba(0, 0, 0, .02);
  border-color: rgba(0, 0, 0, .08);
  color: rgba(20, 30, 40, .8);
}
body[data-theme="light"] .dp-sheet-title { color: #10151b; }

/* ── Extra-small phones ───────────────────────────────────── */
@media (max-width: 400px) {
  .coach-select { max-width: 96px; }
  .logo-kicker { display: none; }
  .theme-btn { padding: 0 7px; font-size: 8px; }
  .dp-page-title { font-size: 21px; }
  .dp-mnav-lbl { font-size: 8px; }
}
