/* ============================================================
   Universal Chatbot Widget — Classic / Professional Red Theme
   Brand red #d62828 paired with clean neutral grays & white cards.
   ============================================================ */

#chatbot-widget {
    /* ---- Theme tokens (single source of truth) ---- */
    --cb-primary: #d62828;
    --cb-primary-dark: #a4161a;
    --cb-primary-darker: #7a0f12;
    --cb-gradient: linear-gradient(135deg, #d62828 0%, #a4161a 100%);
    --cb-gradient-hover: linear-gradient(135deg, #c11f1f 0%, #8f1316 100%);
    --cb-shadow: rgba(164, 22, 26, 0.22);

    /* Clean neutral surface palette (no pink tint) */
    --cb-bg: #ffffff;
    --cb-bg-soft: #f4f5f7;
    --cb-bot-bubble: #ffffff;
    --cb-text: #1f2733;
    --cb-muted: #6b7280;
    --cb-border: #e6e8ec;
    --cb-border-soft: #eef0f3;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

#chatbot-widget *,
#chatbot-widget *::before,
#chatbot-widget *::after {
    box-sizing: border-box;
}

/* ---- Toggle button ---- */
#chatbot-toggle {
    position: relative;
    background: var(--cb-gradient);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    padding: 0;
    cursor: pointer;
    box-shadow: 0 8px 24px var(--cb-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

#chatbot-toggle svg {
    width: 28px;
    height: 28px;
}

#chatbot-toggle:hover {
    box-shadow: 0 12px 30px var(--cb-shadow);
    transform: translateY(-2px) scale(1.05);
}

#chatbot-toggle:active {
    transform: scale(0.97);
}

#chatbot-toggle .pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(214, 40, 40, 0.45);
    animation: cb-pulse 2.2s ease-out infinite;
    pointer-events: none;
}

/* ---- Chat window ---- */
#chatbot-window {
    display: none;
    position: absolute;
    bottom: 78px;
    right: 0;
    width: 372px;
    max-width: calc(100vw - 32px);
    max-height: min(600px, calc(100vh - 120px));
    background: var(--cb-bg);
    border-radius: 16px;
    box-shadow: 0 18px 50px rgba(17, 24, 39, 0.18),
        0 2px 8px rgba(17, 24, 39, 0.08);
    overflow: hidden;
    flex-direction: column;
    border: 1px solid var(--cb-border);
    animation: chatbot-pop 0.26s ease;
}

/* ---- Header ---- */
#chatbot-header {
    background: var(--cb-gradient);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex: 0 0 auto;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.06);
}

#chatbot-header .cb-header-info {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

#chatbot-header .cb-avatar {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

#chatbot-header .cb-avatar svg {
    width: 20px;
    height: 20px;
}

#chatbot-header .cb-titles {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

#chatbot-header .cb-title {
    font-weight: 600;
    font-size: 15.5px;
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#chatbot-header .cb-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 400;
    opacity: 0.92;
    margin-top: 1px;
}

#chatbot-header .cb-status::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

#chatbot-header .close-btn {
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.14);
    border: none;
    color: #fff;
    font-size: 16px;
    line-height: 1;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.92;
    transition: opacity 0.2s, background 0.2s;
}

#chatbot-header .close-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.26);
}

/* ---- Messages ---- */
#chatbot-messages {
    padding: 16px 14px;
    flex: 1 1 auto;
    height: 340px;
    overflow-y: auto;
    background: var(--cb-bg-soft);
    font-size: 14.5px;
    line-height: 1.5;
    color: var(--cb-text);
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

#chatbot-messages::-webkit-scrollbar {
    width: 7px;
}

#chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(31, 39, 51, 0.16);
    border-radius: 4px;
}

#chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(31, 39, 51, 0.28);
}

.chatbot-msg {
    max-width: 84%;
    padding: 10px 14px;
    border-radius: 14px 14px 14px 4px;
    background: var(--cb-bot-bubble);
    color: var(--cb-text);
    align-self: flex-start;
    border: 1px solid var(--cb-border-soft);
    box-shadow: 0 1px 2px rgba(17, 24, 39, 0.05);
    word-break: break-word;
    line-height: 1.5;
}

.chatbot-msg strong {
    font-weight: 600;
    color: var(--cb-primary-dark);
}

.chatbot-msg.user {
    background: var(--cb-gradient);
    color: #fff;
    align-self: flex-end;
    border: none;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 2px 6px var(--cb-shadow);
}

.chatbot-msg.user strong {
    color: rgba(255, 255, 255, 0.92);
}

.chatbot-msg a {
    color: var(--cb-primary);
    font-weight: 500;
}

.chatbot-msg.user a {
    color: #fff;
    text-decoration: underline;
}

/* Container that holds predefined-question / link buttons */
.chatbot-extra {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.chatbot-extra:empty {
    display: none;
}

/* ---- Input area ---- */
#chatbot-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--cb-border);
    background: var(--cb-bg);
    padding: 12px;
    flex: 0 0 auto;
}

#chatbot-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 1px solid var(--cb-border);
    padding: 11px 16px;
    font-size: 14.5px;
    font-family: inherit;
    border-radius: 22px;
    outline: none;
    background: var(--cb-bg-soft);
    color: var(--cb-text);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

#chatbot-input::placeholder {
    color: var(--cb-muted);
}

#chatbot-input:focus {
    border-color: var(--cb-primary);
    box-shadow: 0 0 0 3px rgba(214, 40, 40, 0.12);
    background: #fff;
}

/* Send + Mic share one circular look */
#chatbot-send,
#micBtn {
    flex: 0 0 auto;
    background: var(--cb-gradient);
    color: #fff;
    border: none;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px var(--cb-shadow);
    transition: transform 0.15s ease, background 0.2s ease, box-shadow 0.2s ease;
}

#chatbot-send:hover,
#micBtn:hover {
    background: var(--cb-gradient-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px var(--cb-shadow);
}

#chatbot-send:active,
#micBtn:active {
    transform: scale(0.95);
}

/* ============================================================
   Animations
   ============================================================ */
@keyframes chatbot-pop {
    0% {
        transform: scale(0.9) translateY(8px);
        opacity: 0;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes cb-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(214, 40, 40, 0.45);
    }
    70% {
        box-shadow: 0 0 0 14px rgba(214, 40, 40, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(214, 40, 40, 0);
    }
}

@media (prefers-reduced-motion: reduce) {
    #chatbot-window,
    #chatbot-toggle .pulse {
        animation: none;
    }
}

/* ============================================================
   Responsive
   ============================================================ */

/* Tablet / small desktop: keep it anchored but never overflow */
@media (max-width: 768px) {
    #chatbot-widget {
        bottom: 18px;
        right: 18px;
    }

    #chatbot-window {
        width: calc(100vw - 28px);
        right: 0;
        max-height: min(72vh, calc(100vh - 110px));
    }
}

/* Phones: full-screen sheet */
@media (max-width: 480px) {
    #chatbot-widget {
        bottom: 16px;
        right: 16px;
    }

    #chatbot-toggle {
        width: 58px;
        height: 58px;
    }

    #chatbot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-width: none;
        max-height: none;
        border: none;
        border-radius: 0;
    }

    #chatbot-messages {
        height: auto;
        flex: 1 1 auto;
        font-size: 15px;
    }

    /* Respect notches / home indicator */
    #chatbot-header {
        padding-top: calc(14px + env(safe-area-inset-top));
    }

    #chatbot-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
}
