/**
 * AI Chatbot Widget Styles
 *
 * Responsive CSS for the chatbot floating widget.
 * Customizable colors via CSS variables.
 */

/* ===========================
   ROOT VARIABLES
   =========================== */

:root {
    --ai-chatbot-primary-color: #007BFF;
    --ai-chatbot-secondary-color: #FFFFFF;
    --ai-chatbot-text-color: #333333;
    --ai-chatbot-border-color: #E0E0E0;
    --ai-chatbot-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
    --ai-chatbot-border-radius: 12px;
}

/* ===========================
   MAIN CONTAINER
   =========================== */

#ai-chatbot-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 380px;
    height: 600px;
    background-color: #FFFFFF;
    border-radius: var(--ai-chatbot-border-radius);
    box-shadow: var(--ai-chatbot-shadow);
    display: flex;
    flex-direction: column;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
                 "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: #333333;
    overflow: hidden;
    transition: all 0.3s ease;
    box-sizing: border-box;
}

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

/* ===========================
   CLOSED STATE (bubble)
   =========================== */

#ai-chatbot-widget.ai-chatbot-closed {
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--ai-chatbot-primary-color), color-mix(in srgb, var(--ai-chatbot-primary-color) 75%, #000));
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--ai-chatbot-primary-color) 35%, transparent);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    border: 1px solid rgba(255, 255, 255, 0.15);
    position: fixed; /* Ensures containment bounds */
}

#ai-chatbot-widget.ai-chatbot-closed::after {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border-radius: 50%;
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--ai-chatbot-primary-color) 60%, transparent);
    animation: ai-pulse 2.2s infinite cubic-bezier(0.24, 0, 0.38, 1);
    z-index: -1;
    pointer-events: none;
}

#ai-chatbot-widget.ai-chatbot-closed:hover {
    transform: translateY(-5px) scale(1.06);
    box-shadow: 0 12px 30px color-mix(in srgb, var(--ai-chatbot-primary-color) 50%, transparent);
}

@keyframes ai-pulse {
    0% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--ai-chatbot-primary-color) 70%, transparent);
        opacity: 1;
    }
    70% {
        box-shadow: 0 0 0 16px color-mix(in srgb, var(--ai-chatbot-primary-color) 0%, transparent);
        opacity: 0;
    }
    100% {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--ai-chatbot-primary-color) 0%, transparent);
        opacity: 0;
    }
}

/* Specialized override when using raw full-color SVGs like premium_robot */
#ai-chatbot-widget.ai-chatbot-closed.ai-chatbot-icon-raw {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible !important;
}

#ai-chatbot-widget.ai-chatbot-closed.ai-chatbot-icon-raw::after {
    display: none !important;
}

#ai-chatbot-widget.ai-chatbot-closed.ai-chatbot-icon-raw .ai-chatbot-header {
    padding: 0 !important;
    width: 60px !important;
    height: 60px !important;
    background: transparent !important;
    border: none !important;
}

#ai-chatbot-widget.ai-chatbot-closed.ai-chatbot-icon-raw .ai-chatbot-toggle {
    width: 60px !important;
    height: 60px !important;
    background: transparent !important;
    border: none !important;
}

#ai-chatbot-widget.ai-chatbot-closed.ai-chatbot-icon-raw .ai-chatbot-toggle svg {
    width: 60px !important;
    height: 60px !important;
    filter: drop-shadow(0 6px 12px rgba(123, 31, 162, 0.35));
}

#ai-chatbot-widget.ai-chatbot-closed .ai-chatbot-messages-container,
#ai-chatbot-widget.ai-chatbot-closed .ai-chatbot-input-area {
    display: none;
}

#ai-chatbot-widget.ai-chatbot-closed .ai-chatbot-header {
    border-radius: 50%;
    padding: 8px;
    background: transparent;
    justify-content: center;
}

#ai-chatbot-widget.ai-chatbot-closed .ai-chatbot-title {
    display: none;
}

#ai-chatbot-widget.ai-chatbot-closed .ai-chatbot-toggle {
    font-size: 28px;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: transform 0.4s ease;
}

#ai-chatbot-widget.ai-chatbot-closed:hover .ai-chatbot-toggle {
    transform: scale(1.08) rotate(8deg);
}

.ai-chatbot-toggle svg {
    display: block;
    margin: 0 auto;
    pointer-events: none;
    transition: transform 0.3s ease;
}

/* ===========================
   HEADER
   =========================== */

.ai-chatbot-header {
    background: linear-gradient(135deg, var(--ai-chatbot-primary-color), var(--ai-chatbot-primary-color));
    color: #FFFFFF;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: var(--ai-chatbot-border-radius) var(--ai-chatbot-border-radius) 0 0;
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
}

