/* ─── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  /* Colors */
  --bg-0: #0a0a0a;        /* deepest background */
  --bg-1: #111111;        /* page background */
  --bg-2: #1a1a1a;        /* card background */
  --bg-3: #222222;        /* elevated card / input */
  --bg-4: #2c2c2c;        /* hover state */

  --border: #2a2a2a;
  --border-strong: #3a3a3a;

  --text-0: #f5f5f5;      /* primary text */
  --text-1: #a0a0a0;      /* secondary text */
  --text-2: #666666;      /* muted / disabled */

  --accent:   #e85d04;    /* orange — primary action */
  --accent-2: #f48c06;    /* lighter orange — hover */
  --accent-dim: rgba(232, 93, 4, 0.15);

  --green:  #22c55e;
  --red:    #ef4444;
  --yellow: #eab308;
  --blue:   #3b82f6;

  --success-bg: rgba(34, 197, 94, 0.12);
  --warning-bg: rgba(234, 179, 8, 0.12);
  --danger-bg:  rgba(239, 68, 68, 0.12);

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', monospace;

  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;

  /* Spacing */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Layout */
  --nav-height: 56px;
  --max-width: 480px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.6);

  /* Transitions */
  --transition: 150ms ease;
  --transition-slow: 300ms ease;
}

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

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

body {
  font-family: var(--font-sans);
  background: var(--bg-1);
  color: var(--text-0);
  line-height: 1.5;
  min-height: 100%;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

img, svg { display: block; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ─── App Shell ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: var(--max-width);
  margin: 0 auto;
  position: relative;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
  padding-bottom: calc(var(--nav-height) + var(--space-4));
}

/* ─── Top Bar ────────────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top-bar__title {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.top-bar__subtitle {
  font-size: var(--text-xs);
  color: var(--text-1);
  margin-top: 1px;
}

/* ─── Bottom Nav ─────────────────────────────────────────────────────────────── */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--max-width);
  height: var(--nav-height);
  background: var(--bg-2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 20;
}

.bottom-nav__items {
  display: flex;
  width: 100%;
  height: 100%;
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: 500;
  transition: color var(--transition);
  padding: var(--space-2);
  text-decoration: none;
}

.bottom-nav__item svg {
  width: 22px;
  height: 22px;
}

.bottom-nav__item.active {
  color: var(--accent);
}

.bottom-nav__item:active {
  background: var(--bg-3);
}

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.card + .card {
  margin-top: var(--space-3);
}

.card--elevated {
  background: var(--bg-3);
  border-color: var(--border-strong);
}

.card--accent {
  border-color: var(--accent);
  background: var(--accent-dim);
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-md);
  border: none;
  font-size: var(--text-base);
  font-weight: 600;
  transition: background var(--transition), transform var(--transition);
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

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

.btn--primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
}
.btn--primary:hover, .btn--primary:active {
  background: var(--accent-2);
}

.btn--secondary {
  background: var(--bg-3);
  color: var(--text-0);
  border: 1px solid var(--border-strong);
}
.btn--secondary:hover { background: var(--bg-4); }

.btn--ghost {
  background: transparent;
  color: var(--text-1);
  padding: var(--space-2) var(--space-3);
}
.btn--ghost:hover { color: var(--text-0); }

.btn--danger {
  background: var(--danger-bg);
  color: var(--red);
  border: 1px solid var(--red);
}

.btn--sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

.btn--lg {
  padding: var(--space-4) var(--space-6);
  font-size: var(--text-lg);
  border-radius: var(--radius-md);
  font-size: var(--text-xl);
}

.btn--icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-full);
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  color: var(--text-0);
  font-size: var(--text-xl);
}

/* ─── Rep Input (big +/- buttons) ────────────────────────────────────────────── */
.rep-input {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  justify-content: center;
}

.rep-input__btn {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-full);
  background: var(--bg-3);
  border: 2px solid var(--border-strong);
  color: var(--text-0);
  font-size: var(--text-3xl);
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), border-color var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.rep-input__btn:active {
  background: var(--bg-4);
  border-color: var(--accent);
}

.rep-input__count {
  font-size: var(--text-4xl);
  font-weight: 800;
  min-width: 80px;
  text-align: center;
  letter-spacing: -0.03em;
  color: var(--text-0);
  font-variant-numeric: tabular-nums;
}

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-group + .form-group {
  margin-top: var(--space-4);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-input {
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  color: var(--text-0);
  font-size: var(--text-lg);
  padding: var(--space-3) var(--space-4);
  width: 100%;
  transition: border-color var(--transition);
  -webkit-appearance: none;
  appearance: none;
}

.form-input:focus {
  outline: none;
  border-color: var(--accent);
}

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

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-2);
}

/* ─── Set Row ────────────────────────────────────────────────────────────────── */
.set-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}

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

.set-row__number {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-1);
  flex-shrink: 0;
}

.set-row--active .set-row__number {
  background: var(--accent);
  color: #fff;
}

.set-row--done .set-row__number {
  background: var(--green);
  color: var(--bg-1);
}

