/* public/css/library.css — M6 exercise & routine library (class prefix .lib-).
   Every color, spacing, radius, and tap size comes from tokens.css vars (§7).
   No color literals and no stacking-order declarations here (§8 gate 7). */

/* ---------- shared list chrome ---------- */

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

.lib-seg {
  margin-bottom: var(--sp-1);
}

.lib-search {
  width: 100%;
}

.lib-section-title {
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: var(--sp-4) 0 var(--sp-2);
}

/* Row shell: attachSwipe rewraps the row's children into .ui-swipe-content, so
   the shell carries only surface/border/radius; .lib-row-inner does the layout. */
.lib-row {
  background: var(--surface);
  border: 1px solid var(--outline);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.lib-row + .lib-row {
  margin-top: var(--sp-2);
}

.lib-row-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap-min);
  padding: var(--sp-3) var(--sp-4);
}

.lib-row-main {
  flex: 1 1 auto;
  min-width: 0;
}

.lib-row-name {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.lib-add {
  width: 100%;
  margin-top: var(--sp-4);
}

.lib-empty {
  color: var(--text-dim);
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
}

/* Underlay pruning: rows offering only one left-swipe action. Built-in
   exercises are never deletable (hide red delete); routine rows and routine
   items delete-only on left swipe (hide amber edit). */
.lib-swipe-noedit .ui-swipe-ic--edit {
  display: none;
}

.lib-swipe-nodelete .ui-swipe-ic--delete {
  display: none;
}

/* ---------- edit screens (exercise-edit, routine-edit header) ---------- */

.lib-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.lib-back {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  display: inline-flex;
  align-items: center;
  color: var(--accent);
  font-weight: 600;
  font-size: 16px;
}

.lib-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

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

.lib-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}

.lib-input {
  width: 100%;
}

.lib-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.lib-chip {
  min-height: var(--tap-min);
  min-width: var(--tap-min);
  padding: 0 var(--sp-3);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  color: var(--text-dim);
  font-weight: 600;
}

.lib-chip[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: transparent;
}

.lib-metric-seg {
  margin-bottom: var(--sp-2);
}

.lib-explainer {
  color: var(--text-dim);
  font-size: 14px;
}

.lib-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: var(--tap-min);
  width: 100%;
  text-align: left;
  font-weight: 600;
}

.lib-toggle-knob {
  width: 52px;
  height: 32px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--outline);
  position: relative;
  flex: none;
  transition: background 0.15s ease;
}

.lib-toggle-knob::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s ease, background 0.15s ease;
}

.lib-toggle[aria-pressed="true"] .lib-toggle-knob {
  background: var(--accent);
  border-color: transparent;
}

.lib-toggle[aria-pressed="true"] .lib-toggle-knob::after {
  transform: translateX(20px);
  background: var(--accent-contrast);
}

.lib-hidden {
  display: none;
}

.lib-actions {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
}

/* ---------- routine builder ---------- */

.lib-name-input {
  width: 100%;
  font-size: 20px;
  font-weight: 700;
}

.lib-item-inner {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3) var(--sp-3);
}

.lib-item-top {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
}

.lib-drag {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 20px;
  touch-action: none; /* the handle drags; it never scrolls */
  cursor: grab;
}

.lib-item-controls {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-3);
  width: 100%;
  flex-wrap: wrap;
}

.lib-ctl {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

.lib-ctl-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.lib-ctl-row {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
}

.lib-clear {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  color: var(--text-dim);
  font-size: 18px;
}

.lib-reps-add {
  min-height: var(--tap-min);
  padding: 0 var(--sp-3);
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--outline);
  color: var(--text-dim);
  font-weight: 600;
}

/* Drag state: siblings animate into their shifted slots; the lifted row
   follows the finger with no transition (its z comes from an inline token
   var set in JS, like the overlay components do). */
.lib-list--drag .lib-item {
  transition: transform 0.15s ease;
}

.lib-item--drag,
.lib-list--drag .lib-item--drag {
  transition: none;
  position: relative;
  border-color: var(--accent);
  opacity: 0.95;
}

/* ---------- add-exercise picker (bottom-sheet body) ---------- */

.lib-picker {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--sp-4);
}

.lib-picker .lib-section-title {
  margin-top: var(--sp-3);
}

.lib-picker-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: var(--tap-min);
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  text-align: left;
}

.lib-picker-row:active {
  background: var(--surface-2);
}

.lib-picker-name {
  font-weight: 600;
}

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