/* public/css/workout.css — M5 (prefix .wk-). Tokens only (§7): no color
   literals, no z-index literals. Thumb-zone layout per §6.1: tag chips →
   steppers → 64px COMPLETE SET anchored at the very bottom (R2.1/R2.2). */

/* ============================ workout-setup ============================ */

.wk-setup { display: flex; flex-direction: column; gap: var(--sp-4); }

.wk-setup-date {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.wk-setup-date-label { color: var(--text-dim); font-weight: 600; }

.wk-setup-date input { flex: 1 1 auto; }

.wk-setup-sub { color: var(--text-dim); }

.wk-setup-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.wk-setup-routine {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
  min-height: var(--tap-primary);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
  text-align: left;
}

.wk-setup-routine:active { background: var(--surface-2); }

/* Routine handed over via {routineId} (planner swipe-right / plan card, §6.4). */
.wk-setup-routine--preselected {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.wk-setup-routine--empty { border-style: dashed; }

.wk-setup-routine-name { font-size: 18px; font-weight: 700; }

.wk-setup-routine-count { color: var(--text-dim); font-size: 14px; }

.wk-setup-empty { padding: var(--sp-2) 0; }

/* ============================ workout-active ============================ */

/* Scrollable content must clear the fixed bottom log panel. The panel has no
   max-height (it must fit its content — see .wk-logpanel), so clear its
   tallest form: the cardio layout's ~390px min-content, or 40vh when that is
   larger, plus the safe-area inset the panel adds below its content. */
.wk-active {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding-bottom: calc(
    max(var(--thumb-zone), 400px) + var(--sp-5) + env(safe-area-inset-bottom, 0px)
  );
}

/* ---- header (R3.2) ---- */

.wk-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.wk-header-info { min-width: 0; }

.wk-title {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wk-elapsed {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.wk-end {
  flex: 0 0 auto;
  min-height: var(--tap-min);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius);
  background: var(--danger);
  color: var(--accent-contrast);
  font-weight: 700;
}

/* ---- carousel: native scroll-snap chip strip (R3.3, §6.4) ---- */

.wk-carousel {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-1) 0 var(--sp-2);
  scrollbar-width: none;
}

.wk-carousel::-webkit-scrollbar { display: none; }

.wk-chip {
  flex: 0 0 auto;
  scroll-snap-align: center;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: var(--tap-min);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--outline);
  color: var(--text-dim);
  font-weight: 600;
  max-width: 70vw;
}

.wk-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wk-chip-count {
  flex: 0 0 auto;
  min-width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 12px;
}

.wk-chip--active {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
}

.wk-chip--active .wk-chip-count {
  background: var(--accent-contrast);
  color: var(--accent);
}

/* ---- toolbar (R3.7) ---- */

.wk-toolbar { display: flex; gap: var(--sp-2); }

.wk-tool {
  flex: 1 1 0;
  min-height: var(--tap-min);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  font-weight: 600;
}

/* ---- done-set list ---- */

.wk-body { flex: 1 1 auto; }

.wk-exname { margin-bottom: var(--sp-3); }

.wk-empty { padding: var(--sp-3) 0; }

.wk-sets { display: flex; flex-direction: column; gap: var(--sp-2); }

.wk-set {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap-min);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
}

/* attachSwipe rewraps the row's children into a plain-block .ui-swipe-content
   (§6.4): restore the row layout on that wrapper so number / value / tags keep
   their single-line flex layout (non-swiped .wk-set rows are untouched). */
.wk-set > .ui-swipe-content {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: 1 1 auto;
  min-width: 0;
}

.wk-set-num {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
}

.wk-set-val { flex: 1 1 auto; font-weight: 600; }

.wk-set-tags { display: inline-flex; gap: var(--sp-1); }

.wk-set-tag {
  display: inline-flex;
  align-items: center;
  padding: 0 var(--sp-2);
  min-height: 20px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.wk-set-tag--warmup { color: var(--warn); }
.wk-set-tag--working { color: var(--accent); }
.wk-set-tag--drop { color: var(--text); }
.wk-set-tag--failure { color: var(--danger); }

/* ---- bottom log panel (§6.1, bottom 40%) ---- */

.wk-logpanel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: var(--z-nav);
  /* No max-height: the panel grows to fit its min-content (cardio stacks
     three stepper rows, ~390px on phone widths, which overflows 40vh on small
     screens and would push COMPLETE SET below the viewport — R2.2). The
     panel is unscrollable, so it must always fit its content; .wk-active's
     padding-bottom provides the matching clearance. */
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4)
    calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--outline);
}

.wk-tags { display: flex; gap: var(--sp-2); }

