/* --- Modal Basis --- */
.chatbase-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: none; /* Default hidden */
    place-items: center; /* Center content */
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.chatbase-modal.is-visible {
    display: grid; /* Modern CSS Grid as requested */
    opacity: 1;
    pointer-events: auto;
}

.chatbase-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 1;
}

/* --- Content Container (Viewport Height) --- */
.chatbase-modal-content {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 800px;
    
    /* Liquid Design: 100dvh für mobile Browser, fallback 100% */
    height: 100%;
    height: 100dvh; 
    
    background: transparent;
    padding: 10px;
    box-sizing: border-box;
    overflow: hidden; /* Verhindert Scrollen auf Elternebene */
    
    display: flex;
    flex-direction: column;
}

/* --- Header --- */
.chatbase-header {
    height: 60px;
    background: rgba(0,0,0,0.4);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-sizing: border-box;
    flex-shrink: 0;
    z-index: 101;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    margin-bottom: 15px;
}

.chatbase-header-title {
    font-weight: bold;
    font-size: 1.1rem;
}

.chatbase-menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.chatbase-menu-toggle:hover {
    transform: scale(1.1);
}

.chatbase-header-actions {
    position: relative;
}

/* --- Dropdown --- */
.chatbase-menu-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 10px;
    background: white;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-radius: 8px;
    width: 200px;
    display: none;
    overflow: hidden;
}

.chatbase-menu-dropdown.is-open {
    display: block;
}

.chatbase-menu-dropdown ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.chatbase-menu-dropdown li {
    border-bottom: 1px solid #eee;
}

.chatbase-menu-dropdown li:last-child {
    border-bottom: none;
}

.chatbase-menu-dropdown a {
    display: block;
    padding: 12px 20px;
    color: #333;
    text-decoration: none;
    font-size: 0.95rem;
    transition: background 0.1s;
}

.chatbase-menu-dropdown a:hover {
    background: #f5f5f5;
}

/* --- Close Button REMOVED (Legacy style kept just in case but not used) --- */
.chatbase-close {
    display: none; /* Safely hide if still present in markup */
}

/* --- DAS GRID LAYOUT --- */
.chatbase-chat-container {
    width: 100%;
    height: 90%;
    
    display: grid;
    /* Zeile 1: Disclaimer (auto - so hoch wie Inhalt)
       Zeile 2: Nachrichten (1fr - nimmt den GANZEN restlichen Platz)
       Zeile 3: Input & Footer (auto - so hoch wie Inhalt)
    */
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 100%;
    
    /* INITIAL-ZUSTAND: 
       Wenn keine Nachrichten da sind (display:none), kollabiert die 1fr Zeile.
       'align-content: center' zentriert Disclaimer und Input vertikal in der Mitte.
    */
    align-content: center; 
    gap: 10px; /* Optional: Abstand zwischen den Elementen */
    transition: all 0.5s ease;
}

/* ZUSTAND: Chat Aktiv (Klasse per JS hinzufügen!) */
.chatbase-chat-container.has-messages {
    /* Streckt das Grid über die volle Höhe, Input wandert nach unten */
    align-content: stretch; 
}



/* --- Zeile 2: Nachrichten (Scrollbar Bereich) --- */
.chatbase-messages {
    /* Initial ausgeblendet */
    display: none; 
    
    width: 100%;
    /* Grid spezifisch: min-height: 0 verhindert Overflow-Probleme */
    min-height: 0; 
    
    /* Scroll-Verhalten */
    overflow-y: auto;
    overscroll-behavior: contain;
    
    background: rgba(255, 255, 255, 0.8);
    border-radius: 10px;
    padding: 0; /* Padding moves to inner content or handle differently if using height transition */
    box-sizing: border-box;
    margin-bottom: 0;
    
    transition: flex-grow 0.5s ease; /* If flex used, but we are grid */
}

.chatbase-messages.active {
    display: block;
    padding: 20px;
    margin-bottom: 10px;
    /* Wichtig: Sobald block, greift das '1fr' vom Grid Parent */
}

.chatbase-messages.active {
    display: block;
    /* Wichtig: Sobald block, greift das '1fr' vom Grid Parent */
}

/* Nachricht-Styling (unverändert) */
.chatbase-message {
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 8px;
    max-width: 80%;
    line-height: 1.2;
}
.chatbase-message.user {
    background-color: var(--chatbase-chat-color, #007bff);
    color: white;
    margin-left: auto;
}
.chatbase-message.assistant {
    background-color: #f1f1f1;
    color: #333;
    margin-right: auto;
}

.chatbase-message a {
    text-decoration: underline;
}

/* --- Zeile 3: Bottom Group (Input + Footer) --- */
.chatbase-bottom-group {
    width: 100%;
    /* Stellt sicher, dass Input und Footer zusammenbleiben */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chatbase-input-wrapper {
    width: 100%;
    position: relative;
}

.chatbase-modal input#chatbase-input {
    width: 100%;
    padding: 15px 50px 15px 20px;
    font-size: 1.1rem;
    border: 2px solid #ddd;
    border-radius: 50px;
    outline: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    background: rgba(255, 255, 255, 0.9);
    box-sizing: border-box;
}

.chatbase-submit {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.5rem;
    color: var(--chatbase-main-color, #007bff);
}

.chatbase-footer {
    margin-top: 10px;
    text-align: center;
}

.chatbase-footer a {
    font-size: 12px; 
    color: #FFFFFF; 
    text-decoration: none;
}

/* Chatbubble */
.chatbase-bubble {
    position: fixed;
    width: 60px;
    height: 60px;
    background-color: var(--chatbase-main-color, #007bff);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 99998; /* Just below modal */
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.chatbase-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0,0,0,0.2);
}

.chatbase-bubble svg {
    width: 30px;
    height: 30px;
    fill: white;
}

/* Animation for loading state */
@keyframes chatbase-siri-glow {
    0% {
        box-shadow: 0 0 8px rgba(255, 0, 0, 0.6), inset 0 0 8px rgba(255, 0, 0, 0.1);
        border: 2px solid rgba(255, 0, 0, 0.6);
    }
    20% {
        box-shadow: 0 0 8px rgba(255, 165, 0, 0.6), inset 0 0 8px rgba(255, 165, 0, 0.1);
        border: 2px solid rgba(255, 165, 0, 0.6);
    }
    40% {
        box-shadow: 0 0 8px rgba(255, 255, 0, 0.6), inset 0 0 8px rgba(255, 255, 0, 0.1);
        border: 2px solid rgba(255, 255, 0, 0.6);
    }
    60% {
        box-shadow: 0 0 8px rgba(0, 128, 0, 0.6), inset 0 0 8px rgba(0, 128, 0, 0.1);
        border: 2px solid rgba(0, 128, 0, 0.6);
    }
    80% {
        box-shadow: 0 0 8px rgba(0, 0, 255, 0.6), inset 0 0 8px rgba(0, 0, 255, 0.1);
        border: 2px solid rgba(0, 0, 255, 0.6);
    }
    100% {
        box-shadow: 0 0 8px rgba(238, 130, 238, 0.6), inset 0 0 8px rgba(238, 130, 238, 0.1);
        border: 2px solid rgba(238, 130, 238, 0.6);
    }
}

.chatbase-messages.loading-response {
    animation: chatbase-siri-glow 2s linear infinite alternate;
    transition: all 0.3s ease;
}

.chatbase-no-scroll {
    overflow: hidden !important;
}