/* ==========================================
   GRUNDLAYOUT (Side-by-Side für PC)
   ========================================== */
body {
    font-family: Arial, sans-serif;
    background-color: #f0f2f5;
    margin: 0;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.main-layout {
    display: flex;
    width: 100%;
    max-width: 1800px;
    height: 100%;
    gap: 20px;
}

/* ==========================================
   LINKER BEREICH: CHAT
   ========================================== */
.app-container {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 350px;
}

header {
    background: #2c3e50;
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.header-title h1 { margin: 0 0 5px 0; font-size: 20px; }

.model-badge {
    display: inline-block;
    background-color: #1abc9c;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 12px;
    letter-spacing: 0.5px;
}

.auth-bar { display: flex; gap: 10px; }
#auth-pwd { padding: 8px; border-radius: 4px; border: none; outline: none; width: 120px; }
#reset-context-btn {
    background: #e74c3c; color: white; border: none; padding: 8px 12px;
    border-radius: 4px; cursor: pointer; font-weight: bold;
}
#reset-context-btn:hover { background: #c0392b; }

/* ==========================================
   NEU: NAVIGATION BUTTONS ÜBER DEM CHAT
   ========================================== */
.nav-buttons-bar {
    display: flex;
    gap: 10px;
    padding: 10px 20px;
    background: #fdfdfd;
    border-bottom: 1px solid #ddd;
}

.nav-btn {
    flex: 1;
    text-align: center;
    text-decoration: none;
    background-color: #3498db;
    color: white;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    transition: background 0.3s;
}

.nav-btn:hover {
    background-color: #2980b9;
}

/* ==========================================
   CHAT BEREICH
   ========================================== */
#chat-box {
    flex-grow: 1; overflow-y: auto; padding: 20px; background: #fafafa;
    display: flex; flex-direction: column; gap: 15px;
}

