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

:root {
  --bg:           #0f1117;
  --bg-card:      #1a1d27;
  --bg-card2:     #212436;
  --bg-input:     #141620;
  --border:       #2a2e44;
  --border-light: #323650;
  --accent:       #4f7ef8;
  --accent-hover: #3b6de6;
  --accent-dim:   rgba(79,126,248,0.12);
  --success:      #22c55e;
  --success-dim:  rgba(34,197,94,0.12);
  --danger:       #ef4444;
  --danger-dim:   rgba(239,68,68,0.12);
  --warning:      #f59e0b;
  --warning-dim:  rgba(245,158,11,0.12);
  --text:         #e2e8f0;
  --text-muted:   #8896ae;
  --text-dim:     #4e5a74;
  --radius:       10px;
  --radius-sm:    6px;
  --radius-lg:    16px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.3);
  --nav-h:        60px;
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  /* Exact viewport height so navbars are never covered by iOS Safari chrome.
     Cascade: var(--app-height) set by JS on old iOS → 100dvh on modern browsers */
  height: var(--app-height, 100vh);
  height: 100dvh; /* overrides when dvh is supported (iOS 16.4+, Chrome 108+) */
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top nav ────────────────────────────────────────────────────────────────── */
/* ── PWA install banner (iOS guidance) ──────────────────────────────────────── */
.ios-install-banner {
  display: flex; align-items: center; justify-content: center; gap: 0.75rem;
  background: var(--accent-dim); border-bottom: 1px solid var(--accent);
  padding: 0.6rem 1rem; font-size: 0.85rem; color: var(--text);
  padding-top: calc(0.6rem + var(--safe-top));
}
.ios-install-dismiss {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 1rem; line-height: 1; padding: 0.15rem 0.4rem; flex-shrink: 0;
}
.ios-install-dismiss:hover { color: var(--text); }

/* ── PWA install button (Android/Chrome — shown when beforeinstallprompt fires) */
.pwa-install-btn {
  font-size: 0.8rem; padding: 0.25rem 0.65rem;
  background: var(--accent-dim); color: var(--accent);
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
}
.pwa-install-btn:hover { background: var(--accent); color: #fff; }

.topnav {
  /* In-flow flex item — no longer position:fixed, so iOS toolbar can't cover it */
  flex-shrink: 0;
  position: relative; z-index: 10; /* stacking above view content for dropdown */
  height: calc(var(--nav-h) + var(--safe-top));
  background: rgba(26,29,39,0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 0;
  padding: var(--safe-top) 1.5rem 0;
}
.topnav-brand { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.brand-icon { font-size: 1.4rem; }
.brand-text { font-size: 1.1rem; font-weight: 700; letter-spacing: -0.02em; color: var(--text); }
.topnav-links { display: flex; gap: 0.25rem; margin-left: 2rem; flex: 1; }
.nav-link {
  padding: 0.4rem 0.85rem; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 0.9rem; font-weight: 500;
  transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--bg-card2); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }
.topnav-user { display: flex; align-items: center; gap: 0.75rem; margin-left: auto; }
.nav-username {
  font-size: 0.875rem; color: var(--text-muted);
  cursor: pointer; padding: 0.25rem 0.5rem;
  border-radius: var(--radius); user-select: none;
}
.nav-username:hover { color: var(--text); background: var(--bg-card2); }
.topnav-user { position: relative; }

/* ── Username dropdown ──────────────────────────────────────────────────────── */
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  min-width: 148px; z-index: 300;
  display: none; flex-direction: column;
  overflow: hidden;
}
.user-dropdown.open { display: flex; }
.user-dropdown-item {
  display: block; padding: 0.65rem 1rem;
  color: var(--text); font-size: 0.875rem; text-decoration: none;
  transition: background 0.12s;
}
.user-dropdown-item:hover { background: var(--bg-card2); text-decoration: none; }

/* ── Views ──────────────────────────────────────────────────────────────────── */
/* flex:1 fills space between the two navbars; overflow-y scrolls content internally
   so the body never scrolls → iOS Safari toolbar stays stable */
.view { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
#view-auth { display: flex; align-items: center; justify-content: center; padding: 2rem; }

.view-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem; /* topnav is now in-flow, no large top clearance needed */
}

/* ── Auth ───────────────────────────────────────────────────────────────────── */
.auth-container {
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; align-items: center; gap: 2rem;
}
.auth-brand { text-align: center; }
.brand-icon-lg { font-size: 3rem; }
.auth-title { font-size: 2rem; font-weight: 800; margin-top: 0.25rem; letter-spacing: -0.04em; }
.auth-subtitle { color: var(--text-muted); font-size: 0.95rem; margin-top: 0.25rem; }
.auth-card {
  width: 100%; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 2rem;
}
.auth-switch { text-align: center; color: var(--text-muted); font-size: 0.875rem; margin-top: 1.25rem; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.card-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); font-weight: 600; }
.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }

