:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Outfit', sans-serif;

  /* Color Palette - Dark Theme Defaults */
  --bg-base: #0b0f19;
  --bg-surface: #111827;
  --bg-surface-elevated: #1e293b;
  --bg-surface-hover: #334155;
  --border-color: #334155;
  --border-light: rgba(255, 255, 255, 0.08);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-primary-glow: rgba(59, 130, 246, 0.25);
  
  --accent-success: #10b981;
  --accent-success-hover: #059669;
  --accent-success-glow: rgba(16, 185, 129, 0.25);

  --accent-danger: #ef4444;
  --accent-danger-hover: #dc2626;

  --accent-warning: #f59e0b;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.6);
  --shadow-glow: 0 0 25px var(--accent-primary-glow);

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
}

body.theme-light {
  --bg-base: #f1f5f9;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #f8fafc;
  --bg-surface-hover: #e2e8f0;
  --border-color: #cbd5e1;
  --border-light: rgba(0, 0, 0, 0.06);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;

  --accent-primary-glow: rgba(59, 130, 246, 0.15);
  --accent-success-glow: rgba(16, 185, 129, 0.15);

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.12);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Header & Workflow Stepper
   ========================================================================== */
.app-header {
  height: 68px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--accent-primary), #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  box-shadow: 0 4px 12px var(--accent-primary-glow);
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-pro {
  font-size: 0.65rem;
  font-weight: 800;
  background: linear-gradient(135deg, #f59e0b, #ec4899);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

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

/* Workflow Stepper */
.workflow-stepper {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-base);
  padding: 6px 14px;
  border-radius: 30px;
  border: 1px solid var(--border-color);
}

.step-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 20px;
  transition: var(--transition-fast);
}

.step-bubble {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}

.step-item.active {
  color: var(--text-primary);
  background: var(--bg-surface-elevated);
}

.step-item.active .step-bubble {
  background: var(--accent-primary);
  color: #fff;
}

.step-item.completed {
  color: var(--accent-success);
}

.step-item.completed .step-bubble {
  background: var(--accent-success);
  color: #fff;
}

.step-divider {
  width: 12px;
  height: 2px;
  background: var(--border-color);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ==========================================================================
   Buttons & UI Elements
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--font-main);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-primary {
  background: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--accent-primary-glow);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
}

.btn-success {
  background: var(--accent-success);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--accent-success-glow);
}

.btn-success:hover {
  background: var(--accent-success-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

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

.btn-danger {
  background: var(--accent-danger);
  color: #fff;
}

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

.btn-text {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
}

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

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

.btn-lg {
  padding: 14px 26px;
  font-size: 1rem;
  border-radius: var(--radius-lg);
}

.btn-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
}

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

.btn-micro {
  width: 26px;
  height: 26px;
  border-radius: 4px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  cursor: pointer;
}

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

.w-100 {
  width: 100%;
}

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }

/* Badges */
.badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
}

/* App Main & Panels */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.step-panel {
  display: flex;
  flex-direction: column;
  flex: 1;
}

/* ==========================================================================
   STEP 1: Upload Container
   ========================================================================== */
.upload-container {
  max-width: 720px;
  margin: 60px auto;
  width: 100%;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.hero-text h1 {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-text p {
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 36px;
  max-width: 580px;
}

.dropzone-card {
  width: 100%;
  background: var(--bg-surface);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-xl);
  padding: 48px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-md);
}

.dropzone-card:hover, .dropzone-card.drag-over {
  border-color: var(--accent-primary);
  background: var(--bg-surface-elevated);
  transform: translateY(-2px);
  box-shadow: var(--shadow-glow);
}

.dropzone-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-primary-glow);
  color: var(--accent-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin-bottom: 18px;
}

.dropzone-card h3 {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.dropzone-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.upload-features {
  display: flex;
  gap: 20px;
  margin-top: 32px;
  border-top: 1px solid var(--border-light);
  padding-top: 20px;
}

.upload-features span {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.upload-progress-card {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-top: 24px;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 8px;
}

.progress-bar-track {
  width: 100%;
  height: 8px;
  background: var(--bg-surface-elevated);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-success));
  transition: width 0.2s ease;
}

.progress-status {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: left;
}

/* ==========================================================================
   STEP 8: Success / Download Screen
   ========================================================================== */
.download-container {
  max-width: 640px;
  margin: 60px auto;
  padding: 0 20px;
  width: 100%;
}

.success-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 48px 36px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.success-icon-badge {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-success-glow);
  color: var(--accent-success);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.75rem;
  margin: 0 auto 20px;
  animation: pulseSuccess 2s infinite;
}

@keyframes pulseSuccess {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  70% { transform: scale(1.05); box-shadow: 0 0 0 16px rgba(16, 185, 129, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.success-card h2 {
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 8px;
}

.success-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 28px;
}

.file-summary-box {
  background: var(--bg-base);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 32px;
  text-align: left;
}

.file-icon {
  font-size: 2rem;
  color: var(--accent-danger);
}

.file-details {
  flex: 1;
}

.file-details h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.file-details span {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge-verified {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-success);
  background: var(--accent-success-glow);
  padding: 4px 10px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.download-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
}

.next-actions {
  border-top: 1px solid var(--border-light);
  padding-top: 18px;
}

/* ==========================================================================
   Modals
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-dialog {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-xl {
  max-width: 1000px;
}

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

.modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent-primary);
}

.modal-title h3 {
  font-size: 1.15rem;
  color: var(--text-primary);
  font-family: var(--font-display);
}

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

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

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

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: var(--bg-base);
}

/* ==========================================================================
   Full Document Preview Modal
   ========================================================================== */
.preview-modal-dialog {
  max-width: 980px;
  height: 92vh;
  display: flex;
  flex-direction: column;
}

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

.preview-doc-summary {
  font-size: 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  display: block;
  margin-top: 2px;
}

.preview-header-tools {
  display: flex;
  align-items: center;
  gap: 16px;
}

.preview-modal-body {
  display: flex;
  flex-direction: column;
  gap: 28px;
  align-items: center;
  background: #090d16;
  padding: 32px 20px;
  overflow-y: auto;
  flex: 1;
}

.preview-page-card {
  position: relative;
  background: #ffffff;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.7);
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0 !important;
  transition: transform var(--transition-fast);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.preview-page-card:hover {
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.85);
}

.preview-page-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 8px;
  max-width: 100%;
}

.preview-card-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.preview-page-card canvas {
  display: block;
  width: 100% !important;
  height: auto !important;
}

.preview-page-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.preview-badge-sig {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
}

.preview-badge-init {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.preview-badge-logo {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.preview-badge-none {
  background: rgba(100, 116, 139, 0.2);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.3);
}

.preview-page-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ==========================================================================
   Toasts & Global Loader
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
}

.toast {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  padding: 12px 18px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  min-width: 280px;
  animation: slideInRight 0.25s ease forwards;
}

.toast.toast-success i { color: var(--accent-success); }
.toast.toast-error i { color: var(--accent-danger); }
.toast.toast-info i { color: var(--accent-primary); }

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.85);
  backdrop-filter: blur(8px);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader-content {
  text-align: center;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(59, 130, 246, 0.2);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.loader-content h4 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  margin-bottom: 6px;
}

.loader-content p {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Responsive adjustments */
@media (max-width: 900px) {
  .workflow-stepper {
    display: none;
  }
}