.set-row__weight {
  font-size: var(--text-xl);
  font-weight: 700;
  flex: 1;
}

.set-row__reps {
  font-size: var(--text-base);
  color: var(--text-1);
}

.set-row__actual {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--green);
  min-width: 40px;
  text-align: right;
}

.set-row__amrap-badge {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
}

/* ─── Rest Timer ─────────────────────────────────────────────────────────────── */
.rest-timer {
  text-align: center;
  padding: var(--space-6);
}

.rest-timer__time {
  font-size: 4rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--accent);
}

.rest-timer__time.urgent {
  color: var(--red);
}

.rest-timer__label {
  font-size: var(--text-sm);
  color: var(--text-1);
  margin-top: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ─── Bottom Sheet ────────────────────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 40;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-slow);
}

.sheet-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%) translateY(100%);
  width: 100%;
  max-width: var(--max-width);
  background: var(--bg-2);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border-top: 1px solid var(--border-strong);
  z-index: 50;
  transition: transform var(--transition-slow);
  max-height: 85dvh;
  display: flex;
  flex-direction: column;
}

.sheet.open {
  transform: translateX(-50%) translateY(0);
}

.sheet__handle {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  margin: var(--space-3) auto var(--space-1);
  flex-shrink: 0;
}

.sheet__header {
  padding: var(--space-3) var(--space-5) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sheet__title {
  font-size: var(--text-lg);
  font-weight: 700;
}

.sheet__body {
  padding: 0 var(--space-5) var(--space-6);
  overflow-y: auto;
  flex: 1;
}

/* ─── Tags / Badges ──────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  line-height: 1.4;
}

.badge--accent {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.badge--green {
  background: var(--success-bg);
  color: var(--green);
}

.badge--yellow {
  background: var(--warning-bg);
  color: var(--yellow);
}

.badge--red {
  background: var(--danger-bg);
  color: var(--red);
}

/* ─── Section Headers ────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.section-title {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-1);
}

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

/* ─── Empty State ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-2);
}

.empty-state__icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: 600;
  color: var(--text-1);
  margin-bottom: var(--space-2);
}

/* ─── Offline Banner ─────────────────────────────────────────────────────────── */
.offline-banner {
  background: var(--warning-bg);
  border-bottom: 1px solid var(--yellow);
  color: var(--yellow);
  font-size: var(--text-xs);
  font-weight: 600;
  text-align: center;
  padding: var(--space-2);
  display: none;
}

body.offline .offline-banner { display: block; }

/* ─── Progress Ring (for rep goal) ──────────────────────────────────────────── */
.rep-goal-info {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
}

.rep-goal-info__label {
  font-size: var(--text-xs);
  color: var(--text-1);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.rep-goal-info__value {
  font-size: var(--text-xl);
  font-weight: 800;
  color: var(--accent);
}

/* ─── Lift Card ──────────────────────────────────────────────────────────────── */
.lift-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.lift-card__name {
  font-size: var(--text-2xl);
  font-weight: 800;
  letter-spacing: -0.02em;
}

.lift-card__tm {
  font-size: var(--text-sm);
  color: var(--text-1);
  margin-top: 2px;
}

/* ─── Workout Summary ────────────────────────────────────────────────────────── */
.summary-stat {
  text-align: center;
  padding: var(--space-4);
}

.summary-stat__value {
  font-size: var(--text-3xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-0);
}

.summary-stat__label {
  font-size: var(--text-xs);
  color: var(--text-1);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: var(--space-1);
}

.summary-stat__delta {
  font-size: var(--text-sm);
  font-weight: 600;
  margin-top: var(--space-1);
}

.summary-stat__delta.up { color: var(--green); }
.summary-stat__delta.same { color: var(--text-2); }
.summary-stat__delta.down { color: var(--red); }

/* ─── History List ───────────────────────────────────────────────────────────── */
.history-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  -webkit-tap-highlight-color: transparent;
}

.history-item:hover, .history-item:active {
  background: var(--bg-3);
  border-color: var(--border-strong);
}

.history-item + .history-item { margin-top: var(--space-2); }

.history-item__lift {
  flex: 1;
  font-weight: 700;
  font-size: var(--text-base);
}

.history-item__meta {
  font-size: var(--text-xs);
  color: var(--text-1);
  margin-top: 2px;
}

.history-item__1rm {
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--accent);
  text-align: right;
}

/* ─── Scroll helpers ─────────────────────────────────────────────────────────── */
.scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll-x::-webkit-scrollbar { display: none; }

/* ─── Utilities ──────────────────────────────────────────────────────────────── */
.text-accent  { color: var(--accent); }
.text-green   { color: var(--green); }
.text-red     { color: var(--red); }
.text-muted   { color: var(--text-1); }
.text-dim     { color: var(--text-2); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.font-bold    { font-weight: 700; }
.font-black   { font-weight: 900; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }

.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.w-full { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--space-3); }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ─── Animations ─────────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.animate-fade-in { animation: fadeIn 200ms ease forwards; }
.animate-slide-up { animation: slideUp 250ms ease forwards; }
.animate-pulse { animation: pulse 2s infinite; }
