/* =============================
   CrispyCore Program Builder
   Dark theme — variables defined in styles.css
   ============================= */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ========== LAYOUT ========== */
.app-shell {
  padding: var(--space-lg);
  padding-top: 80px;
  max-width: 1600px;
  margin: 0 auto;
}

.builder-grid {
  display: grid;
  grid-template-columns: 176px minmax(0, 1fr) 272px;
  gap: var(--space-lg);
  align-items: start;
}

/* ========== STEPPER ========== */
.stepper {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  position: sticky;
  top: 80px;
}

.step {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  background: var(--bg-card);
  border-radius: 999px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
  color: var(--muted);
  transition: border-color 0.2s, background 0.2s, color 0.2s;
}

.step:hover {
  border-color: rgba(79,163,232,0.25);
  color: var(--text);
}

.step.active {
  border-color: var(--accent);
  background: rgba(79,163,232,0.08);
  color: var(--text);
}

.step-index {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.8rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
  transition: background 0.2s, color 0.2s;
}

.step.active .step-index {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ========== PANEL ========== */
.panel {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 72vh;
}

.panel-header {
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.panel-header h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel-body {
  padding: var(--space-lg);
  display: none;
  flex: 1;
}

.panel-body.active { display: block; }

.panel-actions {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  align-items: center;
  gap: var(--space-sm);
}

.panel-footer {
  margin-top: auto;
  padding: var(--space-md) var(--space-lg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* ========== SUMMARY SIDEBAR ========== */
.summary {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  position: sticky;
  top: 80px;
}

.summary h2 {
  margin: 0 0 4px;
  font-size: 1.1rem;
  font-weight: 700;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
}

.summary-card h3 {
  margin: 0 0 var(--space-sm);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.summary-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--muted);
}

.summary-line:last-child { border-bottom: none; }

.summary-line strong {
  color: var(--text);
  font-weight: 600;
  font-size: 0.875rem;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.file-list li {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  padding: 3px 0;
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}

.file-list li:last-child { border-bottom: none; }

/* ========== BUTTONS ========== */
button {
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-weight: 600;
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

button:active { transform: translateY(1px); }

button.primary {
  background: var(--gradient);
  color: #fff;
  box-shadow: 0 4px 16px rgba(79,163,232,0.28);
}

button.primary:hover {
  opacity: 0.9;
  box-shadow: 0 6px 20px rgba(79,163,232,0.38);
}

button.ghost {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(79,163,232,0.18);
}

button.ghost:hover {
  background: rgba(79,163,232,0.18);
  border-color: rgba(79,163,232,0.3);
}

button.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(248,81,73,0.18);
}

/* ========== GRID SYSTEM ========== */
.grid {
  display: grid;
  gap: var(--space-sm);
}

.grid.two   { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.four  { grid-template-columns: repeat(4, minmax(0,1fr)); }

/* ========== FORM FIELDS ========== */
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

.field span:first-child {
  display: flex;
  align-items: center;
  gap: 4px;
}

.field input,
.field select,
.field textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
  outline: none;
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--faint);
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--border-focus);
  background: rgba(255,255,255,0.06);
}

.field select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.field select option {
  background: #1c2330;
  color: var(--text);
}

.field.full { grid-column: 1 / -1; }

.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: var(--space-xs);
  color: var(--text);
  font-weight: 500;
}

.field.checkbox input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  background: var(--bg-input);
  border: 1px solid var(--border);
  padding: 0;
  cursor: pointer;
}

.field.placeholder {
  justify-content: flex-end;
  color: var(--faint);
  font-size: 0.75rem;
  padding-bottom: 2px;
}

/* ========== TAGS ========== */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  transition: border-color 0.2s;
}

.tags:focus-within {
  border-color: var(--border-focus);
}

.tags input {
  background: none;
  border: none;
  padding: 4px;
  flex: 1 1 160px;
  font-size: 0.875rem;
  color: var(--text);
  outline: none;
  min-width: 80px;
}

.tags input::placeholder { color: var(--faint); }

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid rgba(79,163,232,0.2);
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
}

