/* ============================================================
   CHATBOT WIDGET — FULLY SCOPED STYLES
   ------------------------------------------------------------
   Every rule is namespaced with #chat-widget, so:
     • widget styles never leak out onto the page
     • page/theme styles are neutralised inside the widget
   ============================================================ */

/* ------------------------------------------------------------
   1. HARD RESET (widget subtree only)
   ------------------------------------------------------------ */
#chat-widget,
#chat-widget *,
#chat-widget *::before,
#chat-widget *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    border: 0;
    outline: 0;
    background: transparent;
    box-shadow: none;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, sans-serif;
    font-weight: 400;
    font-style: normal;
    line-height: 1.4;
    color: inherit;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    text-decoration: none;
    text-shadow: none;
    list-style: none;
    float: none;
    vertical-align: baseline;
}

/* Re-apply the base look on the wrapper itself (after the reset) */
#chat-widget {
    /* design tokens scoped to the widget */
    --primary-blue: #0066cc;
    --dark-blue: #003366;
    --light-bg: #f4f6f8;
    --bot-bubble: #eef2f6;
    --user-bubble: #0066cc;
    --text-dark: #333333;
    --text-light: #777777;

    position: relative;
    z-index: 2147483000;
    /* keeps the whole widget above the page */
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-dark);
}

/* Element-level safety inside the widget */
#chat-widget button {
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
    font: inherit;
    color: inherit;
}

#chat-widget input,
#chat-widget textarea {
    -webkit-appearance: none;
    appearance: none;
    font: inherit;
    color: inherit;
}

#chat-widget svg {
    display: block;
    flex-shrink: 0;
}

#chat-widget img {
    display: block;
    max-width: 100%;
    height: auto;
}

#chat-widget p {
    margin: 0;
}

#chat-widget ul,
#chat-widget ol {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ------------------------------------------------------------
   2. LAUNCHER BUTTON
   ------------------------------------------------------------ */
#chat-widget #chat-launcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--primary-blue);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background-color 0.2s;
    z-index: 9999;
}

#chat-widget #chat-launcher:hover {
    transform: scale(1.05);
    background-color: var(--dark-blue);
}

#chat-widget #chat-launcher svg {
    width: 24px;
    height: 24px;
    display: block;
    fill: #fff;
}

/* ------------------------------------------------------------
   3. CHAT WINDOW
   ------------------------------------------------------------ */
#chat-widget #chat-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 600px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9998;
    transition: opacity 0.3s, transform 0.3s;
}

#chat-widget #chat-window.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

/* ------------------------------------------------------------
   4. HEADER
   ------------------------------------------------------------ */
#chat-widget .chat-header {
    background-color: var(--dark-blue);
    color: #fff;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex: 0 0 auto;
}

#chat-widget .header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

#chat-widget .avatar {
    width: 36px;
    height: 36px;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#chat-widget .avatar svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

#chat-widget .header-text h4 {
    font-size: 15px;
    font-weight: 600;
    color: #eaeaea;
    line-height: 1.2;
    margin: 0;
}

#chat-widget .header-text span {
    display: block;
    font-size: 12px;
    opacity: 0.8;
    line-height: 1.2;
}

#chat-widget .header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#chat-widget .btn-outline {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.5);
    color: #fff;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

#chat-widget .btn-outline:hover {
    background: rgba(255, 255, 255, 0.1);
}

#chat-widget #close-chat {
    background: transparent;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    padding: 0;
}

#chat-widget #close-chat:hover {
    opacity: 1;
}

#chat-widget #close-chat svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ------------------------------------------------------------
   5. MESSAGES AREA
   ------------------------------------------------------------ */
#chat-widget .chat-messages {
    flex: 1 1 auto;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background-color: #fff;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

#chat-widget .message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

#chat-widget .message p {
    margin: 0;
    font-size: inherit;
    line-height: inherit;
}

#chat-widget .bot-message {
    background-color: var(--bot-bubble);
    color: var(--text-dark);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

#chat-widget .user-message {
    background-color: var(--user-bubble);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

