* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #eef2ff;
  --bg-card: #ffffff;
  --bg-input: #eef2ff;
  --accent: #190080;
  --accent-dim: #0f0c5d;
  --text: #0f0c5d;
  --text-dim: #6b82a0;   /* accessible secondary text — 4.5:1 on white */
  --text-muted: #4f6a88; /* accessible tertiary text — 6.5:1 on white */
  --text-faint: #b7c5d9; /* decorative only (chevrons, dividers) — fails contrast as text */
  --text-warn: #6a0005;
  --danger: #a0001a;     /* destructive actions — distinct from warmup dark-red */
  --interactive-bg: #cdd5e8;
  --success: #117743;
  --border: #d6daf0;
  --superset-bg: #d6daf0;
  --olive: #7a983a;
  --warmup-bg: #feffee;
  --warmup-text: #6a0005;
  --stretch-bg: #e8f5f0;
  --stretch-text: #1a5c40;
  --beige: #ede0d6;
  --duration-bg: #d6daf0;
  --duration-text: #0f0c5d;
  --success-dim: #7a983a;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

/* --- Loading Skeletons --- */
.skeleton-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
}

.skeleton-line {
  height: 12px;
  border-radius: 6px;
  margin-bottom: 10px;
  background: linear-gradient(90deg, var(--bg-input) 25%, var(--border) 50%, var(--bg-input) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}

.skeleton-line:last-child {
  margin-bottom: 0;
}

.skeleton-line-wide { width: 60%; height: 16px; }
.skeleton-line-short { width: 35%; }

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton-line { animation: none; }
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  background: rgba(24, 27, 31, 0.94);
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.3;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18);
  z-index: 1000;
  max-width: min(88vw, 340px);
  text-align: center;
}

.app-toast.hidden {
  display: none;
}

#app {
  padding-bottom: 70px;
  max-width: 480px;
  margin: 0 auto;
}

body.auth-active #app {
  display: none;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: var(--bg);
}

.auth-card {
  width: min(100%, 360px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 12px 30px rgba(15, 12, 93, 0.12);
}

.auth-title {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 18px;
  color: var(--text);
}

.auth-field {
  display: block;
  margin-bottom: 12px;
}

.auth-field span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.auth-field input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 16px;
}

.auth-submit {
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

.auth-link-btn {
  width: 100%;
  margin-top: 10px;
  padding: 8px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.auth-helper-text {
  margin: 8px 0 12px;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 8px 12px;
  max-width: 480px;
  margin: 0 auto;
  /* Light surface visually demotes the bar below the workout content it frames */
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.account-name {
  font-weight: 700;
}

.account-menu {
  position: relative;
}

.account-menu-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
}

.account-role {
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.account-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 150;
  min-width: 190px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  box-shadow: 0 12px 28px rgba(15, 12, 93, 0.16);
}

.account-menu-list button {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.account-menu-list button:hover {
  background: var(--bg-input);
}

.account-modal-form {
  display: grid;
  gap: 10px;
}

.account-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}

.account-sessions-list {
  display: grid;
  gap: 10px;
}

.account-session-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
}

.account-session-title {
  font-weight: 800;
}

.account-session-meta {
  margin-top: 3px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.35;
}

.account-session-current {
  flex: 0 0 auto;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.admin-panel {
  display: grid;
  gap: 14px;
}

.admin-invite-form {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
}

.admin-invite-form input,
.admin-invite-form select {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
}

.admin-result {
  color: var(--text-dim);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.admin-section-title {
  font-size: 12px;
  font-weight: 900;
  color: var(--text-dim);
  text-transform: uppercase;
}

.admin-list {
  display: grid;
  gap: 8px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
}

.admin-row-title {
  font-weight: 800;
}

.admin-row-meta {
  margin-top: 3px;
  color: var(--text-dim);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.admin-row-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.admin-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-dim);
  font-size: 10px;
  text-transform: uppercase;
}

.admin-events {
  display: grid;
  gap: 6px;
}

.admin-event-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  color: var(--text-dim);
  font-size: 12px;
}

@media (max-width: 430px) {
  .admin-invite-form,
  .admin-row,
  .admin-event-row {
    grid-template-columns: 1fr;
  }

  .admin-row-actions {
    justify-content: flex-start;
  }
}

/* --- Bottom Nav --- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 0 8px;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  touch-action: manipulation; /* disable double-tap-to-zoom so both taps fire immediately */
}

.nav-btn.active {
  color: var(--accent);
}

.nav-icon {
  font-size: 18px;
}

/* --- Tabs --- */
.tab-content {
  display: none;
  padding: 12px;
}

.tab-content.active {
  display: block;
}

.tab-content h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: var(--text-dim);
}

/* --- Week Nav --- */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 0 8px;
}

.week-nav span {
  font-size: 15px;
  font-weight: 600;
  min-width: 160px;
  text-align: center;
}

.btn-today {
  width: auto;
  min-width: 58px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
}

.template-duplicate-btn {
  margin-left: 8px;
  flex-shrink: 0;
}

/* --- Week Strip --- */
.week-strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 4px 0 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.week-strip::-webkit-scrollbar {
  display: none;
}

.week-day {
  flex: 1 1 0;
  min-width: 0;
  padding: 8px 4px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  box-shadow: 0 1px 3px rgba(15, 12, 93, 0.08);
}

.week-day:active {
  background: var(--bg-input);
}

.week-day.selected {
  border-color: var(--accent);
  background: var(--bg-input);
}

.week-day.today {
  border-color: var(--success);
}

.week-day.today.selected {
  border-color: var(--accent);
}