/* ── Page headers ───────────────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem; gap: 1rem; flex-wrap: wrap;
}
.page-title { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem 1.25rem; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  border: none; transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary  { background: var(--accent);   color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-success  { background: var(--success);  color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-danger   { background: var(--danger);   color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost    { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-light); background: var(--bg-card2); }
.btn-lg  { padding: 0.8rem 1.75rem; font-size: 1rem; border-radius: var(--radius); }
.btn-sm  { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn-icon { padding: 0.4rem; background: transparent; color: var(--text-muted); border: none; font-size: 1rem; }
.btn-icon:hover { color: var(--text); }

/* ── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.4rem; }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.form-input, .form-select {
  width: 100%; padding: 0.6rem 0.875rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 0.9rem; font-family: var(--font);
  transition: border-color 0.15s;
  appearance: none;
}
.form-input:focus, .form-select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,126,248,0.15);
}
.form-input::placeholder { color: var(--text-dim); }
.form-input-sm { width: 72px; padding: 0.4rem 0.6rem; }
.form-error { color: var(--danger); font-size: 0.85rem; margin-top: 0.5rem; padding: 0.5rem 0.75rem; background: var(--danger-dim); border-radius: var(--radius-sm); }
.form-inline { display: flex; align-items: center; gap: 0.5rem; }
.search-input { max-width: 320px; }

/* ── Dashboard ──────────────────────────────────────────────────────────────── */
.plan-switcher-bar { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.plan-pill {
  padding: 0.3rem 0.875rem; border-radius: 99px;
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: transparent; color: var(--text-muted);
  transition: all 0.15s;
}
.plan-pill:hover { border-color: var(--accent); color: var(--accent); }
.plan-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.dashboard-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem;
}
@media (max-width: 720px) { .dashboard-grid { grid-template-columns: 1fr; } }

.next-session-card { display: flex; flex-direction: column; gap: 0.75rem; }
.next-day-name { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.03em; }
.day-counter { font-size: 0.75rem; font-weight: 700; color: var(--accent); background: var(--accent-dim); padding: 0.2rem 0.6rem; border-radius: 99px; }
.exercise-preview-list { display: flex; flex-direction: column; gap: 0.3rem; margin: 0.25rem 0; }
.exercise-preview-item { font-size: 0.875rem; color: var(--text-muted); }
.exercise-preview-item strong { color: var(--text); }
.session-actions { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; flex-wrap: wrap; }

.recent-sessions {
  display: flex; flex-direction: column; gap: 0.5rem;
  max-height: 480px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.recent-session-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 1rem 0.6rem 0; border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}
.recent-session-row:last-child { border-bottom: none; }
.recent-session-day { font-weight: 600; }
.recent-session-date { color: var(--text-muted); font-size: 0.8rem; }

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 4rem 2rem;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.empty-icon { font-size: 3rem; }
.empty-state h3 { font-size: 1.25rem; font-weight: 700; }
.empty-state p  { color: var(--text-muted); max-width: 380px; }

/* ── Plans ──────────────────────────────────────────────────────────────────── */
.plans-grid  { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.days-grid   { display: flex; flex-direction: column; gap: 0.75rem; }
.plan-card, .day-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; transition: border-color 0.15s, background 0.15s;
}
.plan-card:hover, .day-card:hover { border-color: var(--accent); background: var(--bg-card2); }
.plan-card.active-plan { border-color: var(--accent); }
.plan-card-body { display: flex; flex-direction: column; gap: 0.3rem; }
.plan-card-name, .day-card-name { font-weight: 700; font-size: 1rem; }
.plan-card-meta, .day-card-meta { font-size: 0.8rem; color: var(--text-muted); }
.plan-card-actions, .day-card-actions { display: flex; gap: 0.25rem; flex-shrink: 0; }
.active-badge { font-size: 0.7rem; font-weight: 700; color: var(--accent); background: var(--accent-dim); padding: 0.15rem 0.5rem; border-radius: 99px; }

