/* =====================================================
   WORKOUT APP — COMPLETE STYLESHEET
   ===================================================== */

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---- CSS Variables ---- */
:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --success: #22c55e;
  --success-light: #dcfce7;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --radius-full: 9999px;
  --nav-height: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,0.12), 0 4px 10px rgba(0,0,0,0.06);
  --transition: 0.2s ease;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --surface-3: #475569;
    --border: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --primary-light: #1e1b4b;
    --success-light: #14532d;
    --warning-light: #451a03;
    --danger-light: #450a0a;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.4);
  }
}

/* ---- App Shell ---- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100svh;
  position: relative;
}

#main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 16px;
  overscroll-behavior-y: contain;
}

/* ---- Bottom Navigation ---- */
#bottom-nav {
  flex-shrink: 0;
  height: calc(var(--nav-height) + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  padding-top: 8px;
  padding-bottom: var(--safe-bottom);
  box-shadow: 0 -1px 12px rgba(0,0,0,0.06);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  transition: color var(--transition);
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.nav-item svg {
  width: 22px;
  height: 22px;
  transition: transform var(--transition);
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active svg {
  transform: scale(1.1);
}

.nav-item:active {
  opacity: 0.7;
}

/* ---- Layout ---- */
.page {
  min-height: 100%;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

.page-header {
  padding: calc(var(--safe-top) + 16px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.section {
  padding: 16px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

/* ---- Cards ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.card:active {
  box-shadow: var(--shadow);
}

.card + .card {
  margin-top: 10px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---- Typography ---- */
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 14px; font-weight: 600; }

.text-muted { color: var(--text-muted); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-lg { font-size: 18px; }
.text-xl { font-size: 22px; }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: all var(--transition);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.01em;
  text-decoration: none;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(99,102,241,0.35);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(99,102,241,0.45);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-3);
}

.btn-danger {
  background: var(--danger);
  color: white;
  box-shadow: 0 2px 8px rgba(239,68,68,0.3);
}

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-success {
  background: var(--success);
  color: white;
  box-shadow: 0 2px 8px rgba(34,197,94,0.3);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
  min-height: 36px;
  border-radius: var(--radius-xs);
}

.btn-lg {
  padding: 14px 24px;
  font-size: 16px;
  min-height: 52px;
  border-radius: var(--radius);
}

.btn-full {
  width: 100%;
}

.btn-icon {
  padding: 10px;
  min-height: 44px;
  width: 44px;
  border-radius: var(--radius-sm);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* ---- FAB ---- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(99,102,241,0.45);
  transition: all var(--transition);
  z-index: 90;
  -webkit-tap-highlight-color: transparent;
}

.fab:active {
  transform: scale(0.92);
}

.fab svg {
  width: 26px;
  height: 26px;
}

/* ---- Form Elements ---- */
.form-group {
  margin-bottom: 16px;
}

.label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  letter-spacing: 0.02em;
}

.input {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  min-height: 44px;
  -webkit-appearance: none;
  appearance: none;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

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

.input-sm {
  padding: 8px 10px;
  font-size: 14px;
  min-height: 36px;
}

select.input {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 18px;
  padding-right: 36px;
}

textarea.input {
  resize: vertical;
  min-height: 80px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.toggle-label {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.toggle-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--surface-3);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--primary);
}

.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(20px);
}

/* ---- Quantity Stepper ---- */
.quantity-stepper {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.quantity-stepper button {
  width: 44px;
  height: 44px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition);
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.quantity-stepper button:active {
  background: var(--border);
  color: var(--text);
}

.quantity-stepper .qty-value {
  flex: 1;
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: none;
  min-width: 52px;
  padding: 0 4px;
  -webkit-appearance: none;
  appearance: none;
}

.quantity-stepper .qty-value:focus {
  outline: none;
}

/* ---- Unit Chips ---- */
.unit-chips-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 4px 0;
}

.unit-chips-container::-webkit-scrollbar {
  display: none;
}

.unit-chips {
  display: flex;
  gap: 8px;
  width: max-content;
  padding: 2px 0;
}

.unit-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  min-height: 36px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}

.unit-chip.active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.unit-chip .chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  flex-shrink: 0;
}