.week-day-name {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.week-day-date {
  font-size: 18px;
  font-weight: 700;
  margin: 2px 0;
}

.week-day-workout {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.week-day-workout.rest {
  color: var(--text-dim);
  font-weight: 400;
}

.week-day-workout-stretch {
  color: var(--stretch-text);
}

/* "+N" count for days with multiple scheduled templates */
.week-day-more {
  display: inline-block;
  background: var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 0 4px;
  font-size: 9px;
  font-weight: 700;
}

.js-weight-trend-card .progress-chart-svg {
  touch-action: none;
}

.week-day.has-workout {
  border-color: var(--success);
}

.week-day.has-workout.selected {
  border-color: var(--accent);
}

.week-day-done {
  color: var(--success);
  font-weight: 700;
}

/* --- Preview Banner --- */
.preview-banner {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 6px 0 10px;
}

.preview-card {
  opacity: 0.7;
}

/* --- Buttons --- */
.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon:active {
  background: var(--bg-input);
}

.btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
}

.btn:active {
  background: var(--accent-dim);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 12px;
  min-height: 36px;
}

.btn-outline {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:active {
  background: var(--bg-input);
}

.btn-danger {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
}

/* Inline legend trigger inside the template editor body */
.tmpl-inline-legend-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
  min-height: 36px;
  display: block;
  margin-left: auto;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}

.tmpl-inline-legend-btn:active {
  color: var(--accent);
}

/* Danger zone: keeps Delete Template visually and spatially apart from Add Exercise */
.template-danger-zone {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

/* --- Exercise Card --- */
.exercise-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15, 12, 93, 0.08);
}

.exercise-card.skipped {
  opacity: 0.5;
}

.exercise-card.stretch-card {
  background: var(--stretch-bg);
  border-color: #a8d8c8;
}
.exercise-card.stretch-card.stretch-done {
  opacity: 0.6;
}
.stretch-done-btn {
  background: none;
  border: 2px solid #a8d8c8;
  border-radius: 50%;
  color: #a8d8c8;
  width: 28px;
  height: 28px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-left: auto;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.stretch-done-btn.done {
  background: var(--stretch-text);
  border-color: var(--stretch-text);
  color: #fff;
}

.exercise-card.superset-start {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-bottom: 0;
  border-bottom: none;
}

.exercise-card.superset-mid {
  border-radius: 0;
  margin-bottom: 0;
  border-bottom: none;
  border-top: 1px dashed var(--border);
}

.exercise-card.superset-end {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  border-top: 1px dashed var(--border);
}

.superset-label {
  font-size: 11px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 6px;
}

.exercise-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.exercise-name {
  font-size: 15px;
  font-weight: 600;
  flex: 1;
}

.exercise-target {
  font-size: 13px;
  color: var(--text-dim);
  margin-left: 8px;
}

.exercise-sub-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.previous-data {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-style: italic;
}

.previous-data.prev-note {
  margin-bottom: 8px;
  color: var(--text-warn);
  opacity: 0.8;
}

.template-note {
  font-size: 0.82em;
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 6px;
  padding: 2px 4px;
  border-left: 2px solid var(--border);
  cursor: pointer;
}
.template-note:hover {
  border-left-color: var(--accent);
  color: var(--text);
}

/* --- Default note inline editor --- */
.default-note-edit-btn {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.9em;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0.6;
}
.default-note-edit-btn:hover {
  opacity: 1;
  color: var(--accent);
  background: var(--bg-alt);
}
.default-note-edit-wrapper {
  margin-bottom: 6px;
}
.default-note-input {
  width: 100%;
  font-size: 0.82em;
  padding: 3px 6px;
  border: 1px solid var(--accent);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  box-sizing: border-box;
}

/* --- Assisted Badge --- */
.assisted-badge {
  display: inline-block;
  background: var(--beige);
  color: #6b4226;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 8px;
  cursor: help;
}

/* --- Set Row --- */
.set-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.warmup-set-row {
  background: rgba(196, 154, 108, 0.12);
  border: 1px solid rgba(196, 154, 108, 0.28);
  border-radius: 8px;
  padding: 5px 6px;
  margin-left: -7px;
  margin-right: -7px;
}

.set-label {
  font-size: 12px;
  color: var(--text-dim);
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}

.set-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px;
  font-size: 16px;
  width: 70px;
  text-align: center;
  -moz-appearance: textfield;
}

.set-input::-webkit-inner-spin-button,
.set-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.set-input:focus {
  border-color: var(--accent);
  outline: none;
}

.set-input.partial {
  border-color: var(--text-warn);
}

.set-separator {
  color: var(--text-dim);
  font-size: 12px;
}

.set-unit {
  color: var(--text-dim);
  font-size: 12px;
  width: 20px;
}

.warmup-set-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  width: 52px;
  flex-shrink: 0;
}

/* --- Per-Set AMRAP Toggle --- */
.amrap-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 4px 8px;
  min-width: 36px;
  min-height: 36px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  position: relative;
}

/* Expand touch target toward 44px without crowding the set row */
.amrap-toggle::after {
  content: '';
  position: absolute;
  inset: -4px;
}

.amrap-toggle.active {
  background: var(--beige);
  border-color: var(--beige);
  color: var(--text);
}

/* --- AMRAP Marker in History --- */
.amrap-marker {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  margin-left: 2px;
  vertical-align: super;
}

/* --- Set Actions (add/remove) --- */
.set-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
  margin-bottom: 4px;
}

/* --- Exercise Note --- */
.exercise-note {
  margin-top: 8px;
}

.exercise-note textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  min-height: 36px;
}

.exercise-note textarea:focus {
  border-color: var(--accent);
  outline: none;
}

.default-note {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* --- Reorder Buttons --- */
.reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reorder-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 6px 12px;
  line-height: 1;
  position: relative;
}

/* Expand touch target — the two stacked arrows split a ~44px-wide column */
.reorder-btn::after {
  content: '';
  position: absolute;
  inset: -2px -6px;
}

.reorder-btn:active {
  color: var(--accent);
}

/* --- History --- */
.history-week {
  margin-bottom: 16px;
}

.history-week-header {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 4px;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(15, 12, 93, 0.08);
}

.history-item:active {
  background: var(--bg-input);
}

/* Imported (Apple Watch) sessions: subtle cool-blue border distinguishes them
   from self-logged workouts without shouting */
.history-item-external {
  border: 1px solid var(--superset-bg);
  box-shadow: none;
}

