/* Chatbot Widget Styles */
:root {
    --chatbot-primary: #7C3AED;
    --chatbot-logo-bg: #7C3AED;
    --chatbot-user-msg: #7C3AED;
    --chatbot-bg-light: #FFFFFF;
    --chatbot-bg-dark: #1F2937;
    --chatbot-text-light: #1F2937;
    --chatbot-text-dark: #F3F4F6;
    --chatbot-bot-msg: #F3F4F6;
    --chatbot-border-light: #E5E7EB;
    --chatbot-border-dark: #374151;
    --chatbot-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Floating Chat Button */
.chatbot-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chatbot-primary) !important;
    color: white !important;
    border: none !important;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 9998;
}

.chatbot-button i {
    line-height: 1;
}

.chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.chatbot-button.hidden {
    display: none;
}

/* Chat Container */
.chatbot-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 600px;
    border-radius: 12px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    transition: opacity 0.3s, transform 0.3s;
}

.chatbot-container.hidden {
    display: none;
}

.chatbot-container.light {
    background: var(--chatbot-bg-light);
    color: var(--chatbot-text-light);
}

.chatbot-container.dark {
    background: var(--chatbot-bg-dark);
    color: var(--chatbot-text-dark);
}

/* Header */
.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid;
}

.chatbot-container.light .chatbot-header {
    background: var(--chatbot-bg-light);
    border-bottom-color: var(--chatbot-border-light);
}

.chatbot-container.dark .chatbot-header {
    background: var(--chatbot-bg-dark);
    border-bottom-color: var(--chatbot-border-dark);
}

.chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-logo {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: var(--chatbot-logo-bg) !important;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white !important;
    font-weight: bold;
    font-size: 18px;
    overflow: hidden;
}

.chatbot-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.chatbot-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.chatbot-container.light .chatbot-title {
    color: var(--chatbot-text-light) !important;
}

.chatbot-container.dark .chatbot-title {
    color: var(--chatbot-text-dark) !important;
}

.chatbot-header-right {
    display: flex;
    gap: 8px;
}

.chatbot-icon-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background 0.2s;
}

.chatbot-icon-btn i {
    line-height: 1;
}

.chatbot-container.light .chatbot-icon-btn {
    background: #F3F4F6;
    color: var(--chatbot-text-light);
}

.chatbot-container.dark .chatbot-icon-btn {
    background: #374151;
    color: var(--chatbot-text-dark);
}

.chatbot-icon-btn:hover {
    opacity: 0.8;
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chatbot-container.light .chatbot-messages {
    background: #F9FAFB;
}

.chatbot-container.dark .chatbot-messages {
    background: #111827;
}

.chatbot-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 14px;
    word-wrap: break-word;
}

/* Markdown content styling in bot messages */
.chatbot-message.bot a {
    color: var(--chatbot-primary);
    text-decoration: underline;
}

.chatbot-container.dark .chatbot-message.bot a {
    color: #A78BFA;
}

.chatbot-message.bot strong,
.chatbot-message.bot b {
    font-weight: 600;
}

.chatbot-message.bot em,
.chatbot-message.bot i {
    font-style: italic;
}

.chatbot-message.bot h1,
.chatbot-message.bot h2,
.chatbot-message.bot h3 {
    font-weight: 600;
    line-height: 1.3;
    margin: 10px 0 4px;
}

.chatbot-message.bot h1 { font-size: 1.15em; }
.chatbot-message.bot h2 { font-size: 1.05em; }
.chatbot-message.bot h3 { font-size: 0.97em; }

.chatbot-message.bot ul,
.chatbot-message.bot ol {
    margin: 8px 0;
    padding-left: 20px;
}

.chatbot-message.bot li {
    margin: 4px 0;
}

.chatbot-message.bot p {
    margin: 0;
}

.chatbot-message.bot p + p {
    margin-top: 8px;
}

.chatbot-message.bot br {
    line-height: 1.5;
}

.chatbot-message.bot hr {
    border: none;
    border-top: 1px solid var(--chatbot-border-light);
    margin: 10px 0;
}

.chatbot-container.dark .chatbot-message.bot hr {
    border-top-color: var(--chatbot-border-dark);
}

/* Inline code */
.chatbot-message.bot code {
    background: rgba(0, 0, 0, 0.07);
    border-radius: 4px;
    padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.875em;
}

.chatbot-container.dark .chatbot-message.bot code {
    background: rgba(255, 255, 255, 0.1);
}

/* Code blocks */
.chatbot-message.bot pre {
    background: rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    padding: 10px 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-size: 0.85em;
}

.chatbot-container.dark .chatbot-message.bot pre {
    background: rgba(0, 0, 0, 0.3);
}

.chatbot-message.bot pre code {
    background: none;
    padding: 0;
    font-size: inherit;
    border-radius: 0;
    white-space: pre;
}

.chatbot-message.bot {
    align-self: flex-start;
    background: var(--chatbot-bot-msg);
    color: var(--chatbot-text-light);
    border-bottom-left-radius: 4px;
}

.chatbot-container.dark .chatbot-message.bot {
    background: #374151;
    color: var(--chatbot-text-dark);
}

.chatbot-message.user {
    align-self: flex-end;
    background: var(--chatbot-user-msg);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Loading Animation */
.chatbot-loading {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--chatbot-bot-msg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
}

.chatbot-container.dark .chatbot-loading {
    background: #374151;
}

.chatbot-loading.hidden {
    display: none;
}

.chatbot-loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9CA3AF;
    animation: loading-bounce 1.4s infinite ease-in-out both;
}

