/* App-owned styles — not part of the kit; wires kit tokens/patterns into the
   two-state (mobile tab bar / desktop rail) layout plus the page-level
   patterns the server-rendered templates need (page header, coach's note,
   calendar day heads, session rows, data tables, stat cards, menus).
   The kit under tokens/ + patterns/ stays vendored and untouched.
   Import after styles.css.

   .tabbar a / .rail-nav a below reproduce the kit's declared look (same
   tokens, same color states) against an anchor selector instead of a button
   selector: patterns/navigation.css styles .tabbar button (the kit's React
   demo swaps tabs client-side) and leaves .rail with no nav-link styling at
   all, but this server-rendered multi-page app navigates with real
   <a href> links. */

/* ---------- shell (mobile-first) ---------- */
.shell {
  max-width: 420px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  background: var(--paper);
}

.shell .rail { display: none; } /* hidden below breakpoint */
.plan-desktop-pane { display: none; }
.plan-mobile-pane { display: block; }

.shell-main {
  padding: var(--sp-5) var(--gutter-mobile) 96px; /* 96px clears the fixed 56px tab bar */
  /* Full-bleed webview (viewport-fit=cover): keep content out of the notch /
     Dynamic Island and home-indicator zones. env() is 0 in desktop browsers. */
  padding-top: calc(var(--sp-5) + env(safe-area-inset-top, 0px));
  padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.tabbar {
  height: calc(56px + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-sizing: border-box;
}

.wordmark-lg { font-size: 20px; }

.tabbar a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font: var(--w-medium) var(--fs-small)/1 var(--font-sans);
  color: var(--ink-4);
  text-decoration: none;
  transition: color 120ms;
}
.tabbar a.selected { color: var(--ink); }

.rail-nav { display: flex; flex-direction: column; gap: var(--sp-2); }
.rail-nav a {
  font: var(--w-medium) var(--fs-body)/1 var(--font-sans);
  color: var(--ink-3);
  text-decoration: none;
  padding: var(--sp-2) 0;
}
.rail-nav a.active { color: var(--ink); font-weight: var(--w-semibold); }

.rail-logout { margin-top: auto; }
.link-button {
  background: none; border: 0; padding: 0; cursor: pointer;
  font: var(--w-regular) var(--fs-small)/1 var(--font-sans);
  color: var(--ink-3);
}
.link-button:hover { color: var(--link-hover); }

/* Desktop: nav-only rail + full-width main. The calendar needs ~7 real
   columns, so the rail/calendar state starts at 960px; below that the
   mobile card list is the better layout even on tablets. */
@media (min-width: 960px) {
  .shell {
    max-width: none;
    display: flex;
    min-height: 100vh;
  }
  .shell .rail { display: flex; width: 208px; }
  .shell-main {
    flex: 1;
    min-width: 0;
    padding: var(--sp-6) var(--sp-8) var(--sp-8);
  }
  .tabbar { display: none; }
  .plan-desktop-pane { display: block; }
  .plan-mobile-pane { display: none; }
}

.auth-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6) var(--gutter-mobile);
  box-sizing: border-box;
}
.auth-shell > .card { width: 100%; max-width: 360px; }

/* ---------- landing page (public marketing, minimal_chrome without auth-shell) ---------- */
.landing { max-width: 960px; margin: 0 auto; padding: var(--sp-8) var(--gutter-mobile) var(--sp-10); }
.landing-section + .landing-section { margin-top: var(--sp-8); }
@media (min-width: 960px) {
  .landing-section + .landing-section { margin-top: calc(var(--sp-8) * 2); } /* 64px exception, see UI-SPEC Spacing */
}
.landing-section h2 { font-size: var(--fs-h1); }
/* Landing grids hold text cards, not stat numbers — 150px min columns cram
   prose into two skinny columns on phones. 240px stacks them there and still
   gives three-up on desktop. (.shots keeps its mobile flex carousel.) */