.history-watch-icon {
  font-size: 12px;
}

.history-date {
  font-weight: 600;
  font-size: 14px;
}

.history-day {
  font-size: 13px;
  color: var(--text-dim);
}

.history-detail-card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15, 12, 93, 0.08);
}

.history-exercise-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  cursor: pointer;
  color: var(--accent);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

/* Click affordance — decorative, so the low-contrast faint grey is fine here */
.history-chevron {
  color: var(--text-faint);
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.history-exercise-name:hover {
  text-decoration: underline;
}

.history-sets {
  font-size: 13px;
  color: var(--text-dim);
}

.history-back {
  margin-bottom: 12px;
}

/* --- Template Sub-tabs --- */
.template-tab-headers {
  display: flex;
  gap: 4px;
  padding: 0 0 12px;
}

.template-tab-btn {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}

.template-tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}


/* --- Template --- */
.template-day {
  background: var(--bg-card);
  border-radius: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(15, 12, 93, 0.08);
}

.template-day-header {
  display: flex;
  flex-direction: column;
  font-weight: 600;
}

.tmpl-header-main {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
}

.tmpl-header-main:active {
  background: var(--bg-input);
}

.tmpl-header-actions {
  display: flex;
  gap: 8px;
  padding: 0 14px 10px;
  align-items: center;
  flex-wrap: wrap;
  width: 100%;
}

.template-day-label {
  min-width: 90px;
  font-size: 14px;
  color: var(--text-dim);
}

.template-day-name-input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
}

.template-day-name-input:focus {
  border-color: var(--accent);
  outline: none;
}

.template-day-name-input::placeholder {
  color: var(--text-dim);
  font-weight: 400;
}

.template-chevron {
  font-size: 18px;
  color: var(--text-dim);
  padding-left: 4px;
}

.template-day-body {
  display: none;
  padding: 0 14px 14px;
}

.template-day-body.open {
  display: block;
}

.template-exercise {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.template-exercise:last-child {
  border-bottom: none;
}

.template-exercise-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.template-reorder-btns {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.template-reorder-btns .reorder-btn {
  width: 22px;
  height: 18px;
  font-size: 10px;
  padding: 0;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 4px;
  cursor: pointer;
}

.template-reorder-btns .reorder-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.template-exercise-info {
  flex: 1;
  min-width: 0;
}

.template-exercise-name {
  font-size: 14px;
}

.template-exercise-detail {
  font-size: 12px;
  color: var(--text-dim);
}

.template-exercise-note {
  font-size: 11px;
  color: var(--text-dim);
  font-style: italic;
  margin-top: 2px;
}

.template-exercise-actions {
  display: grid;
  grid-template-columns: repeat(2, max-content);
  grid-auto-flow: row;
  gap: 4px;
  align-items: center;
  justify-content: end;
  flex-shrink: 0;
}

.tmpl-ss-toggle,
.tmpl-gs-toggle,
.tmpl-warmup-toggle,
.tmpl-duration-toggle,
.tmpl-assisted-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  cursor: pointer;
}

.tmpl-ss-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.tmpl-gs-toggle {
  border-color: var(--accent);
  color: var(--accent);
}

.tmpl-warmup-toggle.active {
  background: var(--warmup-text);
  border-color: var(--warmup-text);
  color: white;
}

.tmpl-duration-toggle.active {
  background: var(--duration-text);
  border-color: var(--duration-text);
  color: white;
}

.tmpl-assisted-toggle.active {
  background: var(--beige);
  border-color: #a0724e;
  color: #6b4226;
}

.tmpl-amrap-toggle,
.tmpl-amrap-last-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 4px;
  cursor: pointer;
}

.tmpl-amrap-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.tmpl-amrap-last-toggle.active {
  background: var(--accent-dim);
  border-color: var(--accent-dim);
  color: white;
}

.tmpl-superset-start {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  margin-top: 4px;
  border-bottom: none;
}

.tmpl-superset-mid {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  border-bottom: none;
}

.tmpl-superset-end {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  margin-bottom: 4px;
}

.tmpl-superset-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 2px;
}

.add-exercise-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.add-exercise-form input:not([type="checkbox"]),
.add-exercise-form select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px;
  font-size: 14px;
  width: 100%;
  margin-bottom: 6px;
}

.add-exercise-form input:not([type="checkbox"]):focus,
.add-exercise-form select:focus {
  border-color: var(--accent);
  outline: none;
}

.add-exercise-row {
  display: flex;
  gap: 6px;
}

.add-exercise-row input {
  width: auto;
  flex: 1;
}

/* --- Modal --- */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 12, 93, 0.3);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

/* --- Confirmation Dialog (destructive actions) --- */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 12, 93, 0.3);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.confirm-box {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 18px;
  width: min(100%, 320px);
  box-shadow: 0 12px 30px rgba(15, 12, 93, 0.2);
}

.confirm-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 8px;
}

.confirm-message {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 14px;
  line-height: 1.4;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.confirm-cancel {
  background: var(--border);
  color: var(--text);
}

.confirm-danger {
  background: var(--danger);
  color: white;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  /* No padding here — header and body carry their own padding so the
     sticky header can extend edge-to-edge without a gap. */
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 16px 12px;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  border-radius: 16px 16px 0 0;
  border-bottom: 1px solid var(--border);
  z-index: 1;
}

.modal-header h3 {
  font-size: 16px;
}

#progression-body {
  padding: 12px 16px 16px;
}

.template-legend {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.template-legend-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 12px;
  align-items: start;
}

.template-legend-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
}

.template-legend-copy {
  color: var(--text);
  font-size: 13px;
  line-height: 1.35;
}

/* --- Progression --- */
.progression-table {
  width: 100%;
  font-size: 13px;
  border-collapse: collapse;
}

.progression-table th {
  text-align: left;
  color: var(--text-dim);
  padding: 6px 4px;
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}

.progression-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}

.progression-table .partial {
  color: var(--text-warn);
}

.progression-table .skipped-row {
  color: var(--text-dim);
  font-style: italic;
}