.tag button {
  padding: 0;
  background: none;
  border: none;
  color: inherit;
  font-size: 0.9rem;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
  box-shadow: none;
}

.tag button:hover { opacity: 1; }

/* ========== LIST EDITOR ========== */
.list-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
}

.list-items {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.list-item {
  display: flex;
  gap: 7px;
  align-items: center;
}

.list-item input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.list-item input:focus { border-color: var(--border-focus); }

/* ========== CARDS & ROWS ========== */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  background: var(--bg-elevated);
}

.card.workout {
  border-color: rgba(79,163,232,0.12);
}

.card.block {
  background: rgba(255,255,255,0.02);
  border-style: dashed;
}

.card.phase {
  border-color: rgba(155,109,255,0.15);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
}

.inline-actions {
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid var(--border);
}

.row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.row.item {
  background: rgba(255,255,255,0.02);
  border-style: dashed;
}

/* ========== HINTS & MISC ========== */
.hint {
  font-size: 0.72rem;
  color: var(--faint);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

.empty {
  padding: var(--space-lg);
  text-align: center;
  color: var(--faint);
  font-size: 0.875rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  margin-top: var(--space-sm);
}

.subtle {
  color: var(--muted);
  font-size: 0.85rem;
}

.notice {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: rgba(79,163,232,0.08);
  border: 1px solid rgba(79,163,232,0.2);
  color: var(--accent);
  margin-bottom: var(--space-sm);
  font-size: 0.875rem;
  font-weight: 500;
}

/* ========== HELP TOOLTIPS ========== */
.help-icon {
  font-size: 0.68em;
  width: 1.2em;
  height: 1.2em;
  border-radius: 50%;
  background: var(--faint);
  color: var(--bg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: help;
  position: relative;
  flex-shrink: 0;
  vertical-align: middle;
  line-height: 1;
  transition: background 0.15s;
}

.help-icon:hover { background: var(--muted); }

.help-icon::before {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: #2d333b;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.55;
  z-index: 200;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.15s, visibility 0.15s;
  pointer-events: none;
  width: 340px;
  white-space: normal;
  text-align: left;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}

.help-icon:hover::before {
  visibility: visible;
  opacity: 1;
}

/* ========== STEP INFO CALLOUT ========== */
.step-info {
  background: rgba(79,163,232,0.06);
  border: 1px solid rgba(79,163,232,0.15);
  border-radius: var(--radius-sm);
  padding: var(--space-sm) var(--space-md);
  margin-bottom: var(--space-md);
  font-size: 0.875rem;
  color: var(--muted);
  line-height: 1.6;
}

.step-info p { margin: 0; }
.step-info p + p { margin-top: 0.5rem; }
.step-info strong { color: var(--text); font-weight: 600; }
.step-info em { color: var(--accent); font-style: normal; }

.block-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem 1.5rem;
  margin: 0.6rem 0 0.5rem;
  font-size: 0.82rem;
}
.block-pills span { color: var(--muted); }

/* ========== SIDEBAR ACTIONS ========== */
.actions-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.btn-full {
  width: 100%;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.btn-danger {
  background: var(--danger-soft) !important;
  color: var(--danger) !important;
  border-color: rgba(248,81,73,0.18) !important;
}

.btn-danger:hover {
  background: rgba(248,81,73,0.18) !important;
}

/* ========== EXERCISE LIBRARY ========== */
.library {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  margin-bottom: var(--space-md);
  background: var(--bg-elevated);
}

.library-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-sm);
  flex-wrap: wrap;
}

.library-header > div h3 {
  margin: 0 0 3px;
  font-size: 1rem;
  font-weight: 600;
}

.library-header > div p {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.library-header input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
  min-width: 200px;
}

.library-header input::placeholder { color: var(--faint); }
.library-header input:focus { border-color: var(--border-focus); }

.library-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-sm);
  max-height: 340px;
  overflow-y: auto;
  padding-right: 4px;
}

