/* ============================================
   LATEX EDITOR MODAL STYLES
   ============================================ */

/* Modal Overlay */
.latex-editor-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    animation: fadeIn 0.2s ease-out;
}

.latex-editor-modal.hidden {
    display: none !important;
    pointer-events: none;
}

.latex-editor-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    cursor: pointer;
}

/* Main Container */
.latex-editor-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 90%;
    max-width: 1200px;
    height: 90vh;
    max-height: 800px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.3);
    z-index: 10001;
    animation: slideUp 0.3s ease-out;
}

/* Header */
.latex-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.latex-editor-title-section {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.latex-editor-header h2 {
    margin: 0;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.latex-field-label {
    opacity: 0.85;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 500;
}

.latex-editor-close-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 24px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.latex-editor-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Content Area */
.latex-editor-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    flex: 1;
    overflow: hidden;
    background: #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
}

/* Panels */
.latex-editor-panel {
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
}

.latex-editor-left {
    border-right: 1px solid #e5e7eb;
}

.latex-editor-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    font-weight: 600;
    font-size: 13px;
    color: #374151;
    flex-shrink: 0;
}

.latex-char-count {
    font-weight: 400;
    color: #6b7280;
    font-size: 12px;
}

/* Monaco Editor Container */
.monaco-editor-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    border: none;
}

.monaco-editor-container textarea {
    width: 100%;
    height: 100%;
    padding: 16px;
    font-family: 'Courier New', 'Monaco', 'Menlo', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: #1f2937;
    background: white;
    border: none;
    resize: none;
    outline: none;
    box-sizing: border-box;
    white-space: pre;
    word-wrap: off;
    overflow: auto;
}

.monaco-editor-container textarea:focus {
    outline: none;
}

/* Editor Hints */
.latex-editor-hints {
    padding: 8px 16px;
    background: #fef3c7;
    border-top: 1px solid #fcd34d;
    color: #92400e;
    font-size: 12px;
    flex-shrink: 0;
}

/* Preview Container */
.latex-preview-container {
    position: relative;
    flex: 1;
    overflow: auto;
    padding: 16px;
    background: white;
    -webkit-overflow-scrolling: touch;
}

.latex-preview {
    min-height: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 20px 0;
}

.latex-preview-message {
    color: #9ca3af;
    font-style: italic;
    font-size: 13px;
    text-align: center;
    padding: 20px;
}

/* Error Messages */
.latex-editor-error {
    padding: 12px 16px;
    margin: 0;
    background: #fee2e2;
    border: 1px solid #fecaca;
    color: #991b1b;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.latex-editor-error.hidden {
    display: none;
}

.latex-editor-error strong {
    font-weight: 600;
}

/* Footer */
.latex-editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: #f9fafb;
    border-top: 1px solid #e5e7eb;
    gap: 12px;
    flex-shrink: 0;
}

.latex-editor-footer-spacer {
    flex: 1;
}

/* AI Section */
.latex-editor-ai-section {
    padding: 16px 20px;
    background: #f0f9ff;
    border-top: 1px solid #bfdbfe;
    border-bottom: 1px solid #bfdbfe;
    flex-shrink: 0;
}

.latex-editor-ai-section.hidden {
    display: none;
}

.latex-ai-prompt-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    min-height: 0;
}

.latex-ai-label {
    font-size: 12px;
    font-weight: 600;
    color: #0c4a6e;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.latex-ai-prompt-input {
    padding: 10px 12px;
    border: 1px solid #7dd3fc;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13px;
    color: #1f2937;
    background: white;
    resize: vertical;
    min-height: 100px;
    flex: 1;
}

.latex-ai-prompt-input:focus {
    outline: none;
    border-color: #0284c7;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.1);
}

/* Buttons */
.latex-insert-menu-btn,
.latex-editor-ai-toggle-btn,
.latex-editor-cancel-btn,
.latex-editor-save-btn,
.latex-editor-ai-send-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.latex-insert-menu-btn {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
    position: relative;
}

