/* Popup-Container - Adaptive und kleinere Grundgröße */
.formula-popup {
    position: fixed;
    top: 10vh;
    left: 50%;
    transform: translateX(-50%);
    background: #f5f5f5;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 9999;
    padding: 0;

    /* Kleinere, adaptive Größenbestimmung */
    width: clamp(400px, 60vw, 800px);
    height: clamp(300px, 50vh, 500px);

    /* Fallback für kleinere Bildschirme */
    min-width: 320px;
    max-width: 90vw;
    max-height: 70vh;

    /* Layout */
    display: flex;
    flex-direction: column;
    font-family: system-ui, sans-serif;

    /* Für manuelles Resizing */
    resize: both;
    overflow: hidden;
}

/* Spezielle Anpassungen wenn virtuelle Tastatur sichtbar ist */
body.keyboard-visible .formula-popup {
    /* Deutlich kleiner wenn Tastatur da ist */
    height: clamp(250px, 35vh, 350px);
    top: 5vh;
    max-height: 40vh;

    /* Auf mobilen Geräten noch kompakter */
    width: clamp(320px, 85vw, 600px);
}

/* Responsive Anpassungen für verschiedene Bildschirmgrößen */
@media (max-width: 768px) {
    .formula-popup {
        top: 5vh;
        width: clamp(300px, 90vw, 500px);
        height: clamp(280px, 45vh, 400px);
        max-height: 60vh;
        resize: none; /* Kein manuelles Resize auf kleinen Bildschirmen */
    }

    body.keyboard-visible .formula-popup {
        height: clamp(200px, 25vh, 280px);
        top: 2vh;
        max-height: 30vh;
    }
}

@media (max-height: 600px) {
    .formula-popup {
        top: 2vh;
        height: clamp(250px, 60vh, 350px);
        max-height: 80vh;
    }

    body.keyboard-visible .formula-popup {
        height: clamp(180px, 30vh, 220px);
        max-height: 35vh;
    }
}

/* Sehr kleine Bildschirme (Smartphones im Querformat) */
@media (max-height: 450px) {
    .formula-popup {
        height: clamp(200px, 70vh, 300px);
        top: 1vh;
    }

    body.keyboard-visible .formula-popup {
        height: clamp(150px, 25vh, 180px);
        max-height: 30vh;
    }
}

/* Große Bildschirme - etwas größer aber nicht übertrieben */
@media (min-width: 1200px) and (min-height: 800px) {
    .formula-popup {
        width: clamp(500px, 50vw, 900px);
        height: clamp(350px, 45vh, 600px);
    }
}

/* Tabs oben - fixe Höhe */
.popup-tabs {
    display: flex;
    border-bottom: 1px solid #ccc;
    flex-shrink: 0; /* Tabs werden nicht verkleinert */
}

.tab-button {
    flex: 1;
    padding: 10px 14px;
    font-weight: bold;
    cursor: pointer;
    border: none;
    background: #e0e0e0;
    transition: background 0.2s ease-in-out;
    font-size: 13px;
}

.tab-button.active {
    background: #10767a;
    color: white;
}

.tab-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Inhalt - nimmt verfügbaren Platz ein */
.popup-content {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow: hidden;
    position: relative;
}

/* Kompakterer Inhalt auf kleinen Bildschirmen */
@media (max-width: 768px) {
    .popup-content {
        padding: 12px;
        gap: 10px;
    }
}

body.keyboard-visible .popup-content {
    padding: 10px;
    gap: 8px;
}

/* Tab-Content Container */
.tab-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0; /* Wichtig für flex-shrink */
}

/* Mathfield - flexibel und scrollbar */
#math-field {
    flex: 1;
    width: 100%;
    font-size: 1.1em;
    background: white;
    border-radius: 8px;
    border: 2px solid #ddd;
    padding: 12px;

    /* Scrolling für große Formeln */
    overflow: auto;
    min-height: 80px;
    max-height: none;

    /* Bessere Lesbarkeit */
    line-height: 1.3;
}

/* Kleinere Schriftgröße bei kompaktem Layout */
body.keyboard-visible #math-field {
    font-size: 1em;
    padding: 10px;
    min-height: 60px;
}

@media (max-width: 768px) {
    #math-field {
        font-size: 1em;
        padding: 10px;
        min-height: 70px;
    }
}

#math-field:focus {
    border-color: #10767a;
    outline: none;
    box-shadow: 0 0 0 3px rgba(16, 118, 122, 0.1);
}