/* Exercises table in day editor */
.exercises-table-wrap { overflow-x: auto; }
.exercises-table {
  width: 100%; border-collapse: collapse; font-size: 0.875rem;
}
.exercises-table th {
  text-align: left; padding: 0.6rem 0.875rem;
  color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.exercises-table td { padding: 0.75rem 0.875rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.exercises-table tr:last-child td { border-bottom: none; }
.exercises-table tr:hover td { background: var(--bg-card2); }
.ex-cat-badge {
  font-size: 0.7rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 99px;
  text-transform: capitalize;
}
.ex-cat-badge.strength          { background: var(--accent-dim);  color: var(--accent);  }
.ex-cat-badge.conditioning      { background: var(--warning-dim); color: var(--warning); }
.ex-cat-badge.warmup            { background: rgba(74,222,128,0.15);  color: #22c55e; }
.ex-cat-badge.cardio_continuous { background: rgba(167,139,250,0.15); color: #a855f7; }
.ex-cat-badge.cardio_interval   { background: rgba(251,146,60,0.15);  color: #f97316; }

/* ── Category checkbox group (create / admin edit modals) ────────────────────── */
.category-checkbox-group { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.35rem; }
.cat-checkbox-label      { display: flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; cursor: pointer; }

/* ── Per-category badge buttons in add-exercise modal ───────────────────────── */
.add-ex-cats         { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.add-ex-cat-btn      { cursor: pointer; border: 2px solid transparent; transition: border-color 0.15s, box-shadow 0.15s; font-size: 0.72rem; }
.add-ex-cat-btn.selected { border-color: currentColor; box-shadow: 0 0 0 2px currentColor; }

/* ── Cardio session UI ───────────────────────────────────────────────────────── */
.cardio-phases        { display: flex; gap: 0.75rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.cardio-phase         { background: var(--bg-card2); border: 1px solid var(--border);
                        border-radius: var(--radius-sm); padding: 0.35rem 0.65rem;
                        font-size: 0.82rem; color: var(--text-muted); }
.cardio-phase.active  { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.cardio-phase.done    { opacity: 0.45; text-decoration: line-through; }
.cardio-timer-display { font-size: 0.95rem; font-weight: 600; margin: 0.4rem 0; }
.cardio-countdown     { font-size: 2rem; font-weight: 800; color: var(--accent); }

.sets-input { width: 64px; padding: 0.35rem 0.5rem; background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); text-align: center; font-size: 0.875rem; }
.sets-input:focus { outline: none; border-color: var(--accent); }

/* ── Breadcrumb ──────────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.875rem; color: var(--text-muted); margin-bottom: 1.25rem;
}
.breadcrumb-item { cursor: pointer; }
.breadcrumb-item:hover { color: var(--accent); }
.breadcrumb-sep { color: var(--text-dim); }

/* ── Active session ──────────────────────────────────────────────────────────── */
.progress-bar-outer {
  height: 6px; background: var(--bg-card2); border-radius: 99px;
  margin-bottom: 2rem; overflow: hidden;
}
.progress-bar-inner { height: 100%; background: var(--accent); transition: width 0.3s ease; border-radius: 99px; }
.progress-pill {
  font-size: 0.85rem; font-weight: 700; padding: 0.35rem 0.875rem;
  background: var(--accent-dim); color: var(--accent); border-radius: 99px;
}

.session-exercise-block {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.25rem;
}
.session-exercise-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.session-exercise-name { font-weight: 700; font-size: 1.05rem; }
.session-exercise-meta { display: flex; gap: 0.5rem; align-items: center; }

.sets-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.sets-table th {
  text-align: center; padding: 0.4rem 0.5rem;
  color: var(--text-dim); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.sets-table th.prev-col { color: var(--text-dim); }
.sets-table th.curr-col { color: var(--accent); }
.sets-table td { padding: 0.5rem; text-align: center; }
.sets-table td.set-num { color: var(--text-muted); font-weight: 600; }
.sets-table td.prev-val { color: var(--text-dim); font-size: 0.85rem; }
.sets-table tr:last-child td { border-bottom: none; }
.sets-table .divider-col { width: 1px; background: var(--border); padding: 0; }

.session-input {
  width: 80px; padding: 0.4rem 0.5rem;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  text-align: center; font-size: 0.875rem; font-family: var(--font);
}
.session-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(79,126,248,0.2); }
.session-input.filled { border-color: var(--success); background: rgba(34,197,94,0.06); }

.session-header-actions { display: flex; align-items: center; gap: 1rem; }
.session-footer { display: flex; align-items: center; gap: 1rem; margin-top: 2rem; flex-wrap: wrap; }

/* ── Summary ─────────────────────────────────────────────────────────────────── */
.summary-cards { display: flex; flex-direction: column; gap: 1.25rem; }
.summary-exercise-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.summary-ex-header { padding: 1rem 1.5rem; background: var(--bg-card2); display: flex; align-items: center; justify-content: space-between; }
.summary-ex-name { font-weight: 700; }
.summary-ex-body { padding: 1rem 1.5rem; }
.volume-comparison { display: flex; gap: 2rem; margin-bottom: 1rem; flex-wrap: wrap; }
.volume-stat { display: flex; flex-direction: column; gap: 0.15rem; }
.volume-stat-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); }
.volume-stat-value { font-size: 1.4rem; font-weight: 800; }
.volume-diff { font-size: 0.875rem; font-weight: 700; padding: 0.2rem 0.6rem; border-radius: 99px; }
.volume-diff.positive { color: var(--success); background: var(--success-dim); }
.volume-diff.negative { color: var(--danger);  background: var(--danger-dim); }
.volume-diff.neutral  { color: var(--text-muted); background: var(--bg-card2); }

.summary-sets-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; margin-top: 0.75rem; }
.summary-sets-table th { text-align: left; padding: 0.4rem 0.6rem; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.summary-sets-table td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); }
.summary-sets-table tr:last-child td { border-bottom: none; }

/* ── Library ─────────────────────────────────────────────────────────────────── */
.library-filters { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.library-grid { display: flex; flex-direction: column; gap: 0; }
.library-row {
  display: flex; align-items: center; padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border); background: var(--bg-card);
  transition: background 0.15s; gap: 0.75rem;
}
.library-row:first-child { border-radius: var(--radius) var(--radius) 0 0; border-top: 1px solid var(--border); }
.library-row:last-child  { border-radius: 0 0 var(--radius) var(--radius); }
.library-row:hover { background: var(--bg-card2); }
.lib-history-btn  { flex-shrink: 0; }
.library-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.2rem; }
.library-row-name { font-weight: 600; }
.lib-tags         { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.lib-meta-dim     { font-size: 0.7rem; color: var(--text-dim); }
.lib-tags-more    { display: none; font-size: 0.72rem; color: var(--text-muted); white-space: nowrap; }
.library-row-actions { display: flex; gap: 0.25rem; opacity: 0; transition: opacity 0.15s; flex-shrink: 0; }
.library-row:hover .library-row-actions { opacity: 1; }

/* ── Session Quote Card ──────────────────────────────────────────────────────── */
.modal-quote-card {
  text-align: center;
  padding: 2.25rem 2rem 2rem;
  border-color: var(--accent);
  position: relative;
  overflow: hidden;
}
.modal-quote-card::before {
  content: '\201C'; /* " */
  position: absolute; top: 0.5rem; left: 1rem;
  font-size: 5rem; line-height: 1;
  color: var(--accent); opacity: 0.15;
  font-family: Georgia, serif; pointer-events: none;
}
.quote-text {
  font-size: 1.15rem; font-style: italic; line-height: 1.65;
  color: var(--text); margin: 0.75rem 0 1.25rem;
  padding: 0 0.5rem;
}
.quote-source {
  font-size: 0.85rem; font-weight: 700;
  color: var(--accent); letter-spacing: 0.06em;
  text-transform: uppercase; margin-bottom: 1.75rem;
}

/* ── Modal ───────────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.65); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal {
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius-lg); padding: 1.75rem; width: 100%; max-width: 460px;
  box-shadow: var(--shadow);
  animation: modal-in 0.15s ease;
}
.modal-lg { max-width: 600px; }
@keyframes modal-in { from { opacity: 0; transform: scale(0.95) translateY(8px); } to { opacity: 1; transform: none; } }
.modal-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 1.25rem; }
.modal-body { color: var(--text-muted); margin-bottom: 1.25rem; line-height: 1.6; }
.modal-footer { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.25rem; }

.add-exercise-list { max-height: 280px; overflow-y: auto; display: flex; flex-direction: column; gap: 0; margin: 0.75rem 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.add-ex-row {
  padding: 0.7rem 0.875rem;
  border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 0.75rem;
}
.add-ex-row:last-child { border-bottom: none; }
.add-ex-row:hover { background: var(--bg-card2); }
.add-ex-row-name { font-weight: 600; flex: 1; font-size: 0.9rem; }

.add-ex-queue-label { font-size: 0.8rem; color: var(--text-muted); margin: 0.5rem 0 0.25rem; font-weight: 600; }
.add-ex-queue-item  { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.add-ex-queue-item:last-child { border-bottom: none; }
.add-ex-queue-name  { flex: 1; font-weight: 600; }
.add-ex-queue-input { width: 58px; }

/* ── Toast ───────────────────────────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 300; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
  padding: 0.75rem 1.25rem; border-radius: var(--radius); font-size: 0.875rem; font-weight: 600;
  box-shadow: var(--shadow); animation: toast-in 0.2s ease;
  min-width: 240px; max-width: 380px;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast-success { background: #15803d; color: #fff; }
.toast-error   { background: var(--danger); color: #fff; }
.toast-info    { background: var(--accent); color: #fff; }

/* ── Utilities ───────────────────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); font-size: 0.9rem; }
.text-dim    { color: var(--text-dim); }
.text-accent { color: var(--accent); }
.text-success{ color: var(--success); }
.text-danger { color: var(--danger); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.6s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state { display: flex; align-items: center; justify-content: center; padding: 3rem; gap: 0.75rem; color: var(--text-muted); }

/* ── Rest Timer ─────────────────────────────────────────────────────────────── */
.rest-timer {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), 0 0 24px rgba(79,126,248,0.2);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  z-index: 200;
  min-width: 280px;
}
.rest-timer-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}
.rest-timer-countdown {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
  min-width: 3.5rem;
  text-align: center;
}
.rest-timer-bar-wrap {
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  min-width: 60px;
}
.rest-timer-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.9s linear;
}

