/**
 * Enhanced LaTeX Styling for Dark Mode - ProductPardesLine
 * Professional mathematical formula presentation with pedagogy focus
 */

/* === KATEX DARK MODE OPTIMIZATION === */

.latex-content {
    color: var(--text-high);
    line-height: var(--line-relaxed);
    font-size: var(--text-body);
}

/* Override KaTeX default colors for dark theme */
.katex {
    color: #e8e8e8 !important;
    font-size: 1.1em !important;
}

.katex .mord {
    color: #e8e8e8 !important;
}

/* Mathematical operators with accent color */
.katex .mbin,
.katex .mrel {
    color: #62A0EA !important;
}

.katex .mop {
    color: #78A8CC !important;
}

/* Function names and text */
.katex .mord.text,
.katex .text {
    color: #c8c8c8 !important;
}

/* Subscripts and superscripts */
.katex .msupsub {
    color: #d8d8d8 !important;
}

/* Fraction lines and delimiters */
.katex .mfrac > span {
    border-color: #6a6a6a !important;
}

.katex .delimsizing,
.katex .delim-size1,
.katex .delim-size2,
.katex .delim-size3,
.katex .delim-size4 {
    color: #9a9a9a !important;
}

/* Square roots */
.katex .sqrt > .root {
    border-color: #7a7a7a !important;
}

.katex .sqrt > .vlist-t {
    border-left-color: #7a7a7a !important;
}

/* === DISPLAY EQUATIONS === */

.katex-display {
    background: linear-gradient(
        135deg,
        rgba(43, 124, 233, 0.04) 0%,
        rgba(94, 140, 174, 0.03) 100%
    );
    border-left: 4px solid var(--primary);
    border-radius: var(--radius-md);
    padding: var(--space-lg) var(--space-xl);
    margin: var(--space-lg) 0;
    overflow-x: auto;
    overflow-y: hidden;
    box-shadow: var(--shadow-sm);
    position: relative;
    transition: all var(--transition-base);
}

.katex-display:hover {
    background: linear-gradient(
        135deg,
        rgba(43, 124, 233, 0.06) 0%,
        rgba(94, 140, 174, 0.05) 100%
    );
    box-shadow: var(--shadow-md);
    border-left-color: var(--primary-variant);
}

/* Numbered equations */
.equation-numbered {
    display: flex;
    align-items: center;
    gap: var(--space-xl);
}

.equation-number {
    position: absolute;
    right: var(--space-lg);
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-medium);
    font-size: var(--text-small);
    font-weight: var(--weight-semibold);
    background: var(--color-03);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    user-select: none;
}

/* === INLINE EQUATIONS === */

