/* ============================================================
   RESET & BASE
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  /* Lock body scroll; each tab panel scrolls independently */
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ============================================================
   CSS VARIABLES
   ============================================================ */

:root {
  --bg:             #f2f2f7;
  --card:           #ffffff;
  --accent:         #007aff;
  --accent-light:   rgba(0, 122, 255, 0.12);
  --green:          #34c759;
  --red:            #ff3b30;
  --separator:      rgba(60, 60, 67, 0.12);
  --text-1:         #000000;
  --text-2:         #3c3c43;
  --text-3:         rgba(60, 60, 67, 0.6);
  --text-4:         rgba(60, 60, 67, 0.25);

  --safe-t: env(safe-area-inset-top,    0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left,   0px);
  --safe-r: env(safe-area-inset-right,  0px);

  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #000000;
    --card:         #1c1c1e;
    --accent:       #0a84ff;
    --accent-light: rgba(10, 132, 255, 0.15);
    --green:        #30d158;
    --red:          #ff453a;
    --separator:    rgba(84, 84, 88, 0.6);
    --text-1:       #ffffff;
    --text-2:       #ebebf5;
    --text-3:       rgba(235, 235, 245, 0.6);
    --text-4:       rgba(235, 235, 245, 0.18);
  }
}

/* ============================================================
   APP SHELL
   ============================================================ */

#app {
  display: flex;
  flex-direction: column;
  height: 100vh; /* fallback */
  height: 100dvh; /* shrinks when browser chrome is visible — keeps tab bar above it */
}

#main-content {
  flex: 1;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.tab-panel {
  display: none;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  background: var(--bg);
}

.tab-panel.active {
  display: block;
}

/* Extra bottom padding so content clears above the rounded edge */
.content-pad {
  padding: 0 0 calc(20px + var(--safe-b));
}

/* ============================================================
   NAVIGATION BAR (sticky within each scroll panel)
   ============================================================ */

.nav-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(var(--safe-t) + 16px) 20px 10px;
  background: rgba(242, 242, 247, 0.88);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}

@media (prefers-color-scheme: dark) {
  .nav-bar { background: rgba(0, 0, 0, 0.88); }
}

.nav-title {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.35px;
  color: var(--text-1);
  line-height: 1.1;
}

/* ============================================================
   SECTION HEADERS
   ============================================================ */

.section-header {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 20px 20px 8px;
}

/* ============================================================
   FORM GROUPS (white cards)
   ============================================================ */

.form-group {
  background: var(--card);
  border-radius: var(--radius);
  margin: 0 16px;
  overflow: hidden;
}

.form-row {
  display: flex;
  align-items: center;
  padding: 11px 16px;
  min-height: 44px;
  gap: 8px;
  border-bottom: 0.5px solid var(--separator);
}

.form-row:last-child {
  border-bottom: none;
}

.form-label {
  font-size: 17px;
  color: var(--text-1);
  flex: 1;
  min-width: 0;
}

.form-input {
  font-size: 17px;
  color: var(--text-1);
  border: none;
  outline: none;
  background: transparent;
  text-align: right;
  width: 72px;
  font-family: inherit;
  /* Remove number input spinners */
  -moz-appearance: textfield;
}

.form-input::-webkit-outer-spin-button,
.form-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
}

.form-input.small {
  width: 52px;
}

.form-input::placeholder {
  color: var(--text-4);
}

.form-unit {
  font-size: 17px;
  color: var(--text-3);
  flex-shrink: 0;
}

.form-separator {
  font-size: 17px;
  color: var(--text-3);
  flex-shrink: 0;
}

/* ============================================================
   SEGMENTED CONTROL
   ============================================================ */

.segmented-control {
  display: flex;
  width: 100%;
  background: rgba(118, 118, 128, 0.12);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
}

.segmented-btn {
  flex: 1;
  padding: 6px 4px;
  border: none;
  border-radius: 7px;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-1);
  cursor: pointer;
  font-family: inherit;
  line-height: 1.4;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}

.segmented-btn.active {
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  font-weight: 600;
}

/* ============================================================
   MILESTONE STATUS ROWS
   ============================================================ */

.status-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.status-icon.complete {
  background: var(--green);
  color: #fff;
}

.status-icon.complete svg {
  width: 14px;
  height: 14px;
}

.status-icon.incomplete {
  width: 22px;
  height: 22px;
  border: 2px solid var(--text-4);
  margin: 1px;
}

.status-text {
  flex: 1;
  min-width: 0;
}

.status-detail {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 1px;
}

/* ============================================================
   PROGRESS HEADER (Training Log)
   ============================================================ */

