/* BestOCR - Premium Theme System & Aesthetics */

:root {
  /* Default Theme: Dark (Futuristic / Professional) */
  --primary: #6366f1;
  --primary-rgb: 99, 102, 241;
  --secondary: #a855f7;
  --secondary-rgb: 168, 85, 247;
  --accent: #ec4899;

  /* Backgrounds */
  --bg-body: #0a0a16;
  --bg-canvas: #0f111a;
  --bg-card: rgba(18, 18, 35, 0.7);
  --bg-header: rgba(10, 10, 22, 0.8);
  --bg-footer: rgba(10, 10, 22, 0.9);

  /* Borders & Dividers */
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.15);
  --border-active: var(--primary);

  /* Text */
  --text-main: #f8fafc;
  --text-dim: #94a3b8;
  --text-mute: #64748b;
  --text-on-primary: #ffffff;

  /* Shadows & Blurs */
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 10px 30px -5px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 20px 50px -10px rgba(0, 0, 0, 0.5);
  --backdrop-blur: 16px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 0.3s;
}

[data-theme="light"] {
  --bg-body: #f8fafc;
  --bg-canvas: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.8);
  --bg-header: rgba(248, 250, 252, 0.9);
  --bg-footer: rgba(241, 245, 249, 0.9);

  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.12);

  --text-main: #0f172a;
  --text-dim: #475569;
  --text-mute: #94a3b8;

  --shadow-lg: 0 20px 40px -12px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 10px 20px -5px rgba(0, 0, 0, 0.05);
}

/* Global Reset & Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: "Inter", sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
  transition:
    background-color var(--duration) var(--ease),
    color var(--duration) var(--ease);
}

body::before {
  content: "";
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(var(--primary-rgb), 0.05) 0%,
    transparent 70%
  );
  pointer-events: none;
  z-index: 0;
}

.container {
  max-width: 1920px; /* Wider container for more space */
  margin: 0 auto;
  padding: 0.75rem 1rem; /* Tighter padding */
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header Aesthetics */
.header {
  margin-bottom: 0.75rem; /* Reduced margin */
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 0.5rem;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 0;
  width: 100%;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo svg {
  width: 32px;
  height: 32px;
}

.logo h1 {
  font-family: "Outfit", sans-serif;
  font-size: 1.5rem; /* Smaller font */
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo h1 span {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.9rem;
  color: var(--text-dim);
  font-weight: 400;
  margin-left: auto; /* Push to right or hide on small screens */
  margin-right: 1.5rem;
}

/* Theme Toggle Component */
.theme-toggle {
  display: flex;
  background: var(--bg-canvas);
  border: 1px solid var(--border-strong);
  padding: 2px;
  border-radius: 99px;
  box-shadow: var(--shadow-sm);
}

.theme-btn {
  width: 32px; /* Smaller buttons */
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
  transition: all var(--duration) var(--ease);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
}

.theme-btn:hover {
  color: var(--text-main);
}

.theme-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 2px 8px rgba(var(--primary-rgb), 0.3);
}

/* Main Content - 50/50 Split */
.main-content {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem; /* Reduced gap */
  min-height: 0; /* Important for flex child scroll */
  margin-bottom: 0.5rem;
}

.column {
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  backdrop-filter: blur(var(--backdrop-blur));
  -webkit-backdrop-filter: blur(var(--backdrop-blur));
  border: 1px solid var(--border);
  border-radius: 16px; /* Slightly squarer corners */
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition:
    transform var(--duration) var(--ease),
    border-color var(--duration) var(--ease);
}

.column:hover {
  border-color: var(--border-strong);
}

.column-header {
  padding: 0.75rem 1rem; /* Tighter header */
  background: rgba(var(--primary-rgb), 0.03);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  height: 48px; /* Fixed smaller height */
}

.column-header h3 {
  font-family: "Outfit", sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.column-body {
  flex: 1;
  padding: 0; /* Removing padding from body container */
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
  display: flex;
  flex-direction: column;
}

.column-body::-webkit-scrollbar {
  width: 6px;
}

.column-body::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
}

.column-footer {
  padding: 0.75rem 1rem;
  background: rgba(var(--primary-rgb), 0.03);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Compact Upload Card */
.compact-upload-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  /* min-height removed to allow full flex stretching */
}

.drop-zone {
  flex: 1;
  border: none; /* Removed dashed border for cleaner look */
  border-radius: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all var(--duration) var(--ease);
  cursor: pointer;
  background: transparent;
  padding: 2rem;
}

.drop-zone:hover,
.drop-zone.drag-over {
  background: rgba(var(--primary-rgb), 0.05);
}

.upload-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  text-align: center;
}

.upload-icon {
  width: 48px;
  height: 48px;
  color: var(--primary);
  opacity: 0.8;
  margin: 0;
}

.drop-zone h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.browse-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}

.browse-link:hover {
  text-decoration: none;
}

/* Compact Preview Overlay */
.preview-area {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-canvas);
  border-radius: 0; /* Remove radius since it fills the column */
  border: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.preview-header-overlay {
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(8px);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 20;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.file-badge {
  background: rgba(var(--primary-rgb), 0.2);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clear-btn-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.2);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 0.75rem;
}

.clear-btn-icon:hover {
  background: #ef4444;
}

