/* WP AI Chatbot Styles - v1.0.4 - MOBILE RESPONSIVE FIX */

.chatbot-widget {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.chatbot-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.chatbot-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

/* Chat Button */
.chatbot-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--chatbot-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
}

.chatbot-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff4444;
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

/* Chat Window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px); /* FIX #2: Prevent going above viewport */
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.chatbot-widget.bottom-right .chatbot-window {
    right: 0;
}

.chatbot-widget.bottom-left .chatbot-window {
    left: 0;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.chatbot-header {
    background: var(--chatbot-primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* FIX #2: Prevent header from shrinking */
    gap: 12px; /* MOBILE FIX v1.0.5: Space between elements */
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0; /* MOBILE FIX v1.0.5: Allow shrinking */
    overflow: hidden; /* MOBILE FIX v1.0.5: Prevent overflow */
}

.status-dot {
    width: 10px;
    height: 10px;
    background: #4CAF50;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(76, 175, 80, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0);
    }
}

.chatbot-name {
    font-weight: 600;
    font-size: 16px;
    overflow: hidden; /* MOBILE FIX v1.0.5 */
    text-overflow: ellipsis; /* MOBILE FIX v1.0.5 */
    white-space: nowrap; /* MOBILE FIX v1.0.5 */
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px; /* MOBILE FIX v1.0.5: Larger touch target */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
    flex-shrink: 0; /* MOBILE FIX v1.0.5: Always visible */
    margin-left: 8px; /* MOBILE FIX v1.0.5: Space from name */
    min-width: 36px; /* MOBILE FIX v1.0.5: Minimum size */
    min-height: 36px; /* MOBILE FIX v1.0.5: Minimum size */
}

.chatbot-close:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Messages */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden; /* FIX #2: Prevent horizontal scroll */
    padding: 20px;
    background: #f7f8fa;
    min-height: 0; /* FIX #2: Allow flex shrinking */
}

.chat-message {
    margin-bottom: 16px;
    display: flex;
    animation: fadeIn 0.3s ease;
    word-wrap: break-word; /* FIX #2: Prevent text overflow */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-user {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    word-wrap: break-word;
    overflow-wrap: break-word; /* FIX #2: Better word breaking */
}

.message-user .message-bubble {
    background: var(--chatbot-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
}

/* Products Display */
.chatbot-products {
    padding: 10px;
    background: white;
    border-top: 1px solid #e5e5e5;
    max-height: 200px;
    overflow-y: auto;
    flex-shrink: 0; /* FIX #2: Prevent products area from shrinking */
}

.product-card {
    display: flex;
    gap: 12px;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.product-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}

.product-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0; /* FIX #2: Prevent image from shrinking */
}

.product-info {
    flex: 1;
    min-width: 0; /* FIX #2: Allow flex item to shrink */
}

.product-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    color: #333;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.product-price {
    color: var(--chatbot-primary);
    font-weight: bold;
    font-size: 14px;
}

.product-sale-badge {
    display: inline-block;
    background: #ff4444;
    color: white;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    margin-left: 8px;
}

/* Input Area */
.chatbot-input-area {
    padding: 16px;
    background: white;
    border-top: 1px solid #e5e5e5;
    flex-shrink: 0; /* FIX #2: Keep input area fixed size */
}

#chatbot-form {
    display: flex;
    gap: 10px;
    align-items: center; /* MOBILE FIX v1.0.5: Proper alignment */
    width: 100%; /* MOBILE FIX v1.0.5: Full width */
}

#chatbot-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e5e5e5;
    border-radius: 24px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
    min-width: 0; /* FIX #2: Allow input to shrink */
    max-width: 100%; /* MOBILE FIX v1.0.5: Prevent overflow */
}

#chatbot-input:focus {
    border-color: var(--chatbot-primary);
}

#chatbot-send {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    flex-shrink: 0; /* FIX #2: Keep button fixed size */
    min-width: 36px; /* MOBILE FIX v1.0.5: Minimum touch target */
    min-height: 36px; /* MOBILE FIX v1.0.5: Minimum touch target */
}

#chatbot-send svg {
    flex-shrink: 0; /* MOBILE FIX v1.0.5: Keep SVG size */
    width: 20px;
    height: 20px;
}

#chatbot-send:hover {
    transform: scale(1.1);
}

#chatbot-send:active {
    transform: scale(0.95);
}

/* Typing Indicator */
.typing-indicator {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

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

/* Lead Form Overlay */
.lead-form-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 12px;
    padding: 20px; /* FIX #2: Add padding for mobile */
    box-sizing: border-box;
}

.lead-form {
    background: white;
    padding: 24px;
    border-radius: 12px;
    width: 90%;
    max-width: 320px;
    animation: fadeIn 0.3s ease;
    max-height: 90%; /* FIX #2: Prevent form from being too tall */
    overflow-y: auto; /* FIX #2: Allow scrolling if needed */
}