.progress-header {
  padding: 12px 16px;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.progress-text {
  font-size: 14px;
  color: var(--text-3);
}

.progress-pct {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.progress-bar-container {
  height: 4px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 12px;
}

@media (prefers-color-scheme: dark) {
  .progress-bar-container { background: rgba(255, 255, 255, 0.1); }
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.done-btn {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: opacity 0.15s;
}

.done-btn:active { opacity: 0.75; }

.done-btn.clear-btn { background: var(--red); }

/* ============================================================
   EXERCISE CARDS
   ============================================================ */

.exercise-card {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
}

.exercise-card:last-child {
  border-bottom: none;
}

.exercise-name-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-align: left;
  width: 100%;
  font-family: inherit;
  display: block;
  margin-bottom: 8px;
}

.routine-exercise .exercise-name-btn {
  margin-bottom: 0; /* no lift row below in the routine tab */
}

.exercise-name {
  font-size: 17px;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 2px;
}

.exercise-prescription {
  font-size: 14px;
  color: var(--text-3);
  margin-bottom: 2px;
}

.exercise-notes {
  font-size: 12px;
  color: var(--text-3);
  font-style: italic;
}

/* ============================================================
   LIFT INPUT ROW
   ============================================================ */

.lift-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lift-label {
  font-size: 13px;
  color: var(--text-3);
  width: 28px;
  flex-shrink: 0;
}

.lift-input {
  flex: 1;
  font-size: 15px;
  border: none;
  border-bottom: 0.5px solid var(--separator);
  outline: none;
  background: transparent;
  padding: 4px 0;
  font-family: inherit;
  color: var(--text-1);
  min-width: 0;
}

.lift-input.completed { color: var(--green); }

.lift-input::placeholder { color: var(--text-4); }

.check-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: transparent;
  border: 2px solid var(--text-4);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: transparent;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.check-icon.visible {
  background: var(--green);
  border-color: var(--green);
  color: #fff;
}

.check-icon svg {
  width: 12px;
  height: 12px;
}

/* ============================================================
   WEEK TITLE CARD (Routine tab)
   ============================================================ */

.week-title-card {
  padding: 16px;
}

.week-title-card h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
}

.week-title-card p {
  font-size: 16px;
  color: var(--text-3);
  margin-top: 2px;
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  gap: 8px;
  text-align: center;
}

.empty-state svg {
  width: 56px;
  height: 56px;
  color: var(--text-4);
}

.empty-text {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-1);
}

.empty-sub {
  font-size: 15px;
  color: var(--text-3);
}

/* ============================================================
   BOTTOM TAB BAR
   ============================================================ */

#tab-bar {
  display: flex;
  flex-shrink: 0;
  padding-bottom: max(var(--safe-b), 8px);
  background: rgba(242, 242, 247, 0.88);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}

@media (prefers-color-scheme: dark) {
  #tab-bar { background: rgba(28, 28, 30, 0.88); }
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: none;
  background: transparent;
  color: var(--text-3);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 4px;
  font-family: inherit;
  min-height: 49px;
  letter-spacing: 0.01em;
}

.tab-btn svg {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.tab-btn.active { color: var(--accent); }
.tab-btn:active { opacity: 0.7; }

/* ============================================================
   EXERCISE MODAL (bottom sheet)
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.modal-sheet {
  background: var(--card);
  border-radius: 12px 12px 0 0;
  padding: 12px 20px calc(24px + var(--safe-b));
  width: 100%;
  max-height: 80vh;
  max-height: 80dvh;
  overflow-y: auto;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
}

.modal-overlay.visible .modal-sheet {
  transform: translateY(0);
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: rgba(60, 60, 67, 0.18);
  border-radius: 2px;
  margin: 0 auto 20px;
}

@media (prefers-color-scheme: dark) {
  .modal-handle { background: rgba(235, 235, 245, 0.18); }
}

.modal-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 6px;
}

.modal-prescription {
  font-size: 16px;
  color: var(--text-3);
  margin-bottom: 6px;
}

.modal-notes {
  font-size: 14px;
  color: var(--text-3);
  line-height: 1.5;
  font-style: italic;
  margin-bottom: 16px;
}

.image-placeholder {
  background: var(--bg);
  border-radius: var(--radius);
  height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-4);
  font-size: 13px;
  margin: 12px 0;
}

.image-placeholder svg {
  width: 48px;
  height: 48px;
}

.modal-close-btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  margin-top: 8px;
  transition: opacity 0.15s;
}

.modal-close-btn:active { opacity: 0.7; }

/* ============================================================
   ADVANCE WEEK DIALOG
   ============================================================ */

.advance-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.advance-overlay.visible {
  opacity: 1;
  pointer-events: all;
}

.advance-dialog {
  background: var(--card);
  border-radius: 14px;
  padding: 20px;
  max-width: 280px;
  width: 100%;
  text-align: center;
}

#advance-content h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: 8px;
  line-height: 1.3;
}

#advance-content p {
  font-size: 13px;
  color: var(--text-3);
  margin-bottom: 20px;
  line-height: 1.45;
}

.advance-btn {
  display: block;
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 8px;
  font-family: inherit;
  transition: opacity 0.15s;
}

.advance-btn:active { opacity: 0.75; }

.advance-btn.secondary {
  background: transparent;
  color: var(--accent);
  margin-bottom: 0;
  font-weight: 400;
}
