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

:root {
  --bg: #0a0a0f;
  --surface: #151520;
  --surface2: #1e1e2e;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --strength: #e17055;
  --hypertrophy: #00b894;
  --cardio: #0984e3;
  --rest: #636e72;
  --skip: #2d3436;
  --success: #00b894;
  --danger: #d63031;
  --radius: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Views */
.view { display: none; padding: 16px 16px calc(80px + var(--safe-bottom)); }
.view.active { display: block; }

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  padding: 16px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 16px);
  border-bottom: 1px solid var(--border);
}
.header-date {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.header-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-top: 2px;
}
.header-back {
  background: none;
  border: none;
  color: var(--accent-light);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 0;
  display: none;
}
.header-back.visible { display: inline-block; }

/* Bottom Nav */
.nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}
.nav-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 10px 0 8px;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.2s;
}
.nav-btn.active { color: var(--accent-light); }
.nav-btn svg { width: 22px; height: 22px; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}
.card-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 4px;
}
.card-subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* Today's Workout Card */
.today-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.today-card .session-type {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  margin-bottom: 8px;
}
.type-strength { background: var(--strength); color: #fff; }
.type-hypertrophy { background: var(--hypertrophy); color: #fff; }
.type-cardio { background: var(--cardio); color: #fff; }

.today-exercises {
  list-style: none;
  margin-top: 12px;
}
.today-exercises li {
  padding: 6px 0;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}
.today-exercises li:last-child { border-bottom: none; }
.today-exercises .exercise-meta {
  color: var(--text-dim);
  font-size: 0.8rem;
}

/* Session Nav */
.session-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 14px;
}
.session-arrow {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.session-arrow:active { background: var(--accent); }
.session-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
}
.session-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  transition: all 0.2s;
}
.session-dot.active {
  background: var(--accent-light);
  width: 20px;
  border-radius: 4px;
}
.session-dot.next:not(.active) {
  background: var(--text-dim);
}

/* Week Summary */
.week-row {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}
.week-day {
  text-align: center;
  padding: 8px 2px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 0.7rem;
}
.week-day .day-label {
  color: var(--text-dim);
  margin-bottom: 4px;
  display: block;
}
.week-day .day-value {
  font-weight: 600;
  font-size: 0.75rem;
}
.week-day.today { border-color: var(--accent); }
.week-day.done-weights .day-value { color: var(--strength); }
.week-day.done-cardio .day-value { color: var(--cardio); }
.week-day.done-rest .day-value { color: var(--rest); }

.week-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
}
.week-stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
}
.week-stat .stat-value {
  font-size: 1.4rem;
  font-weight: 700;
}
.week-stat .stat-label {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 2px;
}

/* Action Buttons */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
.action-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 12px;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
}
.action-btn:active { transform: scale(0.97); }
.action-btn.primary {
  grid-column: 1 / -1;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 1rem;
  padding: 16px;
}
.action-btn.primary:active { background: var(--accent-light); }

/* Log Workout View */
.exercise-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.exercise-card .ex-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.exercise-card .ex-name {
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--accent-light);
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.exercise-card .ex-target {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.set-row {
  display: grid;
  grid-template-columns: 40px 1fr 1fr 40px;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.set-row .set-num {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
}
.set-row input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 8px;
  color: var(--text);
  font-size: 0.9rem;
  text-align: center;
  width: 100%;
  -webkit-appearance: none;
}
.set-row input:focus {
  outline: none;
  border-color: var(--accent);
}
.set-row input::placeholder { color: var(--text-dim); }
.set-row .set-check {
  background: none;
  border: 2px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}
.set-row .set-check.done {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.add-set-btn {
  background: none;
  border: 1px dashed var(--border);
  border-radius: 6px;
  padding: 8px;
  color: var(--text-dim);
  font-size: 0.8rem;
  width: 100%;
  cursor: pointer;
  margin-top: 4px;
}

/* Cardio Log */
.cardio-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}
.cardio-option {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.2s;
}
.cardio-option.selected { border-color: var(--cardio); }
.cardio-option .co-name { font-weight: 600; }
.cardio-option .co-desc { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }

.cardio-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.field input, .field textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  color: var(--text);
  font-size: 0.9rem;
  -webkit-appearance: none;
}
.field input:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field.full { grid-column: 1 / -1; }
.field textarea { resize: vertical; min-height: 60px; font-family: inherit; }

/* History */
.history-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  cursor: pointer;
}
.history-card .hc-date {
  font-size: 0.75rem;
  color: var(--text-dim);
}
.history-card .hc-title {
  font-weight: 600;
  margin-top: 2px;
}
.history-card .hc-summary {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-top: 4px;
}
.history-card .hc-detail {
  display: none;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.history-card.expanded .hc-detail { display: block; }
.hc-detail-exercise {
  margin-bottom: 8px;
}
.hc-detail-exercise .hde-name {
  font-size: 0.85rem;
  font-weight: 600;
}
.hc-detail-exercise .hde-sets {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Progress */
.progress-select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
  margin-bottom: 16px;
  -webkit-appearance: none;
}
.chart-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 16px;
}
.chart-container canvas { width: 100% !important; }
.pr-card {
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface2) 100%);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  margin-bottom: 12px;
}
.pr-card .pr-label {
  font-size: 0.75rem;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.pr-card .pr-value {
  font-size: 2rem;
  font-weight: 700;
  margin-top: 4px;
}
.pr-card .pr-date {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.empty-state .es-icon { font-size: 2rem; margin-bottom: 8px; }
.empty-state .es-text { font-size: 0.9rem; }

/* Utils */
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: 0.85rem; }

/* Loading */
.loading {
  display: flex;
  justify-content: center;
  padding: 40px;
}
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Exercise Swap Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--safe-bottom);
}
.modal-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header .modal-title { font-weight: 600; font-size: 1rem; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 4px 8px;
}
.modal-search {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.modal-search input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9rem;
  -webkit-appearance: none;
}
.modal-search input:focus { outline: none; border-color: var(--accent); }
.modal-search input::placeholder { color: var(--text-dim); }
.modal-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
}
.modal-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}
.modal-item:active { background: var(--surface2); }
.modal-item .mi-name { font-size: 0.9rem; font-weight: 500; }
.modal-item .mi-last {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}
.modal-item.custom-entry {
  color: var(--accent-light);
  font-weight: 600;
}