/* ---- Difficulty Buttons ---- */
.difficulty-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.diff-btn {
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 52px;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  -webkit-tap-highlight-color: transparent;
  line-height: 1.2;
  text-align: center;
}

.diff-btn .diff-icon {
  font-size: 18px;
}

.diff-btn.easy.active,
.diff-btn.easy:active {
  background: var(--success-light);
  border-color: var(--success);
  color: var(--success);
}

.diff-btn.near_failure.active,
.diff-btn.near_failure:active {
  background: var(--warning-light);
  border-color: var(--warning);
  color: var(--warning);
}

.diff-btn.failure.active,
.diff-btn.failure:active {
  background: var(--danger-light);
  border-color: var(--danger);
  color: var(--danger);
}

/* ---- Muscle Tags ---- */
.muscle-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 6px;
}

.muscle-tag {
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  letter-spacing: 0.02em;
  text-transform: capitalize;
}
/* Major secondary (0.5) — same hue, softer */
.muscle-tag-secondary {
  background: color-mix(in srgb, var(--primary-light) 55%, transparent);
  color: color-mix(in srgb, var(--primary) 65%, var(--text-muted));
  font-weight: 500;
}
/* Minor secondary (0.25) — outline only, muted */
.muscle-tag-minor {
  background: transparent;
  color: var(--text-muted);
  font-weight: 400;
  border: 1px solid var(--border);
}

/* ---- Exercise Cards ---- */
.exercise-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.exercise-card:active {
  background: var(--surface-2);
}

.exercise-card + .exercise-card {
  margin-top: 8px;
}

.exercise-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 20px;
}

.exercise-info {
  flex: 1;
  min-width: 0;
}

.exercise-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Toast Notifications ---- */
#toast-container {
  position: fixed;
  top: calc(var(--safe-top) + 16px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(-12px) scale(0.96);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast-info {
  background: var(--surface);
  color: var(--text);
  border-left: 4px solid var(--primary);
}

.toast-success {
  background: var(--success-light);
  color: #15803d;
  border-left: 4px solid var(--success);
}

.toast-error {
  background: var(--danger-light);
  color: #b91c1c;
  border-left: 4px solid var(--danger);
}

/* ---- Modal ---- */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: overlayIn 0.2s ease;
}

#modal-overlay.hidden {
  display: none;
}

@keyframes overlayIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  padding-bottom: calc(var(--safe-bottom) + 16px);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-center {
  align-items: center;
  padding: 16px;
}

.modal-center .modal {
  border-radius: var(--radius);
  max-height: 80dvh;
  max-height: 80vh;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface-2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  transition: background var(--transition);
}

.modal-close:active {
  background: var(--surface-3);
}

.modal-body {
  padding: 16px;
}

.modal-footer {
  padding: 12px 16px;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--border);
}

.modal-footer .btn {
  flex: 1;
}

/* ---- Auth Page ---- */
.auth-page {
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 24px calc(24px + var(--safe-bottom));
  background: var(--bg);
}

.auth-logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.auth-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 15px;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.auth-tabs {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border: none;
  background: none;
  border-radius: var(--radius-xs);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---- Timer Ring ---- */
.timer-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  animation: fadeIn 0.2s ease;
}

.timer-heading {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 32px;
}

.timer-ring-wrap {
  position: relative;
  width: 220px;
  height: 220px;
  margin-bottom: 32px;
}

.timer-ring-svg {
  width: 220px;
  height: 220px;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 10;
}

.timer-ring-progress {
  fill: none;
  stroke: var(--success);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.25s linear, stroke 0.5s ease;
}

.timer-ring-progress.amber {
  stroke: var(--warning);
}

.timer-ring-progress.red {
  stroke: var(--danger);
}

.timer-display {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.timer-time {
  font-size: 52px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.timer-next {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  max-width: 260px;
  margin-bottom: 24px;
  line-height: 1.4;
}

.timer-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 280px;
}

.timer-add-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
}

.timer-add-btn:active {
  background: var(--surface-2);
}

.timer-skip-btn {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--primary);
  font-size: 14px;
  font-weight: 600;
  color: white;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 44px;
}