/* Textarea - flexibel und scrollbar */
#latex-textarea {
    flex: 1;
    width: 100%;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    padding: 12px;
    border-radius: 8px;
    border: 2px solid #ddd;
    background: white;

    /* Scrolling und Resize */
    resize: vertical;
    min-height: 80px;
    overflow: auto;

    /* Bessere Code-Darstellung */
    line-height: 1.4;
    tab-size: 2;
}

/* Kompaktere Textarea bei kleinem Layout */
body.keyboard-visible #latex-textarea {
    font-size: 12px;
    padding: 8px;
    min-height: 60px;
}

@media (max-width: 768px) {
    #latex-textarea {
        font-size: 12px;
        padding: 10px;
        min-height: 70px;
    }
}

#latex-textarea:focus {
    border-color: #10767a;
    outline: none;
    box-shadow: 0 0 0 3px rgba(16, 118, 122, 0.1);
}

/* Warnnachricht - kompakter */
.popup-message {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    padding: 8px 10px;
    margin: 5px 0;
    font-size: 13px;
    line-height: 1.3;
}

.popup-message p {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Button-Container - kompakter */
.popup-buttons {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid #ddd;
    flex-shrink: 0;
    gap: 10px;
}

body.keyboard-visible .popup-buttons {
    padding-top: 8px;
}

/* Buttons - etwas kompakter */
.insert-button {
    padding: 10px 20px;
    background-color: #10767a;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s ease-in-out;
    min-width: 90px;
}

.insert-button:hover {
    background-color: #0e5f63;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(16, 118, 122, 0.3);
}

.insert-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(16, 118, 122, 0.3);
}

/* Abbrechen-Button - kompakter */
.popup-cancel {
    background-color: #f8f9fa;
    color: #6c757d;
    border: 1px solid #dee2e6;
    font-size: 13px;
    padding: 10px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-weight: 500;
}

.popup-cancel:hover {
    color: #495057;
    background-color: #e9ecef;
    border-color: #adb5bd;
}

/* Versteckt */
.hidden {
    display: none !important;
}

/* Resize-Handle - nur bei größeren Bildschirmen sichtbar */
.formula-popup::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 16px;
    height: 16px;
    background: linear-gradient(-45deg,
        transparent 30%,
        #ccc 30%,
        #ccc 35%,
        transparent 35%,
        transparent 65%,
        #ccc 65%,
        #ccc 70%,
        transparent 70%);
    cursor: se-resize;
    border-bottom-right-radius: 12px;
}

@media (max-width: 768px) {
    .formula-popup::after {
        display: none;
    }
}

/* Scrollbar-Styling für bessere UX */
#math-field::-webkit-scrollbar,
#latex-textarea::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

#math-field::-webkit-scrollbar-track,
#latex-textarea::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

#math-field::-webkit-scrollbar-thumb,
#latex-textarea::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

#math-field::-webkit-scrollbar-thumb:hover,
#latex-textarea::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Accessibility */
.formula-popup:focus-within {
    box-shadow: 0 8px 24px rgba(0,0,0,0.3), 0 0 0 4px rgba(16, 118, 122, 0.2);
}

/* Loading-Animation (optional) */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.formula-popup.loading #math-field {
    animation: pulse 1.5s infinite;
}

/* Sigma-Symbol im TinyMCE Button - größer und fetter ohne Hover-Effekte */
button[aria-label*="Formel einfügen"] .tox-tbtn__select-label,
button[title*="Formel einfügen"] .tox-tbtn__select-label,
button[data-mce-name="latexButton"] .tox-tbtn__select-label {
    font-size: 18px !important;
    font-weight: 900 !important;
    font-family: "Times New Roman", "DejaVu Serif", serif !important;
    color: #333 !important;
    line-height: 1 !important;
    display: inline-block !important;
}

/* Print-Styles */
@media print {
    .formula-popup {
        display: none;
    }
}

/* Spezielle Anpassungen für sehr hohe Auflösungen */
@media (min-height: 1200px) and (min-width: 1400px) {
    .formula-popup {
        width: clamp(600px, 45vw, 1000px);
        height: clamp(400px, 40vh, 700px);
    }
}

/*
 * NEU: Styling für die Format-Auswahl (Inline/Block)
 */
.formula-format-controls {
    display: flex;
    justify-content: center; /* Zentriert die Elemente horizontal */
    align-items: center;
    gap: 24px; /* Abstand zwischen den beiden Optionen */
    padding: 8px 0;
    margin-top: 5px;
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 6px;
}

.formula-format-controls label {
    display: flex;
    align-items: center;
    gap: 6px; /* Abstand zwischen Radio-Button und Text */
    cursor: pointer;
    font-size: 13px;
}