.ai-chatbot-header:hover {
    opacity: 0.95;
}

.ai-chatbot-title {
    font-size: 16px;
    font-weight: 600;
    color: #FFFFFF;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chatbot-title::before {
    content: "💬";
    font-size: 18px;
}

.ai-chatbot-toggle {
    background: none;
    border: none;
    color: #FFFFFF;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    line-height: 1;
}

.ai-chatbot-toggle:hover {
    transform: scale(1.1);
}

.ai-chatbot-new-chat-btn {
    background: none;
    border: none;
    color: #FFFFFF;
    font-size: 16px;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
    line-height: 1;
}

.ai-chatbot-new-chat-btn:hover {
    transform: rotate(45deg) scale(1.1);
}

/* Hide reset button when widget is collapsed */
#ai-chatbot-widget.ai-chatbot-closed .ai-chatbot-new-chat-btn {
    display: none !important;
}

/* ===========================
   MESSAGES CONTAINER
   =========================== */

.ai-chatbot-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: #F5F5F5;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-chatbot-messages-container::-webkit-scrollbar {
    width: 6px;
}

.ai-chatbot-messages-container::-webkit-scrollbar-track {
    background: #F5F5F5;
}

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

.ai-chatbot-messages-container::-webkit-scrollbar-thumb:hover {
    background: #999999;
}

/* ===========================
   MESSAGE STYLES
   =========================== */

.ai-chatbot-message {
    display: flex;
    animation: ai-chatbot-slide-up 0.3s ease;
    gap: 8px;
}

@keyframes ai-chatbot-slide-up {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- User Message --- */
.ai-chatbot-message.user {
    justify-content: flex-end;
}

.ai-chatbot-message.user .ai-chatbot-message-bubble {
    background-color: var(--ai-chatbot-primary-color);
    color: #FFFFFF;
    margin-left: 40px;
    margin-right: 0;
}

/* --- Bot Message --- */
.ai-chatbot-message.bot {
    justify-content: flex-start;
}

.ai-chatbot-message.bot .ai-chatbot-message-bubble {
    background-color: #FFFFFF;
    color: #333333;
    border: 1px solid var(--ai-chatbot-border-color);
    margin-right: 40px;
    margin-left: 0;
}

/* --- Message Bubble --- */
.ai-chatbot-message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    white-space: pre-wrap;
    word-wrap: break-word;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.5;
    max-width: 85%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* Welcome Message */
.ai-chatbot-message.welcome .ai-chatbot-message-bubble {
    background-color: #E8F4F8;
    border: 1px solid #B8E0E8;
    color: #333333;
}

/* Error Message */
.ai-chatbot-message.error .ai-chatbot-message-bubble {
    background-color: #FFE8E8;
    border: 1px solid #FFB8B8;
    color: #B80000;
}

/* ===========================
   TYPING INDICATOR
   =========================== */

.ai-chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background-color: #FFFFFF;
    border: 1px solid var(--ai-chatbot-border-color);
    border-radius: 18px;
    width: fit-content;
    margin-right: 40px;
}

.ai-chatbot-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--ai-chatbot-primary-color);
    animation: ai-chatbot-typing 1.4s infinite;
}

.ai-chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes ai-chatbot-typing {
    0%, 60%, 100% {
        opacity: 0.5;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-8px);
    }
}

/* ===========================
   INPUT AREA
   =========================== */

.ai-chatbot-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    background-color: #FFFFFF;
    border-top: 1px solid var(--ai-chatbot-border-color);
    flex-shrink: 0;
    border-radius: 0 0 var(--ai-chatbot-border-radius) var(--ai-chatbot-border-radius);
    align-items: flex-end;
}

/* --- Input Field --- */
.ai-chatbot-input-field {
    flex: 1;
    border: 1px solid var(--ai-chatbot-border-color);
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    line-height: 1.5;

    /* Explicit colours so theme CSS cannot override */
    background-color: #F9F9F9;
    color: #333333;
    -webkit-text-fill-color: #333333; /* Safari override */
    cursor: text !important;
    caret-color: #333333 !important;
}

.ai-chatbot-input-field:focus {
    border-color: var(--ai-chatbot-primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.12);
    background-color: #FFFFFF;
}

.ai-chatbot-input-field::placeholder {
    color: #999999;
    opacity: 1; /* Firefox fix */
}

/* --- Send Button --- */
.ai-chatbot-send-btn {
    background-color: var(--ai-chatbot-primary-color);
    color: #FFFFFF;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    line-height: 1;
}

.ai-chatbot-send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 2px 10px rgba(0, 123, 255, 0.35);
}

.ai-chatbot-send-btn:active:not(:disabled) {
    transform: scale(0.96);
}

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

