/* ============================================================
   ConverText — Workspace Styles
   ============================================================ */

/* --- Workspace View --- */
.workspace {
  display: none;
  min-height: 100vh;
  padding-top: 80px;
}

.workspace.active {
  display: block;
}

/* --- Workspace Header --- */
.workspace-header {
  padding: var(--space-xl) 0 var(--space-lg);
}

.workspace-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  margin-bottom: var(--space-lg);
}

.workspace-back svg {
  width: 16px;
  height: 16px;
  transition: transform var(--transition-fast);
}

.workspace-back:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.workspace-back:hover svg {
  transform: translateX(-3px);
}

.workspace-title {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: 8px;
}

.workspace-title-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}

.workspace-title-icon.pdf {
  background: var(--pdf-surface);
  color: var(--pdf-primary);
}

.workspace-title-icon.img {
  background: var(--img-surface);
  color: var(--img-primary);
}

.workspace-title h2 {
  font-size: var(--text-3xl);
  font-weight: 800;
}

.workspace-desc {
  color: var(--text-secondary);
  font-size: var(--text-base);
  margin-left: 64px;
}

/* --- Dropzone --- */
.dropzone {
  position: relative;
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-xl);
  padding: var(--space-3xl) var(--space-xl);
  text-align: center;
  transition: all var(--transition-base);
  cursor: pointer;
  background: var(--bg-surface);
  margin-bottom: var(--space-xl);
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--brand-primary);
  background: rgba(124, 58, 237, 0.05);
}

.dropzone.dragover {
  transform: scale(1.01);
  box-shadow: var(--shadow-glow-brand);
}

.dropzone.pdf:hover,
.dropzone.pdf.dragover {
  border-color: var(--pdf-primary);
  background: var(--pdf-surface);
}

.dropzone.pdf.dragover {
  box-shadow: var(--shadow-glow-pdf);
}

.dropzone.img:hover,
.dropzone.img.dragover {
  border-color: var(--img-primary);
  background: var(--img-surface);
}

.dropzone.img.dragover {
  box-shadow: var(--shadow-glow-img);
}

.dropzone-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto var(--space-md);
  border-radius: var(--radius-lg);
  background: var(--bg-surface-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  transition: transform var(--transition-spring);
}

.dropzone:hover .dropzone-icon {
  transform: translateY(-4px);
}

.dropzone-title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: 4px;
}

.dropzone-hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

/* --- File List --- */
.file-list {
  margin-bottom: var(--space-xl);
}

.file-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
  transition: all var(--transition-fast);
  animation: fadeInUp 0.3s ease-out;
}

.file-item:hover {
  border-color: var(--border-default);
  background: var(--bg-surface-hover);
}

.file-item-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.file-item-icon.pdf {
  background: var(--pdf-surface);
  color: var(--pdf-primary);
}

.file-item-icon.img {
  background: var(--img-surface);
  color: var(--img-primary);
}

.file-item-info {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.file-item-remove {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.file-item-remove:hover {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
}

.file-item-handle {
  width: 24px;
  height: 24px;
  color: var(--text-muted);
  cursor: grab;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  user-select: none;
}

.file-item-handle svg {
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.file-item-handle:hover {
  color: var(--brand-primary);
  background: var(--bg-surface-hover);
}

.file-item-handle:active {
  cursor: grabbing;
}

.file-item.dragging {
  opacity: 0.4;
  border-style: dashed;
  border-color: var(--brand-primary);
}

.file-item.drag-over {
  border-color: var(--brand-primary);
  background: rgba(124, 58, 237, 0.08);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.15);
}

/* --- File List Toolbar (Rearrange / Sort Controls) --- */
.file-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  margin-bottom: var(--space-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  gap: var(--space-sm);
}

.file-list-count {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}

.file-list-count svg {
  color: var(--brand-primary);
  flex-shrink: 0;
}

.file-list-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-tool-sort {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-tool-sort:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
  border-color: var(--border-default);
}

.btn-tool-sort.btn-tool-clear:hover {
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
}

/* --- Quick Selection Chips --- */
.btn-chip {
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-chip:hover {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
  background: var(--bg-surface-hover);
}

.btn-chip.active {
  color: #fff;
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}

/* --- File Order Badge --- */
.file-item-order {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--brand-primary);
  flex-shrink: 0;
  user-select: none;
}

/* --- Move Up/Down Buttons --- */
.file-item-movers {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.file-item-move {
  width: 28px;
  height: 20px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition-fast);
  cursor: pointer;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  padding: 0;
}

.file-item-move:hover:not(:disabled) {
  color: var(--brand-primary);
  background: var(--bg-surface-hover);
  border-color: var(--brand-primary);
  transform: scale(1.05);
}

.file-item-move:disabled {
  opacity: 0.18;
  cursor: not-allowed;
  pointer-events: none;
}

/* --- Options Panel --- */
.options-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.options-title {
  font-size: var(--text-base);
  font-weight: 700;
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: 8px;
}

.options-title svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.options-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-md);
  align-items: end;
}