.preview-scroll-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow-y: auto; /* Enable vertical scrolling */
  overflow-x: hidden;
  padding: 3rem 1rem 1rem;
  background: repeating-conic-gradient(
      rgba(var(--primary-rgb), 0.03) 0% 25%,
      transparent 0% 50%
    )
    50% / 20px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.preview-scroll-container img {
  display: block;
  max-width: 100%;
  margin: 0 auto;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* PDF Page Preview */
.pdf-page-preview {
  position: relative;
  background: var(--bg-card);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  flex-shrink: 0; /* Don't shrink pages */
}

.pdf-page-preview .page-number {
  position: absolute;
  top: 0.5rem;
  left: 0.5rem;
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 3px;
  z-index: 2;
}

.pdf-page-preview img {
  width: 100%;
  height: auto; /* Auto height to show full page */
  display: block;
}

/* Preview Loading/Error States */
.preview-loading,
.preview-error {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.preview-error {
  color: var(--error, #ef4444);
}

/* Compact Settings Bar */
.settings-bar {
  padding: 0.5rem 1rem;
  background: var(--bg-canvas);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 0.75rem;
  align-items: center;
  height: 60px; /* Reduced height */
}

.compact-settings {
  display: flex;
  gap: 0.5rem;
  flex: 1;
}

.compact-setting-item {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  background: rgba(var(--primary-rgb), 0.05); /* Lighter background */
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0.5rem;
  height: 36px; /* Smaller inputs */
}

.compact-setting-item i {
  color: var(--text-dim);
  font-size: 0.8rem;
  margin-right: 0.5rem;
}

.compact-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: monospace;
  font-weight: 600;
  font-size: 0.85rem;
  outline: none;
}

/* Hide spin buttons for cleaner look */
.compact-input::-webkit-outer-spin-button,
.compact-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.process-btn-compact {
  height: 36px;
  padding: 0 1.25rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 12px rgba(var(--primary-rgb), 0.3);
  transition: all 0.2s;
  white-space: nowrap;
}

.process-btn-compact:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(1);
}

.process-btn-compact:hover:not(:disabled) {
  transform: translateY(-1px);
  filter: brightness(1.1);
}

/* Results Display */
.results-actions {
  display: flex;
  gap: 0.5rem;
}

.icon-btn {
  padding: 0.4rem 0.8rem;
  background: var(--bg-canvas);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.icon-btn:hover {
  background: var(--border);
  border-color: var(--primary);
}

.icon-btn i {
  color: var(--primary);
  font-size: 0.8rem;
}

/* Results Section Updates */
.results-section {
  display: flex;
  flex-direction: column;
  flex: 1; /* Take full height */
  gap: 0;
}

.results-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%; /* Important for internal scrolling */
}

.results-content {
  flex: 1; /* Stretch to fill available space */
  display: flex;
  flex-direction: column;
  min-height: 0; /* Enable internal scroll */
}

#preview-content {
  font-size: 1rem;
  line-height: 1.6;
  padding: 1.5rem; /* Padding inside content area */
  color: var(--text-main);
  overflow-y: auto; /* Internal scroll */
  flex: 1;
}

#preview-content h1,
#preview-content h2,
#preview-content h3 {
  font-family: "Outfit", sans-serif;
  margin: 1rem 0 0.75rem;
  color: var(--primary);
}

#preview-content p {
  margin-bottom: 1rem;
}

#preview-content code {
  background: rgba(var(--primary-rgb), 0.1);
  padding: 0.2em 0.4em;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.9em;
}

#ocrResult {
  white-space: pre-wrap;
  font-family: "Fira Code", "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem;
  background: transparent; /* Remove bg here, let container handle it or use full dark */
  padding: 1.5rem;
  border-radius: 0;
  color: #8be9fd;
  overflow-y: auto;
  flex: 1;
  margin: 0; /* Remove margin */
}

/* Footer (inside results) handling */
.results-footer {
  display: flex;
  justify-content: flex-end;
  gap: 1.5rem;
  padding: 0.75rem 1rem;
  color: var(--text-mute);
  font-size: 0.75rem;
  font-family: monospace;
  background: rgba(var(--primary-rgb), 0.02);
  border-top: 1px solid var(--border);
}

/* ===== Table Styling ===== */
/* Support for both HTML tables (from model) and Markdown tables */
#preview-content table,
#preview-content .table-ocr,
#preview-content .table-markdown {
  border-collapse: collapse;
  width: 100%;
  margin: 1.5rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

#preview-content table thead,
#preview-content table th {
  background: linear-gradient(
    135deg,
    rgba(var(--primary-rgb), 0.1),
    rgba(var(--secondary-rgb), 0.1)
  );
  font-weight: 600;
  text-align: left;
  color: var(--text-main);
}

#preview-content table th,
#preview-content table td {
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  vertical-align: top;
}

#preview-content table tr:hover {
  background: rgba(var(--primary-rgb), 0.03);
  transition: background 0.2s ease;
}

#preview-content table tr:nth-child(even) {
  background: rgba(var(--bg-canvas-rgb), 0.3);
}

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(var(--bg-canvas), 0.8);
  backdrop-filter: blur(8px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.loading-subtext {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Footer (global) - make tiny */
.footer {
  text-align: center;
  padding: 0.75rem 0;
  border-top: none;
  color: var(--text-mute);
  font-size: 0.75rem;
  flex-shrink: 0;
  opacity: 0.7;
}

.footer strong {
  color: var(--text-dim);
}

.footer a {
  color: var(--primary);
  text-decoration: none;
}

/* Responsive Scaling */
@media (max-width: 1200px) {
  .main-content {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .container {
    height: auto;
    padding: 1rem;
  }

  .column {
    height: 600px;
  }
}

@media (max-width: 768px) {
  .header-top {
    flex-direction: column;
    gap: 1rem;
  }

  .subtitle {
    display: none;
  }

  .column {
    height: 500px;
  }
}

/* Notifications Styling */
.notification {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  z-index: 10000;
  font-size: 0.9rem;
}

/* Utility classes */
.hidden {
  display: none !important;
}