.landing .stat-grid { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
/* Phone screenshots: on small screens three stacked full-width phone shots
   made the page enormous — swipe through them instead. */
@media (max-width: 959px) {
  /* .stat-grid.shots: must out-rank .stat-grid's display:grid, which is
     declared later in this file */
  .stat-grid.shots {
    display: flex;
    overflow-x: auto;
    gap: var(--sp-3);
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .stat-grid.shots::-webkit-scrollbar { display: none; }
  .stat-grid.shots .card { flex: 0 0 78%; scroll-snap-align: center; }
}

/* ---------- page header ---------- */
.page-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
}
.page-head .page-actions {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  margin-left: auto;
}

/* ---------- coach's note ---------- */
/* The one editorial moment on the plan page: the coach's voice at heading
   scale over the calendar's dense mono grid. */
.note {
  border-left: 3px solid var(--ink);
  padding-left: var(--sp-4);
  margin: var(--sp-5) 0;
  max-width: 56ch;
}
/* In the desktop aside the note leads the panel; the panel provides the width cap */
.plan-aside .note { margin-top: 0; max-width: none; }
@media (min-width: 960px) {
  .plan-aside .note p { font-size: var(--fs-h2); font-weight: var(--w-medium); }
}
.note .label { display: block; margin-bottom: var(--sp-2); }
details.note > summary { list-style: none; cursor: pointer; }
details.note > summary::-webkit-details-marker { display: none; }
details.note > summary .label { display: inline; margin-bottom: 0; }
details.note[open] > summary .teaser { display: none; }
.note p {
  font-size: var(--fs-h2);
  font-weight: var(--w-medium);
  line-height: 1.45;
  letter-spacing: var(--track-heading);
  color: var(--ink);
}
@media (min-width: 960px) {
  .note p { font-size: var(--fs-h1); font-weight: var(--w-regular); }
}
.note p + p { margin-top: var(--sp-3); }
.note p.muted {
  color: var(--ink-3);
  font-size: var(--fs-body);
  font-weight: var(--w-regular);
  letter-spacing: normal;
}

/* ---------- overflow menu (native <details>) ---------- */
details.menu { position: relative; display: inline-block; }
details.menu > summary {
  list-style: none;
  font: var(--w-semibold) var(--fs-body)/1 var(--font-mono);
  padding: 8px 10px;
  border-radius: var(--r-btn);
  color: var(--ink-3);
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}
details.menu > summary::-webkit-details-marker { display: none; }
details.menu > summary:hover, details.menu[open] > summary { background: var(--wash); color: var(--ink); }
.menu-list {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 5;
  width: 220px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-card);
  padding: 6px;
  display: flex;
  flex-direction: column;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  text-decoration: none;
  font: var(--w-regular) var(--fs-body)/1.3 var(--font-sans);
  color: var(--ink);
  padding: 9px 10px;
  border: 0;
  background: none;
  border-radius: calc(var(--r-card) - 6px);
  cursor: pointer;
}
.menu-item:hover { background: var(--wash); }
.menu-list hr { margin: 6px 0; }

/* ---------- plan page: desktop calendar + detail panel ---------- */
.plan-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--sp-6);
  align-items: start;
}
@media (min-width: 1200px) {
  .plan-layout { grid-template-columns: minmax(0, 1fr) 320px; }
  .plan-aside { position: sticky; top: var(--sp-6); }
}

.cal-heads { display: flex; }
.cal-heads .cal-axis-spacer { width: 44px; flex: none; }
.cal-heads .cal-head { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.cal-head .day-num {
  font: var(--w-regular) 11px/1 var(--font-mono);
  color: var(--ink-3);
  padding: 3px 7px;
  border-radius: var(--r-pill);
}
.cal-head.today .day-num { background: var(--ink); color: var(--surface); }

.cal-day.today { background: color-mix(in srgb, var(--wash) 55%, transparent); }
.now-line {
  position: absolute;
  left: 0; right: 0;
  border-top: 2px solid var(--ink);
  z-index: 2;
  pointer-events: none;
}
.now-line::before {
  content: "";
  position: absolute;
  left: -3px; top: -4px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--ink);
}

a.cal-block { text-decoration: none; color: inherit; }
.cal-block.done { opacity: .45; }
.cal-block.selected { outline: 2px solid var(--ink); }

.session-detail-head { display: flex; align-items: center; gap: var(--sp-2); }
.session-detail-head h2 { flex: 1; min-width: 0; }

/* ---------- plan page: mobile session list ---------- */
.day-list { display: flex; flex-direction: column; gap: var(--sp-2); }

/* One date per day; session cards and event rows group under it. */
.day-list .day-header {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  margin-top: var(--sp-3);
}
.day-list .day-header:first-child { margin-top: 0; }
.day-header .rest-tag { color: var(--ink-4); font-size: var(--fs-small); }