.progression-volume {
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
}

.trend-up { color: var(--success); }
.trend-down { color: var(--text-warn); }
.trend-flat { color: var(--text-dim); }

/* --- Set Completion Checkbox --- */
.set-check {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  color: transparent;
  transition: all 0.15s;
  position: relative;
}

/* Expand the touch target to ~44px without growing the visual size */
.set-check::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}

.set-check.done {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

@media (hover: hover) {
  .set-check.done:hover {
    background: var(--border);
    border-color: var(--border);
  }
}

/* --- Warmup Badge --- */
.warmup-badge {
  display: inline-block;
  background: var(--warmup-bg);
  color: var(--warmup-text);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 8px;
}

/* --- Stretch Badge --- */
.stretch-badge {
  display: inline-block;
  background: var(--stretch-bg);
  color: var(--stretch-text);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 8px;
  border: 1px solid #a8d8c8;
}

/* Stretch set rows: no checkbox, just label + input */
.stretch-card .set-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Duration Badge --- */
.duration-badge {
  display: inline-block;
  background: var(--duration-bg);
  color: var(--duration-text);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 8px;
}

/* --- AMRAP Badge --- */
.amrap-badge {
  display: inline-block;
  background: var(--border);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 8px;
}


.add-toggles-row {
  display: flex;
  gap: 6px;
  margin: 4px 0 8px;
}

/* --- Duration Input --- */
.duration-input {
  width: 100px;
}

/* --- Begin Workout --- */
.begin-workout {
  text-align: center;
  padding: 40px 20px;
}

.begin-workout-btn {
  background: var(--success);
  color: white;
  border: none;
  padding: 14px 32px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.begin-workout-btn:active {
  background: var(--success-dim);
}

.begin-workout-day {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 12px;
}

/* --- Skip Toggle --- */
.skip-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 8px 12px;
  min-height: 36px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
}

.skip-toggle:active {
  background: var(--bg-input);
}

.skip-toggle.is-skipped {
  background: var(--text-warn);
  border-color: var(--text-warn);
  color: white;
}

/* --- Swap / Alt exercise --- */
.swap-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-dim);
  padding: 8px 12px;
  min-height: 36px;
  font-size: 12px;
  cursor: pointer;
  margin-left: 6px;
}

.swap-toggle:active {
  background: var(--bg-input);
}

.swap-toggle.is-swapped {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.swap-badge {
  display: inline-block;
  font-size: 13px;
  margin-left: 4px;
  color: var(--accent);
  vertical-align: middle;
}

.swap-panel {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.swap-input {
  flex: 1;
  min-width: 160px;
  background: var(--bg-input);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 8px;
  font-size: 13px;
  font-family: inherit;
}

.swap-input:focus {
  outline: none;
}

/* --- Add Exercise to Workout --- */
.add-exercise-to-workout {
  margin: 12px 0 4px;
  text-align: center;
}

.add-ex-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.add-ex-name {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--accent);
  border-radius: 4px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}

.add-ex-name:focus {
  outline: none;
}

.add-ex-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.add-ex-sets {
  width: 56px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 13px;
  font-family: inherit;
}

.add-ex-reps {
  width: 56px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 4px 6px;
  font-size: 13px;
  font-family: inherit;
}

.add-ex-after-label {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}

.add-ex-after {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 13px;
  font-family: inherit;
  flex: 1;
}

.add-ex-template-label {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.add-ex-actions {
  display: flex;
  gap: 8px;
}

/* --- Workout Section Header (multi-template per day) --- */
.workout-section-header {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 12px 0 6px;
  border-bottom: 2px solid var(--accent);
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.workout-delete-btn {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 500;
}

.history-template-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  padding: 8px 0 4px;
  margin-top: 8px;
}

/* --- Template Section --- */
.template-section {
  margin-bottom: 24px;
}

.template-section-title {
  font-size: 14px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  font-weight: 600;
}

/* --- Schedule Day Row --- */
.schedule-day-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 6px;
  box-shadow: 0 1px 3px rgba(15, 12, 93, 0.08);
}

.schedule-day-label {
  min-width: 40px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.schedule-chips {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.schedule-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.schedule-chip.schedule-chip-stretch {
  background: var(--stretch-bg);
  border-color: #a8d8c8;
  color: var(--stretch-text);
}
.schedule-chip.dragging {
  opacity: 0.4;
}
.schedule-chip.drag-over-before {
  border-left: 2px solid var(--accent);
}
.schedule-chip.drag-over-after {
  border-right: 2px solid var(--accent);
}

.schedule-chip-remove {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}

.schedule-chip-remove:active {
  color: var(--text-warn);
}

.schedule-add-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px dashed var(--border);
  background: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.schedule-add-btn:active {
  background: var(--bg-input);
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Schedule Dropdown --- */
.schedule-dropdown {
  position: absolute;
  z-index: 50;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(15, 12, 93, 0.15);
  min-width: 160px;
  max-height: 200px;
  overflow-y: auto;
  margin-top: 4px;
}

.schedule-dropdown-option {
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.schedule-dropdown-option:last-child {
  border-bottom: none;
}

.schedule-dropdown-option:active {
  background: var(--bg-input);
}

/* --- Create Template Form --- */
.create-template-btn {
  width: 100%;
  margin-bottom: 12px;
}

.create-template-form {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 12px;
}

.create-template-form .template-day-name-input {
  flex: 1;
}

/* --- Template "After:" position selector --- */
.add-after-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85em;
  color: var(--text-dim);
  margin-top: 4px;
}
.add-after-label select {
  flex: 1;
  font-size: 0.9em;
}

/* --- Template Footer Actions (Add Exercise + Delete Template) --- */
.template-footer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}


/* --- Position relative for dropdown parent --- */
.schedule-chips {
  position: relative;
}

/* --- Inline Edit (Template Exercises) --- */
.template-exercise-editable {
  cursor: pointer;
  min-width: 0;
  flex: 1;
  margin-right: 8px;
}

.inline-edit-form {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.inline-edit-form input {
  background: var(--bg-input);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 13px;
  font-family: inherit;
}

.inline-edit-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.inline-edit-name,
.inline-edit-note {
  width: 100%;
}

.inline-edit-row {
  display: flex;
  gap: 4px;
  align-items: center;
}

.inline-targets-row {
  flex-wrap: wrap;
}

.inline-edit-sets,
.inline-edit-reps,
.inline-edit-warmup-weight,
.inline-edit-warmup-reps {
  width: 60px;
}

.inline-edit-x {
  color: var(--text-dim);
  font-size: 12px;
}

.inline-edit-label {
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  margin-left: 8px;
}

/* --- Linked exercise indicator --- */
.linked-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: var(--accent);
  margin-top: 2px;
  opacity: 0.85;
}

.linked-indicator.targets-independent {
  color: var(--text-dim);
  opacity: 1;
}

.sync-chain-icon {
  flex-shrink: 0;
}

/* --- Sync targets toggle button in inline edit form --- */
.sync-targets-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid;
  cursor: pointer;
  background: transparent;
  transition: color 0.15s, border-color 0.15s;
  line-height: 1.2;
  margin-bottom: 2px;
}

.sync-targets-btn.is-synced {
  color: var(--success);
  border-color: var(--success);
}

.sync-targets-btn.is-independent {
  color: var(--text-dim);
  border-color: var(--border);
}

/* --- Archived (soft-deleted) exercises in template editor --- */
.archived-exercises {
  margin: 8px 0;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.archived-exercises > summary {
  cursor: pointer;
  color: var(--text-dim);
  padding: 4px 0;
  user-select: none;
}
.archived-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}
.archived-row:first-of-type { border-top: none; margin-top: 4px; }
.archived-info { flex: 1; min-width: 0; }
.archived-name { font-weight: 500; }
.archived-meta { font-size: 11px; color: var(--text-dim); margin-top: 1px; }
.archived-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* --- Copy weight button --- */
.copy-weight-btn {
  margin-left: auto;
}

.mark-all-done-btn {
  min-width: 74px;
}

/* --- Utility --- */
.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.mt-8 { margin-top: 8px; }
.mb-8 { margin-bottom: 8px; }
.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
}

/* --- Body Tab --- */

.body-today-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 16px 16px;
  margin-bottom: 12px;
  text-align: center;
}