.chatbot-loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.chatbot-loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading-bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input Area */
.chatbot-input-area {
    padding: 16px 20px;
    border-top: 1px solid;
}

.chatbot-container.light .chatbot-input-area {
    background: var(--chatbot-bg-light);
    border-top-color: var(--chatbot-border-light);
}

.chatbot-container.dark .chatbot-input-area {
    background: var(--chatbot-bg-dark);
    border-top-color: var(--chatbot-border-dark);
}

.chatbot-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-container.light .chatbot-input {
    background: #F9FAFB;
    border-color: var(--chatbot-border-light);
    color: var(--chatbot-text-light);
}

.chatbot-container.dark .chatbot-input {
    background: #1F2937;
    border-color: var(--chatbot-border-dark);
    color: var(--chatbot-text-dark);
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary) !important;
    outline: none !important;
}

.chatbot-input::placeholder {
    color: #9CA3AF;
}

.chatbot-send-btn {
    padding: 12px 24px;
    background: var(--chatbot-primary) !important;
    color: white !important;
    border: none !important;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.2s;
}

.chatbot-send-btn:hover:not(:disabled) {
    filter: brightness(0.85);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 3px;
}

.chatbot-container.dark .chatbot-messages::-webkit-scrollbar-thumb {
    background: #4B5563;
}

/* Message Wrapper (groups bubble + rating) */
.chatbot-message-wrapper {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
}

/* Rating buttons */
.chatbot-rating {
    display: flex;
    gap: 4px;
    padding-left: 2px;
    visibility: hidden;
}

.chatbot-rating.visible {
    visibility: visible;
}

.chatbot-rate-btn {
    background: none;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 13px;
    line-height: 1.4;
    opacity: 0.55;
    transition: opacity 0.15s, background 0.15s, border-color 0.15s;
}

.chatbot-rate-btn:hover:not(:disabled) {
    opacity: 1;
    background: rgba(0, 0, 0, 0.06);
}

.chatbot-rate-btn.active {
    opacity: 1;
    border-color: rgba(0, 0, 0, 0.3);
    background: rgba(0, 0, 0, 0.08);
}

.chatbot-container.dark .chatbot-rate-btn {
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--chatbot-text-dark);
}

.chatbot-container.dark .chatbot-rate-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.chatbot-container.dark .chatbot-rate-btn.active {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.12);
}

/* Suggestion Area (fixed bottom, above input) */
.chatbot-suggestions-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid;
    flex-shrink: 0;
}

.chatbot-suggestions-area.hidden {
    display: none;
}

.chatbot-container.light .chatbot-suggestions-area {
    background: var(--chatbot-bg-light);
    border-top-color: var(--chatbot-border-light);
}

.chatbot-container.dark .chatbot-suggestions-area {
    background: var(--chatbot-bg-dark);
    border-top-color: var(--chatbot-border-dark);
}

.chatbot-suggestion-btn {
    background: none;
    border: 1.5px solid var(--chatbot-primary);
    color: var(--chatbot-primary);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 12.5px;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
    line-height: 1.35;
    transition: background 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
    overflow: hidden;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-suggestion-btn:hover {
    background: var(--chatbot-primary);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.chatbot-suggestion-btn:active {
    transform: translateY(0);
    box-shadow: none;
}

.chatbot-container.dark .chatbot-suggestion-btn {
    border-color: rgba(167, 139, 250, 0.6);
    color: #A78BFA;
}

.chatbot-container.dark .chatbot-suggestion-btn:hover {
    background: rgba(167, 139, 250, 0.25);
    border-color: rgba(167, 139, 250, 0.9);
    color: #C4B5FD;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    /* Chat-Button */
    .chatbot-button {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: 16px;
        width: 52px;
        height: 52px;
        font-size: 20px;
    }

    /* Chat-Fenster: volle Breite, unten angedockt, max 85vh */
    .chatbot-container {
        width: 100%;
        max-height: 85dvh;
        height: 85dvh;
        bottom: 0;
        right: 0;
        left: 0;
        border-radius: 16px 16px 0 0;
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Größere Touch-Targets für Buttons */
    .chatbot-icon-btn {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    /* Input-Bereich */
    .chatbot-input-area {
        padding: 12px 16px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    .chatbot-input {
        font-size: 16px; /* verhindert Auto-Zoom auf iOS */
        padding: 12px 14px;
    }

    .chatbot-send-btn {
        padding: 12px 18px;
        font-size: 14px;
    }

    /* Nachrichten */
    .chatbot-messages {
        padding: 16px;
    }

    .chatbot-message {
        max-width: 90%;
        font-size: 15px;
    }

    /* Header */
    .chatbot-header {
        padding: 14px 16px;
    }

    /* Suggestions: etwas kompakter auf Mobile */
    .chatbot-suggestions-area {
        gap: 6px;
        padding: 10px 12px;
    }

    .chatbot-suggestion-btn {
        font-size: 12px;
        padding: 7px 10px;
        min-height: 40px;
    }
}

/* Bei sehr kleinen Displays (Höhe < 600px): Widget dockt oben an */
@media (max-width: 480px) and (max-height: 600px) {
    .chatbot-container {
        top: env(safe-area-inset-top, 0px);
        bottom: 0;
        height: auto;
        max-height: 100dvh;
        border-radius: 0;
    }
}