.timer-skip-btn:active {
  background: var(--primary-dark);
}

/* ---- Set Logger ---- */
.set-logger {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.logger-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.logger-field {
  min-width: 0;
}

.logger-field label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 6px;
}

/* ---- Session Screen ---- */
.session-page {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.session-header {
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.session-progress-bar {
  height: 3px;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}

.session-progress-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.4s ease;
  border-radius: 2px;
}

.session-exercise-card {
  margin: 16px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.session-ex-name {
  font-size: 24px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.session-set-progress {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 8px;
}

.session-last-time {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-xs);
  padding: 6px 10px;
  margin-top: 8px;
}

.session-logs {
  margin: 0 16px;
}

.set-log-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  font-size: 14px;
}

.set-log-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.set-log-details {
  flex: 1;
  color: var(--text);
  font-weight: 500;
}

.set-log-diff {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.set-log-diff.easy { background: var(--success-light); color: #15803d; }
.set-log-diff.near_failure { background: var(--warning-light); color: #92400e; }
.set-log-diff.failure { background: var(--danger-light); color: #b91c1c; }

/* ---- Session Complete ---- */
.complete-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px 24px;
  text-align: center;
  min-height: 100%;
}

.complete-icon {
  font-size: 72px;
  margin-bottom: 16px;
  animation: popIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes popIn {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.complete-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.complete-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  margin: 24px 0;
  width: 100%;
}

.complete-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 10px;
  text-align: center;
}

.complete-stat-val {
  font-size: 22px;
  font-weight: 800;
  color: var(--primary);
  display: block;
  letter-spacing: -0.02em;
}

.complete-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 2px;
}

/* ---- History ---- */
.history-week {
  margin-bottom: 20px;
}

.history-week-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 16px;
  background: var(--surface-2);
}

.history-card {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  cursor: pointer;
  transition: background var(--transition);
}

.history-card:active {
  background: var(--surface-2);
}

.history-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.history-card-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.history-card-date {
  font-size: 12px;
  color: var(--text-muted);
}

.history-card-meta {
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  gap: 12px;
}

.history-expanded {
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.history-ex-group {
  margin-bottom: 12px;
}

.history-ex-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.history-set-row {
  font-size: 12px;
  color: var(--text-muted);
  padding: 2px 0;
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ---- Routines / Builder ---- */
.template-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}

.template-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.template-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.badge {
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.badge-public {
  background: var(--primary-light);
  color: var(--primary);
}

.badge-private {
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge-active {
  background: #14532d33;
  color: #4ade80;
}

.badge-paused {
  background: #78350f33;
  color: #fbbf24;
}

.badge-pending {
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge-stopped {
  background: #450a0a33;
  color: #f87171;
}

.template-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ---- Active Session Banner ---- */
.active-session-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 0 16px 16px;
}
.active-session-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.active-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #4ade80;
  flex-shrink: 0;
  box-shadow: 0 0 0 3px rgba(74,222,128,0.35);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(74,222,128,0.35); }
  50% { box-shadow: 0 0 0 6px rgba(74,222,128,0.1); }
}
.active-session-label {
  font-size: 11px;
  font-weight: 600;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.active-session-name {
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.active-session-banner .btn-primary {
  background: rgba(255,255,255,0.2);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
}
.active-session-banner .btn-primary:hover {
  background: rgba(255,255,255,0.3);
}
.active-session-banner .btn-ghost {
  color: rgba(255,255,255,0.8);
}

.template-card-active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.2);
}

/* ---- Session Log Overlay ---- */
.slog-exercise {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.slog-exercise-current {
  border-color: var(--primary);
}
.slog-ex-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
}
.slog-ex-name {
  font-size: 14px;
  font-weight: 600;
}
.slog-set-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}
.slog-set-pending {
  opacity: 0.5;
}
.slog-set-num {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.slog-set-pending .slog-set-num {
  background: var(--surface-2);
  color: var(--text-muted);
}
.slog-set-detail {
  flex: 1;
  font-size: 13px;
}
.slog-edit-btn {
  font-size: 12px;
  padding: 2px 8px;
  height: auto;
  min-height: 28px;
}

/* ---- Builder ---- */
.builder-exercise-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  position: relative;
}

.builder-ex-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 8px;
}

.builder-ex-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.builder-ex-controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.builder-ex-field label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

.builder-ex-field .mini-stepper {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: var(--surface-2);
}

.mini-stepper button {
  width: 32px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 16px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.mini-stepper button:active {
  background: var(--border);
}

.mini-stepper .mini-val {
  flex: 1;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  min-width: 28px;
  background: none;
  border: none;
}

.mini-stepper .mini-val:focus {
  outline: none;
}

.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: grab;
  touch-action: none;
  padding: 4px 2px;
  -webkit-tap-highlight-color: transparent;
}

.drag-handle:active {
  cursor: grabbing;
}

.sortable-ghost {
  opacity: 0.4;
}

.sortable-drag {
  opacity: 1;
}

/* ---- Settings ---- */
.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.settings-section-header {
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

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

.settings-row-label {
  font-size: 15px;
  color: var(--text);
  font-weight: 500;
}

.settings-row-value {
  font-size: 14px;
  color: var(--text-muted);
}

/* ---- Loading Spinner ---- */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--surface-2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-center {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
}

/* ---- Empty State ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
}

.empty-icon {
  font-size: 52px;
  margin-bottom: 16px;
  opacity: 0.7;
}

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

.empty-desc {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 260px;
  line-height: 1.5;
  margin-bottom: 20px;
}

/* ---- Muscle Group Filter Chips ---- */
.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  -ms-overflow-style: none;
}

.filter-chips::-webkit-scrollbar { display: none; }

.filter-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  min-height: 36px;
  display: flex;
  align-items: center;
  transition: all var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.filter-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ---- Progress Bar ---- */
.progress-bar {
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* ---- Stats Grid ---- */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
  display: block;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 2px;
}

/* ---- Color Input ---- */
input[type="color"] {
  width: 44px;
  height: 36px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  cursor: pointer;
  padding: 2px;
  background: var(--surface);
}

/* ---- Search Input ---- */
.search-wrap {
  position: relative;
  padding: 12px 16px;
}

.search-icon {
  position: absolute;
  left: 28px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.search-input {
  padding-left: 40px;
}

/* ---- Divider ---- */
.divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* ---- Confirm Dialog ---- */
.confirm-dialog {
  padding: 24px;
  text-align: center;
}

.confirm-dialog h3 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.confirm-dialog p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 20px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 10px;
}

.confirm-actions .btn {
  flex: 1;
}

/* ---- Utilities ---- */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ---- Scrollable List ---- */
.scrollable-list {
  overflow-y: auto;
  max-height: 50vh;
  -webkit-overflow-scrolling: touch;
}

/* ---- Tab Bar ---- */
.tab-bar {
  display: flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: none;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition);
  min-height: 36px;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ---- Greeting Header ---- */
.greeting-header {
  padding: calc(var(--safe-top) + 20px) 16px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
}

.greeting-text {
  font-size: 13px;
  opacity: 0.8;
  font-weight: 500;
  margin-bottom: 2px;
}

.greeting-name {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* ---- Pill / Badge ---- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
}

/* ---- File input ---- */
.file-input-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  transition: all var(--transition);
  min-height: 44px;
}

.file-input-label:hover {
  border-color: var(--primary);
  color: var(--primary);
}

input[type="file"] {
  display: none;
}

/* ---- Custom Scrollbar ---- */
@media (pointer: fine) {
  ::-webkit-scrollbar { width: 6px; height: 6px; }
  ::-webkit-scrollbar-track { background: transparent; }
  ::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 3px; }
  ::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
}

/* ---- Challenge Cards ---- */
.challenge-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.challenge-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.challenge-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.challenge-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.challenge-progress-wrap {
  margin-bottom: 8px;
}

.challenge-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
}

.challenge-progress-label {
  font-weight: 600;
  color: var(--text);
}

.challenge-progress-pct {
  font-weight: 700;
  color: var(--primary);
}

.challenge-progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.challenge-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

.challenge-periods {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
}

.challenge-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