.body-today-label {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.body-today-date {
  font-size: 13px;
  color: var(--text);
  margin-bottom: 14px;
}

.body-weight-entry {
  min-width: 0;
}

/* Quiet backfill affordance — yesterday's entry is optional, today's is primary */
.body-prev-toggle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  min-height: 36px;
  margin-top: 8px;
}

.body-prev-toggle:active {
  color: var(--accent);
}

.body-prev-toggle.hidden,
.body-prev-row.hidden {
  display: none;
}

.body-prev-row {
  margin-top: 8px;
}

.body-prev-row .body-today-input {
  font-size: 24px;
}

.body-today-input-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
}

.body-today-input {
  width: 110px;
  font-size: 36px;
  font-weight: 700;
  text-align: center;
  border: none;
  border-bottom: 2px solid var(--accent);
  background: transparent;
  color: var(--text);
  padding: 4px 0;
  -moz-appearance: textfield;
}
.body-today-input::-webkit-outer-spin-button,
.body-today-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.body-today-input:focus { outline: none; }

.body-today-unit {
  font-size: 20px;
  color: var(--text-dim);
  font-weight: 500;
}

.body-today-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
}

/* Sparkline */

.body-sparkline-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px 4px;
  margin-bottom: 12px;
  overflow: hidden;
}

.body-sparkline-svg {
  width: 100%;
  height: 68px;
  display: block;
}

.sparkline-line {
  stroke: var(--accent);
  stroke-width: 1.5px;
}

.sparkline-dot {
  fill: var(--accent);
  opacity: 0.45;
}

.sparkline-dot-today {
  fill: var(--accent);
  opacity: 1;
}

.sparkline-label {
  fill: var(--text-dim);
  font-size: 8px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.body-sparkline-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  padding: 10px 0 6px;
}

/* Body history list */

.body-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.body-history-item:last-child {
  border-bottom: none;
}

.body-history-date {
  font-size: 14px;
  color: var(--text);
}