/* Set done tick button */
.done-col { width: 36px; text-align: center; }
.btn-tick {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border-light);
  background: transparent;
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-tick:hover { border-color: var(--success); color: var(--success); }
.btn-tick.done  { border-color: var(--success); background: var(--success-dim); color: var(--success); font-weight: 700; }
.set-done td { opacity: 0.6; }
.set-done .btn-tick { opacity: 1; }

/* Rest input in exercises table */
.rest-input {
  width: 64px;
  padding: 0.3rem 0.4rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  text-align: center;
}
.rest-input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── Exercise resting (timer active) ────────────────────────────────────────── */
.exercise-resting {
  opacity: 0.45;
  pointer-events: none;
  position: relative;
}
.exercise-resting::after {
  content: 'Resting…';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.06em;
  pointer-events: none;
}

/* ── Admin panel ─────────────────────────────────────────────────────────────── */
.admin-stats-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.admin-stat-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.5rem; display: flex; flex-direction: column; align-items: center; gap: 0.2rem;
  min-width: 90px;
}
.admin-stat-value { font-size: 1.75rem; font-weight: 800; color: var(--accent); }
.admin-stat-label { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }

.admin-users-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.admin-users-table th {
  text-align: left; padding: 0.5rem 0.75rem;
  color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}
.admin-users-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-users-table tr:last-child td { border-bottom: none; }
.admin-users-table tr:hover td { background: var(--bg-card2); }
.admin-count-cell { text-align: center; color: var(--text-muted); }
.admin-role-select, .admin-coach-select { padding: 0.3rem 0.5rem; font-size: 0.8rem; width: auto; }
.admin-detail-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border); gap: 1rem;
}
.admin-detail-row:last-child { border-bottom: none; }

