/* ==========================================================================
   That One Web Guy - Image Utility
   components.css: UI Components, Inputs, Sliders, Cropper, Modals & Toast
   ========================================================================== */

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  line-height: 1.2;
  user-select: none;
}

.btn-primary {
  background: var(--gradient-primary);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.4);
}
.btn-primary:hover {
  box-shadow: 0 4px 16px rgba(99, 102, 241, 0.6);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border-medium);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
}

.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-danger {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border-color: rgba(244, 63, 94, 0.3);
}
.btn-danger:hover {
  background: rgba(244, 63, 94, 0.25);
  border-color: #f43f5e;
}

.btn-accent {
  background: var(--gradient-accent);
  color: #ffffff;
}

/* --- Form Inputs & Controls --- */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-value-badge {
  font-family: monospace;
  font-size: 11.5px;
  color: var(--accent-sky);
  background: rgba(56, 189, 248, 0.1);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.form-input, .form-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition-fast);
}

.form-input:focus, .form-select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

/* Row of inputs */
.input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.input-row .form-group {
  flex: 1;
  margin-bottom: 0;
}

/* Segmented Control Pills */
.segmented-control {
  display: flex;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  gap: 2px;
}

.segment-btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
  white-space: nowrap;
}

.segment-btn:hover {
  color: var(--text-primary);
}

.segment-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.4);
}

/* Custom Range Slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: #1e293b;
  outline: none;
  margin: 6px 0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 2px solid #ffffff;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.6);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Toggle Switch */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider-switch {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background-color: #1e293b;
  border: 1px solid var(--border-medium);
  transition: var(--transition-fast);
  border-radius: 22px;
}

.slider-switch:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: #ffffff;
  transition: var(--transition-fast);
  border-radius: 50%;
}

input:checked + .slider-switch {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

input:checked + .slider-switch:before {
  transform: translateX(18px);
}

/* --- Accordion in Left Sidebar --- */
.accordion-item {
  border-bottom: 1px solid var(--border-subtle);
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 16px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.accordion-header:hover {
  background: rgba(255, 255, 255, 0.03);
}

.accordion-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.accordion-icon {
  width: 16px;
  height: 16px;
  color: var(--accent-sky);
}

.accordion-chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform var(--transition-normal);
}

.accordion-item.open .accordion-chevron {
  transform: rotate(180deg);
}

.accordion-body {
  padding: 0 16px 16px 16px;
  display: none;
}

.accordion-item.open .accordion-body {
  display: block;
}

/* Preset Cards Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.preset-card {
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
}

.preset-card:hover {
  border-color: var(--accent-primary);
  background: var(--bg-card-hover);
  transform: translateY(-1px);
}

.preset-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}

.preset-dims {
  font-size: 10.5px;
  color: var(--accent-sky);
  margin-top: 2px;
}

/* Aspect Ratio Buttons */
.aspect-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.aspect-btn {
  padding: 6px 4px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
}

.aspect-btn:hover {
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.aspect-btn.active {
  background: var(--accent-primary);
  color: #ffffff;
  border-color: var(--accent-primary);
}

/* --- Center Stage Viewport --- */
.canvas-viewport {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: default;
}

.canvas-viewport.panning {
  cursor: grab;
}
.canvas-viewport.is-panning {
  cursor: grabbing;
}

.canvas-wrapper {
  position: relative;
  display: inline-block;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.7);
  border-radius: 4px;
}

#mainCanvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  user-select: none;
}

/* Interactive Cropper Overlay */
.cropper-overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  z-index: 10;
}

.cropper-overlay.hidden {
  display: none;
}

.crop-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
}

.crop-box {
  position: absolute;
  border: 2px solid #38bdf8;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.65), 0 0 12px rgba(56, 189, 248, 0.6);
  cursor: move;
  box-sizing: border-box;
}

.crop-badge {
  position: absolute;
  top: -28px;
  left: 0;
  background: rgba(15, 23, 42, 0.9);
  color: #38bdf8;
  font-family: monospace;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(56, 189, 248, 0.4);
  white-space: nowrap;
  pointer-events: none;
}

.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crop-grid-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.3);
}

.crop-grid-line.h-1 { top: 33.33%; left: 0; right: 0; height: 1px; }
.crop-grid-line.h-2 { top: 66.66%; left: 0; right: 0; height: 1px; }
.crop-grid-line.v-1 { left: 33.33%; top: 0; bottom: 0; width: 1px; }
.crop-grid-line.v-2 { left: 66.66%; top: 0; bottom: 0; width: 1px; }

