/* =====================================================================
   ResizePixel - Interactive Canvas Editor Styles
   High-performance, touch-friendly, responsive canvas editor
   ===================================================================== */

.editor-view {
  display: none;
  padding: 1.5rem 0 3rem;
  background: var(--bg-body);
}

.editor-shell {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.5rem;
  align-items: start;
}

/* ---------------- Left Sidebar & Tool Panel ---------------- */
.editor-sidebar {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.sidebar-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-subtle);
  padding: 0.35rem;
  gap: 0.25rem;
}

.tool-tab-btn {
  flex: 1 1 calc(25% - 0.25rem);
  min-width: 64px;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.25rem;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: all 0.15s ease;
}
.tool-tab-btn span.icon {
  font-size: 1.15rem;
}
.tool-tab-btn:hover {
  background: #ffffff;
  color: var(--primary);
}
.tool-tab-btn.active {
  background: #ffffff;
  color: var(--primary);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
}

.tool-controls-body {
  padding: 1.25rem;
}

.tool-panel-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.tool-panel-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 1.25rem;
  line-height: 1.4;
}

/* Input Fields & Forms */
.form-group {
  margin-bottom: 1rem;
}
.form-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.35rem;
}
.form-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.input-text, .input-select {
  width: 100%;
  height: 40px;
  padding: 0 0.75rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-main);
  background: #ffffff;
  transition: border-color 0.15s ease;
}
.input-text:focus, .input-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

/* Range Sliders */
.slider-group {
  margin-bottom: 1rem;
}
.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
}
.slider-val {
  color: var(--primary);
  font-weight: 700;
}
.range-slider {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.range-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
}

/* Preset Pill Buttons */
.preset-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
  margin-bottom: 1rem;
}
.preset-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.preset-btn:hover {
  background: #ffffff;
  border-color: var(--primary);
  color: var(--primary);
}
.preset-btn.active {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

/* Checkbox & Switches */
.switch-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
}

/* Primary Tool Action Buttons */
.btn-apply-tool {
  width: 100%;
  height: 42px;
  background: var(--primary);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.btn-apply-tool:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

/* ---------------- Right Stage / Canvas Area ---------------- */
.editor-stage {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.stage-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border-light);
}

.scaled-indicator {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tool-icon-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.65rem;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.15s ease;
}
.tool-icon-btn:hover {
  background: #ffffff;
  color: var(--primary);
  border-color: var(--primary-border);
}

/* Canvas Viewport */
.canvas-viewport {
  background: repeating-conic-gradient(#f1f5f9 0% 25%, #ffffff 0% 50%) 50% / 16px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  min-height: 420px;
  max-height: 560px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  user-select: none;
}

#previewHolder {
  position: relative;
  display: inline-block;
  line-height: 0;
  max-width: 100%;
  max-height: 100%;
}

#previewCanvas {
  display: block;
  max-width: 100%;
  max-height: 500px;
  object-fit: contain;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
}

/* ---------------- Interactive Crop Box Overlay ---------------- */
#cropBox {
  position: absolute;
  top: 0;
  left: 0;
  border: 2px dashed #3b82f6;
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.55);
  cursor: move;
  display: none;
  box-sizing: border-box;
}

/* Rule of Thirds Grid */
#cropBox::before, #cropBox::after {
  content: '';
  position: absolute;
  pointer-events: none;
  border-color: rgba(255, 255, 255, 0.4);
}
#cropBox::before {
  top: 33.33%;
  left: 0;
  right: 0;
  height: 33.33%;
  border-top: 1px dashed rgba(255, 255, 255, 0.4);
  border-bottom: 1px dashed rgba(255, 255, 255, 0.4);
}
#cropBox::after {
  left: 33.33%;
  top: 0;
  bottom: 0;
  width: 33.33%;
  border-left: 1px dashed rgba(255, 255, 255, 0.4);
  border-right: 1px dashed rgba(255, 255, 255, 0.4);
}