/* ── Coach panel ─────────────────────────────────────────────────────────────── */
.coach-section { margin-bottom: 2rem; }
.coach-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.coach-section-title { font-size: 1.1rem; font-weight: 700; }
.coach-clients-list, .coach-templates-list { display: flex; flex-direction: column; gap: 0.75rem; }
.coach-client-card, .coach-template-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.25rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.coach-card-info { display: flex; flex-direction: column; gap: 0.2rem; flex: 1; }
.coach-card-name { font-weight: 700; }
.coach-card-meta { font-size: 0.8rem; color: var(--text-muted); }
.coach-template-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.coach-context-label { color: var(--accent); font-weight: 600; }

/* ── Scrollbar ──────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Bottom Nav ─────────────────────────────────────────────────────────────── */
:root {
  --bottomnav-h: 60px;
  --sai-top:     0px;   /* JS overrides on Android when env() = 0 */
  --sai-bottom:  0px;   /* JS overrides on Android when env() = 0 */
  --safe-top:    max(env(safe-area-inset-top,    0px), var(--sai-top));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--sai-bottom));
}

.bottomnav {
  /* In-flow flex item — always below the content, above iOS home indicator */
  flex-shrink: 0;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  background: rgba(26,29,39,0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex; align-items: stretch;
}
.bottomnav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0.2rem;
  color: var(--text-muted); text-decoration: none;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.bottomnav-item:hover { text-decoration: none; }
.bottomnav-item.active { color: var(--accent); }
.bottomnav-icon { font-size: 1.3rem; line-height: 1; }
.bottomnav-label { line-height: 1; }

/* Hide bottom nav on desktop */
@media (min-width: 769px) {
  .bottomnav { display: none !important; }
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Top nav: hide links (bottom nav handles navigation) */
  .topnav-links { display: none; }
  .nav-username  { display: none; }

  /* Toast: keep above bottom nav */
  .toast-container {
    bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 0.75rem);
    right: 0.75rem; left: 0.75rem;
    align-items: stretch;
  }
  .toast { min-width: unset; max-width: unset; width: 100%; }

  /* Rest timer: full-width above bottom nav */
  .rest-timer {
    left: 0.75rem; right: 0.75rem;
    bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 0.75rem);
    transform: none;
    min-width: unset;
    flex-wrap: wrap;
    gap: 0.75rem;
  }
  .rest-timer-label { max-width: none; flex-basis: 100%; order: -1; }

  /* Session exercise blocks */
  .session-exercise-block { padding: 1rem 0.75rem; }
  .session-exercise-header { flex-wrap: wrap; gap: 0.5rem; }

  /* Session sets table: hide previous-session columns to fit 4 cols on screen */
  .sets-table .prev-col,
  .sets-table .prev-val,
  .sets-table .divider-col { display: none; }

  /* Summary sets table: hide previous-session columns on mobile */
  .summary-sets-table .prev-val { display: none; }

  /* Larger touch targets for inputs and tick button */
  .session-input {
    width: 72px;
    padding: 0.55rem 0.4rem;
    font-size: 1rem;
  }
  .sets-table th, .sets-table td { padding: 0.45rem 0.3rem; }

  .done-col { width: 44px; }
  .btn-tick { width: 38px; height: 38px; font-size: 1.1rem; }

  /* Session footer: stack buttons full-width */
  .session-footer {
    flex-direction: column;
    gap: 0.75rem;
  }
  .session-footer .btn { width: 100%; }

  /* Dashboard grid: single column */
  .dashboard-grid { grid-template-columns: 1fr; }

  /* Plans grid: single column */
  .plans-grid { grid-template-columns: 1fr; }

  /* Plan/day builder exercises table: allow horizontal scroll */
  .exercises-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Library: always show action buttons (no hover on touch); collapse extra tags */
  .library-row-actions { opacity: 1; }
  .lib-tag-x           { display: none; }
  .lib-tags-more       { display: inline-block; }

  /* Page header */
  .page-title { font-size: 1.25rem; }

  /* Modals: sit at bottom like a sheet */
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
  }

  .weight-log-form { flex-direction: column; gap: 0.75rem; }
  .weight-log-form .form-group { min-width: unset; width: 100%; }
  .weight-log-form .btn { width: 100%; align-self: stretch; }
  .profile-card-body { padding: 1rem; }
  .profile-card-body .btn { width: 100%; text-align: center; }
}

