/* ============================================
   LipiScan — Design System & Styles
   ============================================ */

:root {
  /* Color palette — deep indigo / violet */
  --bg-primary: #0a0a12;
  --bg-secondary: #111125;
  --bg-card: rgba(18, 18, 42, 0.7);
  --bg-card-hover: rgba(24, 24, 56, 0.8);
  --border-subtle: rgba(99, 102, 241, 0.15);
  --border-active: rgba(99, 102, 241, 0.4);

  --accent-primary: #818cf8;
  --accent-secondary: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #a78bfa 100%);

  --text-primary: #e8eaf6;
  --text-secondary: #9ca3c0;
  --text-muted: #5c6187;

  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;

  /* Spacing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Typography */
  --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-malayalam: 'Noto Sans Malayalam', 'Inter', sans-serif;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ---- Animated Background ---- */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(99, 102, 241, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99, 102, 241, 0.03) 1px, transparent 1px);
  background-size: 60px 60px;
  z-index: 0;
  pointer-events: none;
}

.bg-glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.4;
  pointer-events: none;
  z-index: 0;
  animation: float 20s ease-in-out infinite;
}

.bg-glow-1 {
  width: 500px;
  height: 500px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.15), transparent 70%);
  top: -10%;
  left: -5%;
  animation-delay: 0s;
}

.bg-glow-2 {
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.12), transparent 70%);
  bottom: -10%;
  right: -5%;
  animation-delay: -7s;
}

.bg-glow-3 {
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(167, 139, 250, 0.1), transparent 70%);
  top: 40%;
  left: 50%;
  animation-delay: -14s;
}

@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -20px) scale(1.05); }
  50% { transform: translate(-20px, 30px) scale(0.95); }
  75% { transform: translate(20px, 20px) scale(1.03); }
}

/* ---- App Container ---- */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 24px 16px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 24px;
  animation: slideDown 0.6s var(--transition-base);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

.logo-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-gradient);
  border-radius: var(--radius-md);
  color: white;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 400;
  letter-spacing: 0.02em;
}

.header-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.2);
  border-radius: 100px;
  font-size: 0.78rem;
  color: var(--success);
  font-weight: 500;
}

.badge-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s ease-in-out infinite;
}

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

/* ---- Main Content ---- */
.main-content {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  flex: 1;
  animation: fadeIn 0.8s var(--transition-base);
}

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

/* ---- Panels ---- */
.panel {
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 24px;
  display: flex;
  flex-direction: column;
  transition: border-color var(--transition-base);
}

.panel:hover {
  border-color: var(--border-active);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.panel-header h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
}

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

/* ---- Language Selector ---- */
.language-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}

.language-selector label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
  white-space: nowrap;
}

.language-selector select {
  appearance: none;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 32px 8px 12px;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  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='%239ca3c0' 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 10px center;
}

.language-selector select:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.language-selector select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* ---- Dropzone ---- */
.dropzone {
  flex: 1;
  border: 2px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  position: relative;
  cursor: pointer;
  transition: all var(--transition-base);
  overflow: hidden;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--accent-primary);
  background: rgba(99, 102, 241, 0.04);
}

.dropzone.drag-over {
  box-shadow: inset 0 0 40px rgba(99, 102, 241, 0.08);
}

.dropzone-content {
  text-align: center;
  padding: 40px;
}

.dropzone-icon {
  color: var(--text-muted);
  margin-bottom: 16px;
  transition: color var(--transition-base), transform var(--transition-base);
}

.dropzone:hover .dropzone-icon {
  color: var(--accent-primary);
  transform: translateY(-4px);
}

.dropzone-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.dropzone-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---- Image Preview ---- */
.image-preview {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.image-preview img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
  object-fit: contain;
  animation: scaleIn 0.3s var(--transition-base);
}

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.btn-remove {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 113, 113, 0.15);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 50%;
  color: var(--error);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-remove:hover {
  background: rgba(248, 113, 113, 0.3);
  transform: scale(1.1);
}