.body-history-weight {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.body-history-input {
  width: 58px;
  text-align: right;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 2px 0;
  -moz-appearance: textfield;
}
.body-history-input::-webkit-outer-spin-button,
.body-history-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.body-history-input:focus { outline: none; border-bottom-color: var(--accent); }

.body-history-unit {
  font-size: 12px;
  color: var(--text-dim);
}

/* =====================================================
   Progress Tab
   ===================================================== */

.progress-shell {
  display: flex;
  flex-direction: column;
  padding-bottom: 80px; /* clear bottom nav */
}

/* Segment control */
.progress-segments {
  display: flex;
  gap: 0;
  margin: 12px 12px 0;
  background: var(--border);
  border-radius: 10px;
  padding: 2px;
}

.seg-btn {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  touch-action: manipulation;
}

.seg-btn.active {
  background: var(--bg-card);
  color: var(--accent);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

/* Range buttons */
.progress-range-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 12px 4px;
  justify-content: center;
}

.range-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.range-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.progress-export-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.progress-export-btn:active {
  background: var(--bg-input);
}

.health-import-modal {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.health-import-file {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  border-radius: 12px;
  padding: 10px;
}

.health-import-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.health-import-file-name {
  min-width: 0;
  flex: 1;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  word-break: break-word;
}

.health-import-error {
  border: 1px solid var(--text-warn);
  background: var(--warmup-bg);
  color: var(--text-warn);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
}

.health-import-actions {
  display: flex;
  gap: 8px;
}

.health-import-actions .btn {
  flex: 1;
}

.health-import-preview {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: var(--bg-input);
}

.health-import-preview-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.health-import-preview-subtitle {
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
}

.health-import-preview-section {
  margin-top: 12px;
}

.health-import-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}

.health-import-detail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.health-import-detail-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

/* Content area */
.progress-content {
  flex: 1;
  padding: 8px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.progress-loading {
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  padding: 24px 0;
}

/* Chart cards */
.progress-chart-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 12px;
}

.progress-chart-expandable {
  cursor: pointer;
}

.progress-chart-expandable:active {
  background: var(--bg-input);
}

.progress-chart-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.chart-title-unit {
  font-weight: 400;
  color: var(--text-dim);
}

.progress-chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Chart elements */
.chart-grid-line {
  stroke: rgba(24, 35, 70, 0.12);
  stroke-width: 1;
}

.chart-line {
  stroke: var(--accent);
  stroke-width: 2.5;
}

.chart-trendline {
  stroke: var(--accent);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  opacity: 0.72;
}

.chart-trendline.chart-line-secondary {
  stroke: var(--olive);
}

.chart-area {
  fill: rgba(30, 11, 129, 0.08);
}

.chart-line-secondary {
  stroke: var(--olive);
  stroke-width: 2.5;
}

.chart-area.chart-line-secondary {
  fill: rgba(111, 125, 45, 0.10);
}

.chart-dot {
  fill: var(--accent);
}

.chart-dot-measured {
  fill: var(--accent);
}

.chart-bar {
  fill: var(--accent);
  opacity: 0.88;
}

.chart-bar-selected {
  fill: var(--accent);
  opacity: 1;
  filter: brightness(1.1);
}

.chart-hit-target {
  fill: transparent;
  cursor: pointer;
}

.chart-point-hit {
  fill: transparent;
  cursor: pointer;
  touch-action: none;
}

.weight-selection-band {
  fill: rgba(26, 92, 64, 0.12);
  pointer-events: none;
}

.weight-selection-edge {
  stroke: var(--stretch-text);
  stroke-width: 1.5;
  pointer-events: none;
}

.weight-selection-trendline {
  stroke: var(--stretch-text);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  pointer-events: none;
}

.weight-selection-handle-zone {
  fill: transparent;
  cursor: ew-resize;
  touch-action: none;
}

.weight-selection-handle {
  fill: var(--stretch-text);
  stroke: #fff;
  stroke-width: 2;
  cursor: ew-resize;
  touch-action: none;
}

.weight-chart-readout {
  min-height: 20px;
  margin-top: 6px;
  font-size: 13px;
  color: var(--stretch-text);
  font-weight: 600;
}

.weight-total-change {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  padding: 9px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.weight-total-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
}

.weight-total-change strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 20px;
  line-height: 1.1;
}

.weight-total-meta {
  max-width: 62%;
  color: var(--text-dim);
  font-size: 12px;
  text-align: right;
  line-height: 1.35;
}

.progress-accuracy-card {
  cursor: default;
}

.progress-accuracy-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.progress-accuracy-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}

.progress-accuracy-confidence {
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(17, 119, 67, 0.10);
  color: var(--success);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.progress-accuracy-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.progress-accuracy-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.progress-accuracy-grid div {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  min-width: 0;
}

.progress-accuracy-grid span {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.progress-accuracy-grid strong {
  display: block;
  font-size: 13px;
  color: var(--text);
}

.chart-label {
  fill: var(--text-dim);
  font-size: 9px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.chart-empty {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  padding: 20px 0 8px;
}

.history-apple-summary {
  margin: 8px 0 12px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-input);
}

.history-apple-summary-header {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.history-apple-link-card + .history-apple-link-card {
  margin-top: 8px;
}

.history-apple-link-card {
  cursor: pointer;
}

.history-apple-link-card:active {
  opacity: 0.8;
}

.history-apple-link-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.history-apple-link-summary {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-dim);
}

.progress-helper-text {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.progress-info-card {
  padding-top: 10px;
}

/* Collapsed developer-facing details (backup status) — demoted to a quiet footer */
.data-footer-details {
  margin: 4px 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
}

.data-footer-summary {
  color: var(--text-dim);
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.data-footer-details[open] {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.data-footer-details[open] .data-footer-summary {
  margin-bottom: 6px;
}

.progress-info-value {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
}

.update-msg {
  font-size: 13px;
  color: var(--text-dim);
  min-height: 18px;
  margin-bottom: 6px;
}

.update-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.restart-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.restart-box {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 32px 24px;
  max-width: 300px;
  text-align: center;
}

.restart-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.restart-msg {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.5;
}

.chart-modal-view .progress-chart-svg {
  width: 100%;
}

.chart-modal-copy {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

.chart-subtitle {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Exercise picker */
.exercise-picker-card {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 10px 12px;
  position: relative;
}

.exercise-favorites-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.favorite-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  touch-action: manipulation;
}

.favorite-chip:active {
  background: var(--border);
}

.favorite-chip-star {
  color: var(--accent);
  line-height: 1;
}

.favorite-chip-name {
  white-space: nowrap;
}

.exercise-search-input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  font-size: 15px;
  color: var(--text);
  padding: 4px 0 6px;
  outline: none;
}

.exercise-search-input:focus {
  border-bottom-color: var(--accent);
}

.exercise-search-results {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 10px 10px;
  z-index: 20;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: 0 4px 12px rgba(0,0,0,0.10);
}

.exercise-result-item {
  padding: 11px 14px;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  touch-action: manipulation;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.result-name {
  flex: 1;
  min-width: 0;
}
.result-last-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.result-favorite-btn {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
}

.result-favorite-btn.active {
  color: var(--accent);
}

.exercise-result-item:last-child {
  border-bottom: none;
}

.exercise-result-item:active {
  background: var(--bg-input);
}

.strength-chart-area {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Workouts stats */
.progress-stats-row {
  display: flex;
  gap: 10px;
}

.body-stats-row .progress-stat-value {
  font-size: 22px;
}

.progress-stat-card {
  flex: 1;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 14px 12px;
  text-align: center;
}

.progress-stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.progress-stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

.template-volume-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.template-volume-item {
  border-top: 1px solid var(--border);
}

.template-volume-item:first-child {
  border-top: none;
}

.template-volume-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 0;
  cursor: pointer;
  list-style: none;
}

.template-volume-summary::-webkit-details-marker {
  display: none;
}

.template-volume-summary::after {
  content: '›';
  color: var(--text-dim);
  font-size: 18px;
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}

.template-volume-item[open] .template-volume-summary::after {
  transform: rotate(90deg);
}

.template-volume-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
}

.template-volume-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: auto;
  white-space: nowrap;
}

.template-volume-chart {
  padding: 0 0 12px;
}

/* Body history (collapsible) */
.progress-history-section {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-history-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.toggle-arrow {
  font-size: 12px;
  color: var(--text-dim);
}

.progress-history-list {
  border-top: 1px solid var(--border);
}

.progress-history-list.hidden {
  display: none;
}

/* Week detail panel (Workouts bar tap) */

.week-detail-panel {
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
}

.week-detail-panel.hidden {
  display: none;
}

.week-detail-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 10px 14px 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.week-detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 14px;
  border-top: 1px solid var(--border);
}

.week-detail-date {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
}

.week-detail-templates {
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
  text-align: right;
}

.week-detail-empty {
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  padding: 16px;
}

/* --- Nutrition Tab --- */

.nutrition-topbar {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  padding: 12px 16px 0;
}

.nutrition-view-toggle {
  display: inline-grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 4px;
  width: 100%;
  max-width: 220px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  margin: 0 auto 10px;
}

.nutrition-view-btn {
  border: none;
  background: transparent;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
}

.nutrition-view-btn.active {
  background: var(--accent);
  color: #fff;
}

.nutrition-date-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0;
}

#nutr-date-display {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}

#nutrition-content {
  padding: 8px 16px 24px;
}

.nutrition-summary-nav {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}

.nutrition-range-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.nutrition-range-pill {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.nutrition-range-pill.active {
  border-color: var(--accent);
  background: var(--bg-input);
  color: var(--accent);
}

.nutrition-day-badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 12px;
  letter-spacing: 0.3px;
}

.nutrition-day-badge.training {
  background: var(--bg);
  color: var(--accent);
}

.nutrition-day-badge.rest {
  background: var(--border);
  color: var(--success);
}

.nutrition-no-targets {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  padding: 8px 0 12px;
}

.nutrition-targets-bar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}

.target-bar-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 4px;
}