.latex-insert-menu-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.latex-editor-cancel-btn {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.latex-editor-cancel-btn:hover:not(:disabled) {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.latex-editor-save-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.latex-editor-save-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.latex-editor-save-btn:disabled {
    background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
    cursor: not-allowed;
    opacity: 0.6;
}

.latex-editor-ai-toggle-btn {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}

.latex-editor-ai-toggle-btn:hover:not(:disabled) {
    background: #e5e7eb;
    border-color: #9ca3af;
}

.latex-editor-ai-toggle-btn.active {
    background: #dbeafe;
    border-color: #7dd3fc;
    color: #0c4a6e;
}

.latex-editor-ai-send-btn {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.latex-editor-ai-send-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.latex-editor-ai-send-btn:disabled {
    background: linear-gradient(135deg, #9ca3af 0%, #6b7280 100%);
    cursor: not-allowed;
    opacity: 0.6;
}

.latex-editor-ai-send-btn.hidden {
    display: none;
}

.latex-editor-ai-send-btn.loading {
    pointer-events: none;
    opacity: 0.7;
}

.latex-editor-save-btn:active:not(:disabled) {
    transform: translateY(0);
}

/* Insert Menu */
.latex-insert-menu {
    position: fixed;
    display: flex;
    flex-direction: column;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    z-index: 10002;
    max-width: 400px;
    max-height: 600px;
    overflow-y: auto;
    animation: slideDown 0.2s ease-out;
}

.latex-insert-menu.hidden {
    display: none !important;
}

.latex-insert-menu-content {
    padding: 0;
}

.latex-menu-category {
    border-bottom: 1px solid #f3f4f6;
}

.latex-menu-category:last-child {
    border-bottom: none;
}

.latex-menu-category h4 {
    margin: 0;
    padding: 12px 16px 8px;
    background: #f9fafb;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.latex-insert-item {
    display: block;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: white;
    text-align: left;
    cursor: pointer;
    font-size: 13px;
    color: #374151;
    border-bottom: 1px solid #f3f4f6;
    transition: all 0.15s ease;
    font-family: 'Courier New', monospace;
}

.latex-insert-item:last-child {
    border-bottom: none;
}

.latex-insert-item:hover {
    background: #f3f4f6;
    color: #667eea;
    padding-left: 20px;
}

.latex-insert-item:active {
    background: #e5e7eb;
}

/* Field Styling */
.latex-field-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.latex-field-preview {
    padding: 12px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    overflow: hidden;
}

.latex-field-preview.empty {
    color: #9ca3af;
    font-style: italic;
    justify-content: flex-start;
}

.latex-field-preview.has-content {
    background: #f0fdf4;
    border-color: #86efac;
}

.latex-preview-code {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.latex-field-preview.empty .latex-preview-code {
    color: #9ca3af;
}

.btn-latex-editor {
    padding: 10px 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-latex-editor:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

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

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

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

/* Responsive Design */
@media (max-width: 1024px) {
    .latex-editor-container {
        max-width: 95%;
        height: 85vh;
        max-height: 600px;
    }
}

@media (max-width: 768px) {
    .latex-editor-container {
        width: 98%;
        height: 95vh;
        max-height: none;
        border-radius: 8px;
    }

    .latex-editor-content {
        grid-template-columns: 1fr;
        grid-auto-rows: 1fr;
    }

    .latex-editor-left {
        border-right: none;
        border-bottom: 1px solid #e5e7eb;
    }

    .latex-editor-header {
        padding: 16px 20px;
    }

    .latex-editor-header h2 {
        font-size: 18px;
    }

    .latex-editor-close-btn {
        width: 36px;
        height: 36px;
        font-size: 20px;
    }

    .latex-editor-footer {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .latex-insert-menu-btn,
    .latex-editor-cancel-btn,
    .latex-editor-save-btn {
        flex: 1;
    }

    .latex-insert-menu {
        max-width: 90vw;
        max-height: 400px;
    }
}

@media (max-width: 480px) {
    .latex-editor-container {
        width: 99%;
        height: 98vh;
        border-radius: 4px;
    }

    .latex-editor-header {
        padding: 12px 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .latex-editor-title-section {
        width: 100%;
    }

    .latex-editor-close-btn {
        align-self: flex-end;
    }

    .latex-editor-label {
        padding: 10px 12px;
        font-size: 12px;
    }

    .latex-char-count {
        font-size: 11px;
    }

    .latex-editor-hints {
        padding: 6px 12px;
        font-size: 11px;
    }

    .latex-insert-menu-btn,
    .latex-editor-cancel-btn,
    .latex-editor-save-btn {
        padding: 8px 16px;
        font-size: 12px;
    }
}

/* KaTeX Display Styles */
.katex-display {
    margin: 20px 0;
    text-align: center;
}

.katex {
    font-size: 1.1em;
}

/* Print Styles */
@media print {
    .latex-editor-modal {
        display: none !important;
    }
}
