/* --- Premium Chatbot UI --- */

/* Chatbot Toggler Button */
.chatbot-toggler {
    position: fixed;
    bottom: 30px;
    right: 35px;
    outline: none;
    border: none;
    height: 50px;
    width: auto;
    padding: 0 20px;
    display: flex;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    border-radius: 50px;
    background: linear-gradient(135deg, var(--main-color), var(--accent-color));
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(14, 165, 233, 0.4);
    gap: 8px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(14, 165, 233, 0.7);
    }

    70% {
        box-shadow: 0 0 0 15px rgba(14, 165, 233, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(14, 165, 233, 0);
    }
}

.chatbot-toggler:hover {
    transform: scale(1.05);
    animation: none;
    /* Stop pulsing on hover */
    box-shadow: 0 15px 35px rgba(14, 165, 233, 0.6);
}

body.show-chatbot .chatbot-toggler {
    transform: rotate(0);
    background: var(--second-bg-color);
    width: 50px;
    height: 50px;
    padding: 0;
    border-radius: 50%;
    animation: none;
}

.chatbot-toggler span {
    color: var(--bg-color);
    font-size: 2.2rem;
    transition: all 0.3s ease;
}

/* Text Label Style */
.chatbot-toggler .chatbot-text {
    font-size: 1.6rem;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.5px;
}

/* Hide normal icons/text when open */
body.show-chatbot .chatbot-toggler span.material-symbols-outlined:first-child,
body.show-chatbot .chatbot-toggler .chatbot-text {
    display: none;
}

/* Logic for Close Icon */
.chatbot-toggler .close-icon {
    display: none;
}

body.show-chatbot .chatbot-toggler .close-icon {
    display: block;
    color: var(--main-color);
    font-size: 2.4rem;
}

/* Chatbot Container */
.chatbot {
    position: fixed;
    right: 35px;
    bottom: 100px;
    /* Adjusted to sit nicely above button */
    width: 400px;
    height: 600px;
    /* Fixed height for better layout */
    max-width: 90vw;
    max-height: 80vh;
    /* Prevent overflow on small screens */
    background: rgba(17, 25, 40, 0.85);
    /* Glassmorphism Base */
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9) translateY(20px);
    transform-origin: bottom right;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    transition: all 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    z-index: 1000;
    display: flex;
    flex-direction: column;
}

body.show-chatbot .chatbot {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1) translateY(0);
}

/* Chat Header */
.chatbot header {
    padding: 20px 0;
    position: relative;
    text-align: center;
    background: linear-gradient(135deg, var(--main-color), var(--accent-color));
    box-shadow: 0 4px 15px rgba(14, 165, 233, 0.2);
    flex-shrink: 0;
}

.chatbot header h2 {
    color: #fff;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.chatbot header .close-btn {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 2rem;
    display: none;
    /* Hidden on desktop by default as toggle btn handles it */
    transition: color 0.3s ease;
}

.chatbot header .close-btn:hover {
    color: #fff;
}

/* Chatbox Messages */
.chatbot .chatbox {
    overflow-y: auto;
    flex: 1;
    /* Take remaining space */
    padding: 25px 20px 20px;
    /* Reduced bottom padding */
    scroll-behavior: smooth;
    background: transparent;
}

/* Custom Scrollbar */
.chatbot .chatbox::-webkit-scrollbar {
    width: 5px;
}

.chatbot .chatbox::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot .chatbox::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

.chatbot .chatbox:hover::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages */
.chatbox .chat {
    display: flex;
    list-style: none;
    margin-bottom: 20px;
    opacity: 0;
    transform: translateY(10px);
    animation: fadeSlideIn 0.3s forwards;
}

@keyframes fadeSlideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbox .outgoing {
    justify-content: flex-end;
}

.chatbox .incoming {
    justify-content: flex-start;
}

/* Avatar Icon */
.chatbox .incoming span {
    width: 35px;
    height: 35px;
    color: #fff;
    cursor: default;
    text-align: center;
    line-height: 35px;
    align-self: flex-end;
    background: linear-gradient(135deg, var(--main-color), var(--accent-color));
    border-radius: 50%;
    margin: 0 10px 7px 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
    font-size: 1.8rem;
}

