/* ========================================
   Chat Widget Styles
   ======================================== */

/* Chat Bubble - Floating Button */
.chat-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 100px;
    height: 100px;
    cursor: pointer;
    z-index: 9999;
    transition: transform 0.2s ease;
}

.chat-bubble:hover {
    transform: scale(1.05);
}

.chat-bubble-bg {
    position: absolute;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.chat-bubble-icon {
    position: absolute;
    width: 109px;
    height: 111px;
    top: -5px;
    left: -5px;
    object-fit: contain;
}

/* Chat Modal */
.chat-modal {
    position: fixed;
    bottom: 130px;
    right: 20px;
    width: 350px;
    max-width: calc(100vw - 40px);
    height: 450px;
    max-height: calc(100vh - 120px);
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    z-index: 9998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

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

/* Chat Header */
.chat-modal-header {
    background-color: #00A26A;
    color: white;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.chat-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: white;
}

.chat-close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

.chat-close-btn:hover {
    opacity: 0.8;
}

/* Chat Body - Messages Area */
.chat-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background-color: #f5f5f5;
}

.chat-welcome {
    background-color: white;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chat-welcome p {
    margin: 0;
    color: #333;
}

/* Message Bubbles */
.chat-message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.chat-message.user {
    align-items: flex-end;
}

.chat-message.assistant {
    align-items: flex-start;
}

.chat-message .bubble {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
}

.chat-message.user .bubble {
    background-color: #00A26A;
    color: white;
    border-bottom-right-radius: 4px;
}

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

/* Typing Indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background-color: white;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    width: fit-content;
}

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

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.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); }
    30% { transform: translateY(-4px); }
}

/* Chat Footer - Input Area */
.chat-modal-footer {
    padding: 12px;
    background-color: white;
    border-top: 1px solid #e0e0e0;
}

.chat-input-container {
    display: flex;
    gap: 8px;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
    font-size: 14px;
}

.chat-input:focus {
    border-color: #00A26A;
}

.chat-input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #00A26A;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-send-btn:hover {
    background-color: #008b5a;
}

.chat-send-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
}

/* Send button with spinner */
.chat-send-btn.loading {
    position: relative;
}

.chat-send-btn.loading i {
    visibility: hidden;
}

.chat-send-btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error message */
.chat-message.error .bubble {
    background-color: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.chat-message.error .bubble i {
    color: #ef4444;
    margin-right: 6px;
}

/* Retry button */
.retry-btn {
    margin-top: 8px;
    padding: 6px 12px;
    background-color: #991b1b;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.retry-btn:hover {
    background-color: #7f1d1d;
}

.retry-btn i {
    color: white !important;
    margin-right: 4px;
}

/* Skeleton Loader */
.chat-skeleton {
    padding: 16px;
}

.skeleton-message {
    display: flex;
    margin-bottom: 12px;
}

.skeleton-message.left {
    justify-content: flex-start;
}

.skeleton-message.right {
    justify-content: flex-end;
}

.skeleton-bubble {
    width: 60%;
    height: 40px;
    background: linear-gradient(90deg, #e0e0e0 25%, #f0f0f0 50%, #e0e0e0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 12px;
}

.skeleton-bubble.short {
    width: 40%;
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

/* Toast notification */
.chat-toast {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background-color: #333;
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    z-index: 10000;
    animation: fadeIn 0.3s ease;
}

.chat-toast.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Offline indicator */
.chat-offline-banner {
    background-color: #fef3cd;
    color: #856404;
    padding: 8px;
    text-align: center;
    font-size: 12px;
}

/* Scrollbar styling */
.chat-modal-body::-webkit-scrollbar {
    width: 6px;
}

.chat-modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.chat-modal-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

.chat-modal-body::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ========================================
   Mobile Responsive
   ======================================== */

@media (max-width: 480px) {
    .chat-modal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        z-index: 10000 !important;
    }

    .chat-modal-header {
        padding: 16px;
        flex-shrink: 0;
    }

    .chat-header-title span {
        font-size: 18px;
    }

    .chat-close-btn {
        font-size: 32px;
        padding: 0 8px;
    }

    .chat-modal-body {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chat-modal-footer {
        flex-shrink: 0;
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        background-color: white;
        border-top: 1px solid #e0e0e0;
    }

    .chat-input {
        font-size: 16px; /* Prevents iOS zoom on focus */
        padding: 12px 16px;
    }

    .chat-send-btn {
        width: 44px;
        height: 44px;
    }

    .chat-bubble {
        bottom: 10px;
        right: 10px;
        width: 80px;
        height: 80px;
    }

    .chat-bubble-bg {
        width: 80px;
        height: 80px;
    }

    .chat-bubble-icon {
        width: 87px;
        height: 89px;
        top: -4px;
        left: -4px;
    }
}

/* Tablet adjustments */
@media (max-width: 768px) and (min-width: 481px) {
    .chat-modal {
        width: 320px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) {
    .chat-modal {
        height: 100%;
        max-height: 100%;
    }
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .chat-bubble,
    .chat-modal {
        animation: none;
        transition: none;
    }

    .typing-indicator span {
        animation: none;
    }
}
