/* ========================================
   LaTeX STYLING FOR NOTEBOOK MODE
   Beautiful math rendering with KaTeX
   ======================================== */

/* Display math (centered, larger) */
.notebook-cell-markdown .katex-display {
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.5rem 0;
}

/* Inline math (in text flow) */
.notebook-cell-markdown .katex {
  font-size: 1.1em;
  color: var(--text-primary);
}

/* Make display math slightly larger */
.notebook-cell-markdown .katex-display .katex {
  font-size: 1.3em;
}

/* Scrollable for very long equations */
.notebook-cell-markdown .katex-display {
  max-width: 100%;
}

.notebook-cell-markdown .katex-display > .katex {
  display: inline-block;
  white-space: nowrap;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Error styling */
.notebook-cell-markdown .katex-error {
  color: #cc0000;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9em;
  background: rgba(204, 0, 0, 0.1);
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  border-left: 3px solid #cc0000;
}

/* Math in headings */
.notebook-cell-markdown h1 .katex,
.notebook-cell-markdown h2 .katex,
.notebook-cell-markdown h3 .katex,
.notebook-cell-markdown h4 .katex {
  font-size: inherit;
}

/* Math in lists */
.notebook-cell-markdown li .katex {
  vertical-align: middle;
}

/* Math in tables */
.notebook-cell-markdown td .katex,
.notebook-cell-markdown th .katex {
  font-size: 1em;
}

/* Add subtle background to display math for emphasis */
.notebook-cell-markdown .katex-display {
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 3px var(--shadow);
}

/* Theme-specific adjustments */

/* Light theme - subtle background */
.light .notebook-cell-markdown .katex-display {
  background: rgba(59, 130, 246, 0.02);
  border: 1px solid rgba(59, 130, 246, 0.1);
}

/* Dark theme - slightly lighter background */
.dark .notebook-cell-markdown .katex-display {
  background: rgba(96, 165, 250, 0.05);
  border: 1px solid rgba(96, 165, 250, 0.15);
}

/* Elegant theme - purple tint */
.elegant .notebook-cell-markdown .katex-display {
  background: rgba(139, 125, 216, 0.05);
  border: 1px solid rgba(139, 125, 216, 0.15);
}

/* Contrast theme - high visibility */
.contrast .notebook-cell-markdown .katex-display {
  background: rgba(0, 255, 0, 0.03);
  border: 2px solid rgba(0, 255, 0, 0.2);
}

/* Caravan theme - warm tint */
.caravan .notebook-cell-markdown .katex-display {
  background: rgba(184, 133, 106, 0.05);
  border: 1px solid rgba(184, 133, 106, 0.15);
}

/* Meadow theme - green tint */
.meadow .notebook-cell-markdown .katex-display {
  background: rgba(136, 176, 143, 0.05);
  border: 1px solid rgba(136, 176, 143, 0.15);
}

/* Hover effect for display math */
.notebook-cell-markdown .katex-display:hover {
  box-shadow: 0 2px 8px var(--shadow);
  transform: translateY(-1px);
  transition: all 0.2s ease;
}

/* Prevent text selection issues */
.notebook-cell-markdown .katex .katex-html {
  user-select: none;
}

/* Copy button styling (optional enhancement) */
.katex-display-wrapper {
  position: relative;
}

.katex-copy-btn {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s;
  padding: 0.25rem 0.5rem;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
}

.katex-display-wrapper:hover .katex-copy-btn {
  opacity: 1;
}

/* Print styles */
@media print {
  .notebook-cell-markdown .katex-display {
    background: white;
    border: 1px solid #ddd;
    page-break-inside: avoid;
  }
  
  .katex-copy-btn {
    display: none;
  }
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .notebook-cell-markdown .katex-display .katex {
    font-size: 1.1em;
  }
  
  .notebook-cell-markdown .katex {
    font-size: 1em;
  }
}

/* Accessibility: Ensure good contrast */
.notebook-cell-markdown .katex {
  color: var(--text-primary);
}

/* Fix for very long fractions */
.notebook-cell-markdown .katex .frac-line {
  border-bottom-width: 0.06em;
}

/* Fix for matrices */
.notebook-cell-markdown .katex .arraycolsep {
  width: 0.5em;
}

/* Fix for large operators (sum, integral, etc.) */
.notebook-cell-markdown .katex .mop {
  color: var(--accent);
}

/* Highlight variables and functions */
.notebook-cell-markdown .katex .mord.mathdefault,
.notebook-cell-markdown .katex .mord.mathrm {
  color: var(--text-primary);
}

/* Style delimiters */
.notebook-cell-markdown .katex .delimsizing {
  color: var(--text-secondary);
}

/* ======================================
   CSS FOR DISPLAY MATH ($$...$$)
   Add this to your main CSS file
   ====================================== */

/* Wrapper for display math equations */
.math-display {
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
  overflow-y: hidden;
}

/* Reset KaTeX display margins inside wrapper */
.math-display .katex-display {
  margin: 0;
}

/* Ensure display math scrolls horizontally if too wide */
.math-display .katex-html {
  overflow-x: auto;
  overflow-y: hidden;
}

/* Optional: Add subtle background for display equations */
.notebook-cell-markdown .math-display {
  padding: 1rem;
  background: rgba(0, 0, 0, 0.02);
  border-radius: 4px;
}

/* Dark theme adjustment */
.dark .notebook-cell-markdown .math-display,
.elegant .notebook-cell-markdown .math-display {
  background: rgba(255, 255, 255, 0.03);
}

/* Contrast theme adjustment */
.contrast .notebook-cell-markdown .math-display {
  background: rgba(255, 255, 255, 0.05);
}


/* ======================================
   ALTERNATIVE: Minimal version (no background)
   Use this if you prefer clean look
   ====================================== */

/*
.math-display {
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
}

.math-display .katex-display {
  margin: 0;
}
*/

.math-display {
  margin: 1.5rem 0;
  text-align: center;
  overflow-x: auto;
}

.math-display .katex-display {
  margin: 0;
}