/* =========================================================
   SDBau – KI-Verkaufsberater (Chat-Widget)
   Desktop: schwebendes Fenster unten rechts
   Mobil (< 640px): Vollbild
   ========================================================= */

.sdb-chat-launcher {
    position: fixed;
    right: 88px;
    bottom: 22px;
    z-index: 1000;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 54px;
    padding: 0 20px 0 8px;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    color: #fff;
    font: inherit;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.22);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

    .sdb-chat-launcher:hover {
        transform: translateY(-2px);
        box-shadow: 0 14px 30px rgba(99, 102, 241, 0.35);
    }

    .sdb-chat-launcher:focus-visible {
        outline: 3px solid #0f172a;
        outline-offset: 3px;
    }

    .sdb-chat-launcher[aria-expanded="true"] {
        opacity: 0;
        pointer-events: none;
    }

.sdb-chat-launcher__icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    font-size: 1.1rem;
}

.sdb-chat-launcher__text strong {
    font-weight: 800;
}

/* ---------- Fenster ---------- */
.sdb-chat {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 10001;
    width: 400px;
    max-width: calc(100vw - 32px);
    height: 640px;
    max-height: calc(100vh - 44px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 20px;
    background: #fff;
    color: #0f172a;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    font-size: 0.95rem;
    line-height: 1.5;
    animation: sdbChatIn 0.22s ease-out;
}

    .sdb-chat[hidden] {
        display: none;
    }

@keyframes sdbChatIn {
    from {
        opacity: 0;
        transform: translateY(16px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

.sdb-chat .visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sdb-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 12px 14px 16px;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    color: #fff;
    flex-shrink: 0;
}

.sdb-chat__avatar {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    font-size: 1.15rem;
}

.sdb-chat__heading {
    flex: 1;
    min-width: 0;
}

.sdb-chat__title {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 800;
    color: #fff;
    line-height: 1.2;
}

.sdb-chat__subtitle {
    margin: 2px 0 0;
    font-size: 0.78rem;
    opacity: 0.92;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sdb-chat__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.3);
}

.sdb-chat__icon-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #fff;
    font-size: 1.05rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

    .sdb-chat__icon-btn:hover {
        background: rgba(255, 255, 255, 0.18);
    }

    .sdb-chat__icon-btn:focus-visible {
        outline: 2px solid #fff;
        outline-offset: 1px;
    }

/* ---------- Einwilligung ---------- */
.sdb-chat__consent {
    flex: 1;
    overflow-y: auto;
    padding: 22px 20px;
    text-align: center;
    background: #f8fafc;
}

    .sdb-chat__consent[hidden] {
        display: none;
    }

    .sdb-chat__consent h3 {
        margin: 10px 0 6px;
        font-size: 1.1rem;
        font-weight: 800;
        color: #0f172a;
    }

    .sdb-chat__consent p {
        margin: 0 0 14px;
        color: #475569;
    }

.sdb-chat__consent-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    color: #fff;
    font-size: 1.6rem;
}

.sdb-chat__consent-list {
    list-style: none;
    margin: 0 0 18px;
    padding: 0;
    text-align: left;
}

    .sdb-chat__consent-list li {
        display: flex;
        gap: 10px;
        margin-bottom: 10px;
        padding: 10px 12px;
        border-radius: 12px;
        background: #fff;
        border: 1px solid #e2e8f0;
        font-size: 0.85rem;
        color: #334155;
    }

    .sdb-chat__consent-list i {
        margin-top: 3px;
        color: #0ea5e9;
    }

.sdb-chat__primary {
    width: 100%;
    padding: 13px 18px;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.2s ease;
}

    .sdb-chat__primary:hover {
        filter: brightness(1.07);
    }

    .sdb-chat__primary:focus-visible {
        outline: 3px solid #0f172a;
        outline-offset: 2px;
    }

.sdb-chat__consent-links {
    margin: 12px 0 0 !important;
    font-size: 0.8rem;
}

.sdb-chat a {
    color: #0284c7;
    text-decoration: underline;
}

/* ---------- Verlauf ---------- */
.sdb-chat__body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
}

    .sdb-chat__body[hidden] {
        display: none;
    }

.sdb-chat__log {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overscroll-behavior: contain;
}

    .sdb-chat__log:focus-visible {
        outline: 2px solid #0ea5e9;
        outline-offset: -2px;
    }

.sdb-chat__msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.sdb-chat__msg--assistant {
    align-self: flex-start;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 6px;
    color: #1e293b;
}

