/* --- 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;
}

/* Wrapper becomes the border container */
.chatbase-input-wrapper {
    width: 100%;
    position: relative;
    border-radius: 26px; /* Matches the input curvature */
    background: #ffffff;
    border: 1px solid #e0e0e0;
    box-sizing: border-box;
    min-height: 52px; /* Ensure visual stability */
    transition: height 0.1s ease;
}

/* 3. The Textarea itself */
.chatbase-modal textarea#chatbase-input {
    width: 100%;
    padding: 14px 50px 14px 20px; /* Padding for text */
    font-size: 1.1rem;
    border: none;
    background: transparent;
    outline: none;
    box-sizing: border-box;
    resize: none; 
    overflow-y: hidden; /* Hide scrollbar initially */
    line-height: 1.1rem;
    font-family: inherit;
    display: block;
    height: 52px; /* Initial height matching single line + padding */
    color: #333;
}

.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 */
/* Animation for loading bubble (Rainbow Cycle) */
@keyframes chatbase-border-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.chatbase-message.chatbase-loader {
    position: relative;
    background: transparent !important;
    z-index: 1;
    overflow: hidden;
    color: #333;
    /* Ensure text is standard color since we override background */
}

/* Gradient Background */
.chatbase-message.chatbase-loader::before {
    content: "";
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(
        #ff4545, 
        #00ff99, 
        #006aff, 
        #ff0095, 
        #ff4545
    );
    animation: chatbase-border-spin 4s linear infinite;
    z-index: -2;
}

/* Mask for inner content */
.chatbase-message.chatbase-loader::after {
    content: "";
    position: absolute;
    inset: 2px; /* Border width */
    background: #f1f1f1; /* Match regular assistant bubble */
    border-radius: 6px; /* 8px outer - 2px border */
    z-index: -1;
}

.chatbase-messages.loading-response {
    /* Container glow removed */
    animation: none; 
}

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