.message { padding: 12px 18px; border-radius: 8px; max-width: 85%; line-height: 1.5; }
.message.user { background: #007bff; color: white; align-self: flex-end; border-bottom-right-radius: 0; }
.message.ai { background: #e9ecef; color: #333; align-self: flex-start; border-bottom-left-radius: 0; }

.message.ai p { margin-top: 0; margin-bottom: 10px; }
.message.ai p:last-child { margin-bottom: 0; }
.message.ai pre { background: #2d2d2d; color: #ccc; padding: 10px; border-radius: 5px; overflow-x: auto; }
.message.ai code { background: rgba(0,0,0,0.1); padding: 2px 4px; border-radius: 4px; font-family: monospace; }
.message.ai pre code { background: transparent; padding: 0; }

.input-area { display: flex; border-top: 1px solid #ddd; background: #fff; }
#chat-input { flex-grow: 1; padding: 20px; border: none; outline: none; font-size: 16px; }
#chat-send { padding: 0 30px; background: #28a745; color: white; border: none; font-size: 16px; font-weight: bold; cursor: pointer; }
#chat-send:hover { background: #218838; }
#chat-send:disabled { background: #ccc; cursor: not-allowed; }

/* ==========================================
   RECHTER BEREICH: PDF ANSICHT
   ========================================== */
.pdf-container {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    overflow: hidden;
}

.pdf-container iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ==========================================
   MOBILE OPTIMIERUNG (FULL SCREEN SCROLLING)
   ========================================== */
@media screen and (max-width: 900px) {
    body {
        padding: 0; 
        height: auto; /* Erlaubt scrollen am gesamten Body */
    }
    
    .main-layout {
        flex-direction: column;
        gap: 0;
    }
    
    .app-container {
        border-radius: 0;
        /* Chat nimmt 100% des sichbaren Smartphone-Bildschirms ein */
        height: 100dvh; 
        min-height: 100dvh;
        box-shadow: none;
        /* Harte Kante als Trenner zur PDF unten */
        border-bottom: 6px solid #2c3e50; 
    }

    .pdf-container {
        border-radius: 0;
        /* PDF nimmt beim Runterscrollen auch wieder 100% des Bildschirms ein */
        height: 100dvh; 
        min-height: 100dvh;
        box-shadow: none;
    }

    /* Damit die Nav-Buttons auf winzigen Displays nicht zu gequetscht sind: */
    .nav-buttons-bar {
        flex-direction: column;
        gap: 5px;
    }
}

/* ==========================================
   RECHTER BEREICH: PDF ANSICHT
   ========================================== */
.pdf-container {
    flex: 1;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#pdf-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    flex-grow: 1;
}

/* Fallback-Bereich auf dem PC standardmäßig verstecken */
.mobile-pdf-fallback {
    display: none; 
}

/* ==========================================
   MOBILE OPTIMIERUNG (FULL SCREEN SCROLLING & PDF FALLBACK)
   ========================================== */
@media screen and (max-width: 900px) {
    body {
        padding: 0; 
        height: auto; 
    }
    
    .main-layout {
        flex-direction: column;
        gap: 0;
    }
    
    .app-container {
        border-radius: 0;
        height: 100dvh; 
        min-height: 100dvh;
        box-shadow: none;
        border-bottom: 6px solid #2c3e50; 
    }

    .nav-buttons-bar {
        flex-direction: column;
        gap: 5px;
    }

    /* --- DER MOBILE PDF FIX --- */
    .pdf-container {
        border-radius: 0;
        /* Wir machen den Bereich unten nur so groß, wie der Text & Button es brauchen */
        height: auto; 
        min-height: auto;
        box-shadow: none;
        padding: 40px 20px;
        background: #fdfdfd;
    }

    /* Das kaputte Iframe auf dem Handy ausblenden */
    #pdf-iframe {
        display: none;
    }

    /* Den schicken Handy-Hinweis & Button einblenden */
    .mobile-pdf-fallback {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 15px;
    }

    .mobile-pdf-fallback h2 {
        margin: 0;
        color: #2c3e50;
    }

    .mobile-pdf-fallback p {
        color: #555;
        font-size: 15px;
        margin: 0 0 10px 0;
    }

    /* Der Button zum Öffnen der PDF */
    .mobile-pdf-btn {
        background-color: #e67e22; /* Ein schickes Orange zur Hervorhebung */
        color: white;
        padding: 15px 30px;
        text-decoration: none;
        border-radius: 8px;
        font-size: 16px;
        font-weight: bold;
        box-shadow: 0 4px 10px rgba(230, 126, 34, 0.3);
        transition: background 0.3s;
    }

    .mobile-pdf-btn:hover {
        background-color: #d35400;
    }
}

/* ==========================================
   CHAT BEREICH & NACHRICHTEN
   ========================================== */
#chat-box {
    flex-grow: 1; overflow-y: auto; padding: 20px; background: #fafafa;
    display: flex; flex-direction: column; gap: 15px;
}

.message { 
    padding: 12px 18px; 
    border-radius: 8px; 
    max-width: 85%; 
    line-height: 1.6; 
    
    /* FIX 1: Verhindert, dass lange URLs oder Wörter ausbrechen */
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.message.user { background: #007bff; color: white; align-self: flex-end; border-bottom-right-radius: 0; }
.message.ai { background: #e9ecef; color: #333; align-self: flex-start; border-bottom-left-radius: 0; }

/* ==========================================
   MARKDOWN OPTIMIERUNG (Listen, Code, Tabellen)
   ========================================== */
.message.ai p { margin-top: 0; margin-bottom: 12px; }
.message.ai p:last-child { margin-bottom: 0; }

/* Listen schöner machen */
.message.ai ul, .message.ai ol { 
    margin-top: 0; 
    margin-bottom: 12px; 
    padding-left: 20px; 
}
.message.ai li { margin-bottom: 4px; }

/* Code Blöcke mit internem Scrollen (FIX 2) */
.message.ai pre { 
    background: #2d2d2d; 
    color: #ccc; 
    padding: 12px; 
    border-radius: 6px; 
    
    /* Wenn Code zu breit wird, Scrollbalken IM Codeblock zeigen! */
    overflow-x: auto; 
    max-width: 100%; 
    margin: 10px 0;
}

/* Wichtig: Code innerhalb von "pre" darf nicht den Break-Word-Fix von oben erben */
.message.ai pre code { 
    background: transparent; 
    padding: 0; 
    word-break: normal; 
    word-wrap: normal; 
    white-space: pre; /* Erhält die originalen Einrückungen von Python/JS */
}

/* Inline Code-Schnipsel im Text */
.message.ai code { 
    background: rgba(0,0,0,0.1); 
    padding: 2px 5px; 
    border-radius: 4px; 
    font-family: 'Courier New', Courier, monospace; 
    font-size: 0.9em;
}

/* Tabellen (KI nutzt oft Markdown-Tabellen) */
.message.ai table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
    display: block;
    overflow-x: auto; /* Tabellen seitlich scrollbar machen */
}
.message.ai th, .message.ai td {
    border: 1px solid #ccc;
    padding: 8px;
    text-align: left;
}
.message.ai th { background: rgba(0,0,0,0.05); }

/* Verhindert, dass Bilder (falls Gemini welche sendet) ausbrechen */
.message.ai img { max-width: 100%; height: auto; border-radius: 5px; }