.lead-form h3 {
    margin: 0 0 8px 0;
    color: #333;
    font-size: 18px;
}

.lead-form p {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 14px;
}

.lead-form input,
.lead-form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
    outline: none;
    box-sizing: border-box;
}

.lead-form input:focus,
.lead-form textarea:focus {
    border-color: var(--chatbot-primary);
}

.form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap; /* FIX #2: Allow buttons to wrap on very small screens */
}

.btn-primary,
.btn-secondary {
    flex: 1;
    min-width: 120px; /* FIX #2: Minimum button width */
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--chatbot-primary);
    color: white;
}

.btn-primary:hover {
    opacity: 0.9;
}

.btn-secondary {
    background: #f5f5f5;
    color: #666;
}

.btn-secondary:hover {
    background: #e5e5e5;
}

/* FIX #2: MOBILE RESPONSIVE - Complete redesign for mobile */
@media (max-width: 768px) {
 /* Keep button in bottom-right */
   .chatbot-widget.bottom-right {
        bottom: 10px !important;
        right: 10px !important;
        left: auto !important;
        top: auto !important;
    }
	
	   
    .chatbot-widget.bottom-left {
        bottom: 10px !important;
        left: 10px !important;
        right: auto !important;
        top: auto !important;
    }
    
    .chatbot-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0 !important;
		padding: 0 !important;}
    
    .chatbot-button {
        width: 56px;
        height: 56px;
    }
    
    /* MOBILE FIX v1.0.5: Header - ensure X button visible */
    .chatbot-header {
        padding: 14px 16px;
        gap: 12px; /* Space between elements */
    }
    
    .chatbot-status {
        gap: 8px;
        overflow: hidden; /* Prevent overflow */
    }
    
    .chatbot-name {
        font-size: 15px;
        max-width: calc(100% - 60px); /* Leave room for X button */
    }
    
    .chatbot-close {
        padding: 8px;
        min-width: 40px; /* MOBILE FIX v1.0.5: Guaranteed touch target */
        min-height: 40px; /* MOBILE FIX v1.0.5: Guaranteed touch target */
    }
    
    .chatbot-close svg {
        width: 20px;
        height: 20px;
    }
    
    .chatbot-messages {
        padding: 15px;
    }
    
    .message-bubble {
        max-width: 85%;
        font-size: 14px;
    }
    
    /* MOBILE FIX v1.0.5: Input area - ensure send button visible */
    .chatbot-input-area {
        padding: 12px 16px;
    }
    
    #chatbot-form {
        gap: 12px;
        width: 100%; /* MOBILE FIX v1.0.5: Full width */
    }
    
    #chatbot-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 10px 14px;
        flex: 1;
        max-width: calc(100% - 56px); /* MOBILE FIX v1.0.5: Leave room for button */
    }
    
    #chatbot-send {
        padding: 10px;
        min-width: 44px; /* MOBILE FIX v1.0.5: Guaranteed visible - iOS standard */
        min-height: 44px; /* MOBILE FIX v1.0.5: Guaranteed visible - iOS standard */
        background: var(--chatbot-primary); /* MOBILE FIX v1.0.5: Make it obvious */
        border-radius: 8px;
    }
    
    #chatbot-send svg {
        width: 20px;
        height: 20px;
    }
    
    /* MOBILE FIX v1.0.5: Make send button icon white on mobile */
    #chatbot-send svg path {
        fill: white !important;
    }
    
    .lead-form-overlay {
        padding: 15px;
    }
    
    .lead-form {
        max-width: 100%;
        padding: 20px;
    }
    
    .lead-form h3 {
        font-size: 16px;
    }
    
    .lead-form input,
    .lead-form textarea {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Extra small screens */
@media (max-width: 360px) {
    .chatbot-button {
        width: 50px;
        height: 50px;
    }
    
    .chatbot-header {
        padding: 12px;
    }
    
    .chatbot-name {
        font-size: 14px;
    }
    
    .chatbot-messages {
        padding: 10px;
    }
    
    .message-bubble {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    .form-buttons {
        flex-direction: column;
    }
    
    .btn-primary,
    .btn-secondary {
        width: 100%;
        min-width: 100%;
    }
}

/* Scrollbar Styling */
.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

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

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Landscape mobile orientation */
@media (max-width: 768px) and (orientation: landscape) {
    .chatbot-window {
        height: 100vh !important;
    }
    
    .chatbot-messages {
        padding: 10px;
    }
    
    .lead-form {
        max-height: 85vh;
        overflow-y: auto;
    }
}








/* CRITICAL: Prevent horizontal scroll on mobile */
@media (max-width: 768px) {
    #wp-ai-chatbot * {
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .chatbot-window,
    .chatbot-header,
    .chatbot-messages,
    .chatbot-input-area,
    .chat-message,
    .message-bubble {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    body.chatbot-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
    }
}