.wk-tag {
  flex: 1 1 0;
  min-height: var(--tap-min);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 14px;
}

.wk-tag--on {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-contrast);
}

.wk-controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  justify-content: center;
}

.wk-ctl {
  flex: 1 1 40%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  position: relative;
}

.wk-ctl-label {
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.wk-platebtn {
  position: absolute;
  top: 0;
  right: 0;
  width: var(--tap-min);
  height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  color: var(--accent);
}

.wk-platebtn svg { width: 24px; height: 24px; }

/* 64px full-width primary, anchored at the very bottom (R2.1/R2.2). */
.wk-complete {
  width: 100%;
  min-height: var(--tap-primary);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.wk-complete:active { filter: brightness(1.15); }

.wk-complete[disabled] { opacity: var(--ghost-opacity); pointer-events: none; }

/* ---- add-exercise picker sheet ---- */

.wk-pick { display: flex; flex-direction: column; gap: var(--sp-3); }

.wk-pick-search { width: 100%; }

.wk-pick-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-height: 50vh;
  overflow-y: auto;
}

.wk-pick-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: var(--tap-min);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
  text-align: left;
  font-weight: 600;
}

.wk-pick-sub { color: var(--text-dim); font-size: 13px; }

.wk-pick-row--create {
  color: var(--accent);
  border-style: dashed;
  justify-content: center;
}

.wk-pick-none { padding: var(--sp-2) 0; }

/* ---- queue reorder sheet (§6.4 long-press drag) ---- */

.wk-queue { display: flex; flex-direction: column; gap: var(--sp-2); }

.wk-queue-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap-min);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
  user-select: none;
  -webkit-user-select: none;
}

.wk-queue-row--lift {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 var(--sp-1) var(--sp-3) var(--outline);
  transform: scale(1.02);
}

.wk-queue-handle {
  color: var(--text-dim);
  font-size: 20px;
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none; /* the handle drags; the rest of the row pans natively */
  cursor: grab;
}

.wk-queue-name { flex: 1 1 auto; font-weight: 600; }

.wk-queue-count { color: var(--text-dim); font-size: 13px; }

/* ---- plate calculator modal (§6.6) ---- */

.wk-plate { display: flex; flex-direction: column; gap: var(--sp-3); }

.wk-plate-target { color: var(--text-dim); font-weight: 600; }

.wk-plate-svg { width: 100%; height: auto; }

.wk-plate-bar { fill: var(--text-dim); }

.wk-plate-disc { fill: var(--accent); }

.wk-plate-label {
  fill: var(--text-dim);
  font-size: 10px;
  font-weight: 600;
}

.wk-plate-list { font-weight: 600; }

.wk-plate-status { color: var(--warn); font-weight: 600; }

.wk-plate-status--exact { color: var(--success); }

.wk-plate-use { margin-top: var(--sp-2); }

/* ============================ workout-summary ============================ */

.wk-summary {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  /* clears the fixed thumb-anchor Done button */
  padding-bottom: calc(var(--tap-primary) + var(--sp-6) + var(--sp-6));
}

.wk-summary-sub { margin-top: calc(-1 * var(--sp-3)); }

.wk-stats { display: flex; gap: var(--sp-2); }

.wk-stat {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
}

.wk-stat-value {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.wk-stat-label {
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.wk-summary-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.wk-summary-ex {
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
}

.wk-summary-ex-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
}

.wk-summary-ex-name { font-weight: 700; }

.wk-pr {
  display: inline-flex;
  align-items: center;
  padding: var(--sp-1) var(--sp-2);
  border-radius: var(--radius-sm);
  background: var(--success);
  color: var(--accent-contrast);
  font-size: 12px;
  font-weight: 800;
}

.wk-summary-ex-detail { font-size: 14px; margin-top: var(--sp-1); }

/* =============================== history =============================== */

.wk-history { display: flex; flex-direction: column; gap: var(--sp-4); }

.wk-history-list { display: flex; flex-direction: column; gap: var(--sp-2); }

.wk-history-row {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
}

.wk-history-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-1);
  width: 100%;
  min-height: var(--tap-primary);
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
}

.wk-history-title { font-weight: 700; }

.wk-history-sub { color: var(--text-dim); font-size: 14px; }

.wk-history-detail-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
}

.wk-back {
  flex: 0 0 auto;
  width: var(--tap-min);
  height: var(--tap-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  font-size: 24px;
  line-height: 1;
}

.wk-history-detail-sub { margin-top: calc(-1 * var(--sp-3)); }

.wk-history-ex {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius);
}

.wk-history-ex-name { font-size: 16px; }

.wk-set--ro { background: var(--surface-2); }
