/* Mathematical notation rendering styles for new output display */
.math-rendered-output {
    background: #ffffff !important;
    color: #333333 !important;
    border: 1px solid #dee2e6 !important;
    border-radius: 0.375rem;
    padding: 15px;
    font-family: 'Times New Roman', serif;
    font-size: 16px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* MathJax specific styles for light theme */
.math-rendered-output .MathJax {
    color: #333333 !important;
    font-size: 1.1em !important;
}

.math-rendered-output .MathJax_Display {
    margin: 1em 0 !important;
    text-align: center !important;
}

/* Ensure math expressions are clearly visible */
.math-rendered-output mjx-container {
    display: inline-block;
    margin: 0.2em;
    color: #333333 !important;
}

.math-rendered-output mjx-container[display="true"] {
    display: block;
    margin: 1em 0;
    text-align: center;
}

/* Math preview overlay */
.math-preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 8px;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
    color: #e0e0e0 !important;
    background: rgba(0, 0, 0, 0.85);
    border: 1px solid #444;
    border-radius: 4px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    z-index: 10;
    pointer-events: auto;
}

/* Make textarea containers relative for overlay positioning */
.form-group {
    position: relative;
}

/* Math preview toggle button */
.math-preview-toggle {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 15;
    border: none;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 12px;
    font-weight: 500;
    background: rgba(108, 117, 125, 0.1);
    color: #6c757d;
    cursor: pointer;
    transition: all 0.2s ease;
}

.math-preview-toggle:hover {
    background: rgba(108, 117, 125, 0.2);
    color: #495057;
}

.math-preview-toggle.btn-warning {
    background: #ffc107;
    color: #000;
}

.math-preview-toggle.btn-warning:hover {
    background: #e0a800;
    color: #000;
}

/* KaTeX styling adjustments for dark theme */
.katex {
    color: #e0e0e0 !important;
}

.katex .base {
    color: #e0e0e0 !important;
}

.katex .mord {
    color: #e0e0e0 !important;
}

.katex .mop {
    color: #4fc3f7 !important;
}

.katex .mbin {
    color: #81c784 !important;
}

.katex .mrel {
    color: #ffb74d !important;
}

.katex .mopen, .katex .mclose {
    color: #f8bbd9 !important;
}

.katex .mpunct {
    color: #e0e0e0 !important;
}

.katex .mfrac > span {
    border-color: #e0e0e0 !important;
}

.katex .sqrt > .sqrt-line {
    border-color: #e0e0e0 !important;
}

/* Math preview toggle button */
.math-preview-toggle {
    position: absolute;
    top: 5px;
    right: 5px;
    z-index: 10;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid #444;
    color: #e0e0e0;
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 12px;
    cursor: pointer;
}

.math-preview-toggle:hover {
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
}

/* Math input help text */
.math-help {
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

.math-help code {
    background: rgba(255, 255, 255, 0.1);
    padding: 1px 3px;
    border-radius: 2px;
    font-size: 10px;
}

/* Ensure proper layering */
textarea {
    position: relative;
    z-index: 1;
    background: rgba(0, 0, 0, 0.3) !important;
}

.math-display-overlay.active {
    color: rgba(224, 224, 224, 0.9) !important;
}

/* Math rendering indicator */
.math-rendering-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    z-index: 100;
    display: none;
}