.rest-row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  padding: 6px var(--sp-4);
  color: var(--ink-4);
  font-size: var(--fs-small);
}
/* External events are context, not content — one line each, truncated. */
.rest-row > span:last-child {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rest-row .mono, .session-row .row-top { color: var(--ink-3); font-size: 11px; }
.session-row .row-start { /* JS target for calendar-drag.js same-day move time updates */ }
.rest-row.has-color { border-left: var(--accent-bar) solid var(--ev-color); padding-left: calc(var(--sp-4) - var(--accent-bar)); }

details.session-row > summary {
  list-style: none;
  cursor: pointer;
  /* Press-and-hold opens the quick-move sheet; without these iOS raises its own
     text-selection callout on top of it. */
  -webkit-touch-callout: none;
  user-select: none;
}
details.session-row > summary::-webkit-details-marker { display: none; }
details.session-row[open] { border-color: var(--ink); box-shadow: var(--shadow-card); }
.session-row .row-top {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
}
.session-row .row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
}
.session-row .row-main .title {
  font-weight: var(--w-medium);
  flex: 1;
  min-width: 0;
}
.session-row .session-detail {
  margin-top: var(--sp-4);
  border-top: 1px solid var(--line);
  padding-top: var(--sp-4);
}

/* ---------- data tables (trends, strength, prescriptions) ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  font: var(--w-semibold) var(--fs-label)/1 var(--font-mono);
  letter-spacing: var(--track-label);
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: right;
  padding: 12px 14px 8px;
  border-bottom: 1px solid var(--line);
}
.data-table td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
}
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .num { font-family: var(--font-mono); font-size: var(--fs-mono); text-align: right; }
.data-table .dim { color: var(--ink-3); }
/* tight: for tables inside cards that manage their own horizontal padding */
.data-table.tight th, .data-table.tight td { padding-left: 0; padding-right: 0; }
.data-table.tight th + th, .data-table.tight td + td { padding-left: 12px; }

.block-list .block-row {
  display: flex;
  gap: var(--sp-3);
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.block-list .block-row:last-child { border-bottom: 0; }
.block-row .block-min { color: var(--ink-3); width: 52px; flex: none; text-align: right; }

.inline-form {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-end;
  margin-top: var(--sp-3);
}
.inline-form .field { flex: 1; min-width: 0; }

/* ---------- trends stat cards + sparklines ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.stat-card .stat-value {
  font: var(--w-semibold) 22px/1 var(--font-mono);
  margin: 8px 0 2px;
}
.stat-card .stat-sub {
  font: var(--w-regular) 11px/1.4 var(--font-mono);
  color: var(--ink-3);
}
.spark { display: block; width: 100%; height: 36px; margin-top: 10px; }
.spark polyline {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.spark circle { fill: var(--ink); }

/* ---------- misc ---------- */
.stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.running-note { display: flex; align-items: center; gap: 10px; }

/* Keyboard/switch access: the kit ships hover states only — give every
   interactive element a visible focus ring. */
a:focus-visible, .btn:focus-visible, .fab:focus-visible, .chip:focus-visible,
.menu-item:focus-visible, .link-button:focus-visible,
details > summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* ---------- plan page: long-press quick-move sheet ---------- */
/* Native <dialog>: Esc, focus trap, and the backdrop come free. Pinned to the
   bottom edge because it opens under the thumb that pressed the row. */
.move-sheet {
  margin: auto auto 0;
  width: 100%;
  max-width: 520px;
  box-sizing: border-box; /* no global reset here — padding must stay inside 100% */
  border: none;
  border-radius: var(--r-card) var(--r-card) 0 0;
  padding: var(--sp-4) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow-card);
}
.move-sheet::backdrop { background: rgb(0 0 0 / .35); }
.move-sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.move-sheet-title { font-weight: 600; }
.move-sheet-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
}
.move-sheet-grid .btn { min-height: 44px; } /* touch target */
.move-sheet-custom { width: 100%; margin-top: var(--sp-2); min-height: 44px; }
.move-sheet [data-move-action]:disabled { opacity: .4; }

/* Kit override: 8×10px padding made the ··· menu a ~30px tap target —
   too small for touch (44px guideline). */
details.menu > summary { padding: 12px 14px; }

/* Kit override (patterns/buttons.css stays vendored): the tab bar is
   56px + safe-area tall, but the kit FAB only clears 56px — on notched
   iPhones / gesture-nav Android the bar overlapped the FAB's lower half
   and ate its taps. Lift the FAB by the same inset and stack it above. */
.fab {
  bottom: calc(56px + var(--sp-3) + env(safe-area-inset-bottom, 0px));
  z-index: 10;
}

/* Onboarding/settings health-source picker: vertical stack of radio cards. */
.source-picker {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