/* 8 handles */
.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border: 2px solid #38bdf8;
  border-radius: 2px;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
  box-sizing: border-box;
}

.handle-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.handle-n  { top: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.handle-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.handle-e  { top: calc(50% - 6px); right: -6px; cursor: ew-resize; }
.handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.handle-s  { bottom: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-w  { top: calc(50% - 6px); left: -6px; cursor: ew-resize; }

/* Before / After Split Slider Container */
.split-slider-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.split-slider-container.hidden {
  display: none;
}

.split-clip-wrapper {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.split-divider {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #ffffff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.7);
  pointer-events: auto;
  cursor: ew-resize;
  z-index: 25;
}

.split-divider-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #ffffff;
  color: #0f172a;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  font-weight: 700;
  font-size: 12px;
}

/* Eyedropper Loupe */
.eyedropper-loupe {
  position: absolute;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 3px solid #ffffff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 30;
  overflow: hidden;
  display: none;
  background: #000000;
  transform: translate(-50%, -50%);
}

.loupe-canvas {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.loupe-crosshair {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.loupe-crosshair::before {
  content: '';
  width: 10px;
  height: 10px;
  border: 1px solid #ffffff;
  box-shadow: 0 0 2px #000000;
}

.loupe-color-badge {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  font-family: monospace;
  font-weight: 700;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.75);
  padding: 1px 6px;
  border-radius: 4px;
}

/* Stage Floating Bottom Toolbar */
.stage-toolbar {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-md);
  z-index: 20;
}

.stage-toolbar-divider {
  width: 1px;
  height: 20px;
  background: var(--border-subtle);
}

.zoom-level-text {
  font-size: 12px;
  font-weight: 600;
  font-family: monospace;
  color: var(--text-secondary);
  min-width: 44px;
  text-align: center;
}

/* --- Right Sidebar Inspector Components --- */
.inspector-card {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.inspector-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Stats Grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-box {
  background: var(--bg-card);
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.stat-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.stat-value {
  font-size: 14px;
  font-weight: 700;
  font-family: monospace;
  color: var(--text-primary);
}

.badge-savings {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
}

/* CMYK Print Proof Warning Card */
.cmyk-warning-card {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: var(--radius-md);
  margin-top: 10px;
  font-size: 11.5px;
  color: #fde68a;
  line-height: 1.4;
}

.cmyk-warning-icon {
  width: 16px;
  height: 16px;
  color: var(--accent-amber);
  flex-shrink: 0;
  margin-top: 2px;
}

/* Color Inspector Card */
.active-color-card {
  display: flex;
  gap: 12px;
  background: var(--bg-card);
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  margin-bottom: 12px;
}

.active-color-swatch {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.active-color-values {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-family: monospace;
}

.color-label {
  color: var(--text-muted);
  font-weight: 600;
}

.color-val {
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.copy-mini-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  display: flex;
  align-items: center;
}
.copy-mini-btn:hover {
  color: var(--accent-sky);
}

/* Color Palette Swatches */
.palette-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(36px, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.palette-swatch-item {
  height: 48px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  position: relative;
  transition: transform var(--transition-fast);
}

.palette-swatch-item:hover {
  transform: scale(1.08);
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
  z-index: 2;
}

.palette-swatch-item.is-dominant::after {
  content: '★';
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 9px;
  color: #ffffff;
  text-shadow: 0 1px 2px #000000;
}

/* --- Modals & Overlays --- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 1;
  transition: opacity var(--transition-normal);
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 680px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border-subtle);
  background: rgba(15, 23, 42, 0.4);
}

/* Batch Table */
.batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.batch-table th {
  text-align: left;
  padding: 8px 10px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
}

.batch-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.batch-thumb {
  width: 42px;
  height: 42px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: #000000;
}

/* Toast System */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 150;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.25s ease-out;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast-success {
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

.toast-info {
  border-color: rgba(56, 189, 248, 0.5);
  color: #38bdf8;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  font-family: monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  background: #1e293b;
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-sm);
  box-shadow: 0 1px 2px rgba(0,0,0,0.4);
}

.badge-status {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
}
.badge-status.pending { background: rgba(148,163,184,0.15); color: #94a3b8; }
.badge-status.processing { background: rgba(56,189,248,0.15); color: #38bdf8; }
.badge-status.completed { background: rgba(16,185,129,0.15); color: #34d399; }
.badge-status.error { background: rgba(244,63,94,0.15); color: #f43f5e; }