.library-list::-webkit-scrollbar { width: 4px; }
.library-list::-webkit-scrollbar-track { background: transparent; }
.library-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.library-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  background: var(--bg-card);
  display: flex;
  flex-direction: column;
  gap: 5px;
  transition: border-color 0.2s;
}

.library-card:hover { border-color: rgba(79,163,232,0.2); }

.library-card.added {
  border-color: rgba(79,163,232,0.4);
  background: rgba(79,163,232,0.05);
}

.library-card h4 {
  margin: 0;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.library-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.library-card button {
  align-self: flex-start;
  margin-top: auto;
  padding: 5px 12px;
  font-size: 0.78rem;
}

/* ========== EXERCISE EDITOR ========== */
.exercise-editor-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: var(--space-md);
  min-height: 50vh;
  align-items: start;
}

.exercise-list-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-sm);
  overflow-y: auto;
  max-height: 60vh;
  background: var(--bg-elevated);
}

.exercise-list-panel::-webkit-scrollbar { width: 4px; }
.exercise-list-panel::-webkit-scrollbar-track { background: transparent; }
.exercise-list-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.exercise-list-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.exercise-list-item {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  font-size: 0.875rem;
}

.exercise-list-item > div:first-child {
  font-weight: 600;
  color: var(--text);
}

.exercise-list-item:hover {
  background: var(--accent-soft);
  border-color: rgba(79,163,232,0.15);
}

.exercise-list-item.active {
  border-color: var(--accent);
  background: rgba(79,163,232,0.1);
}

.exercise-editor-panel {
  padding: var(--space-sm);
}

.exercise-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-sm);
}

.exercise-title {
  font-weight: 700;
  font-size: 1rem;
}

.exercise-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.exercise-actions { display: flex; gap: 8px; }

/* ========== WEEK SCHEDULE ========== */
.week-schedule {
  display: grid;
  grid-template-columns: repeat(7, minmax(0,1fr));
  gap: 8px;
}

.day-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.day-item span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
}

.day-item select {
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  background-image: none;
  color: var(--text);
  font-size: 0.78rem;
  font-family: inherit;
  text-align: center;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

.day-item select:focus { border-color: var(--border-focus); }
.day-item select option { background: #1c2330; color: var(--text); }

/* ========== REVIEW ========== */
.review {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: var(--space-md);
}

.review-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-md);
  background: var(--bg-elevated);
}

.review-card h3 {
  margin: 0 0 var(--space-sm);
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.validation {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.validation li {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(79,163,232,0.06);
  color: var(--accent);
  font-size: 0.875rem;
  border: 1px solid rgba(79,163,232,0.15);
}

.validation li.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(248,81,73,0.2);
}

.preview {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 0.75rem;
  white-space: pre-wrap;
  color: var(--muted);
  max-height: 500px;
  overflow: auto;
  line-height: 1.6;
}

.preview::-webkit-scrollbar { width: 4px; height: 4px; }
.preview::-webkit-scrollbar-track { background: transparent; }
.preview::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ========== WORKOUT / BLOCK TITLE HINTS ========== */
.workout-id-hint,
.item-id-hint {
  font-size: 0.72rem;
  color: var(--faint);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

/* ========== UTILITY ========== */
.hidden { display: none !important; }

.field-small { max-width: 120px; }

/* ========== SCROLLBARS (global) ========== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
  .builder-grid {
    grid-template-columns: 1fr;
  }

  .stepper {
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
  }

  .summary {
    position: static;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }

  .week-schedule {
    grid-template-columns: repeat(4, minmax(0,1fr));
  }
}

@media (max-width: 900px) {
  .exercise-editor-layout {
    grid-template-columns: 1fr;
  }

  .review {
    grid-template-columns: 1fr;
  }

  .library-list {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }
}

@media (max-width: 640px) {
  .app-shell { padding: var(--space-md); padding-top: 80px; }

  .grid.two,
  .grid.three,
  .grid.four {
    grid-template-columns: 1fr;
  }

  .week-schedule {
    grid-template-columns: repeat(2, 1fr);
  }

  button {
    padding: 8px 14px;
    font-size: 0.82rem;
  }
}
