@import url('../../src/styles/_buttons.css');
@import url('../../src/styles/_options.css');
@import url('../../src/styles/_progress.css');

.editor-workspace {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 1rem;
  margin-bottom: 1.5rem;
  animation: slideUp 0.3s ease-out;
}

.editor-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.editor-panel-left,
.editor-panel-right {
  max-height: calc(100vh - 180px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.editor-panel-left::-webkit-scrollbar,
.editor-panel-right::-webkit-scrollbar {
  width: 4px;
}

.editor-panel-left::-webkit-scrollbar-thumb,
.editor-panel-right::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

.editor-panel-center {
  min-width: 0;
}

.panel-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.85rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.panel-title svg {
  color: var(--primary);
  flex-shrink: 0;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
}

.preview-tabs {
  display: flex;
  gap: 4px;
}

.preview-tab {
  padding: 0.4rem 1rem;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: inherit;
}

.preview-tab:hover {
  color: var(--text);
  background: rgba(99, 102, 241, 0.06);
}

.preview-tab.active {
  background: var(--primary);
  color: white;
}

.preview-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.info-sep {
  color: var(--border);
}

.preview-canvas-wrapper {
  position: relative;
  flex: 1;
  height: calc(100vh - 280px);
  min-height: 450px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-image:
    linear-gradient(45deg, #e5e5e5 25%, transparent 25%),
    linear-gradient(-45deg, #e5e5e5 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e5e5 75%),
    linear-gradient(-45deg, transparent 75%, #e5e5e5 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  background-color: #fafafa;
}

.preview-canvas-wrapper canvas {
  position: absolute;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  image-rendering: auto;
}

#original-preview-container {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#original-preview-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.5rem;
}

.preview-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 0.5rem;
  gap: 1rem;
}

.preview-file-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.preview-file-info .file-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.preview-file-info .file-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.zoom-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.zoom-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99, 102, 241, 0.04);
}

.zoom-level {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 48px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.crop-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.crop-overlay.active {
  pointer-events: auto;
}

.crop-region {
  position: absolute;
  border: 2px dashed var(--primary);
  background: rgba(99, 102, 241, 0.1);
  cursor: move;
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: white;
  border: 2px solid var(--primary);
  border-radius: 2px;
}

.crop-handle-tl { top: -6px; left: -6px; cursor: nw-resize; }
.crop-handle-t { top: -6px; left: 50%; margin-left: -6px; cursor: n-resize; }
.crop-handle-tr { top: -6px; right: -6px; cursor: ne-resize; }
.crop-handle-r { top: 50%; right: -6px; margin-top: -6px; cursor: e-resize; }
.crop-handle-br { bottom: -6px; right: -6px; cursor: se-resize; }
.crop-handle-b { bottom: -6px; left: 50%; margin-left: -6px; cursor: s-resize; }
.crop-handle-bl { bottom: -6px; left: -6px; cursor: sw-resize; }
.crop-handle-l { top: 50%; left: -6px; margin-top: -6px; cursor: w-resize; }

.crop-shade {
  position: absolute;
  background: rgba(0, 0, 0, 0.5);
  pointer-events: auto;
}

.crop-shade-top { top: 0; left: 0; right: 0; cursor: move; }
.crop-shade-bottom { bottom: 0; left: 0; right: 0; cursor: move; }
.crop-shade-left { top: 0; left: 0; bottom: 0; cursor: move; }
.crop-shade-right { top: 0; right: 0; bottom: 0; cursor: move; }

.form-group {
  margin-bottom: 0.75rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.form-group select,
.form-group input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--card);
  color: var(--text);
  transition: var(--transition-fast);
  font-family: inherit;
}

.form-group select:focus,
.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.crop-toggle-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.crop-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
}

.crop-toggle input {
  display: none;
}

.crop-toggle-slider {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--border);
  border-radius: 11px;
  transition: var(--transition-fast);
}

.crop-toggle-slider::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.crop-toggle input:checked + .crop-toggle-slider {
  background: var(--primary);
}

.crop-toggle input:checked + .crop-toggle-slider::before {
  left: 21px;
}

.crop-toggle-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.crop-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.crop-input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.crop-presets,
.resize-presets {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.crop-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.btn-crop-apply {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--primary);
  color: white;
  transition: var(--transition-fast);
}

.btn-crop-apply:hover {
  opacity: 0.9;
}

.btn-crop-cancel {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--card);
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.btn-crop-cancel:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.crop-applied-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem;
  background: rgba(99, 102, 241, 0.06);
  border: 1px solid rgba(99, 102, 241, 0.2);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--primary);
  font-weight: 600;
}

.crop-applied-badge svg {
  flex-shrink: 0;
}

.crop-applied-dimensions {
  color: var(--text-secondary);
  font-weight: 500;
}

.btn-crop-remove {
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--card);
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.btn-crop-remove:hover {
  border-color: #ef4444;
  color: #ef4444;
}

.preset-btn {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  font-family: inherit;
}

.preset-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99, 102, 241, 0.04);
}

.preset-btn.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
  color: var(--primary);
}

.resize-inputs {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.resize-inputs .form-group {
  flex: 1;
  margin-bottom: 0;
}

.aspect-lock-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-muted);
  transition: var(--transition-fast);
  flex-shrink: 0;
}

.aspect-lock-btn:hover {
  border-color: var(--primary-light);
}

.aspect-lock-btn.active {
  border-color: var(--primary);
  color: var(--primary);
  background: rgba(99, 102, 241, 0.06);
}

.aspect-lock-btn .icon-unlocked {
  display: block;
}

.aspect-lock-btn .icon-locked {
  display: none;
}

.aspect-lock-btn.active .icon-unlocked {
  display: none;
}

.aspect-lock-btn.active .icon-locked {
  display: block;
}

.action-bar {
  display: flex;
  gap: 1rem;
  justify-content: center;
  align-items: center;
  margin-bottom: 1.5rem;
  animation: slideUp 0.3s ease-out;
}

.action-bar .btn-convert {
  flex: 1;
  max-width: 320px;
}

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

@media (max-width: 1200px) {
  .editor-workspace {
    grid-template-columns: 220px 1fr 240px;
  }
}

@media (max-width: 1000px) {
  .editor-workspace {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .editor-panel-left {
    order: 2;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .editor-panel-left .panel-section {
    flex: 1;
    min-width: 200px;
  }

  .editor-panel-center {
    order: 1;
  }

  .preview-canvas-wrapper {
    min-height: 300px;
  }

  .editor-panel-right {
    order: 3;
    max-height: none;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .editor-panel-right .panel-section {
    flex: 1;
    min-width: 200px;
  }
}

@media (max-width: 600px) {
  .editor-workspace {
    gap: 0.75rem;
  }

  .panel-section {
    padding: 0.85rem;
  }

  .editor-panel-left,
  .editor-panel-right {
    flex-direction: column;
  }

  .editor-panel-left .panel-section,
  .editor-panel-right .panel-section {
    min-width: auto;
  }

  .preview-canvas-wrapper {
    min-height: 250px;
  }

  .resize-inputs {
    flex-wrap: wrap;
  }

  .aspect-lock-btn {
    order: 3;
    margin: 0 auto;
  }

  .action-bar {
    flex-direction: column;
    gap: 0.75rem;
  }

  .action-bar .btn-convert {
    max-width: none;
    width: 100%;
  }
}