/* ============================================================
   Bitzinger Chat Bot — CSS Custom Properties
   Tokens live on the widget (not :root) so Dark Mode can be
   scoped and reliably disabled via --ignore-dark-mode.
   Override any variable in your site CSS to customise the widget.
   ============================================================ */
.bitzinger-chatbot {
    --chatbot-primary: #2563eb;
    --chatbot-primary-dark: #1d4ed8;
    --chatbot-primary-text: #ffffff;
    --chatbot-bg: #ffffff;
    --chatbot-surface: #f8fafc;
    --chatbot-border: #e2e8f0;
    --chatbot-text: #1e293b;
    --chatbot-text-muted: #64748b;
    --chatbot-bubble-user: #2563eb;
    --chatbot-bubble-user-text: #ffffff;
    --chatbot-bubble-bot: #f1f5f9;
    --chatbot-bubble-bot-text: #1e293b;
    --chatbot-radius: 12px;
    --chatbot-radius-sm: 6px;
    --chatbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --chatbot-panel-width: 420px;
    --chatbot-panel-height: 560px;
    --chatbot-z: 9999;
    --chatbot-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    font-family: var(--chatbot-font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--chatbot-text);
    box-sizing: border-box;
}

/* ── Dark mode (only when not explicitly ignored) ────────────── */
@media (prefers-color-scheme: dark) {
    .bitzinger-chatbot:not(.bitzinger-chatbot--ignore-dark-mode) {
        --chatbot-bg: #1e293b;
        --chatbot-surface: #0f172a;
        --chatbot-border: #334155;
        --chatbot-text: #f1f5f9;
        --chatbot-text-muted: #94a3b8;
        --chatbot-bubble-bot: #334155;
        --chatbot-bubble-bot-text: #f1f5f9;
        --chatbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    }
}

/* Force light palette + native form controls when Dark Mode is ignored.
   Outside the media query so it always wins over cascade/order quirks. */
.bitzinger-chatbot.bitzinger-chatbot--ignore-dark-mode {
    color-scheme: only light;
    --chatbot-bg: #ffffff;
    --chatbot-surface: #f8fafc;
    --chatbot-border: #e2e8f0;
    --chatbot-text: #1e293b;
    --chatbot-text-muted: #64748b;
    --chatbot-bubble-bot: #f1f5f9;
    --chatbot-bubble-bot-text: #1e293b;
    --chatbot-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    color: #1e293b;
}

.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__panel,
.bitzinger-chatbot--ignore-dark-mode.bitzinger-chatbot--embedded {
    background: #ffffff;
    color: #1e293b;
}

.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__messages,
.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__typing {
    background: #f8fafc;
}

.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__form {
    background: #ffffff;
    border-top-color: #e2e8f0;
}

.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__input {
    background: #f8fafc;
    color: #1e293b;
    border-color: #e2e8f0;
    color-scheme: only light;
}

.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__message--bot .bitzinger-chatbot__bubble {
    background: #f1f5f9;
    color: #1e293b;
}

.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__hint,
.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__sources-label {
    color: #64748b;
}

.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__typing span {
    background: #64748b;
}

.bitzinger-chatbot *,
.bitzinger-chatbot *::before,
.bitzinger-chatbot *::after {
    box-sizing: inherit;
}

/* ── Floating action button ──────────────────────────────────── */
.bitzinger-chatbot--floating {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--chatbot-z);
}

.bitzinger-chatbot__fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    color: var(--chatbot-primary-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--chatbot-shadow);
    transition: background 0.2s, transform 0.2s;
}

.bitzinger-chatbot__fab:hover {
    background: var(--chatbot-primary-dark);
    transform: scale(1.05);
}

.bitzinger-chatbot__fab-icon {
    display: block;
    width: 42px;
    height: 42px;
    object-fit: contain;
    border-radius: 50%;
}

/* ── Floating panel ──────────────────────────────────────────── */
.bitzinger-chatbot__panel {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: var(--chatbot-panel-width);
    height: var(--chatbot-panel-height);
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;

    /* ADDED: Smooth transition for size and transforms */
    transition:
        opacity 0.2s ease,
        transform 0.5s ease,
        width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    /* Ensure the content inside doesn't "snap" during resize */
    will-change: width, height;
}

.bitzinger-chatbot__panel--open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Embedded mode ───────────────────────────────────────────── */
.bitzinger-chatbot--embedded {
    width: 100%;
    max-width: 640px;
    background: var(--chatbot-bg);
    border: 1px solid var(--chatbot-border);
    border-radius: var(--chatbot-radius);
    display: flex;
    flex-direction: column;
    height: var(--chatbot-panel-height);
    overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────── */
.bitzinger-chatbot__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--chatbot-primary);
    color: var(--chatbot-primary-text);
    flex-shrink: 0;
}

