/* ========================================
   Chatbot Widget Styles
   ======================================== */

/* Floating chat button */
.chatbot-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-green, #6b9c37);
    border: none;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.chatbot-btn:hover {
    background: var(--hover-green, #5a8530);
    transform: scale(1.08);
}

.chatbot-btn.hidden {
    display: none;
}

/* Chat popup window */
.chatbot-popup {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 468px;
    max-height: 624px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    z-index: 1080;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s, transform 0.25s;
}

.chatbot-popup.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.chatbot-header {
    background: var(--dark-green, #1a472a);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

/* On mobile full-screen mode, respect notch / Dynamic Island */
@media (max-width: 767.98px) {
    .chatbot-header {
        padding-top: calc(14px + env(safe-area-inset-top));
    }
}

.chatbot-header-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-header-title i {
    font-size: 18px;
}

.chatbot-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.chatbot-close:hover {
    opacity: 1;
}

/* Messages area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 260px;
    max-height: 416px;
    background: #f8f9fa;
}

/* Message bubbles */
.chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.45;
    /* Aggressive breaking so long URLs don't cause horizontal overflow on iOS */
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
}

.chatbot-msg.bot {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

.chatbot-msg.user {
    align-self: flex-end;
    background: var(--primary-green, #6b9c37);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chatbot-msg a {
    color: var(--primary-green, #6b9c37);
    font-weight: 600;
    text-decoration: underline;
}

.chatbot-msg.bot a {
    color: var(--primary-green, #6b9c37);
}

.chatbot-msg.user a {
    color: #fff;
}

/* Input area */
.chatbot-input-area {
    display: flex;
    padding: 12px;
    gap: 8px;
    border-top: 1px solid #e9ecef;
    background: #fff;
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input:focus {
    border-color: var(--primary-green, #6b9c37);
}

.chatbot-input::placeholder {
    color: #aaa;
}

.chatbot-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--primary-green, #6b9c37);
    border: none;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chatbot-send:hover {
    background: var(--hover-green, #5a8530);
}

/* Lift chat button above sticky bottom bars (checkout, cart) on mobile */
@media (max-width: 991.98px) {
    .chatbot-btn.chatbot-btn-raised {
        bottom: 90px;
    }
}

/* Mobile full-screen chat */
@media (max-width: 767.98px) {
    .chatbot-popup {
        /* Pin to all four edges — height auto-determined, no explicit height needed */
        top: 0;
        bottom: 0;
        right: 0;
        left: 0;
        width: auto;
        height: auto;
        max-height: none;
        border-radius: 0;
        overflow-x: hidden;
        /* Keyboard handling: JS moves `bottom` up via visualViewport on iOS;
           on Android Chrome the browser resizes the viewport automatically. */
    }

    .chatbot-popup,
    .chatbot-popup * {
        box-sizing: border-box;
    }

    .chatbot-messages {
        max-height: none;
        min-height: 0;
        flex: 1;
    }

    .chatbot-input-area {
        /* Keep Send button clear of the iOS home indicator */
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

    /* Prevent iOS Safari auto-zoom on input focus (triggers at < 16px) */
    .chatbot-input {
        font-size: 16px;
    }

    .chatbot-btn {
        bottom: 16px;
        right: 16px;
    }

    .chatbot-btn.chatbot-btn-raised {
        bottom: 90px;
    }
}
