/* ============================================================
   workout-builder.css - Workout builder page (wb-*)
   ============================================================ */

.wb-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 20px;
  align-items: start;
  margin-top: 16px;
}
.wb-layout > * { min-width: 0; }

/* ── Sidebar ── */
.wb-sidebar {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.wb-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.wb-saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}
.wb-saved-item:hover        { background: var(--bg-3); border-color: var(--border); }
.wb-saved-item.wb-saved-active { background: var(--bg-3); border-color: var(--accent); }
.wb-saved-main {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
  cursor: pointer;
  margin-right: 6px;
}
.wb-saved-name {
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 6px;
}
.wb-saved-name:hover { color: var(--accent); }
.wb-saved-date { font-size: 10px; color: var(--text-2); }
.wb-saved-tags { display: flex; flex-wrap: nowrap; gap: 3px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.wb-saved-tags::-webkit-scrollbar { display: none; }
.wb-clone-saved { padding: 2px 5px !important; font-size: 11px !important; color: var(--text-2) !important; margin-right: 2px; }
.wb-clone-saved:hover { color: var(--accent) !important; }
.wb-del-saved  { padding: 2px 7px !important; font-size: 11px !important; }

/* Scrollable saved workouts list - shows ~3 items at a time */
.wb-saved-scroll {
  max-height: 174px; /* ~3 items × 58px each */
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.wb-saved-scroll::-webkit-scrollbar { width: 4px; }
.wb-saved-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.wb-saved-scroll::-webkit-scrollbar-track { background: transparent; }

/* ── Main builder ── */
.wb-main {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  min-width: 0; /* critical: grid children default to min-width:auto, which prevents scroll */
}
.wb-name-row  { margin-bottom: 14px; }
.wb-name-input {
  font-size: 15px !important;
  font-weight: 600 !important;
  max-width: 380px;
}

/* ── Table ── */
.wb-table-wrap {
  display: block;
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}
.wb-table { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 13px; }
.wb-table th {
  background: var(--bg-3);
  color: var(--text-2);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.wb-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.wb-table tbody tr:last-child td { border-bottom: none; }
.wb-table tbody tr:hover { background: var(--bg-3); }

.wb-th-drag     { width: 24px; }
.wb-th-exercise { min-width: 160px; }
.wb-th-sets,
.wb-th-reps     { width: 72px; }
.wb-th-video    { min-width: 200px; }
.wb-th-del      { width: 32px; }
.wb-td-drag     { text-align: center; color: var(--text-2); }

/* ── Video cell ── */
.wb-video-cell {
  display: flex;
  align-items: center;
  gap: 5px;
}
.wb-url-status {
  flex-shrink: 0;
  width: 16px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.wb-url-ok    { color: #4ade80; }
.wb-url-empty { color: var(--text-2); opacity: 0.5; }
.wb-url-input {
  flex: 1;
  min-width: 0;
  font-size: 12px !important;
  padding: 4px 7px !important;
  height: auto !important;
  color: var(--text-2) !important;
}
.wb-url-input.wb-input-autofilled {
  color: var(--accent) !important;
  border-color: rgba(126,232,162,0.3) !important;
}
.wb-url-input:focus { color: var(--text) !important; }
.wb-url-input::placeholder { font-size: 11px; }
.wb-video-watch {
  flex-shrink: 0;
  color: var(--accent);
  font-size: 14px;
  text-decoration: none;
  line-height: 1;
  padding: 2px 3px;
  border-radius: 3px;
  transition: background 0.15s;
}
.wb-video-watch:hover { background: rgba(126,232,162,0.12); }
.wb-drag-handle {
  cursor: grab;
  font-size: 16px;
  opacity: 0.45;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 6px;
  min-width: 32px;
  min-height: 36px;
  border-radius: 4px;
  user-select: none;
  touch-action: none;
  transition: opacity 0.15s, color 0.15s;
}
.wb-drag-handle:hover  { opacity: 1; color: var(--accent); }
.wb-drag-handle:active { cursor: grabbing; }

/* Dragging ghost states */
.wb-row-dragging td { opacity: 0.18; background: var(--bg-3) !important; }
.wb-drag-ghost { border-collapse: collapse; background: var(--bg-3); border: 1px solid var(--accent); }
.wb-drag-ghost td { padding: 5px 6px; vertical-align: middle; white-space: nowrap; overflow: hidden; max-width: 200px; text-overflow: ellipsis; }

.wb-input    { padding: 5px 8px !important; font-size: 13px !important; height: auto !important; }
.wb-input-sm { width: 60px; }
.wb-del-btn  { padding: 3px 8px !important; font-size: 13px !important; line-height: 1 !important; }

/* ── Actions row ── */
.wb-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  flex-wrap: wrap;
  gap: 8px;
}

/* ── Library table ── */
.wb-lib-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.wb-lib-table th {
  background: var(--bg-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 500;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.wb-lib-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.wb-lib-table tbody tr:hover { background: var(--bg-3); }

/* ── Saved tag pills ── */
.wb-saved-tag-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  background: color-mix(in srgb, var(--tag-color) 20%, transparent);
  color: var(--tag-color);
  border: 1px solid color-mix(in srgb, var(--tag-color) 40%, transparent);
  line-height: 1.6;
}

/* ── Filter bar ── */
.wb-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

/* Row 1: tag dropdown + sort */
.wb-filter-row-1 {
  display: flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  box-sizing: border-box;
}

/* Row 2: client search - full width */
.wb-filter-row-2 {
  width: 100%;
  box-sizing: border-box;
}

/* Desktop: tag dropdown - fixed small width */
.wb-tag-dropdown {
  flex: 0 0 auto;
  width: 110px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  box-sizing: border-box;
}
.wb-tag-dropdown:focus { outline: none; border-color: var(--accent); }

/* Mobile: horizontal scroll strip of tag buttons */
.wb-filter-tags {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.wb-filter-tags::-webkit-scrollbar { display: none; }
.wb-filter-tag-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text-2);
  transition: all var(--transition);
  white-space: nowrap;
}
.wb-filter-tag-btn:hover {
  border-color: var(--tag-color, var(--accent));
  color: var(--tag-color, var(--accent));
  background: color-mix(in srgb, var(--tag-color, var(--accent)) 10%, transparent);
}
.wb-filter-tag-btn.wb-filter-tag-active {
  background: color-mix(in srgb, var(--tag-color, var(--accent)) 18%, transparent);
  border-color: var(--tag-color, var(--accent));
  color: var(--tag-color, var(--accent));
  font-weight: 600;
}
.wb-sort-select {
  flex: 0 0 auto;
  width: 110px;
  height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-3);
  color: var(--text);
  font-size: 12px;
  font-family: var(--font-body);
  cursor: pointer;
  box-sizing: border-box;
}

/* ── Tag picker row ── */
.wb-tag-picker-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: nowrap;
}
.wb-tag-picker-label { font-size: 11px; color: var(--text-2); font-weight: 500; white-space: nowrap; }
#wbTagPicker {
  display: flex;
  flex-wrap: nowrap;
  gap: 5px;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
  flex: 1;
  min-width: 0;
}
#wbTagPicker::-webkit-scrollbar { display: none; }

/* Mobile tag search */
.wb-tag-selected-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
}
.wb-tag-pill-remove {
  background: none;
  border: none;
  color: inherit;
  padding: 0 0 0 4px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  opacity: 0.75;
}
.wb-tag-pill-remove:hover { opacity: 1; }
.wb-tag-search-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
.wb-tag-search-input {
  width: 100%;
  height: 32px;
  box-sizing: border-box;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  font-size: 12px;
  font-family: var(--font-body);
  color: var(--text);
  outline: none;
}
.wb-tag-search-input:focus { border-color: var(--accent); }