/* ── Profile view ────────────────────────────────────────────────────────────── */
.profile-grid {
  display: grid;
  /* auto-collapses to 1 column when viewport is too narrow — no media query needed */
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 1.5rem;
}
.profile-card-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.profile-card-body .form-group { margin-bottom: 0.75rem; }
.profile-card-body .btn { align-self: flex-start; margin-top: 0.25rem; }

/* Weight tracker */
.weight-log-form {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.weight-log-form .form-group { margin-bottom: 0; flex: 1; min-width: 120px; }
.weight-log-form .btn { flex-shrink: 0; align-self: flex-end; }

.weight-history-table {
  width: 100%; border-collapse: collapse; font-size: 0.875rem;
}
.weight-history-table th {
  text-align: left; padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border); color: var(--text-muted);
  font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em;
}
.weight-history-table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border-subtle, var(--border)); }
.weight-history-table tr:last-child td { border-bottom: none; }
.weight-val { font-weight: 600; }
.weight-del-cell { text-align: right; }

/* ── Pending approval screen ─────────────────────────────────────────────────── */
.auth-card-pending { text-align: center; }
.pending-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.pending-message {
  color: var(--text-muted); font-size: 0.9375rem;
  line-height: 1.6; margin: 0.75rem 0 1.5rem;
}