#chat-widget .user-message p {
    color: #fff;
}

#chat-widget .timestamp {
    display: block;
    font-size: 10px;
    color: var(--text-light);
    margin-top: 4px;
}

#chat-widget .user-message .timestamp {
    color: rgba(255, 255, 255, 0.7);
    text-align: right;
}

/* ------------------------------------------------------------
   6. QUICK REPLIES
   ------------------------------------------------------------ */
#chat-widget .quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    align-self: flex-start;
    max-width: 100%;
}

#chat-widget .chip {
    background: #fff;
    border: 1px solid var(--primary-blue);
    color: var(--primary-blue);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
    transition: all 0.2s;
}

#chat-widget .chip:hover {
    background: var(--primary-blue);
    color: #fff;
}

/* ------------------------------------------------------------
   7. INPUT AREA
   ------------------------------------------------------------ */
#chat-widget .chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #eaeaea;
    display: flex;
    gap: 10px;
    align-items: center;
    background: #fff;
    flex: 0 0 auto;
}

#chat-widget #chat-input {
    flex: 1 1 auto;
    min-width: 0;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    line-height: 1.2;
    outline: none;
    background: var(--light-bg);
    color: var(--text-dark);
    box-shadow: none;
}

#chat-widget #chat-input::placeholder {
    color: #9aa3ab;
    opacity: 1;
}

#chat-widget #chat-input:focus {
    border-color: var(--primary-blue);
    background: #fff;
}

#chat-widget #send-btn {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 50%;
    background: var(--primary-blue);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    padding: 0;
}

#chat-widget #send-btn:hover {
    background: var(--dark-blue);
}

#chat-widget #send-btn svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

/* ------------------------------------------------------------
   8. FOOTER
   ------------------------------------------------------------ */
#chat-widget .chat-footer {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: #999;
    background: #fff;
    border-top: 1px solid #f0f0f0;
    flex: 0 0 auto;
}

#chat-widget .chat-footer strong {
    font-weight: 600;
}

/* ------------------------------------------------------------
   9. TYPING DOTS
   ------------------------------------------------------------ */
#chat-widget .typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 12px;
}

#chat-widget .typing-dots span {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    display: inline-block;
    animation: chatTypingBounce 1.2s infinite ease-in-out;
}

#chat-widget .typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

#chat-widget .typing-dots span:nth-child(3) {
    animation-delay: 0.30s;
}

@keyframes chatTypingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.5;
    }

    30% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* ------------------------------------------------------------
   10. UNREAD BADGE
   ------------------------------------------------------------ */
#chat-widget .chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: #dc3545;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.4);
    animation: chatUnreadPulse 1.8s infinite;
    pointer-events: none;
    z-index: 1;
}

@keyframes chatUnreadPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }

    100% {
        transform: scale(1);
    }
}

/* ------------------------------------------------------------
   11. MOBILE FULL-SCREEN MODE
   ------------------------------------------------------------ */
@media (max-width: 640px) {

    #chat-widget #chat-window {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        /* accounts for mobile URL bar */
        max-width: none;
        max-height: none;
        border-radius: 0;
        box-shadow: none;
    }

    #chat-widget #chat-window.hidden {
        transform: translateY(100%);
        /* slide down */
        opacity: 1;
        /* keep visible during slide */
    }

    #chat-widget .chat-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
        /* iOS notch */
    }

    #chat-widget .message {
        max-width: 88%;
        font-size: 15px;
    }

    #chat-widget .chip {
        padding: 10px 18px;
        font-size: 14px;
    }

    #chat-widget .chat-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        /* iOS home bar */
    }

    #chat-widget #chat-input {
        font-size: 16px;
        /* prevents iOS auto-zoom on focus */
    }

    #chat-widget #chat-launcher {
        bottom: max(20px, env(safe-area-inset-bottom));
        right: max(20px, env(safe-area-inset-right));
    }

    /* Hide the launcher while the full-screen chat is open */
    body.chatbot-open #chat-widget #chat-launcher {
        display: none;
    }
}