/* ---- Extract Button ---- */
.btn-extract {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 16px 24px;
  margin-top: 16px;
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius-md);
  color: white;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.btn-extract::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.btn-extract:hover:not(:disabled)::before {
  opacity: 1;
}

.btn-extract:hover:not(:disabled) {
  box-shadow: 0 8px 30px var(--accent-glow);
  transform: translateY(-1px);
}

.btn-extract:active:not(:disabled) {
  transform: translateY(0);
}

.btn-extract:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-extract.processing {
  pointer-events: none;
  opacity: 0.85;
}

/* ---- Spinner ---- */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---- Results Panel ---- */
.results-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.empty-icon {
  color: var(--text-muted);
  opacity: 0.4;
  margin-bottom: 16px;
}

.empty-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.empty-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---- Processing Animation ---- */
.results-processing {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
}

.processing-animation {
  position: relative;
  width: 80px;
  height: 80px;
  margin-bottom: 24px;
}

.processing-ring {
  position: absolute;
  inset: 0;
  border: 3px solid transparent;
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 1.2s linear infinite;
}

.processing-ring-2 {
  inset: 8px;
  border-top-color: var(--accent-secondary);
  animation-duration: 1.8s;
  animation-direction: reverse;
}

.processing-ring-3 {
  inset: 16px;
  border-top-color: #a78bfa;
  animation-duration: 2.5s;
}

.processing-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

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

.processing-timer {
  margin-top: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-primary);
  font-variant-numeric: tabular-nums;
}

.processing-steps {
  list-style: none;
  margin: 20px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
  min-width: 220px;
}

.processing-step {
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-left: 22px;
  position: relative;
  transition: color 0.2s ease;
}

.processing-step::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--border-subtle);
  background: transparent;
}

.processing-step.active {
  color: var(--text-primary);
  font-weight: 500;
}

.processing-step.active::before {
  border-color: var(--accent-primary);
  background: var(--accent-primary);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.45);
}

.processing-step.done {
  color: var(--text-secondary);
}

.processing-step.done::before {
  border-color: #22c55e;
  background: #22c55e;
}

.results-content.streaming textarea {
  border-color: rgba(99, 102, 241, 0.35);
}

/* ---- Results Content ---- */
.results-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.5s var(--transition-base);
}

#extracted-text {
  flex: 1;
  width: 100%;
  min-height: 300px;
  background: rgba(10, 10, 18, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  color: var(--text-primary);
  font-size: 0.95rem;
  line-height: 1.8;
  font-family: var(--font-malayalam);
  resize: vertical;
  transition: border-color var(--transition-fast);
}

#extracted-text:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.results-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  padding: 10px 16px;
  background: rgba(99, 102, 241, 0.05);
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ---- Export Actions ---- */
.export-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  font-family: var(--font-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-action:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: translateY(-1px);
}

.btn-action:active {
  transform: translateY(0);
}

/* ---- Footer ---- */
.app-footer {
  text-align: center;
  padding: 20px;
  margin-top: 24px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---- Toast Notification ---- */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-card);
  border: 1px solid var(--border-active);
  backdrop-filter: blur(20px);
  padding: 12px 24px;
  border-radius: 100px;
  font-size: 0.85rem;
  color: var(--text-primary);
  z-index: 1000;
  opacity: 0;
  transition: all var(--transition-slow);
  pointer-events: none;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.toast-success {
  border-color: rgba(52, 211, 153, 0.4);
}

.toast.toast-error {
  border-color: rgba(248, 113, 113, 0.4);
}

/* ---- Responsive ---- */
@media (max-width: 900px) {
  .main-content {
    grid-template-columns: 1fr;
  }

  .app-header {
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
  }

  .panel-header {
    flex-direction: column;
  }

  .export-actions {
    width: 100%;
  }

  .bg-glow { display: none; }
}

@media (max-width: 500px) {
  .app-container {
    padding: 12px 12px 8px;
  }

  .panel {
    padding: 16px;
  }

  .dropzone {
    min-height: 200px;
  }
}