/* ── Admin: enable/disable ───────────────────────────────────────────────────── */
.user-row-pending td { opacity: 0.6; }
.user-row-pending td:first-child { opacity: 1; }
.badge-pending {
  display: inline-block; vertical-align: middle;
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.1rem 0.45rem; border-radius: 999px; margin-left: 0.4rem;
  background: rgba(245,158,11,0.15); color: #f59e0b;
  border: 1px solid rgba(245,158,11,0.3);
}
.admin-row-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: nowrap; }
.btn-success { background: #22c55e; color: #000; border: none; }
.btn-success:hover { background: #16a34a; }

/* ── Dashboard: session history detail ──────────────────────────────────────── */
.recent-session-clickable { cursor: pointer; border-radius: var(--radius-sm); transition: background 0.12s; }
.recent-session-clickable:hover { background: var(--bg-card2); margin: 0 -0.5rem; padding-left: 0.5rem; padding-right: 0.5rem; }
.dash-detail-title { font-weight: 700; font-size: 0.95rem; margin-top: 0.15rem; }
.dash-edit-footer { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.25rem; }
.hist-exercise-block { margin-bottom: 1.5rem; }
.hist-exercise-block:last-child { margin-bottom: 0; }
.hist-exercise-name { font-weight: 700; font-size: 0.95rem; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 0.5rem; }
.hist-sets-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.hist-sets-table th { text-align: left; padding: 0.4rem 0.6rem; color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.hist-sets-table td { padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--border); }
.hist-sets-table tr:last-child td { border-bottom: none; }

/* ── Dashboard: quick weight card ───────────────────────────────────────────── */
.dash-weight-card { margin-top: 1.5rem; }
.dash-weight-form { display: flex; align-items: center; gap: 0.75rem; }
.dash-weight-form .form-input { max-width: 140px; }
.dash-weight-unit { color: var(--text-muted); font-size: 0.9rem; font-weight: 600; flex-shrink: 0; }
.dash-weight-logged { font-size: 0.85rem; font-weight: 700; color: var(--success); }
@media (max-width: 768px) {
  .dash-weight-form .form-input { max-width: unset; flex: 1; }
}

/* ── DNF badge ───────────────────────────────────────────────────────────────── */
.dnf-badge {
  color: #e74c3c; font-weight: 700; font-size: 0.8rem;
}

/* ── Dashboard: total weight in history ─────────────────────────────────────── */
.recent-session-weight {
  font-size: 0.8rem; font-weight: 700;
  color: var(--accent); text-align: right;
}
.dash-detail-total-weight {
  font-size: 0.8rem; font-weight: 600;
  color: var(--accent); margin-top: 0.15rem;
}

/* ── Analyzer view ───────────────────────────────────────────────────────────── */
.analyzer-section { margin-bottom: 1.5rem; }
.analyzer-select  {
  display: block; width: 100%;
  margin: 0.75rem 0 0.5rem;
}
.chart-container  {
  position: relative;
  height: 280px;
  margin-top: 0.75rem;
}
@media (min-width: 600px) {
  .chart-container { height: 320px; }
}

/* ── Active Session Banner ───────────────────────────────────────────────────── */
#active-session-banner {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--card);
  border: 1px solid var(--accent);
  border-radius: 2rem;
  padding: 0.45rem 0.9rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  z-index: 900;
  white-space: nowrap;
  font-size: 0.85rem;
}
.session-banner-dot {
  color: var(--accent);
  font-size: 0.7rem;
  animation: banner-pulse 1.4s ease-in-out infinite;
}
@keyframes banner-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.25; }
}
.session-banner-name  { font-weight: 600; max-width: 12rem; overflow: hidden; text-overflow: ellipsis; }
.session-banner-progress { color: var(--text-muted); font-size: 0.8rem; }
.session-banner-btn   { padding: 0.25rem 0.75rem; font-size: 0.8rem; border-radius: 1rem; }
@media (max-width: 768px) {
  #active-session-banner {
    bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 0.75rem);
    left: 0.75rem;
    right: 0.75rem;
    transform: none;
    border-radius: 1rem;
  }
}