.wb-tag-pill {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--tag-color) 40%, transparent);
  background: color-mix(in srgb, var(--tag-color) 12%, transparent);
  color: var(--tag-color);
  transition: all var(--transition);
}
.wb-tag-pill:hover { background: color-mix(in srgb, var(--tag-color) 22%, transparent); }
.wb-tag-pill.wb-tag-pill-active { background: var(--tag-color); color: #fff; border-color: var(--tag-color); }
.wb-tag-picker-empty { font-size: 11px; color: var(--text-2); }
.wb-tag-text-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.wb-tag-text-btn:hover { opacity: 0.8; }

/* ── Tag manager ── */
.wb-tag-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
  max-height: 220px;
  overflow-y: auto;
}
.wb-tag-manager-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.wb-tag-manager-swatch { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.wb-tag-manager-name   { font-size: 13px; color: var(--text); flex: 1; }

/* ── Color swatches ── */
.wb-color-swatches { display: flex; gap: 5px; flex-wrap: wrap; }
.wb-color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
  flex-shrink: 0;
}
.wb-color-swatch:hover { transform: scale(1.15); }
.wb-color-swatch.wb-swatch-active { border-color: var(--text); transform: scale(1.18); }
.wb-color-custom {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  padding: 0;
  cursor: pointer;
  background: none;
  overflow: hidden;
  flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .wb-layout { grid-template-columns: 1fr; }
}