.bitzinger-chatbot__title {
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.bitzinger-chatbot__icon {
    display: block;
    width: 35px;
    height: 35px;
    flex: 0 0 35px;
    object-fit: contain;
    border-radius: 50%;
}

.bitzinger-chatbot__close {
    background: none;
    border: none;
    color: var(--chatbot-primary-text);
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.15s;
    display: flex;
}

.bitzinger-chatbot__close:hover {
    opacity: 1;
}

/* ── Suggested question pills (above input) ──────────────────── */
.bitzinger-chatbot__suggestions {
    flex-shrink: 0;
    padding: 0 0 10px;
    background: transparent;
}

.bitzinger-chatbot__suggestions[hidden] {
    display: none !important;
}

.bitzinger-chatbot__suggestions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bitzinger-chatbot__pill {
    display: inline-flex;
    align-items: center;
    max-width: 100%;
    padding: 6px 12px;
    border-radius: 999px;
    border: 1px solid var(--chatbot-primary);
    background: transparent;
    color: var(--chatbot-primary);
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bitzinger-chatbot__pill:hover,
.bitzinger-chatbot__pill:focus-visible {
    background: var(--chatbot-primary);
    color: var(--chatbot-primary-text);
    outline: none;
}

.bitzinger-chatbot__pill:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ── Messages area ───────────────────────────────────────────── */
.bitzinger-chatbot__messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--chatbot-surface);
    scroll-behavior: smooth;
}

/* ── Individual message ──────────────────────────────────────── */
.bitzinger-chatbot__message {
    display: flex;
    flex-direction: column;
    min-width: 0;
    max-width: 85%;
}

.bitzinger-chatbot__message--user {
    align-self: flex-end;
    align-items: flex-end;
}

.bitzinger-chatbot__message--bot {
    align-self: flex-start;
    align-items: flex-start;
}

.bitzinger-chatbot__bubble {
    padding: 10px 14px;
    border-radius: var(--chatbot-radius);
    word-break: break-word;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.bitzinger-chatbot__message--user .bitzinger-chatbot__bubble {
    background: var(--chatbot-bubble-user);
    color: var(--chatbot-bubble-user-text);
    border-bottom-right-radius: var(--chatbot-radius-sm);
}

.bitzinger-chatbot__message--bot .bitzinger-chatbot__bubble {
    background: var(--chatbot-bubble-bot);
    color: var(--chatbot-bubble-bot-text);
    border-bottom-left-radius: var(--chatbot-radius-sm);
}

.bitzinger-chatbot__error {
    color: #dc2626;
}

/* ── Sources ─────────────────────────────────────────────────── */
.bitzinger-chatbot__sources {
    margin-top: 8px;
    font-size: 12px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
}

.bitzinger-chatbot__sources-label {
    color: var(--chatbot-text-muted);
    margin: 0 0 4px 0;
    font-weight: 500;
}

.bitzinger-chatbot__sources-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.bitzinger-chatbot__sources-list > li {
    display: flex;
    align-items: baseline;
    min-width: 0;
    max-width: 100%;
    white-space: nowrap;
}

.bitzinger-chatbot__sources-list > li > span:first-child {
    flex: 0 0 auto;
}

.bitzinger-chatbot__sources-list > li[hidden] {
    display: none;
}

.bitzinger-chatbot__sources-toggle {
    appearance: none;
    display: inline-block;
    margin: 5px 0 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--chatbot-primary);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.5;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.bitzinger-chatbot__sources-toggle:hover {
    color: var(--chatbot-primary-dark);
}

.bitzinger-chatbot__sources-toggle:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

.bitzinger-chatbot__source-link {
    color: var(--chatbot-primary);
    text-decoration: none;
    font-size: 12px;
    display: inline-flex;
    align-items: baseline;
    gap: 3px;
    flex: 1 1 0;
    width: 0;
    min-width: 0;
    max-width: none;
    overflow: hidden;
    white-space: nowrap;
}

.bitzinger-chatbot__source-title {
    display: block;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.bitzinger-chatbot__source-link:hover {
    text-decoration: underline;
}

.bitzinger-chatbot__external-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    transform: translateY(-1px);
    transition: transform 0.15s ease;
}

.bitzinger-chatbot__source-link--external:hover .bitzinger-chatbot__external-icon {
    transform: translate(1px, -2px);
}

.bitzinger-chatbot__bubble pre {
    max-width: 100%;
    overflow-x: auto;
}

/* ── Typing indicator ────────────────────────────────────────── */
.bitzinger-chatbot__typing {
    display: none;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    background: var(--chatbot-surface);
    flex-shrink: 0;
}

.bitzinger-chatbot__typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chatbot-text-muted);
    display: inline-block;
    animation: chatbot-bounce 1.2s infinite ease-in-out;
}

