/* ==============================================
   KIM CHAT WIDGET - NEO BRUTALISM
   ============================================== */

.chat-widget {
    /* Hard corners for brutalism */
    position: relative;
    width: 90%;
    max-width: 1200px;
    height: 60vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg-card);
    box-shadow: 8px 8px 0 var(--brutal-shadow);
    border: 3px solid var(--border-color);
    font-family: 'Inter', sans-serif;
}

.chat-widget.closed {
    /* Legacy class support, mainly handled by container now */
    display: none;
}

.chat-controls {
    display: flex;
    align-items: center;
    gap: 0;
}

.chat-widget-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: color-mix(in srgb, var(--color-bg-canvas), transparent 10%);
    z-index: 9998;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Header */
.chat-header {
    background: var(--accent-kim-solid);
    /* Emerald */
    color: var(--color-ink);
    border-bottom: 3px solid var(--border-color);
    padding: 0 1rem 0 1.5rem;
    /* Adjusted padding-right for button */
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    height: 70px;
    flex-shrink: 0;
}

.chat-close-btn {
    background: transparent;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-ink);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 5px;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: var(--overlay-10);
}

.chat-close-btn i {
    font-size: 1.75rem;
    /* Large and bold like cards */
}

.chat-title {
    font-weight: 800;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    text-transform: uppercase;
    letter-spacing: -0.02em;
}

.chat-title i {
    font-size: 1.5rem;
    background: var(--color-ink);
    color: var(--text-light);
    /* Explicit dimensions for perfect circle */
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Body */
.chat-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
    position: relative; /* Wichtig für korrekte offsetTop-Scroll-Berechnung */
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
    background-image: radial-gradient(var(--color-ink) 1px, transparent 1px);
    background-size: 20px 20px;
    /* background-opacity is not a valid property; opacity handled via radial-gradient colors if needed, but here just removing invalid line */
}

/* Messages */
.chat-message {
    display: flex;
    max-width: 85%;
}

.chat-message.bot {
    align-self: flex-start;
}

.chat-message.user {
    align-self: flex-end;
}

.message-content {
    padding: 1rem 1.25rem;
    font-size: 1rem;
    line-height: 1.5;
    position: relative;
    font-weight: 500;
    border: 2px solid var(--border-color);
    box-shadow: 4px 4px 0 var(--brutal-shadow);
}

.chat-message.bot .message-content {
    background: var(--bg-card);
    color: var(--color-ink);
    border-bottom-left-radius: 0;
}

.chat-message.user .message-content {
    background: var(--chat-user-msg-bg);
    /* Weiß auf blauem Hintergrund für guten Kontrast */
    color: var(--chat-user-msg-text);
    border-bottom-right-radius: 0;
}

/* Fix for links inside chat messages (both bot and user) */
.chat-message .message-content a {
    color: currentColor;
    text-decoration: underline;
    text-decoration-thickness: 2px;
}

.chat-message .message-content a:hover {
    background-color: var(--color-yellow);
    color: var(--text-on-bright);
    text-decoration: none;
}

/* Input Area */
.chat-input-area {
    padding: 1.5rem;
    background: var(--bg-card);
    border-top: 3px solid var(--border-color);
}

#chat-input {
    flex: 1;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 0;
    font-size: 16px; /* Verhinderte iOS Zoom + Scroll Sprung */
    outline: none;
    font-weight: 500;
    background: var(--bg-subtle);
    box-shadow: inset 2px 2px 0 var(--overlay-10);
}

#chat-input:focus {
    background: var(--bg-card);
    box-shadow: inset 2px 2px 0 var(--brutal-shadow);
}

#chat-send-btn {
    border: 2px solid var(--border-color);
    background: var(--color-ink);
    color: var(--text-light);
    border-radius: 0;
    padding: 0 1.5rem;
    box-shadow: 4px 4px 0 var(--overlay-20);
    transition: all 0.1s;
}

#chat-send-btn:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 var(--overlay-20);
}

#chat-send-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 0 0 0 var(--overlay-0);
}

/* Consent Overlay */
.chat-consent-overlay {
    display: none;
    position: absolute;
    top: 70px;
    left: 0;
    right: 0;
    bottom: 0;
    background: color-mix(in srgb, var(--color-bg-canvas), transparent 2%);
    z-index: 10;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    text-align: center;
}

.kim-needs-consent .chat-consent-overlay {
    display: flex;
}

.consent-content.warning-box {
    background: var(--accent-marktplatz-bg);
    /* Amber Light */
    border: 2px solid var(--border-color);
    box-shadow: 8px 8px 0 var(--brutal-shadow);
    padding: 2rem;
    max-width: 400px;
}

.consent-content h3 {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--color-ink);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-transform: uppercase;
}

.consent-content p {
    font-size: 1rem;
    color: var(--color-ink);
    margin-bottom: 1rem;
    line-height: 1.5;
}

/* Typing Dots */
.typing-dots span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--color-ink);
    border-radius: 50%;
    margin: 0 3px;
    animation: typing 1.4s infinite ease-in-out;
}

.chat-input-disclaimer {
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    text-align: center;
    line-height: 1.4;
    font-weight: 500;
}

.chat-input-disclaimer a {
    color: var(--text-main);
    text-decoration: underline;
    font-weight: 700;
}

.chat-input-disclaimer a:visited,
.consent-content a:visited {
    color: var(--text-main);
}

.chat-input-disclaimer a:hover,
.consent-content a:hover {
    background-color: var(--color-yellow);
    color: var(--color-text-on-yellow);
    text-decoration: none;
}

@media (max-width: 600px) {
    .chat-widget-overlay {
        /* Platz für fixierte Bottom-Nav, damit Widget nicht dahinter verschwindet */
        padding-bottom: calc(56px + env(safe-area-inset-bottom));
    }

    .chat-widget {
        width: 95%;
        height: 80vh;
        /* Fallback */
        height: 80dvh;
        /* Dynamic Viewport Height for mobile browsers */
        max-height: 600px;
        /* Limit height on landscape/small screens */
        box-shadow: 4px 4px 0 var(--brutal-shadow);
    }

    /* Input Area: Less Padding for Mobile */
    .chat-input-area {
        padding: 0.6rem 0.75rem 0.5rem;
    }

    #chat-form {
        flex-direction: row;
        gap: 0.5rem;
    }

    #chat-input {
        padding: 0.75rem;
        flex: 1;
    }

    #chat-send-btn {
        width: auto;
        margin-top: 0;
        height: 48px;
        padding: 0 1.25rem;
        /* Better touch target without full width */
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .chat-input-disclaimer {
        font-size: 0.65rem;
        margin-top: 0.35rem;
    }

    .chat-body {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .chat-header {
        padding: 0 1rem;
        /* Reduced padding to give more internal space, controlled by flex gap */
        padding-right: 1.5rem;
        /* Extra space on the right for icons */
        height: 60px;
    }

    .chat-controls {
        gap: 0.5rem;
        margin-right: 0.5rem;
        /* Additional buffer from right edge */
    }

    .consent-content.warning-box {
        padding: 1rem;
        box-shadow: 4px 4px 0 var(--brutal-shadow);
    }
}