.target-bar-label {
  font-size: 12px;
  color: var(--text-dim);
}

.target-bar-value {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

.targets-progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px; /* space before the next bar-row */
}

.targets-progress-bar:last-child {
  margin-bottom: 0;
}

.targets-progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease, background 0.3s ease;
}

/* Target range indicators — applied to text spans and the progress fill */
.target-hit  { color: var(--success); }
.target-low  { color: var(--olive); }
.target-high { color: var(--text-warn); }

.targets-progress-fill.target-hit  { background: var(--success); }
.targets-progress-fill.target-low  { background: var(--olive); }
.targets-progress-fill.target-high { background: var(--text-warn); }

.target-bar-helper-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-top: 2px;
  margin-bottom: 14px;
}

.target-bar-helper {
  margin-top: 0;
  font-size: 11px;
  color: var(--text-dim);
}

.target-bar-helper-deficit {
  color: #8a94ad;
  margin-bottom: 0;
  text-align: right;
  white-space: nowrap;
}

.target-bar-helper-row .target-bar-helper {
  margin-bottom: 0;
}

.calorie-progress-wrap {
  display: grid;
  grid-template-columns: 85% 15%;
  gap: 0;
  align-items: center;
  margin-top: 18px;
  margin-bottom: 10px;
  position: relative;
}

.calorie-progress-main {
  min-width: 0;
}

.calorie-progress-value {
  position: absolute;
  bottom: calc(100% + 6px);
  transform: translateX(-100%);
  white-space: nowrap;
  pointer-events: none;
}

.calorie-progress-value-start {
  transform: translateX(0);
}

.calorie-progress-value-end {
  transform: translateX(-100%);
}

.calorie-value-hit {
  color: var(--success);
}

.calorie-value-over-target {
  color: var(--beige);
}

.calorie-value-overflow {
  color: var(--text-warn);
}

.calorie-progress-main.with-overflow .calorie-progress-bar {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.calorie-progress-bar {
  position: relative;
}

.calorie-progress-deficit {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  background: #8a94ad;
  opacity: 0.5;
  z-index: 1;
}

.calorie-progress-segment {
  position: absolute;
  top: 0;
  z-index: 2;
  height: 100%;
}

.calorie-progress-segment-pending {
  background: #8a94ad;
}

.calorie-progress-segment-hit {
  background: var(--success);
}

.calorie-progress-segment-over {
  background: var(--beige);
}

.calorie-progress-overflow-slot {
  height: 6px;
  position: relative;
}

.calorie-progress-overflow-slot:empty {
  display: block;
}

.calorie-progress-overflow-fill {
  height: 6px;
  align-self: stretch;
  background: var(--text-warn);
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
  transition: width 0.3s ease, background 0.3s ease;
  margin-left: 2px;
}

/* Meal cards */

#nutrition-meals {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.meal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.meal-card.unlogged {
  opacity: 0.7;
}

.meal-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 12px;
  cursor: pointer;
  user-select: none;
}

.meal-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 0 0 auto;
}

.meal-summary {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
}

.summary-dim {
  color: var(--text-dim);
  opacity: 0.6;
}

.summary-blank {
  color: var(--text-dim);
  opacity: 0.4;
  font-size: 13px;
}

/* Quick-confirm button (✓) — shown on use_defaults slots */
.meal-confirm-btn {
  background: none;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
}

.meal-confirm-btn:hover {
  background: var(--accent);
  color: #fff;
}

.meal-confirm-btn.confirmed {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  opacity: 0.75;
}

.meal-confirm-btn.confirmed:hover {
  opacity: 1;
}

.meal-delete-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 0 0 0 4px;
  line-height: 1;
  flex-shrink: 0;
}

.meal-delete-btn:hover {
  color: var(--text-warn);
}