/* ── Exercise autocomplete suggestions ── */
.wb-exercise-wrap {
  position: relative;
  display: block;
}
.wb-suggestions {
  /* Position/size set inline by JS (absolute, body-level) so it's never clipped by table stacking contexts */
  position: absolute;
  max-height: calc(37px * 3);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
  background: var(--bg-3);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 99999;
  animation: wbSuggestIn 0.12s ease both;
}
.wb-suggestions::-webkit-scrollbar { width: 4px; }
.wb-suggestions::-webkit-scrollbar-track { background: transparent; }
.wb-suggestions::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }
@keyframes wbSuggestIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.wb-suggestion-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: background 0.12s;
  white-space: nowrap;
}
.wb-suggestion-item + .wb-suggestion-item {
  border-top: 1px solid var(--border);
}
.wb-suggestion-item:hover,
.wb-suggestion-item.wb-suggestion-focused {
  background: var(--bg-4);
}
.wb-suggestion-name { flex: 1; color: var(--text); }
.wb-suggestion-match { color: var(--accent); font-weight: 600; }
.wb-suggestion-badge {
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ── Client search picker ── */
.wb-client-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  max-width: 260px;
}
.wb-client-search-input {
  flex: 1;
  font-size: 12px !important;
  padding: 4px 8px !important;
  height: auto !important;
}
.wb-client-clear {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s;
}
.wb-client-clear:hover { color: var(--red); }
.wb-client-dropdown {
  position: absolute;
  top: calc(100% + 3px);
  left: 0;
  width: 100%;
  min-width: 180px;
  max-height: calc(37px * 3);
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) transparent;
  background: var(--bg-3);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 9999;
  animation: wbSuggestIn 0.12s ease both;
}
.wb-client-dropdown::-webkit-scrollbar { width: 4px; }

/* Fixed-position variant: appended to body so it escapes overflow:hidden parents */
.wb-client-dropdown-fixed {
  position: fixed !important;
  top: auto;
  left: auto;
}
.wb-client-dropdown::-webkit-scrollbar-track { background: transparent; }
.wb-client-dropdown::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }
.wb-client-option {
  display: block;
  width: 100%;
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s;
}
.wb-client-option + .wb-client-option { border-top: 1px solid var(--border); }
.wb-client-option:hover,
.wb-client-option-focused { background: var(--bg-4); }

/* ── Share warning modal ── */
.wb-warn-modal { max-width: 400px; }
.wb-warn-list {
  list-style: none;
  padding: 0;
  margin: 0 0 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.wb-warn-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.45;
}
.wb-warn-icon {
  color: var(--amber);
  font-size: 14px;
  flex-shrink: 0;
  margin-top: 1px;
}
.wb-warn-note {
  font-size: 12px;
  color: var(--text-2);
  line-height: 1.5;
}

/* ── Client filter in saved workouts bar ── */
.wb-client-filter-wrap {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
  height: 32px;
  box-sizing: border-box;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-3);
  padding: 0 8px 0 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.wb-client-filter-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(124,111,255,0.18);
}
.wb-client-filter-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  box-shadow: none;
  padding: 0;
  margin: 0;
  font-size: 12px;
  font-family: var(--font-body);
  color: var(--text);
  line-height: 1.4;
  cursor: text;
}
.wb-client-filter-input::placeholder { color: var(--text-2); opacity: 0.7; }
.wb-client-filter-wrap .wb-client-clear {
  flex-shrink: 0;
  margin-left: 2px;
  font-size: 13px;
  line-height: 1;
  padding: 0 2px;
}