.ai-chatbot-send-btn::before {
    content: "➤";
}

/* ===========================
   POSITION VARIATIONS
   =========================== */

/* Bottom Right (default) */
#ai-chatbot-widget.ai-chatbot-bottom-right {
    bottom: 20px;
    right: 20px;
    left: auto;
    top: auto;
}

/* Bottom Left */
#ai-chatbot-widget.ai-chatbot-bottom-left {
    bottom: 20px;
    left: 20px;
    right: auto;
    top: auto;
}

/* Bottom Left – swap message alignment */
#ai-chatbot-widget.ai-chatbot-bottom-left .ai-chatbot-message.user {
    justify-content: flex-end;
}

#ai-chatbot-widget.ai-chatbot-bottom-left .ai-chatbot-message.bot {
    justify-content: flex-start;
}

/* Top Right */
#ai-chatbot-widget.ai-chatbot-top-right {
    bottom: auto;
    top: 20px;
    right: 20px;
    left: auto;
}

/* Top Left */
#ai-chatbot-widget.ai-chatbot-top-left {
    bottom: auto;
    top: 20px;
    left: 20px;
    right: auto;
}

/* ===========================
   MOBILE RESPONSIVE
   =========================== */

@media (max-width: 480px) {
    #ai-chatbot-widget:not(.ai-chatbot-closed) {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        bottom: 80px;
        right: 12px;
        left: 12px;
        border-radius: 12px;
    }

    #ai-chatbot-widget.ai-chatbot-bottom-left:not(.ai-chatbot-closed) {
        right: 12px;
        left: 12px;
    }

    .ai-chatbot-message-bubble {
        max-width: 92%;
        font-size: 13px;
    }
}

/* ===========================
   DARK MODE SUPPORT
   =========================== */

@media (prefers-color-scheme: dark) {
    #ai-chatbot-widget:not(.ai-chatbot-closed) {
        background-color: #1e1e2e;
    }

    .ai-chatbot-messages-container {
        background-color: #13131f;
    }

    .ai-chatbot-message.bot .ai-chatbot-message-bubble {
        background-color: #2a2a3e;
        color: #E8E8F0;
        border-color: #3a3a50;
    }

    .ai-chatbot-message.welcome .ai-chatbot-message-bubble {
        background-color: #1a2a3a;
        border-color: #2a4a5a;
        color: #E8E8F0;
    }

    .ai-chatbot-input-area {
        background-color: #1e1e2e;
        border-top-color: #3a3a50;
    }

    .ai-chatbot-input-field {
        background-color: #2a2a3e;
        color: #E8E8F0;
        -webkit-text-fill-color: #E8E8F0;
        border-color: #3a3a50;
        caret-color: #E8E8F0 !important;
    }

    .ai-chatbot-input-field:focus {
        background-color: #30304a;
    }

    .ai-chatbot-input-field::placeholder {
        color: #7070a0;
    }
}

/* ===========================
   ACCESSIBILITY
   =========================== */

.ai-chatbot-toggle:focus-visible,
.ai-chatbot-send-btn:focus-visible,
.ai-chatbot-input-field:focus-visible {
    outline: 2px solid var(--ai-chatbot-primary-color);
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: more) {
    .ai-chatbot-message-bubble {
        border-width: 2px;
    }

    .ai-chatbot-input-field,
    .ai-chatbot-send-btn {
        border-width: 2px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .ai-chatbot-message {
        animation: none;
    }

    .ai-chatbot-toggle:hover,
    .ai-chatbot-send-btn:hover:not(:disabled) {
        transform: none;
    }

    .ai-chatbot-typing-dot {
        animation: none;
        opacity: 0.5;
    }

    #ai-chatbot-widget {
        transition: none;
    }
}

/* ===========================
   UTILITIES
   =========================== */

.ai-chatbot-hidden {
    display: none !important;
}

.ai-chatbot-loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Print – hide chatbot completely */
@media print {
    #ai-chatbot-widget {
        display: none !important;
    }
}

/* ===========================
   MARKDOWN MESSAGE STYLES
   =========================== */

.ai-chatbot-message-bubble strong {
    font-weight: 700;
}

.ai-chatbot-message-bubble em {
    font-style: italic;
}

.ai-chatbot-message-bubble a {
    color: inherit;
    text-decoration: underline;
    font-weight: 600;
}

.ai-chatbot-message-bubble a:hover {
    opacity: 0.8;
}

.ai-chatbot-bullet-list {
    margin: 8px 0;
    padding-left: 18px;
    list-style-type: disc;
}

.ai-chatbot-bullet-item {
    margin-bottom: 4px;
    line-height: 1.4;
}
