
:root {
    /* KREMA Branding Farben */
    --primary-accent: #b58c2c; 
    --primary-accent-hover: #a07920;
    --user-bubble-bg: var(--primary-accent);
    --user-bubble-text: #ffffff;
    --bot-bubble-bg: #f1f1f1;
    --bot-bubble-text: #333333;
    --bot-bubble-border: #e0e0e0;
    --chat-bg: #ffffff;
    --widget-bg: #ffffff;
    --header-bg: #ffffff;
    --header-text: #333333;
    --input-area-bg: #ffffff;
    --input-border: #cccccc;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --avatar-size: 32px;
}

/* Grundlegende Reset- und Box-Sizing-Regeln */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Container für Button und Chat-Fenster */
#chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

/* Der schwebende Chat-Button */
#chat-button {
    background-color: var(--primary-accent);
    color: white;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease-in-out;
}
#chat-button:hover {
    transform: scale(1.1);
    background-color: var(--primary-accent-hover);
}

/* Das Chat-Fenster - Desktop */
#chat-window {
    display: none;
    flex-direction: column;
    width: 370px;
    height: 80vh;
    max-height: 650px;
    border-radius: 15px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    overflow: hidden;
    background-color: var(--widget-bg);
    position: absolute;
    bottom: 80px;
    right: 0;
}

/* Header des Chat-Fensters */
#chat-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 12px 16px;
    border-bottom: 1px solid var(--bot-bubble-border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    min-height: 56px; /* Feste Mindesthöhe für stabiles Layout */
}

.assistant-avatar-header {
    width: var(--avatar-size);
    height: var(--avatar-size);
    background-color: var(--primary-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    font-weight: bold;
    color: var(--user-bubble-text);
    font-size: calc(var(--avatar-size) * 0.5);
}

.assistant-name {
    font-weight: 600;
    font-size: 16px;
}

/* Zurück-Button - standardmäßig versteckt */
.back-button {
    display: none;
    align-items: center;
    justify-content: center;
    color: #555;
    text-decoration: none;
    margin-right: 10px;
    padding: 8px;
    border-radius: 50%;
    min-width: 40px;
    min-height: 40px;
}
.back-button:hover {
    background-color: #f0f0f0;
}

/* Nachrichtenbereich */
#chat-messages {
    flex-grow: 1;
    padding: 20px 16px;
    overflow-y: auto;
    background-color: var(--chat-bg);
    -webkit-overflow-scrolling: touch; /* Smooth scrolling für iOS */
    min-height: 0; /* Wichtig für Flexbox overflow */
}

/* Styling für jede einzelne Nachricht */
.message {
    display: flex;
    align-items: flex-end;
    margin-bottom: 15px;
    max-width: 85%;
    opacity: 0;
    transform: translateY(15px);
    animation: messageFadeIn 0.4s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

@keyframes messageFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Avatar in der Nachrichtenzeile */
.assistant-avatar-message {
    width: calc(var(--avatar-size) * 0.9);
    height: calc(var(--avatar-size) * 0.9);
    min-width: calc(var(--avatar-size) * 0.9);
    background-color: var(--primary-accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 10px;
    font-weight: bold;
    color: var(--user-bubble-text);
    font-size: calc(var(--avatar-size) * 0.4);
}

/* Die eigentliche Sprechblase */
.message-content {
    padding: 10px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    position: relative;
    line-height: 1.5;
    font-size: 14px;
    white-space: pre-wrap;
}

/* Benutzernachrichten (rechts) */
.user-message {
    margin-left: auto;
    flex-direction: row-reverse;
}
.user-message .message-content {
    background: var(--user-bubble-bg); 
    color: var(--user-bubble-text); 
    border-bottom-right-radius: 5px;
}

/* Bot-Nachrichten (links) */
.bot-message {
    margin-right: auto;
}
.bot-message .message-content {
    background: var(--bot-bubble-bg);
    color: var(--bot-bubble-text);
    border: 1px solid var(--bot-bubble-border);
    border-bottom-left-radius: 5px;
}

.disclaimer {
    font-size: 0.8em;
    color: #6c757d;
    display: block;
    margin-top: 5px;
}

/* "Schreibt gerade..." Indikator - KORRIGIERT */
.typing-indicator .message-content {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    min-height: 20px;
}

.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-dots span {
    display: block;
    width: 8px;
    height: 8px;
    background-color: #9e9e9e;
    border-radius: 50%;
    animation: typingDotsAnimation 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes typingDotsAnimation {
    0%, 80%, 100% { 
        transform: scale(0.6);
        opacity: 0.5;
    } 
    40% { 
        transform: scale(1.0);
        opacity: 1;
    }
}

/* Eingabebereich */
#chat-input-container {
    padding: 12px 16px;
    background: var(--input-area-bg);
    border-top: 1px solid var(--bot-bubble-border);
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    min-height: 68px; /* Feste Mindesthöhe für stabiles Layout */
}

#chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--input-border);
    border-radius: 22px;
    font-size: 14px;
    outline: none;
    resize: none;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.4;
    background: white;
}

#chat-input:focus {
    border-color: var(--primary-accent);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary-accent) 20%, transparent);
}

