/* ==========================================================================
   DocuScan Pro — Clean White Theme & Studio Styling
   ========================================================================== */

:root {
  /* Color Palette — Clean White & Slate System */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --border-light: #e2e8f0;
  --border-hover: #cbd5e1;
  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  /* Primary Accent Colors */
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #bfdbfe;
  
  /* Status Colors */
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  
  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.08), 0 2px 4px -2px rgb(0 0 0 / 0.06);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.04);
  
  /* Radii */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  
  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Header Styling
   ========================================================================== */

.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-light);
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-xs);
}

.header-container {
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #ffffff;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 10px -2px rgba(37, 99, 235, 0.35);
}

.logo-title {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-main);
  line-height: 1.1;
}

.logo-title span {
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.8em;
  margin-left: 2px;
}

.logo-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
}

.header-badges {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 9999px;
  border: 1px solid transparent;
}

.safe-tag {
  background: var(--success-light);
  color: #065f46;
  border-color: #a7f3d0;
}

.loading-tag {
  background: var(--warning-light);
  color: #92400e;
  border-color: #fde68a;
}

.ready-tag {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.8s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* ==========================================================================
   Main Layout & Container
   ========================================================================== */

.app-main {
  flex: 1;
  padding: 20px 24px 40px;
}

.app-container {
  max-width: 1480px;
  margin: 0 auto;
}

/* ==========================================================================
   Upload / Dropzone Section
   ========================================================================== */

.upload-section {
  padding: 30px 0 60px;
}

.dropzone {
  background: #ffffff;
  border: 2px dashed var(--border-hover);
  border-radius: var(--radius-xl);
  padding: 60px 40px;
  text-align: center;
  max-width: 760px;
  margin: 0 auto;
  box-shadow: var(--shadow-sm);
  transition: all 0.25s ease;
  cursor: pointer;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.drop-illustration {
  width: 80px;
  height: 80px;
  margin: 0 auto 20px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease;
}

.dropzone:hover .drop-illustration {
  transform: scale(1.08);
}

.drop-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.drop-desc {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.drop-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-bottom: 28px;
}

.privacy-note {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  display: inline-block;
  padding: 6px 14px;
  border-radius: 9999px;
  border: 1px solid var(--border-light);
}

/* ==========================================================================
   Multi-Page Carousel Bar
   ========================================================================== */

.page-bar {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 8px 16px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-xs);
  gap: 16px;
}

.page-bar-left, .page-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.page-counter {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
  background: var(--bg-subtle);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-light);
}

.page-thumbnails-container {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 0;
  max-width: 60%;
}

.page-thumb {
  width: 48px;
  height: 60px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border-light);
  object-fit: cover;
  cursor: pointer;
  transition: all 0.15s ease;
  flex-shrink: 0;
  background: #fff;
}

.page-thumb:hover {
  border-color: var(--border-hover);
}

.page-thumb.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-border);
}

/* ==========================================================================
   Studio Grid Layout
   ========================================================================== */

.studio-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 20px;
  align-items: start;
}

@media (max-width: 1100px) {
  .studio-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Viewports (Dual comparison)
   ========================================================================== */

.viewport-area {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.viewports-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

@media (max-width: 850px) {
  .viewports-row {
    grid-template-columns: 1fr;
  }
}

.viewport-box {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewport-header {
  padding: 10px 14px;
  background: #fbfcfd;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.viewport-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.dot-amber { background: #f59e0b; }
.dot-green { background: #10b981; }

.viewport-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tool-btn {
  background: #ffffff;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.tool-btn:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-hover);
}

.tool-btn.highlight {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.tool-btn.highlight:hover {
  background: #dbeafe;
}

.speed-indicator {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

/* Canvas Area */
.canvas-wrapper {
  position: relative;
  width: 100%;
  height: 520px;
  background: #f1f5f9;
  background-image: 
    linear-gradient(45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(-45deg, #e2e8f0 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #e2e8f0 75%), 
    linear-gradient(-45deg, transparent 75%, #e2e8f0 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  user-select: none;
}

.canvas-stage {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.canvas-stage canvas#originalCanvas {
  display: block;
  max-width: 100%;
  max-height: 520px;
  object-fit: contain;
  background: #ffffff;
}

#cropOverlayCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  background: transparent;
  box-shadow: none;
  z-index: 10;
  touch-action: none;
}

#cropOverlayCanvas.dragging {
  cursor: grabbing !important;
}

.btn-accent-gradient {
  background: linear-gradient(135deg, #2563eb 0%, #4f46e5 100%) !important;
  color: #ffffff !important;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25) !important;
}

.btn-accent-gradient:hover {
  background: linear-gradient(135deg, #1d4ed8 0%, #4338ca 100%) !important;
  transform: translateY(-1px);
}

.canvas-hint {
  padding: 6px 12px;
  background: #ffffff;
  border-top: 1px solid var(--border-light);
  font-size: 0.74rem;
  color: var(--text-muted);
  text-align: center;
}

.processing-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 20;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--primary-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ==========================================================================
   Control Panel & Sidebar
   ========================================================================== */

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-card {
  background: #ffffff;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.panel-heading {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.panel-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-heading-row .panel-heading {
  margin-bottom: 0;
}

.btn-text-action {
  background: transparent;
  border: none;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
}

.btn-text-action:hover {
  text-decoration: underline;
}

/* Mode Selectors */
.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-btn {
  background: #ffffff;
  border: 1.5px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  cursor: pointer;
  transition: all 0.15s ease;
}

.mode-btn:hover {
  border-color: var(--border-hover);
  background: #f8fafc;
}

.mode-btn.active {
  border-color: var(--primary);
  background: var(--primary-light);
  box-shadow: 0 0 0 2px var(--primary-border);
}

.mode-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.mode-info {
  display: flex;
  flex-direction: column;
}

.mode-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-main);
}

.mode-desc {
  font-size: 0.72rem;
  color: var(--text-secondary);
}

/* Sliders */
.control-group {
  margin-bottom: 14px;
}

.control-group:last-child {
  margin-bottom: 4px;
}

.control-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.control-value {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--primary);
  background: var(--primary-light);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

.app-slider {
  width: 100%;
  height: 5px;
  border-radius: 9999px;
  background: var(--border-light);
  outline: none;
  -webkit-appearance: none;
}

.app-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.1s;
}

.app-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Export Actions */
.export-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ==========================================================================
   Buttons System
   ========================================================================== */

.btn {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: all 0.18s ease;
  line-height: 1.2;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.25);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 8px rgba(37, 99, 235, 0.35);
}

.btn-outline {
  background: #ffffff;
  border-color: var(--border-light);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--bg-subtle);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover {
  background: var(--danger-light);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: #ffffff;
  border: 1px solid var(--border-light);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-hover);
}

/* ==========================================================================
   Camera Modal
   ========================================================================== */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-content {
  background: #ffffff;
  border-radius: var(--radius-xl);
  max-width: 680px;
  width: 100%;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

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

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

.camera-body {
  position: relative;
  background: #000;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#cameraVideo {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-guide-box {
  position: absolute;
  inset: 15%;
  border: 2px dashed rgba(255, 255, 255, 0.7);
  border-radius: var(--radius-md);
  pointer-events: none;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-light);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
