/* ==========================================================
   Handwritten Mathematical Formula Recognition System
   Design System & Global Styles (Vanilla CSS)
   ========================================================== */

:root {
  --bg-dark: #0a0e17;
  --bg-card: rgba(18, 26, 43, 0.75);
  --bg-card-hover: rgba(28, 39, 64, 0.85);
  --border-color: rgba(255, 255, 255, 0.12);
  --border-focus: #6366f1;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.35);
  
  --accent-cyan: #06b6d4;
  --accent-emerald: #10b981;
  --accent-rose: #f43f5e;
  --accent-amber: #f59e0b;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --font-main: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  
  --shadow-main: 0 20px 40px -15px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px var(--primary-glow);
  --glass-backdrop: blur(16px) saturate(180%);
}

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

body {
  font-family: var(--font-main);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(6, 182, 212, 0.12) 0px, transparent 50%),
    radial-gradient(at 50% 50%, rgba(16, 185, 129, 0.05) 0px, transparent 50%);
  background-attachment: fixed;
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.6;
  overflow-x: hidden;
}

/* Header & Navbar */
.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2.5rem;
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, var(--primary), var(--accent-cyan));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  color: #fff;
  box-shadow: var(--shadow-glow);
}

.brand-text h1 {
  font-size: 1.25rem;
  font-weight: 700;
  background: linear-gradient(90deg, #fff, #cbd5e1);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
}

/* Backend Connection Bar */
.backend-bar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 0.4rem 0.6rem 0.4rem 1.2rem;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: var(--accent-amber);
  box-shadow: 0 0 10px var(--accent-amber);
  transition: all 0.3s ease;
}

.status-dot.connected {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 10px var(--accent-emerald);
}

.status-dot.disconnected {
  background-color: var(--accent-rose);
  box-shadow: 0 0 10px var(--accent-rose);
}

.backend-input {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  width: 260px;
  outline: none;
}

.btn-ping {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-ping:hover {
  background: var(--primary-hover);
  transform: scale(1.03);
}

/* Main Container */
.container {
  max-width: 1300px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

.hero-header {
  text-align: center;
  margin-bottom: 2.5rem;
}

.hero-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 70%, #38bdf8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 650px;
  margin: 0 auto;
}

/* Grid Layout */
.app-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
}

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

/* Card Styling */
.card {
  background: var(--bg-card);
  backdrop-filter: var(--glass-backdrop);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-main);
  transition: border-color 0.3s ease;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

.card-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: #fff;
}

.card-title i {
  color: var(--accent-cyan);
}

/* Upload Dropzone */
.dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  padding: 2.5rem 1.5rem;
  text-align: center;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
  box-shadow: inset 0 0 20px rgba(99, 102, 241, 0.15);
}

.dropzone-icon {
  font-size: 3rem;
  color: var(--primary);
  margin-bottom: 1rem;
  transition: transform 0.3s ease;
}

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

.dropzone-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

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

#file-input {
  display: none;
}

/* Preview Box */
.preview-box {
  margin-top: 1.25rem;
  display: none;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  position: relative;
}

