/* ── Reset & Variables ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0F0F0F;
  --surface: #1A1A1A;
  --surface2: #252525;
  --border: #2E2E2E;
  --primary: #FF6B35;
  --primary-dark: #CC4F20;
  --text: #F5F5F5;
  --text2: #888;
  --text3: #555;
  --success: #4CAF50;
  --danger: #EF5350;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-h: 60px;
  --header-h: 56px;
  --radius: 14px;
  --radius-sm: 8px;
}

html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; }

/* ── Auth ── */
.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: max(var(--safe-top), 24px) 24px max(var(--safe-bottom), 24px);
  gap: 0;
}
.auth-logo { font-size: 56px; margin-bottom: 8px; }
.auth-title { font-size: 26px; font-weight: 700; margin-bottom: 4px; }
.auth-subtitle { color: var(--text2); margin-bottom: 32px; font-size: 14px; }
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.auth-card h2 { font-size: 18px; margin-bottom: 4px; }
.auth-link {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text2);
}
.auth-link a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ── Form elements ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text2); font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px; /* prevent iOS zoom */
  padding: 12px 14px;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}
input:focus, select:focus { border-color: var(--primary); }
.error-msg { color: var(--danger); font-size: 13px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  padding: 14px 20px;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  min-height: 48px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { opacity: .8; transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; width: 100%; }
.btn-primary:disabled { opacity: .5; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-ghost { background: transparent; color: var(--text2); padding: 10px 16px; font-size: 14px; }
.btn-icon { background: var(--surface2); border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 20px; }
.btn-sm { padding: 8px 14px; font-size: 14px; min-height: 36px; }

/* ── Layout ── */
.header {
  padding: max(var(--safe-top), 16px) 16px 12px;
  background: var(--bg);
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-title { font-size: 18px; font-weight: 700; flex: 1; }
.header-back {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 0;
  min-height: 44px;
  touch-action: manipulation;
}

.content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

.nav-bar {
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: max(var(--safe-bottom), 6px);
  flex-shrink: 0;
}
.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 4px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text3);
  font-size: 10px;
  font-weight: 500;
  min-height: 52px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
}
.nav-item.active { color: var(--primary); }
.nav-item .nav-icon { font-size: 22px; line-height: 1; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0 16px 12px;
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.card-sub { font-size: 13px; color: var(--text2); }

/* ── Workout view ── */
.session-hero {
  text-align: center;
  padding: 48px 24px 32px;
}
.session-hero .icon { font-size: 64px; margin-bottom: 16px; }
.session-hero h2 { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.session-hero p { color: var(--text2); font-size: 15px; margin-bottom: 32px; }

.timer {
  font-size: 42px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -1px;
  color: var(--primary);
  text-align: center;
  padding: 12px 0 4px;
}
.timer-label { text-align: center; color: var(--text2); font-size: 12px; margin-bottom: 12px; }

.exercise-block {
  background: var(--surface);
  border-radius: var(--radius);
  margin: 0 16px 10px;
  overflow: hidden;
}
.exercise-block-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
}
.exercise-block-icon { font-size: 22px; }
.exercise-block-name { flex: 1; font-weight: 600; font-size: 15px; }
.exercise-block-sets { color: var(--text2); font-size: 13px; }

.sets-list { padding: 0 16px 12px; display: flex; flex-direction: column; gap: 6px; }
.set-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.set-num { color: var(--text2); min-width: 20px; font-weight: 600; }
.set-data { flex: 1; }
.set-delete { background: none; border: none; color: var(--text3); font-size: 18px; padding: 4px; cursor: pointer; }

.add-exercise-btn {
  margin: 8px 16px 16px;
  background: var(--surface);
  border: 1px dashed var(--border);
  color: var(--text2);
  font-size: 15px;
  font-weight: 500;
  width: calc(100% - 32px);
  border-radius: var(--radius);
  min-height: 48px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.end-session-btn { display: flex; margin: 8px 16px 0; width: calc(100% - 32px); }

/* ── Stepper input ── */
.stepper {
  display: flex;
  align-items: center;
  gap: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.stepper-btn {
  border: none;
  background: none;
  color: var(--text);
  font-size: 22px;
  width: 52px;
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
}
.stepper-btn:active { background: var(--border); }
.stepper-val {
  flex: 1;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  border: none;
  background: none;
  color: var(--text);
  padding: 0;
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

/* ── Saisie directe (durée) ── */
.direct-input-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
}
.direct-input-wrap:focus-within { border-color: var(--primary); }
.direct-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  padding: 4px 0;
  min-width: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.direct-input::-webkit-inner-spin-button,
.direct-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.direct-unit {
  font-size: 18px;
  color: var(--text2);
  font-weight: 500;
  flex-shrink: 0;
}

/* ── Modal / bottom sheet ── */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.7);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}
.sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: max(var(--safe-bottom), 16px);
}
.sheet-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 4px;
  flex-shrink: 0;
}
.sheet-header {
  padding: 8px 16px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.sheet-title { font-size: 18px; font-weight: 700; flex: 1; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }

/* ── Picker ── */
.search-bar {
  margin: 0 16px 12px;
  position: relative;
}
.search-bar input { padding-left: 36px; }
.search-bar::before {
  content: '🔍';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  pointer-events: none;
}

.category-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px 12px;
  scrollbar-width: none;
}
.category-scroll::-webkit-scrollbar { display: none; }
.cat-pill {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text2);
  white-space: nowrap;
  touch-action: manipulation;
}
.cat-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.ex-list { padding: 0 16px; display: flex; flex-direction: column; gap: 1px; }
.ex-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 12px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  border: none;
  color: var(--text);
  width: 100%;
  text-align: left;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 4px;
}
.ex-item:active { background: var(--border); }
.ex-icon { font-size: 22px; width: 32px; text-align: center; }
.ex-cat { font-size: 12px; color: var(--text2); }

