/* ============================================================
   Mathe-Chat — Basis-Styles (Chat, Eingabe, Formeln, Bild-Modal)
   Tastatur-Styles sind in tastatur.css ausgelagert!
   ============================================================ */

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #efeae2;
    color: #1f2937;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    height: 100dvh;
}

/* ============================================================
   Chat-Bereich
   ============================================================ */
#chat-scroll {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
}

/* ============================================================
   Sprechblasen (WhatsApp-Like)
   ============================================================ */
.blase {
    background: #ffffff;
    border-radius: 10px;
    border-top-left-radius: 2px;
    align-self: flex-start;
    max-width: 95%;
    min-width: 0;
    padding: 10px 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.45;
}

.blase.schueler {
    background: #d9fdd3;
    align-self: flex-end;
    border-top-left-radius: 10px;
    border-top-right-radius: 2px;
}

.blase .teil { margin-bottom: 6px; }
.blase .teil:last-child { margin-bottom: 0; }
.blase .fehler { color: #b91c1c; }

/* ============================================================
   KaTeX-Formeln in Blasen (Scrollbalken versteckt)
   ============================================================ */
.blase .katex-display {
    max-width: 100%;
    margin: 6px 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.blase .katex-display::-webkit-scrollbar {
    display: none;
}
.blase .katex {
    font-size: 1.05em;
}

/* ============================================================
   Bild-Thumbnail im Chat (Schüler-Uploads)
   ============================================================ */
.chat-bild {
    display: block;
    max-width: 120px;
    max-height: 120px;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 6px;
    object-fit: cover;
    -webkit-tap-highlight-color: transparent;
}

/* ============================================================
   Eingabebereich
   ============================================================ */
#eingabe-bereich {
    flex-shrink: 0;
    background: #f0f2f5;
    border-top: 1px solid #cbd5e1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
    z-index: 5;
}

#text-input {
    width: 100%;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 16px;
    outline: none;
    resize: none;
    max-height: 100px;
    font-family: inherit;
    line-height: 1.3;
}

/* Platzhalter für das Textfeld */
#text-input::placeholder {
    color: #cbd5e1 !important;
    opacity: 0.8;
}

.formel-zeile {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ============================================================
   MathLive-Feld (Feste Höhe & Menüs blockieren)
   ============================================================ */
math-field {
    flex: 1;
    min-width: 0;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 20px;
    height: 60px; 
    max-height: 60px;
    overflow: hidden; 
    outline: none;
}

/* MathLive Platzhalter (Shadow DOM Fix) */
math-field::part(placeholder) {
    color: #cbd5e1 !important;
    opacity: 0.8;
}

/* Fallback über CSS-Variablen (für ältere MathLive-Versionen) */
math-field {
    --placeholder-color: #cbd5e1 !important;
    --placeholder-opacity: 0.8;
}

/* Alle MathLive-Menüs und Toolbars hart ausblenden */
math-field::part(virtual-keyboard-toggle),
math-field::part(menu-toggle) {
    display: none !important;
}

math-virtual-keyboard,
.ML__keyboard,
.MLK__keyboard,
.ML__toolbar {
    display: none !important;
}

/* ============================================================
   Aktions-Buttons in der Formelzeile
   ============================================================ */
#btn-bild, #sende-btn {
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    -webkit-tap-highlight-color: transparent;
    transition: background 0.1s;
}

#btn-bild { background: #e2e8f0; color: #475569; }
#btn-bild:active { background: #cbd5e1; }

#sende-btn { background: #0284c7; color: #fff; }
#sende-btn:active { background: #0369a1; }

#btn-bild svg, #sende-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}
#sende-btn svg { margin-left: -2px; }

/* ============================================================
   Modal: Bild in Großansicht (iPhone-tauglich, Safe-Area)
   ============================================================ */
#bild-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding:
        calc(env(safe-area-inset-top) + 60px)
        calc(env(safe-area-inset-right) + 12px)
        calc(env(safe-area-inset-bottom) + 12px)
        calc(env(safe-area-inset-left) + 12px);
    touch-action: manipulation;
}

#bild-modal-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
    display: block;
}

#bild-modal-schliessen {
    position: absolute;
    top: calc(env(safe-area-inset-top) + 12px);
    right: calc(env(safe-area-inset-right) + 12px);
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 0;
    border-radius: 50%;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
    z-index: 4001;
}
#bild-modal-schliessen:active { background: rgba(255, 255, 255, 0.3); }

/* ============================================================
   DESKTOP (≥ 800 px)
   ============================================================ */
@media (min-width: 800px) {
    html {
        background: #cfc9bd;
    }
    body {
        max-width: 800px;
        margin: 0 auto;
        box-shadow: 0 0 24px rgba(0,0,0,0.12);
    }
}