/* Crop Resize Handles */
.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #3b82f6;
  border: 2px solid #ffffff;
  border-radius: 2px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}
.handle-nw { top: -6px; left: -6px; cursor: nwse-resize; }
.handle-ne { top: -6px; right: -6px; cursor: nesw-resize; }
.handle-se { bottom: -6px; right: -6px; cursor: nwse-resize; }
.handle-sw { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-n  { top: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.handle-s  { bottom: -6px; left: calc(50% - 6px); cursor: ns-resize; }
.handle-w  { left: -6px; top: calc(50% - 6px); cursor: ew-resize; }
.handle-e  { right: -6px; top: calc(50% - 6px); cursor: ew-resize; }

/* ---------------- Live Specs Comparison Bar ---------------- */
.meta-comparison-bar {
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 0.85rem 1.25rem;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 1rem;
  align-items: center;
}

.spec-item {
  display: flex;
  flex-direction: column;
}
.spec-item-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}
.spec-item-val {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.reduction-badge {
  background: #ecfdf5;
  color: #059669;
  border: 1px solid #a7f3d0;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
}

/* ---------------- Bottom Execution & Download Bar ---------------- */
.stage-bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-light);
}

.stage-actions-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stage-actions-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-secondary-action {
  height: 42px;
  padding: 0 1rem;
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}
.btn-secondary-action:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}
.btn-danger-action {
  color: var(--danger);
  border-color: #fecaca;
}
.btn-danger-action:hover {
  background: var(--danger-light);
  color: #b91c1c;
}

.btn-download-main {
  height: 46px;
  padding: 0 1.75rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #ffffff;
  border: none;
  border-radius: var(--radius-full);
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
  transition: all 0.15s ease;
}
.btn-download-main:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(16, 185, 129, 0.45);
}

/* ---------------- Mobile Responsive Media Queries for Editor ---------------- */
@media (max-width: 960px) {
  .editor-shell {
    grid-template-columns: 1fr;
  }
  .canvas-viewport {
    min-height: 320px;
    max-height: 420px;
  }
  .meta-comparison-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .editor-view {
    padding: 0.5rem 0 2rem;
  }
  .editor-stage {
    padding: 0.85rem;
  }
  .canvas-viewport {
    min-height: 260px;
    max-height: 360px;
  }
  .stage-bottom-bar {
    flex-direction: column-reverse;
    align-items: stretch;
  }
  .stage-actions-right, .stage-actions-left {
    width: 100%;
    justify-content: stretch;
  }
  .btn-download-main {
    width: 100%;
    justify-content: center;
  }
  .btn-secondary-action {
    flex: 1;
    justify-content: center;
  }
}

/* =====================================================================
   v2 – editor mobile layout (placed here so it wins over earlier rules)
   ===================================================================== */
@media (max-width: 960px) {
  .editor-shell { display: flex; flex-direction: column-reverse; gap: 1rem; }
  .sidebar-tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; scroll-snap-type: x proximity; }
  .sidebar-tabs::-webkit-scrollbar { display: none; }
  .tool-tab-btn { flex: 0 0 auto; min-width: 76px; min-height: 60px; scroll-snap-align: center; }
  .canvas-viewport { min-height: 240px; }
  #previewCanvas { max-height: 60vh; }
}
@media (max-width: 640px) {
  .crop-handle { width: 26px; height: 26px; }
  .handle-n, .handle-s, .handle-e, .handle-w { transform-origin: center; }
}
.crop-handle { touch-action: none; }
#cropBox { touch-action: none; }


/* ---- Tool tabs: always visible (no hidden horizontal scroll) ---- */
.sidebar-tabs { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 0.3rem; overflow: visible !important; scroll-snap-type: none !important; }
.sidebar-tabs .tool-tab-btn { flex: none; min-width: 0 !important; min-height: 58px; padding: 0.5rem 0.2rem; font-size: 0.74rem; border: 1px solid transparent; }
.sidebar-tabs .tool-tab-btn.active { border-color: var(--primary); }