/* ── RPE / RIR inputs ────────────────────────────────────────────────────── */
.rpe-input, .rir-input {
  width: 56px !important;
  text-align: center;
}
.rpe-header, .rir-header {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* ── RPE / RIR plan builder toggles ─────────────────────────────────────── */
.rpe-rir-cell { white-space: nowrap; }
.rpe-rir-label {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  cursor: pointer;
  margin-right: 0.4rem;
}
.rpe-rir-label input[type="checkbox"] { accent-color: var(--accent); }

/* ── Muscle group tags ───────────────────────────────────────────────────── */
.muscle-group-tag {
  display: inline-block;
  background: rgba(79,126,248,0.1);
  color: var(--accent);
  border: 1px solid rgba(79,126,248,0.3);
  border-radius: 0.9rem;
  padding: 0.1rem 0.45rem;
  font-size: 0.68rem;
  font-weight: 500;
  margin-right: 0.2rem;
}

/* ── History chart modal ─────────────────────────────────────────────────── */
.chart-tab {
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  padding: 0.3rem 0.75rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.chart-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Session comments ────────────────────────────────────────────────────── */
.comment-block {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.comment-block:last-child { border-bottom: none; }
.comment-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}
.comment-body {
  font-size: 0.88rem;
  color: var(--text);
  white-space: pre-wrap;
}
.comment-role-badge {
  display: inline-block;
  background: rgba(245,158,11,0.15);
  color: var(--warning);
  border-radius: 0.5rem;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
}

/* ── Activity Calendar ──────────────────────────────────────────────────── */
.dash-calendar-card { margin-top: 1rem; }
/* Stack label above month-nav so it never overflows on narrow screens */
.dash-calendar-card .card-header { flex-direction: column; align-items: center; gap: 0.4rem; }
.cal-nav            { display: flex; align-items: center; gap: 0.4rem; width: 100%; justify-content: center; }
.cal-month-label    { font-size: 0.875rem; font-weight: 600; min-width: 9rem; text-align: center; }
.cal-grid           { padding: 0.75rem 0.5rem 0.5rem; }
.cal-loading        { display: flex; justify-content: center; padding: 2rem; }
.cal-dow-row {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 3px; margin-bottom: 4px;
}
.cal-dow   { text-align: center; font-size: 0.7rem; font-weight: 600; color: var(--text-dim); padding: 2px 0; }
.cal-cells { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-cell  {
  aspect-ratio: 1; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; color: var(--text-muted);
}
.cal-cell-empty { background: transparent; }
.cal-day-num    { line-height: 1; }
.cal-today { outline: 2px solid var(--accent); outline-offset: 1px; color: var(--text); }
.cal-lo    { background: rgba(79,126,248,0.18); color: var(--text); }
.cal-mid   { background: rgba(79,126,248,0.45); color: var(--text); }
.cal-hi    { background: var(--accent);          color: #fff; }