.option-group {
  flex: 1;
  min-width: 180px;
}

.option-group label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.option-group select,
.option-group input[type="text"],
.option-group input[type="number"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  transition: border-color var(--transition-fast);
}

.option-group select:focus,
.option-group input:focus {
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px var(--brand-glow);
}

.option-group select {
  cursor: pointer;
  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='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Checkbox styled */
.option-check {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--text-secondary);
  padding: 10px 0;
}

.option-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid var(--border-strong);
  appearance: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  flex-shrink: 0;
}

.option-check input[type="checkbox"]:checked {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
}

.option-check input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
}

/* Range slider */
.option-range {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option-range input[type="range"] {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  appearance: none;
  cursor: pointer;
}

.option-range input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--brand-primary);
  border: 2px solid var(--bg-primary);
  box-shadow: 0 0 0 3px var(--brand-glow);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

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

.option-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--text-muted);
}

/* --- Action Area --- */
.action-area {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-lg) 0;
}

/* --- Processing Overlay --- */
.processing-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: var(--z-modal-backdrop);
  background: rgba(6, 6, 15, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
}

.processing-overlay.active {
  display: flex;
}

.processing-box {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl);
  text-align: center;
  min-width: 360px;
  animation: fadeInUp 0.3s ease-out;
}

.processing-spinner {
  width: 56px;
  height: 56px;
  margin: 0 auto var(--space-lg);
  border: 4px solid var(--border-subtle);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.processing-title {
  font-size: var(--text-lg);
  font-weight: 700;
  margin-bottom: 6px;
}

.processing-status {
  font-size: var(--text-sm);
  color: var(--text-muted);
  margin-bottom: var(--space-lg);
}

/* --- Results Section --- */
.results-section {
  display: none;
  animation: fadeInUp 0.4s ease-out;
}

.results-section.active {
  display: block;
}

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

.results-header h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-xl);
}

.results-header .success-icon {
  color: var(--success);
}

.result-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-sm);
}

.result-item-preview {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  overflow: hidden;
  flex-shrink: 0;
}

.result-item-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-item-info {
  flex: 1;
  min-width: 0;
}

.result-item-name {
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.result-item-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.result-item .btn {
  flex-shrink: 0;
}

/* --- Image Crop Canvas --- */
.crop-container {
  position: relative;
  display: inline-block;
  margin: 0 auto var(--space-lg);
  max-width: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--border-default);
}

.crop-container canvas {
  display: block;
  max-width: 100%;
}

/* --- Toast Notification --- */
.toast-container {
  position: fixed;
  top: calc(72px + var(--space-md));
  right: var(--space-xl);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 500;
  animation: slideInRight 0.3s ease-out;
  max-width: 380px;
}

.toast.success {
  border-color: rgba(16, 185, 129, 0.3);
}

.toast.error {
  border-color: rgba(239, 68, 68, 0.3);
}

.toast-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--error); }

.toast-close {
  width: 20px;
  height: 20px;
  margin-left: auto;
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.toast-close:hover { color: var(--text-primary); }

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* --- Image Preview Grid --- */
.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: var(--space-sm);
  margin-bottom: var(--space-xl);
}

.preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--border-subtle);
  transition: border-color var(--transition-fast);
  cursor: pointer;
}

.preview-item:hover {
  border-color: var(--border-strong);
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-item-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  opacity: 0;
  transition: opacity var(--transition-fast);
  cursor: pointer;
}

.preview-item:hover .preview-item-remove {
  opacity: 1;
}

/* --- Responsive workspace --- */
@media (max-width: 768px) {
  .workspace-desc {
    margin-left: 0;
    margin-top: var(--space-sm);
  }

  .options-row {
    flex-direction: column;
  }

  .option-group {
    min-width: 100%;
  }

  .results-header {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--space-sm);
  }

  .toast-container {
    top: calc(64px + var(--space-sm));
    left: var(--space-md);
    right: var(--space-md);
    bottom: auto;
  }

  .toast {
    max-width: 100%;
  }

  .processing-box {
    min-width: auto;
    margin: 0 var(--space-md);
  }
}