.preview-box img {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

.preview-remove {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(244, 63, 94, 0.8);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.preview-remove:hover {
  background: var(--accent-rose);
  transform: scale(1.1);
}

/* Controls */
.controls-group {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.control-item label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.select-custom, .slider-custom {
  width: 100%;
  padding: 0.65rem 0.9rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.select-custom:focus {
  border-color: var(--primary);
}

/* Action Buttons */
.btn-submit {
  width: 100%;
  margin-top: 1.5rem;
  padding: 1rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  transition: all 0.3s ease;
}

.btn-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 35px var(--primary-glow);
}

.btn-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Sample Presets */
.presets-container {
  margin-top: 1.5rem;
}

.presets-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-subtle);
  margin-bottom: 0.6rem;
  text-transform: uppercase;
}

.presets-flex {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.btn-preset {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-preset:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
  color: #fff;
}

/* Results Display Card */
.result-display {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-height: 380px;
}

.rendered-math-box {
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem 1.5rem;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1.6rem;
  overflow-x: auto;
  box-shadow: inset 0 2px 10px rgba(0,0,0,0.5);
}

.placeholder-text {
  color: var(--text-subtle);
  font-size: 0.95rem;
  font-style: italic;
}

.raw-latex-box {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  position: relative;
}

.raw-latex-code {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--accent-cyan);
  word-break: break-all;
  white-space: pre-wrap;
}

.btn-copy {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-copy:hover {
  background: var(--primary);
  color: #fff;
}

/* Spinner Loader */
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(255,255,255,0.3);
  border-radius: 50%;
  border-top-color: #fff;
  animation: spin 0.8s linear infinite;
  display: inline-block;
}

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

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  background: var(--bg-card);
  border: 1px solid var(--accent-emerald);
  color: #fff;
  padding: 0.9rem 1.4rem;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* Step 2 Pipeline Card Styling */
.pipeline-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.badge-active {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--accent-emerald);
  color: var(--accent-emerald);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pipeline-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

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

.pipeline-box {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.pipeline-box-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.pipeline-img-wrap {
  background: #ffffff;
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pipeline-img-wrap img {
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
}

.pipeline-meta {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: 0.6rem;
  text-align: center;
}

/* Stepper & Progress Bar Styling */
.stepper-container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  max-width: 900px;
  margin: 0 auto 2.5rem auto;
  padding: 0 1rem;
}

.progress-track {
  position: absolute;
  top: 22px;
  left: 60px;
  right: 60px;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
  z-index: 1;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent-cyan));
  border-radius: var(--radius-full);
  box-shadow: 0 0 15px var(--primary-glow);
  transition: width 0.4s ease;
}

.step-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 2;
  position: relative;
}

.step-node {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 2px solid var(--border-color);
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all 0.3s ease;
}

.step-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-subtle);
  transition: color 0.3s ease;
}

.step-item.active .step-node {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-glow);
  transform: scale(1.1);
}

.step-item.active .step-label {
  color: var(--text-main);
}

.step-item.completed .step-node {
  border-color: var(--accent-emerald);
  background: var(--accent-emerald);
  color: #fff;
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
}

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

/* ==========================================================
   Navigation Bar Tabs, History & SIC Presentation Styles
   ========================================================== */
.nav-links {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.nav-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.55rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.25s ease;
}

.nav-btn:hover {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border-color: rgba(99, 102, 241, 0.4);
}

.nav-btn.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(56, 189, 248, 0.3));
  color: #ffffff;
  border-color: var(--primary);
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.4);
}

/* Tab Page Visibility & Animation */
.tab-page {
  display: none;
  animation: fadeInTab 0.35s ease-in-out forwards;
}

.tab-page.active {
  display: block;
}

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

/* History Card & Table Grid */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.25rem;
}

.history-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all 0.3s ease;
}

.history-card:hover {
  border-color: var(--primary);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  transform: translateY(-2px);
}

.history-time {
  font-size: 0.75rem;
  color: var(--text-subtle);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.history-math {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* SIC Presentation Page Styling */
.sic-banner {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(16, 185, 129, 0.2));
  border: 1px solid rgba(99, 102, 241, 0.4);
  border-radius: var(--radius-lg);
  padding: 2.25rem;
  text-align: center;
  margin-bottom: 2rem;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.sic-title {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, #ffffff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

.sic-subtitle {
  color: var(--text-muted);
  font-size: 0.98rem;
  max-width: 750px;
  margin: 0 auto;
  line-height: 1.6;
}

.sic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.sic-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: all 0.3s ease;
}

.sic-card:hover {
  border-color: var(--accent-cyan);
  box-shadow: 0 10px 25px rgba(6, 182, 212, 0.2);
}

.sic-card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent-cyan);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sic-badge-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.sic-badge {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  color: #a5b4fc;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
}
