/* ══════════════════════════════════════════
   components.css — Reusable UI components
══════════════════════════════════════════ */

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background: var(--accent);
  color: #0a0c0f;
  border-color: var(--accent);
}
.btn-primary:hover {
  background: #00e8a8;
  box-shadow: var(--shadow-accent);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.25);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  box-shadow: 0 0 12px rgba(239, 68, 68, 0.2);
}

.full-width {
  width: 100%;
}

/* ─── Algorithm selector grid ─── */
.algo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.algo-btn {
  padding: var(--space-2) var(--space-3);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-align: center;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.algo-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.algo-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--border-accent);
}

/* ─── Sliders ─── */
.slider {
  width: 100%;
  height: 4px;
  appearance: none;
  background: var(--bg-elevated);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  border: 1px solid var(--border-subtle);
  margin-top: var(--space-2);
}

.slider::-webkit-slider-thumb {
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition:
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  box-shadow: 0 0 8px var(--accent-glow);
}

.control-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.control-value {
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ─── Playback controls ─── */
.playback-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

.playback-controls .btn-primary {
  grid-column: 1 / -1;
}

/* ─── Legend ─── */
.legend {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.legend li {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
}

.legend-dot.default {
  background: var(--color-default);
}
.legend-dot.comparing {
  background: var(--color-comparing);
}
.legend-dot.swapping {
  background: var(--color-swapping);
}
.legend-dot.sorted {
  background: var(--color-sorted);
}
.legend-dot.pivot {
  background: var(--color-pivot);
}

/* ─── Stats ─── */
.stats-block {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: var(--space-3);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ─── Complexity header ─── */
.complexity-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-6);
  flex-shrink: 0;
}

.algo-info {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.algo-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

.complexity-badges {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.badge {
  padding: 2px var(--space-3);
  border-radius: 2px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  border: 1px solid transparent;
}

.badge-best {
  background: rgba(0, 210, 150, 0.1);
  color: #00d296;
  border-color: rgba(0, 210, 150, 0.25);
}
.badge-avg {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
  border-color: rgba(245, 158, 11, 0.25);
}
.badge-worst {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.25);
}
.badge-space {
  background: rgba(139, 92, 246, 0.1);
  color: #8b5cf6;
  border-color: rgba(139, 92, 246, 0.25);
}

/* ─── Progress ─── */
.progress-wrap {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 200px;
}

.progress-bar {
  flex: 1;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
  transition: width var(--transition-fast);
  box-shadow: 0 0 8px var(--accent-glow);
}

.progress-text {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
}

/* ─── Explanation panel ─── */
.explanation-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  flex-shrink: 0;
  position: relative;
}

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

.explanation-title {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.explanation-text {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.7;
  min-height: 40px;
  transition: color var(--transition-normal);
}

.explanation-text strong {
  color: var(--accent);
  font-weight: 600;
}

.step-counter {
  position: absolute;
  top: var(--space-4);
  right: var(--space-5);
  font-size: 0.68rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ─── Operation history ─── */
.op-history {
  max-height: 140px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.op-history::-webkit-scrollbar {
  width: 3px;
}
.op-history::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
}

.op-history li {
  font-size: 0.7rem;
  color: var(--text-secondary);
  padding: 3px var(--space-2);
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border-left: 2px solid transparent;
  animation: slideInLeft var(--transition-normal) ease;
}

.op-history li.success {
  border-left-color: var(--color-success);
}
.op-history li.error {
  border-left-color: var(--color-error);
}
.op-history li.info {
  border-left-color: var(--color-info);
}

.history-empty {
  color: var(--text-muted) !important;
  font-style: italic;
}

/* ─── DS operations panel ─── */
.ds-ops {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.ds-op-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.ds-op-row {
  display: flex;
  gap: var(--space-2);
}

.ds-op-input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: var(--space-2) var(--space-3);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color var(--transition-fast);
}

.ds-op-input:focus {
  border-color: var(--border-accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}

.ds-op-input::placeholder {
  color: var(--text-muted);
}

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  padding: var(--space-3) var(--space-5);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease forwards;
  pointer-events: auto;
}

.toast.success {
  border-left: 3px solid var(--color-success);
}
.toast.error {
  border-left: 3px solid var(--color-error);
}
.toast.info {
  border-left: 3px solid var(--color-info);
}

.array-controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