/* ── Set input form ── */
.set-form { padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
.set-form-ex { display: flex; align-items: center; gap: 10px; padding: 12px; background: var(--surface2); border-radius: var(--radius-sm); margin-bottom: 4px; }
.set-form-ex .icon { font-size: 26px; }
.set-form-ex .name { font-weight: 600; font-size: 16px; }
.set-form-ex .cat { font-size: 12px; color: var(--text2); }

.prev-sets { padding: 0 16px 8px; }
.prev-sets h4 { font-size: 13px; color: var(--text2); margin-bottom: 8px; font-weight: 500; }
.prev-set-row { display: flex; gap: 8px; margin-bottom: 4px; }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--surface2);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text2);
  gap: 4px;
}
.badge strong { color: var(--text); }

/* ── History ── */
.day-section { margin-bottom: 4px; }
.day-label { padding: 16px 16px 8px; font-size: 13px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: .5px; }
.session-card {
  background: var(--surface);
  border-radius: var(--radius);
  margin: 0 16px 10px;
  overflow: hidden;
}
.session-card-header {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 10px;
  cursor: pointer;
}
.session-date { font-weight: 600; font-size: 15px; flex: 1; }
.session-meta { font-size: 13px; color: var(--text2); }
.session-detail { padding: 0 16px 14px; display: flex; flex-direction: column; gap: 6px; }
.session-ex-row { font-size: 14px; padding: 8px 10px; background: var(--surface2); border-radius: var(--radius-sm); }
.session-ex-name { font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.session-ex-sets-list { display: flex; flex-direction: column; gap: 4px; }
.session-set-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.session-set-val { flex: 1; font-size: 13px; color: var(--text2); }
.hist-edit-btn, .hist-del-btn {
  background: none;
  border: none;
  font-size: 15px;
  padding: 4px 6px;
  cursor: pointer;
  border-radius: 6px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-width: 32px;
  min-height: 32px;
}
.hist-edit-btn:active { background: var(--border); }
.hist-del-btn:active  { background: rgba(239,83,80,.15); }
.hist-del-session { border-width: 1px; }

.empty-state { text-align: center; padding: 64px 32px; color: var(--text2); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { color: var(--text); margin-bottom: 8px; }

/* ── Stats ── */
.stats-picker { padding: 12px 16px; }
.stats-select { width: 100%; }
.chart-wrap { padding: 16px; }
.chart-card { background: var(--surface); border-radius: var(--radius); padding: 16px; }
.chart-card h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.chart-card p { font-size: 13px; color: var(--text2); margin-bottom: 16px; }
.chart-container { position: relative; height: 220px; }

.stats-summary { display: flex; gap: 10px; padding: 0 16px 16px; }
.stat-box {
  flex: 1;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-val { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ── Profile ── */
.profile-header { padding: 32px 16px 16px; text-align: center; }
.profile-avatar {
  width: 72px; height: 72px;
  background: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin: 0 auto 12px;
}
.profile-name { font-size: 20px; font-weight: 700; }
.profile-email { color: var(--text2); font-size: 14px; }
.profile-section { margin: 8px 16px; }
.profile-section h3 { font-size: 13px; color: var(--text2); padding: 8px 4px; font-weight: 500; text-transform: uppercase; letter-spacing: .5px; }

/* ── Loader ── */
.loader { text-align: center; padding: 48px; color: var(--text2); }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Session start screen ── */
.session-date-pick {
  display: flex; flex-direction: column; gap: 6px;
  width: 100%; max-width: 280px; margin: 0 auto 16px;
  text-align: left;
}
.session-date-pick label { font-size: 13px; color: var(--text2); font-weight: 500; }
.session-date-pick input[type="datetime-local"] {
  width: 100%; padding: 10px 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 15px; color-scheme: dark;
}
.session-hero .btn { max-width: 280px; margin: 0 auto; }
.cancel-session-btn {
  display: flex; margin: 4px 16px 24px;
  width: calc(100% - 32px); color: var(--text2);
  font-size: 14px; background: transparent;
}
.cancel-session-btn:active { opacity: 0.7; }

/* ── Sets count ── */
.sets-count-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-top: 1px solid var(--border); margin-top: 4px;
}
.sets-count-label { font-size: 15px; font-weight: 500; color: var(--text); }
.sets-count-stepper { width: auto; }
.sets-count-stepper .stepper-val { width: 48px; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px);
  left: 50%; transform: translateX(-50%) translateY(12px);
  background: #333; color: var(--text);
  padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 500;
  z-index: 9999; opacity: 0; transition: opacity .2s, transform .2s;
  white-space: nowrap; max-width: 90vw;
}
.toast-show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Session notes ── */
.session-notes-wrap {
  margin: 4px 16px 8px;
}
.session-notes-wrap textarea {
  width: 100%;
  min-height: 64px;
  resize: none;
  font-size: 14px;
  color: var(--text2);
  padding: 10px 12px;
}
.session-notes-display {
  font-size: 13px;
  color: var(--text2);
  font-style: italic;
  padding: 6px 10px;
  margin-top: 4px;
  border-left: 2px solid var(--border);
}

/* ── Exercise picker rows (fav + delete) ── */
.ex-item-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 4px;
}
.ex-item-row .ex-item {
  flex: 1;
  margin-bottom: 0;
}
.ex-fav-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text3);
  padding: 0 8px;
  min-width: 40px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
  transition: color .15s;
}
.ex-fav-btn.active { color: #f0c040; }
.ex-del-btn {
  background: none;
  border: none;
  font-size: 18px;
  padding: 0 6px;
  min-width: 36px;
  min-height: 48px;
  cursor: pointer;
  touch-action: manipulation;
  flex-shrink: 0;
  opacity: .6;
}
.ex-del-btn:active { opacity: 1; }
.ex-last {
  font-size: 12px;
  color: var(--primary);
  margin-top: 1px;
}
.ex-custom-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  vertical-align: middle;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

/* ── PR hint in set form ── */
.pr-hint {
  font-size: 13px;
  color: #f0c040;
  padding: 6px 0 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Frequency calendar ── */
.cal-wrap {
  margin: 0 16px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  overflow: hidden;
}
.cal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.cal-outer {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.cal-outer::-webkit-scrollbar { display: none; }
.cal-day-col {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 18px;
  flex-shrink: 0;
}
.cal-day-label {
  font-size: 9px;
  color: var(--text3);
  height: 12px;
  line-height: 12px;
  width: 14px;
  text-align: center;
}
.cal-months-row {
  display: flex;
  gap: 2px;
  margin-bottom: 2px;
}
.cal-month-cell {
  width: 12px;
  font-size: 9px;
  color: var(--text3);
  white-space: nowrap;
  overflow: visible;
  height: 14px;
  line-height: 14px;
}
.cal-grid {
  display: flex;
  gap: 2px;
}
.cal-week {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cal-cell {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--surface2);
  flex-shrink: 0;
}
.cal-cell.has-workout { background: var(--primary); }
.cal-cell.cal-today { outline: 2px solid var(--primary); outline-offset: 1px; }
.cal-cell.cal-future { opacity: .25; }
.cal-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 11px;
  color: var(--text3);
}
.cal-legend .cal-cell { display: inline-block; flex-shrink: 0; }

/* ── Profile stats ── */
.profile-stats {
  display: flex;
  gap: 10px;
  padding: 0 16px 16px;
  flex-wrap: wrap;
}
.profile-stats .stat-box { min-width: 80px; }

/* ── Utils ── */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.gap-8 { gap: 8px; }