/* Message Bubbles */
.chatbox .chat p {
    white-space: pre-wrap;
    padding: 14px 18px;
    border-radius: 15px 15px 0 15px;
    max-width: 80%;
    font-size: 1.45rem;
    line-height: 1.5;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.chatbox .outgoing p {
    background: linear-gradient(135deg, var(--main-color), var(--accent-color));
    color: #fff;
    border-radius: 15px 15px 0 15px;
}

.chatbox .incoming p {
    background: rgba(255, 255, 255, 0.08);
    /* Transparent Light */
    color: var(--text-color);
    border-radius: 15px 15px 15px 0;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.chatbox .chat p.error {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.2);
}

/* Typing Animation Dots */
.chatbox .incoming p.thinking {
    display: flex;
    gap: 6px;
    align-items: center;
    padding: 18px 20px;
    background: rgba(255, 255, 255, 0.05);
}

.chatbox .incoming p.thinking .dot {
    height: 8px;
    width: 8px;
    background: var(--main-color);
    border-radius: 50%;
    opacity: 0.6;
    animation: typing 1.4s infinite ease-in-out;
}

.chatbox .incoming p.thinking .dot:nth-child(1) {
    animation-delay: 0s;
}

.chatbox .incoming p.thinking .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbox .incoming p.thinking .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {

    0%,
    100% {
        transform: translateY(0);
        opacity: 0.6;
    }

    50% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* Chatbot Footer Wrapper */
.chatbot-footer {
    background: rgba(17, 25, 40, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

/* Chat Input Area */
.chatbot .chat-input {
    display: flex;
    gap: 10px;
    width: 100%;
    padding: 15px 20px;
    /* Remove absolute positioning */
    position: relative;
    bottom: auto;
    background: transparent;
    /* Inherit from footer */
    border-top: none;
    /* Moved border to footer */
}

.chat-input textarea {
    height: 55px;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    outline: none;
    resize: none;
    max-height: 180px;
    padding: 16px 15px;
    font-size: 1.5rem;
    color: var(--text-color);
    transition: all 0.3s ease;
}

/* Custom Scrollbar for Textarea */
.chat-input textarea::-webkit-scrollbar {
    width: 4px;
}

.chat-input textarea::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input textarea::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.chat-input textarea:focus {
    border-color: var(--main-color);
    background: rgba(0, 0, 0, 0.3);
}

.chat-input span {
    align-self: flex-end;
    color: var(--main-color);
    background: rgba(14, 165, 233, 0.1);
    border-radius: 50%;
    height: 50px;
    width: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    visibility: hidden;
    font-size: 2.2rem;
    transition: all 0.3s ease;
    opacity: 0;
    transform: scale(0.8);
}

.chat-input textarea:valid~span {
    visibility: visible;
    opacity: 1;
    transform: scale(1);
}

.chat-input span:hover {
    background: var(--main-color);
    color: #fff;
    box-shadow: 0 0 15px rgba(14, 165, 233, 0.5);
}

/* Mobile Responsiveness */
@media (max-width: 550px) {
    .chatbot-toggler {
        right: 20px;
        bottom: 20px;
        height: 50px;
        width: 50px;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
        display: flex;
        /* Visible when closed */
        z-index: 10000;
    }

    /* Hide the floating toggler when chat is OPEN on mobile, 
       to prevent it from overlaying the send button. 
       Users will use the internal header close button. */
    body.show-chatbot .chatbot-toggler {
        display: none !important;
    }

    .chatbot-toggler .chatbot-text {
        display: none;
    }

    .chatbot-toggler span {
        margin: 0;
    }

    .chatbot {
        right: 0;
        bottom: 0;
        height: 100%;
        width: 100%;
        max-width: 100%;
        border-radius: 0;
        transform: scale(1) translateY(100%);
        /* Start hidden down */
    }

    body.show-chatbot .chatbot {
        transform: scale(1) translateY(0);
    }

    .chatbot .chatbox {
        height: calc(100% - 130px);
        /* Adjust based on header + input */
        padding: 25px 15px 100px;
    }

    .chatbot header {
        padding: 15px 0;
        /* Ensure header stays at top */
    }

    /* Important: Make sure close icon is visible and touchable */
    .chatbot header .close-btn {
        display: block;
        font-size: 2.5rem;
        padding: 10px;
        /* larger touch area */
        right: 15px;
    }
}

/* Chat Suggestions */
.chat-suggestions {
    display: flex;
    gap: 10px;
    padding: 10px 15px 5px;
    /* Add padding */
    overflow-x: auto;
    white-space: nowrap;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    /* Separator line */
    background: transparent;
    /* Inherit from footer */
}

/* Hide scrollbar for suggestions */
.chat-suggestions::-webkit-scrollbar {
    height: 4px;
}

.chat-suggestions::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.suggestion-chip {
    padding: 8px 15px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-color);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 1px solid transparent;
    user-select: none;
}

/* Silver Border */
.suggestion-chip.silver {
    border-color: #C0C0C0;
    box-shadow: 0 0 5px rgba(192, 192, 192, 0.2);
}

/* Golden Border */
.suggestion-chip.gold {
    border-color: #FFD700;
    box-shadow: 0 0 5px rgba(255, 215, 0, 0.2);
}

.suggestion-chip:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.suggestion-chip.silver:hover {
    box-shadow: 0 0 10px rgba(192, 192, 192, 0.4);
}

.suggestion-chip.gold:hover {
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}