.meal-card-body {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
}

.meal-card-body.hidden {
  display: none;
}

.meal-macro-inputs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.macro-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.macro-label {
  font-size: 11px;
  color: var(--text-dim);
  font-weight: 500;
}

.macro-input {
  width: 100%;
  padding: 6px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
  color: var(--text);
  text-align: center;
  -moz-appearance: textfield;
}

.macro-input::-webkit-inner-spin-button,
.macro-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.macro-input:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
}

.btn-add-meal {
  width: 100%;
  padding: 10px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 16px;
}

.btn-add-meal:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Totals */

.nutrition-totals {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
}

.nutrition-totals-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 14px;
}

.totals-row-stack {
  display: block;
}

.totals-label {
  color: var(--text-dim);
}

.totals-value {
  font-weight: 600;
  color: var(--text);
}

.totals-value-forecast {
  font-style: italic;
}

.totals-value.target-hit {
  color: var(--success);
}

.totals-value.target-low {
  color: var(--olive);
}

.totals-value.target-high {
  color: var(--text-warn);
}

.totals-note {
  padding-top: 2px;
  font-size: 12px;
  color: var(--text-dim);
}

.totals-note-inline {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}

.nutr-settings-btn {
  display: block;
  width: 100%;
  text-align: center;
  padding: 10px;
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 4px;
}

.nutrition-summary-hero {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.nutrition-summary-kicker {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.nutrition-summary-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

.nutrition-summary-subtitle {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-dim);
}

.nutrition-summary-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.nutrition-summary-stat {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.nutrition-summary-stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.nutrition-summary-stat-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}

.nutrition-summary-stat-note {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-dim);
}

.nutrition-summary-charts {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
}

/* --- Chart Legend (line vs trendline) --- */
.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
}

.chart-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.chart-legend-swatch {
  display: inline-block;
  width: 18px;
  border-top: 2px solid currentColor;
}

.chart-legend-dashed {
  border-top-style: dashed;
}

.progress-chart-card .chart-line-energy,
.progress-chart-card .chart-area.chart-line-energy {
  stroke: var(--accent);
  fill: rgba(25, 0, 128, 0.12);
}

.progress-chart-card .chart-trendline.chart-line-energy {
  stroke: var(--accent);
}

.progress-chart-card .chart-line-calories,
.progress-chart-card .chart-area.chart-line-calories {
  stroke: var(--olive);
  fill: rgba(122, 152, 58, 0.12);
}

.progress-chart-card .chart-trendline.chart-line-calories {
  stroke: var(--olive);
}

.progress-chart-card .chart-line-active,
.progress-chart-card .chart-area.chart-line-active {
  stroke: var(--success);
  fill: rgba(17, 119, 67, 0.12);
}

.progress-chart-card .chart-trendline.chart-line-active {
  stroke: var(--success);
}

.nutrition-summary-totals {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.nutrition-summary-totals span,
.nutrition-summary-source {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-dim);
}

.nutrition-summary-days {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.nutrition-summary-days-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.nutrition-summary-day-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.nutrition-summary-day-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.nutrition-summary-day-main {
  min-width: 0;
}

.nutrition-summary-day-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.nutrition-summary-day-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 4px;
}

.nutrition-summary-day-stats {
  display: grid;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
}

@media (max-width: 640px) {
  .weight-total-change {
    flex-direction: column;
    gap: 6px;
  }

  .weight-total-meta {
    max-width: none;
    text-align: left;
  }

  .progress-accuracy-grid {
    grid-template-columns: 1fr;
  }

  /* Keep the summary stats 2-up on phones — the cards are compact enough,
     and stacking five single-stat cards forces heavy scrolling. */

  .nutrition-summary-day-row {
    flex-direction: column;
  }

  .nutrition-summary-day-stats {
    text-align: left;
  }
}

/* Settings modal */

.nutrition-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.nutrition-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.nutrition-form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.nutrition-form-field input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
}

.nutrition-form-note {
  min-height: 18px;
  font-size: 12px;
  color: var(--text-dim);
}

.nutrition-form-actions,
.settings-new-template-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.nutr-energy-btn {
  display: block;
  margin: 8px auto 0;
  font-size: 13px;
}

.settings-section {
  margin-bottom: 20px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

.template-row {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.template-row-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.tmpl-name {
  flex: 1;
  padding: 5px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
}

.tmpl-rest-toggle,
.tmpl-quick-toggle {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  cursor: pointer;
}

.tmpl-delete {
  font-size: 14px;
  padding: 0;
  flex-shrink: 0;
}

.template-row-macros {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.tmpl-macro-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tmpl-macro-field label {
  font-size: 11px;
  color: var(--text-dim);
}

.tmpl-macro-input {
  width: 100%;
  padding: 5px 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  text-align: center;
  -moz-appearance: textfield;
}

.tmpl-macro-input::-webkit-inner-spin-button,
.tmpl-macro-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.btn-add-template {
  width: 100%;
  padding: 8px;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  margin-top: 4px;
}

.btn-add-template:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.settings-new-template {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}

.settings-new-template.hidden {
  display: none;
}

.settings-new-template > input {
  width: 100%;
  padding: 6px 8px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  margin-bottom: 8px;
}

.settings-new-template-actions {
  margin-top: 8px;
}

.targets-profiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.targets-profile-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.settings-subsection {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.target-field {
  margin-bottom: 8px;
}

.target-field label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 3px;
}

.target-field input {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  -moz-appearance: textfield;
}

.target-field input::-webkit-inner-spin-button,
.target-field input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

.target-field.target-negative label {
  color: var(--text-warn);
  font-weight: 600;
}

.target-field.target-negative input {
  border-color: rgba(106, 0, 5, 0.35);
}

.target-field.target-positive label {
  color: var(--olive);
  font-weight: 600;
}

.target-field.target-positive input {
  border-color: rgba(122, 152, 58, 0.45);
}

.target-field-hint {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.35;
}

.btn-save-targets {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-save-targets:hover {
  background: var(--accent-dim);
}