.bitzinger-chatbot__typing span:nth-child(2) { animation-delay: 0.2s; }
.bitzinger-chatbot__typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* ── Input form ──────────────────────────────────────────────── */
.bitzinger-chatbot__form {
    padding: 12px;
    border-top: 1px solid var(--chatbot-border);
    background: var(--chatbot-bg);
    flex-shrink: 0;
}

.bitzinger-chatbot__input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.bitzinger-chatbot__input {
    flex: 1;
    resize: none;
    border: 1px solid var(--chatbot-border);
    border-radius: var(--chatbot-radius-sm);
    padding: 8px 12px;
    font-size: 14px;
    font-family: var(--chatbot-font);
    background: var(--chatbot-surface);
    color: var(--chatbot-text);
    outline: none;
    min-height: 38px !important;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.15s;
}

.bitzinger-chatbot__input:focus {
    border-color: var(--chatbot-primary);
}

.bitzinger-chatbot__send {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: var(--chatbot-radius-sm);
    background: var(--chatbot-primary);
    color: var(--chatbot-primary-text);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.bitzinger-chatbot__send:hover {
    background: var(--chatbot-primary-dark);
}

.bitzinger-chatbot__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.bitzinger-chatbot .bitzinger-chatbot__hint {
    font-size: 11px !important;
    color: var(--chatbot-text-muted);
    margin: 6px 0 0 0;
    text-align: center;
}

/* ── Accessibility: screen-reader only ───────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── Mobile: full width panel ────────────────────────────────── */
@media (max-width: 480px) {
    .bitzinger-chatbot--floating {
        bottom: 16px;
        right: 16px;
    }

    .bitzinger-chatbot__panel {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 85vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

.bitzinger-chatbot__bubble > :is(h2) {
    font-size: 1.2rem !important;
}
.bitzinger-chatbot__bubble > :is(h3, h4, h5) {
    font-size: 1.1rem !important;
}

/* Style for the expand button */
.bitzinger-chatbot__expand {
    background: none;
    border: none;
    color: var(--chatbot-primary-text);
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.15s, transform 0.2s;
    display: flex;
}

.bitzinger-chatbot__expand:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* ── The Expanded State ──────────────────────────────────────── */
.bitzinger-chatbot__panel--expanded {
    /* Use clamp to ensure it doesn't get bigger than the screen */
    width: clamp(var(--chatbot-panel-width), 800px, 90vw) !important;
    height: clamp(var(--chatbot-panel-height), 80vh, 90vh) !important;
}
.bitzinger-chatbot__expand svg {
    transition: transform 0.3s ease;
}
/* Optional: Rotate icon when expanded */
.bitzinger-chatbot__panel--expanded .bitzinger-chatbot__expand svg {
    transform: rotate(180deg);
}
.bitzinger-chatbot__panel--expanded .bitzinger-chatbot__expand svg {
    /* Flips the icon or shrinks it slightly to indicate "minimize" */
    transform: scale(0.8) rotate(180deg);
}

/* Ensure header buttons don't shrink */
.bitzinger-chatbot__header div {
    flex-shrink: 0;
}

.bitzinger-chatbot__mic {
    background: none;
    border: none;
    cursor: pointer;
    color: #6B7280;
    padding: 8px;
    display: flex;
    align-items: center;
    transition: color 0.2s;
}

.bitzinger-chatbot__mic:hover {
    color: #22C55E;
}

/* Visuelles Feedback wenn Aufnahme läuft */
.bitzinger-chatbot__mic--active {
    color: #EF4444 !important;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.bitzinger-chatbot__input-row {
    display: flex;
    align-items: flex-end; /* Sorgt dafür, dass Icons unten bündig sind */
}


.bitzinger-chatbot__reset {
    background: none;
    border: none;
    color: var(--chatbot-primary-text);
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: all 0.65s;
    display: flex;
}
.bitzinger-chatbot__reset:hover {
    opacity: 1;
    transform: rotate(360deg); /* Kleiner visueller Effekt */
}

.bitzinger-chatbot__info {
    background: none;
    border: none;
    color: var(--chatbot-primary-text);
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.15s, transform 0.2s, background 0.15s;
    display: flex;
    border-radius: 50%;
}
.bitzinger-chatbot__info:hover {
    opacity: 1;
    transform: scale(1.1);
}
.bitzinger-chatbot__info--active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

/* ── Info panel (RTE HTML, replaces messages + form while open) ─ */
.bitzinger-chatbot__info-panel {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px;
    background: var(--chatbot-surface);
    scroll-behavior: smooth;
}
.bitzinger-chatbot__info[hidden],
.bitzinger-chatbot__info-panel[hidden],
.bitzinger-chatbot__messages[hidden],
.bitzinger-chatbot__form[hidden],
.bitzinger-chatbot__reset[hidden] {
    display: none !important;
}
.bitzinger-chatbot__info-content {
    color: var(--chatbot-text);
    font-size: 14px;
    line-height: 1.55;
    max-width: 100%;
    white-space: normal;
    word-wrap: break-word;
}
.bitzinger-chatbot__info-content > :first-child {
    margin-top: 0;
}
.bitzinger-chatbot__info-content > :last-child {
    margin-bottom: 0;
}
.bitzinger-chatbot__info-content > :is(h2) {
    font-size: 1.2rem !important;
}
.bitzinger-chatbot__info-content > :is(h3, h4, h5) {
    font-size: 1.1rem !important;
}
.bitzinger-chatbot__info-content a {
    color: var(--chatbot-primary);
}
.bitzinger-chatbot__info-content ul,
.bitzinger-chatbot__info-content ol {
    padding-left: 1.25em;
    margin: 0.5em 0;
}
.bitzinger-chatbot__info-content p {
    margin: 0.5em 0;
}
.bitzinger-chatbot__info-content code {
    font-size: 0.9em;
    background: var(--chatbot-bubble-bot, #f1f5f9);
    padding: 0.1em 0.35em;
    border-radius: 4px;
}
.bitzinger-chatbot__info-content pre {
    overflow-x: auto;
    padding: 10px 12px;
    border-radius: var(--chatbot-radius-sm, 6px);
    background: var(--chatbot-bubble-bot, #f1f5f9);
    font-size: 12px;
}
.bitzinger-chatbot__info-content pre code {
    background: none;
    padding: 0;
}
.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__info-panel {
    background: #f8fafc;
}
.bitzinger-chatbot--ignore-dark-mode .bitzinger-chatbot__info-content {
    color: #1e293b;
}

/* ── Confirmation Buttons (Reset-Dialog) ────────────────────── */
.bitzinger-chatbot__btn-confirm,
.bitzinger-chatbot__btn-cancel {
    border: 1px solid var(--chatbot-border);
    background: var(--chatbot-bg);
    color: var(--chatbot-text);
    padding: 6px 16px;
    border-radius: var(--chatbot-radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--chatbot-font);
}

/* "Ja" - Primär-Stil */
.bitzinger-chatbot__btn-confirm {
    background: var(--chatbot-primary);
    color: var(--chatbot-primary-text);
    border-color: var(--chatbot-primary);
}

.bitzinger-chatbot__btn-confirm:hover {
    background: var(--chatbot-primary-dark);
    border-color: var(--chatbot-primary-dark);
}

/* "Nein" - Dezent / Secondary-Stil */
.bitzinger-chatbot__btn-cancel {
    background: var(--chatbot-surface);
    color: var(--chatbot-text-muted);
}

.bitzinger-chatbot__btn-cancel:hover {
    background: #fee2e2; /* Ganz zartes Rot für Abbruch */
    border-color: #fca5a5;
    color: #b91c1c;
}

/* Spezifisch für Dark Mode (falls benötigt) */
@media (prefers-color-scheme: dark) {
    .bitzinger-chatbot:not(.bitzinger-chatbot--ignore-dark-mode) .bitzinger-chatbot__btn-cancel:hover {
        background: #450a0a;
        border-color: #991b1b;
        color: #fca5a5;
    }
}


/* Schriftgröße im gesamten Chatbot auf 15px setzen */
.bitzinger-chatbot {
    font-size: 15px;
}

.bitzinger-chatbot p,
.bitzinger-chatbot .content p,
.bitzinger-chatbot__bubble p {
    font-size: 15px !important;
    line-height: 22.5px;
}

.bitzinger-chatbot .bitzinger-chatbot__sources-list li{
    font-size: 15px !important;
    line-height: 22.5px;
}
.bitzinger-chatbot .bitzinger-chatbot__bubble li{
    font-size: 15px !important;
    line-height: 22.5px;
}

/* ── Citations "[1]" in the answer: link to the source ───────── */
.bitzinger-chatbot__bubble a.bitzinger-chatbot__cite {
    color: var(--chatbot-primary);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    border-radius: 4px;
    transition: background-color 0.15s, color 0.15s;
}

.bitzinger-chatbot__bubble a.bitzinger-chatbot__cite:hover,
.bitzinger-chatbot__bubble a.bitzinger-chatbot__cite:focus-visible {
    background: var(--chatbot-primary);
    color: var(--chatbot-primary-text, #fff);
    text-decoration: none;
}