#chat-send-button {
    width: 44px;
    height: 44px;
    background: var(--primary-accent);
    color: var(--user-bubble-text);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
    padding: 0;
}

#chat-send-button:hover:not(:disabled) {
    background: var(--primary-accent-hover);
}

#chat-send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Custom Scrollbar */
#chat-messages::-webkit-scrollbar { width: 6px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
#chat-messages::-webkit-scrollbar-thumb:hover { background: #bbb; }

/* ================================================================= */
/*                      MOBILE OPTIMIERUNGEN                         */
/* ================================================================= */

@media (max-width: 768px) {
    /* Verhindert Scrolling der Hauptseite wenn Chat offen */
    body.chat-fullscreen-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100vh;
        height: -webkit-fill-available;
        margin: 0;
        padding: 0;
    }

    /* Chat-Fenster im Vollbildmodus */
    #chat-window.fullscreen {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: -webkit-fill-available;
        max-height: none;
        border-radius: 0;
        z-index: 10000;
        display: flex !important;
        background-color: var(--widget-bg);
        
        /* Verhindert Hintergrund-Durchschimmern */
        opacity: 1;
        backdrop-filter: none;
    }

    /* Zeige den Zurück-Button auf Mobile */
    #chat-window.fullscreen .back-button {
        display: flex;
    }

    /* Mobile Header Anpassungen */
    #chat-window.fullscreen #chat-header {
        padding: 12px 16px;
        background: var(--header-bg);
        border-bottom: 1px solid var(--bot-bubble-border);
    }

    /* Chat-Messages Bereich für Mobile optimiert */
    #chat-window.fullscreen #chat-messages {
        flex: 1;
        min-height: 0;
        padding: 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Input Container für Mobile */
    #chat-window.fullscreen #chat-input-container {
        padding: 12px 16px;
        background: var(--input-area-bg);
        border-top: 1px solid var(--bot-bubble-border);
        position: relative;
        z-index: 1;
    }

    /* Input Field Mobile Optimierungen */
    #chat-window.fullscreen #chat-input {
        font-size: 16px; /* Verhindert Zoom auf iOS */
        border-radius: 22px;
        padding: 12px 16px;
        min-height: 44px;
        max-height: 100px;
        
        /* Verhindert Viewport-Sprünge */
        -webkit-user-select: text;
        user-select: text;
        -webkit-appearance: none;
        appearance: none;
    }

    /* Send Button Mobile */
    #chat-window.fullscreen #chat-send-button {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }

    /* Verstecke Chat Button wenn Chat offen */
    body.chat-fullscreen-open #chat-button {
        display: none !important;
    }

    /* Touch-optimierte Nachrichten */
    #chat-window.fullscreen .message {
        margin-bottom: 16px;
    }

    #chat-window.fullscreen .message-content {
        padding: 12px 16px;
        font-size: 15px;
        line-height: 1.4;
    }
}

/* Spezielle Viewport-Anpassungen für iOS Safari */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        #chat-window.fullscreen {
            height: 100vh;
            height: -webkit-fill-available;
        }
    }
}
/* Die Willkommens-Nachricht ist keine normale Sprechblase */
.welcome-message {
    max-width: 100%; /* Nimmt die volle Breite ein */
    margin-right: 0;
}

.welcome-message .message-content {
    background: #fdfdfd; /* Ein sehr leichtes Grau, fast weiß */
    border: 1px solid #f0f0f0;
    box-shadow: none;
    border-radius: 12px;
}

/* Der Avatar wird bei der Willkommens-Nachricht versteckt */
.welcome-message .assistant-avatar-message {
    display: none;
}

.welcome-message h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--header-text);
    margin-bottom: 8px;
}

.welcome-message p {
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 16px;
}

.welcome-message .disclaimer {
    margin-top: 16px;
}

/* Styling für die klickbaren Beispiel-Fragen */
.example-questions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.example-questions button {
    width: 100%;
    padding: 10px 12px;
    background-color: transparent;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    color: #444;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.example-questions button:hover {
    background-color: #f9f9f9;
    border-color: var(--primary-accent);
}