.chatbot-widget-closed #chatbot-panel {
    transform: translateY(100%);
    opacity: 0;
    pointer-events: none;
}

#chatbot-widget {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 9999;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#chatbot-widget.expanded {
    bottom: 0;
    right: 0;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
}

#chatbot-widget.expanded .chatbot-toggle-button {
    display: none;
}

.chatbot-toggle-button {
    width: 52px;
    height: 52px;
    border-radius: 999px;
    background: #1f2937;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 25px rgba(15, 23, 42, 0.4);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.chatbot-toggle-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 35px rgba(15, 23, 42, 0.5);
    background: #111827;
}

.chatbot-panel {
    position: absolute;
    bottom: 64px;
    right: 0;
    width: 340px;
    max-height: 480px;
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.45);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(0);
    opacity: 1;
    transition: transform 0.28s ease, opacity 0.28s ease, width 0.3s ease, height 0.3s ease, max-height 0.3s ease;
    touch-action: pan-y;
    /* Allow vertical scrolling */
}

/* Expanded state - full page size */
.chatbot-panel.expanded {
    position: fixed;
    width: calc(100vw - 32px);
    max-width: 900px;
    max-height: calc(100vh - 32px);
    height: calc(100vh - 32px);
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    right: auto;
    bottom: auto;
    z-index: 10000;
}

@media (max-width: 900px) {
    .chatbot-panel.expanded {
        left: 50%;
        right: auto;
        width: calc(100vw - 32px);
        transform: translate(-50%, -50%);
    }
}

.chatbot-header {
    padding: 10px 14px;
    background: linear-gradient(to right, #111827, #1f2937);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chatbot-panel.expanded .chatbot-header {
    padding: 14px 18px;
}

.chatbot-title {
    font-weight: 600;
    font-size: 14px;
}

.chatbot-close {
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 18px;
    cursor: pointer;
}

.chatbot-messages {
    padding: 10px;
    overflow-y: auto;
    flex: 1;
    background: #f3f4f6;
    -webkit-overflow-scrolling: touch;
    /* Smooth scrolling on iOS */
    overscroll-behavior: contain;
    /* Prevent scroll chaining */
}

.chatbot-panel.expanded .chatbot-messages {
    padding: 16px;
}

.chatbot-message {
    max-width: 90%;
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.chatbot-panel.expanded .chatbot-message {
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14px;
    margin-bottom: 12px;
    line-height: 1.6;
}

.chatbot-message.user {
    margin-left: auto;
    background: #2563eb;
    color: white;
    border-bottom-right-radius: 4px;
}

.chatbot-message.bot {
    margin-right: auto;
    background: #ffffff;
    color: #111827;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.chatbot-message.bot a,
.chatbot-message.bot .chatbot-link {
    color: #2563eb;
    text-decoration: underline;
    word-break: break-word;
    overflow-wrap: break-word;
    display: inline-block;
    max-width: 100%;
    hyphens: auto;
    cursor: pointer;
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.4);
    touch-action: manipulation;
    min-height: 44px;
    padding: 4px 0;
    line-height: 1.6;
    pointer-events: auto !important;
    user-select: none;
    -webkit-user-select: none;
    position: relative;
    z-index: 10;
}

.chatbot-message.bot a:hover,
.chatbot-message.bot .chatbot-link:hover,
.chatbot-message.bot a:active,
.chatbot-message.bot .chatbot-link:active {
    color: #1d4ed8;
    text-decoration: underline;
}

.chatbot-option-header {
    display: block;
    font-weight: 600;
    color: #111827;
    margin-top: 12px;
    margin-bottom: 4px;
    font-size: 14px;
}

.chatbot-product-label {
    font-weight: 600;
    color: #374151;
    display: inline-block;
    min-width: 60px;
}

/* Better link wrapping on mobile */
@media (max-width: 640px) {

    .chatbot-message.bot a,
    .chatbot-message.bot .chatbot-link {
        word-break: break-word;
        overflow-wrap: anywhere;
        display: inline-block;
        max-width: 100%;
        min-height: 44px;
        padding: 6px 0;
        -webkit-tap-highlight-color: rgba(37, 99, 235, 0.5);
        touch-action: manipulation;
        pointer-events: auto !important;
        z-index: 10;
    }

    .chatbot-option-header {
        font-size: 15px;
        margin-top: 16px;
    }

    .chatbot-product-label {
        min-width: 70px;
        font-size: 14px;
    }
}

.chatbot-input-area {
    padding: 8px;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    border-top: 1px solid #e5e7eb;
    background: #ffffff;
}

.chatbot-panel.expanded .chatbot-input-area {
    padding: 12px 16px;
    gap: 8px;
}

.chatbot-input-area textarea {
    flex: 1;
    resize: none;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    padding: 6px 10px;
    font-size: 13px;
    max-height: 80px;
    -webkit-appearance: none;
    /* Remove iOS styling */
    appearance: none;
}

.chatbot-send {
    border-radius: 999px;
    border: none;
    background: #2563eb;
    color: white;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
}

.chatbot-loading-dots {
    display: inline-flex;
    gap: 3px;
}

.chatbot-loading-dots span {
    width: 4px;
    height: 4px;
    border-radius: 999px;
    background: #9ca3af;
    animation: chatbot-bounce 1s infinite ease-in-out;
}

.chatbot-loading-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-loading-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatbot-bounce {

    0%,
    80%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    40% {
        transform: translateY(-3px);
        opacity: 1;
    }
}

@media (max-width: 640px) {
    #chatbot-widget {
        bottom: 12px;
        right: 12px;
        left: auto;
    }

    .chatbot-panel {
        width: calc(100vw - 24px);
        right: 0;
        left: 0;
        max-height: 70vh;
        bottom: 64px;
    }

    .chatbot-panel.expanded {
        position: fixed;
        width: 100vw;
        max-width: 100%;
        max-height: 100vh;
        height: 100vh;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        transform: none;
        border-radius: 0;
        box-shadow: none;
        touch-action: pan-y;
    }

    #chatbot-widget.expanded {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
    }

    .chatbot-toggle-button {
        width: 52px;
        height: 52px;
    }

    .chatbot-message {
        max-width: 85%;
        font-size: 14px;
        padding: 10px 12px;
    }

    .chatbot-panel.expanded .chatbot-message {
        max-width: 80%;
        padding: 12px 14px;
        font-size: 15px;
    }

    .chatbot-messages {
        padding: 12px;
        -webkit-overflow-scrolling: touch;
    }

    .chatbot-panel.expanded .chatbot-messages {
        padding: 16px 12px;
        max-height: calc(100vh - 140px);
        /* Account for header and input */
    }

    .chatbot-input-area {
        padding: 10px;
    }

    .chatbot-panel.expanded .chatbot-input-area {
        padding: 12px;
    }

    .chatbot-input-area textarea {
        font-size: 16px;
        /* Prevents zoom on iOS */
        padding: 8px 12px;
    }

    .chatbot-send {
        padding: 8px 14px;
        font-size: 14px;
    }
}