.sdb-chat__msg--user {
    align-self: flex-end;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
    white-space: pre-wrap;
}

.sdb-chat__msg--error {
    align-self: stretch;
    max-width: none;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    font-size: 0.88rem;
}

.sdb-chat__msg p {
    margin: 0 0 8px;
}

    .sdb-chat__msg p:last-child {
        margin-bottom: 0;
    }

.sdb-chat__msg ul,
.sdb-chat__msg ol {
    margin: 4px 0 8px;
    padding-left: 20px;
}

    .sdb-chat__msg ul:last-child,
    .sdb-chat__msg ol:last-child {
        margin-bottom: 0;
    }

.sdb-chat__msg li {
    margin-bottom: 3px;
}

.sdb-chat__msg strong {
    font-weight: 700;
}

.sdb-chat__typing {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}

    .sdb-chat__typing span {
        width: 7px;
        height: 7px;
        border-radius: 50%;
        background: #94a3b8;
        animation: sdbChatDot 1.2s infinite ease-in-out;
    }

        .sdb-chat__typing span:nth-child(2) {
            animation-delay: 0.15s;
        }

        .sdb-chat__typing span:nth-child(3) {
            animation-delay: 0.3s;
        }

@keyframes sdbChatDot {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }

    40% {
        opacity: 1;
        transform: translateY(-3px);
    }
}

/* ---------- Vorschläge ---------- */
.sdb-chat__chips {
    display: flex;
    gap: 8px;
    padding: 4px 14px 10px;
    overflow-x: auto;
    scrollbar-width: none;
    flex-shrink: 0;
}

    .sdb-chat__chips::-webkit-scrollbar {
        display: none;
    }

    .sdb-chat__chips[hidden] {
        display: none;
    }

.sdb-chat__chip {
    flex-shrink: 0;
    padding: 7px 12px;
    border: 1px solid #bae6fd;
    border-radius: 999px;
    background: #fff;
    color: #0369a1;
    font: inherit;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease;
}

    .sdb-chat__chip:hover {
        background: #e0f2fe;
    }

    .sdb-chat__chip:focus-visible {
        outline: 2px solid #0ea5e9;
        outline-offset: 1px;
    }

/* ---------- Eingabe ---------- */
.sdb-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0;
    padding: 10px 12px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    flex-shrink: 0;
}

.sdb-chat__input {
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    padding: 11px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 14px;
    background: #f8fafc;
    color: #0f172a;
    font: inherit;
    font-size: 16px; /* verhindert Zoom auf iOS */
    line-height: 1.35;
    resize: none;
}

    .sdb-chat__input:focus {
        outline: none;
        border-color: #0ea5e9;
        box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
        background: #fff;
    }

.sdb-chat__send {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
}

    .sdb-chat__send:disabled {
        opacity: 0.5;
        cursor: not-allowed;
    }

    .sdb-chat__send[hidden] {
        display: none;
    }

    .sdb-chat__send:focus-visible {
        outline: 3px solid #0f172a;
        outline-offset: 2px;
    }

.sdb-chat__stop {
    background: #0f172a;
}

.sdb-chat__footnote {
    margin: 0;
    padding: 0 12px 10px;
    background: #fff;
    text-align: center;
    font-size: 0.72rem;
    color: #64748b;
    flex-shrink: 0;
}

    .sdb-chat__footnote a {
        color: #64748b;
    }

/* ---------- Responsiv ---------- */
@media (max-width: 768px) {
    .sdb-chat-launcher {
        right: 73px;
        bottom: 15px;
        height: 48px;
        padding: 0 14px 0 6px;
        font-size: 0.85rem;
    }

    .sdb-chat-launcher__icon {
        width: 36px;
        height: 36px;
    }
}

@media (max-width: 640px) {
    .sdb-chat {
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }

    .sdb-chat__header {
        padding-top: calc(12px + env(safe-area-inset-top));
    }

    .sdb-chat__footnote {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    body.sdb-chat-open {
        overflow: hidden;
    }
}

@media (max-width: 380px) {
    .sdb-chat-launcher__text {
        display: none;
    }

    .sdb-chat-launcher {
        padding: 0 6px;
    }
}

@media print {
    .sdb-chat-launcher,
    .sdb-chat {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sdb-chat,
    .sdb-chat-launcher,
    .sdb-chat__typing span {
        animation: none;
        transition: none;
    }
}