.katex {
    margin: 0 2px;
    padding: 2px 4px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.katex:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* === THEORY CONTENT STRUCTURE === */

.theory-section {
    margin-bottom: var(--space-2xl);
}

.theory-heading {
    font-size: var(--text-h3);
    font-weight: var(--weight-bold);
    color: var(--text-high);
    margin-bottom: var(--space-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding-bottom: var(--space-md);
    border-bottom: 2px solid var(--border-color);
}

.theory-heading .icon {
    font-size: 1.5em;
    color: var(--primary);
}

.theory-body {
    color: var(--text-medium);
    line-height: var(--line-relaxed);
}

.theory-body p {
    margin-bottom: var(--space-md);
}

.theory-body strong {
    color: var(--text-high);
    font-weight: var(--weight-semibold);
}

.theory-body em {
    color: var(--secondary);
    font-style: italic;
}

/* === MATHEMATICAL ENVIRONMENTS === */

/* Definition blocks */
.math-definition,
.math-theorem,
.math-algorithm {
    background: var(--card-bg);
    border: var(--border-width) solid var(--card-border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    margin: var(--space-lg) 0;
    box-shadow: var(--shadow-sm);
}

.math-definition {
    border-left-width: 4px;
    border-left-color: var(--info);
}

.math-theorem {
    border-left-width: 4px;
    border-left-color: var(--success);
}

.math-algorithm {
    border-left-width: 4px;
    border-left-color: var(--warning);
}

.math-env-title {
    font-weight: var(--weight-bold);
    color: var(--primary);
    margin-bottom: var(--space-sm);
    text-transform: uppercase;
    font-size: var(--text-small);
    letter-spacing: 0.5px;
}

/* === ALGORITHM PSEUDOCODE === */

.algorithm-steps {
    font-family: var(--font-mono);
    font-size: var(--text-small);
    line-height: 1.8;
    background: var(--color-00);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin: var(--space-md) 0;
    overflow-x: auto;
}

.algorithm-steps ol {
    list-style: none;
    counter-reset: line;
    margin: 0;
    padding: 0;
}

.algorithm-steps li {
    counter-increment: line;
    position: relative;
    padding-left: var(--space-2xl);
    margin: 4px 0;
}

.algorithm-steps li::before {
    content: counter(line);
    position: absolute;
    left: 0;
    color: var(--text-disable);
    font-weight: var(--weight-semibold);
    min-width: 24px;
    text-align: right;
}

.algorithm-keyword {
    color: var(--primary);
    font-weight: var(--weight-semibold);
}

.algorithm-comment {
    color: var(--text-disable);
    font-style: italic;
}

/* === COMPLEXITY NOTATION === */

.complexity-notation {
    display: inline-flex;
    align-items: center;
    gap: var(--space-xs);
    background: rgba(var(--secondary-rgb), 0.1);
    color: var(--secondary);
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
    font-size: var(--text-small);
    font-weight: var(--weight-medium);
}

/* === PARAMETER REFERENCE === */

.param-ref {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.95em;
    background: rgba(var(--warning), 0.15);
    color: #ffb74d;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    cursor: help;
    transition: all var(--transition-fast);
}

.param-ref:hover {
    background: rgba(var(--warning), 0.25);
    transform: scale(1.05);
}

.param-ref.highlighted {
    animation: pulse 1s infinite;
    background: rgba(var(--warning), 0.35);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* === EQUATION COPYING === */

.copy-equation-btn {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    width: 32px;
    height: 32px;
    border: none;
    background: var(--color-03);
    color: var(--text-medium);
    border-radius: var(--radius-md);
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-base);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.katex-display:hover .copy-equation-btn {
    opacity: 1;
}

.copy-equation-btn:hover {
    background: var(--primary);
    color: white;
    transform: scale(1.1);
}

.copy-equation-btn.copied {
    background: var(--success);
    color: white;
}

.copy-equation-btn.copied::after {
    content: '✓';
    position: absolute;
}

/* === COLLAPSIBLE SECTIONS === */

.theory-collapsible {
    border: var(--border-width) solid var(--border-color);
    border-radius: var(--radius-lg);
    margin: var(--space-md) 0;
    overflow: hidden;
}

.theory-collapsible summary {
    padding: var(--space-md) var(--space-lg);
    background: var(--color-03);
    cursor: pointer;
    user-select: none;
    font-weight: var(--weight-semibold);
    color: var(--text-high);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    transition: all var(--transition-base);
}

.theory-collapsible summary:hover {
    background: var(--color-04);
}

.theory-collapsible summary::marker {
    content: '';
}

.theory-collapsible summary::before {
    content: '▶';
    font-size: 0.8em;
    transition: transform var(--transition-base);
}

.theory-collapsible[open] summary::before {
    transform: rotate(90deg);
}

.theory-collapsible-content {
    padding: var(--space-lg);
    background: var(--color-02);
}

/* === CROSS-REFERENCES === */

.theory-see-also {
    background: var(--color-03);
    border-left: 3px solid var(--secondary);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    margin: var(--space-xl) 0;
}

.theory-see-also-title {
    font-weight: var(--weight-bold);
    color: var(--secondary);
    margin-bottom: var(--space-sm);
    font-size: var(--text-small);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.theory-see-also ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.theory-see-also li {
    margin: var(--space-xs) 0;
}

.theory-see-also a {
    color: var(--text-medium);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.theory-see-also a:hover {
    color: var(--primary);
}

/* === REFERENCES === */

.theory-reference {
    font-size: var(--text-small);
    color: var(--text-disable);
    font-style: italic;
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: var(--border-width) dashed var(--border-color);
}

.theory-reference-list {
    list-style: none;
    margin: var(--space-sm) 0;
    padding: 0;
}

.theory-reference-item {
    margin: var(--space-xs) 0;
    padding-left: var(--space-lg);
    position: relative;
}

.theory-reference-item::before {
    content: '📚';
    position: absolute;
    left: 0;
}

/* === COMPARISON TABLES === */

.theory-comparison-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: var(--space-lg) 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.theory-comparison-table thead {
    background: var(--color-03);
}

.theory-comparison-table th {
    padding: var(--space-md);
    text-align: left;
    font-weight: var(--weight-semibold);
    color: var(--primary);
    font-size: var(--text-small);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.theory-comparison-table td {
    padding: var(--space-md);
    border-top: var(--border-width) solid var(--border-color);
    color: var(--text-medium);
}

.theory-comparison-table tbody tr {
    background: var(--color-02);
    transition: background var(--transition-fast);
}

.theory-comparison-table tbody tr:hover {
    background: var(--color-03);
}

/* === RESPONSIVE ADJUSTMENTS === */

@media (max-width: 768px) {
    .katex-display {
        padding: var(--space-md);
        margin: var(--space-md) 0;
        font-size: 0.9em;
    }

    .equation-number {
        position: static;
        transform: none;
        display: inline-block;
        margin-left: var(--space-md);
    }

    .theory-comparison-table {
        font-size: var(--text-small);
    }

    .theory-comparison-table th,
    .theory-comparison-table td {
        padding: var(--space-sm);
    }

    .algorithm-steps {
        font-size: var(--text-tiny);
    }
}

/* === ACCESSIBILITY === */

@media (prefers-contrast: high) {
    .katex {
        color: #FFFFFF !important;
    }

    .katex-display {
        border-left-width: 6px;
    }

    .param-ref {
        background: rgba(var(--warning), 0.3);
    }
}

/* === PRINT STYLES === */

@media print {
    .katex-display {
        page-break-inside: avoid;
        border-left-color: #000;
        background: white;
    }

    .copy-equation-btn {
        display: none;
    }

    .theory-collapsible summary::before {
        display: none;
    }

    .theory-collapsible {
        border: 1px solid #000;
    }
}
