.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 !important;
    right: 0 !important;
    left: 0 !important;
    top: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
}

#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-width: calc(100vw - 32px);
    max-height: 480px;
    max-height: calc(100vh - 80px);
    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 */
    box-sizing: border-box;
}

/* Expanded state - full page size */
.chatbot-panel.expanded {
    position: fixed !important;
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    height: 100vh !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    transform: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 10000 !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

@media (max-width: 900px) {
    .chatbot-panel.expanded {
        width: 100vw !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
        transform: none !important;
    }
}

/* Ensure body doesn't scroll when chatbot is expanded on mobile */
@media (max-width: 640px) {
    body.chatbot-expanded {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
    }
    
    html.chatbot-expanded {
        overflow: hidden !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
    }
}

/* Prevent overflow on all screen sizes */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

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

/* Ensure toggle button is always visible */
.chatbot-toggle-button {
    position: relative !important;
    z-index: 10002 !important;
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.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;
    flex-shrink: 0;
    min-height: 50px;
}

.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;
    min-height: 36px;
    -webkit-appearance: none;
    /* Remove iOS styling */
    appearance: none;
    width: 100%;
    box-sizing: border-box;
}

.chatbot-send {
    border-radius: 999px;
    border: none;
    background: #2563eb;
    color: white;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
    flex-shrink: 0;
    min-width: 50px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: rgba(37, 99, 235, 0.3);
    touch-action: manipulation;
}

.chatbot-send:hover {
    background: #1d4ed8;
}

.chatbot-send:active {
    background: #1e40af;
}

.chatbot-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.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 !important;
        right: 12px !important;
        left: auto !important;
    }

    .chatbot-panel {
        width: calc(100vw - 24px) !important;
        max-width: calc(100vw - 24px) !important;
        right: 0 !important;
        left: 0 !important;
        max-height: 70vh !important;
        max-height: calc(100vh - 80px) !important;
        bottom: 64px !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
    }

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

    #chatbot-widget.expanded {
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        position: fixed !important;
    }

    .chatbot-toggle-button {
        width: 52px !important;
        height: 52px !important;
        font-size: 24px !important;
        z-index: 10001 !important;
    }

    .chatbot-header {
        padding: 12px 14px !important;
        flex-shrink: 0 !important;
    }

    .chatbot-panel.expanded .chatbot-header {
        padding: 14px 16px !important;
    }

    .chatbot-title {
        font-size: 15px !important;
    }

    .chatbot-close {
        font-size: 24px !important;
        width: 32px !important;
        height: 32px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        -webkit-tap-highlight-color: rgba(255, 255, 255, 0.2) !important;
    }

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

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

    .chatbot-messages {
        padding: 12px !important;
        -webkit-overflow-scrolling: touch !important;
        flex: 1 !important;
        min-height: 0 !important;
        overflow-y: auto !important;
    }

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

    .chatbot-input-area {
        padding: 10px 12px !important;
        display: flex !important;
        align-items: flex-end !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
        border-top: 1px solid #e5e7eb !important;
        background: #ffffff !important;
        min-height: 60px !important;
    }

    .chatbot-panel.expanded .chatbot-input-area {
        padding: 12px 16px !important;
        gap: 10px !important;
        min-height: 70px !important;
    }

    .chatbot-input-area textarea {
        font-size: 16px !important;
        /* Prevents zoom on iOS */
        padding: 10px 14px !important;
        min-height: 40px !important;
        max-height: 120px !important;
        width: 100% !important;
        flex: 1 !important;
        border-radius: 20px !important;
        border: 1px solid #d1d5db !important;
        resize: none !important;
        -webkit-appearance: none !important;
        appearance: none !important;
    }

    .chatbot-send {
        padding: 10px 18px !important;
        font-size: 14px !important;
        font-weight: 600 !important;
        border-radius: 20px !important;
        background: #2563eb !important;
        color: white !important;
        border: none !important;
        cursor: pointer !important;
        flex-shrink: 0 !important;
        min-width: 60px !important;
        height: 40px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        -webkit-tap-highlight-color: rgba(37, 99, 235, 0.3) !important;
        touch-action: manipulation !important;
        transition: background 0.2s ease !important;
    }

    .chatbot-send:hover,
    .chatbot-send:active {
        background: #1d4ed8 !important;
    }

    .chatbot-send:disabled {
        opacity: 0.6 !important;
        cursor: not-allowed !important;
    }
}

/* Extra small mobile devices */
@media (max-width: 375px) {
    #chatbot-widget {
        bottom: 10px !important;
        right: 10px !important;
    }

    .chatbot-toggle-button {
        width: 48px !important;
        height: 48px !important;
        font-size: 22px !important;
    }

    .chatbot-panel {
        width: calc(100vw - 20px) !important;
        bottom: 60px !important;
    }

    .chatbot-header {
        padding: 10px 12px !important;
    }

    .chatbot-title {
        font-size: 14px !important;
    }

    .chatbot-input-area {
        padding: 8px 10px !important;
        gap: 6px !important;
        min-height: 56px !important;
    }

    .chatbot-panel.expanded .chatbot-input-area {
        padding: 10px 12px !important;
        min-height: 64px !important;
    }

    .chatbot-input-area textarea {
        padding: 8px 12px !important;
        font-size: 16px !important;
        min-height: 36px !important;
    }

    .chatbot-send {
        padding: 8px 16px !important;
        font-size: 13px !important;
        min-width: 55px !important;
        height: 36px !important;
    }

    .chatbot-messages {
        padding: 10px !important;
    }

    .chatbot-panel.expanded .chatbot-messages {
        padding: 12px 10px !important;
        max-height: calc(100vh - 150px) !important;
    }
}

/* Landscape mobile orientation */
@media (max-width: 896px) and (orientation: landscape) and (max-height: 500px) {
    .chatbot-panel.expanded .chatbot-messages {
        max-height: calc(100vh - 120px) !important;
    }

    .chatbot-panel.expanded .chatbot-input-area {
        padding: 8px 12px !important;
        min-height: 56px !important;
    }

    .chatbot-input-area textarea {
        min-height: 32px !important;
        max-height: 80px !important;
    }

    .chatbot-send {
        height: 32px !important;
        padding: 6px 14px !important;
    }
}