/* 
 * Lumina AI Chat Widget - Glassmorphism Design
 * Version: WEBA - Hosting Compatible
 * Fix: Nút X bị ẩn + Input wrapper bị cao + Outline
 */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Base Widget Container */
#chatbot-ai-widget {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    position: fixed !important;
    bottom: 24px !important;
    right: 24px !important;
    left: auto !important;
    top: auto !important;
    z-index: 999999 !important;
}

/* Chat Button - Glassmorphism */
#chatbot-ai-button {
    width: 64px !important;
    height: 64px !important;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.9) 0%, rgba(147, 51, 234, 0.9) 100%);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 8px 32px rgba(59, 130, 246, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.2);
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    border: none;
    margin: 0;
    padding: 0;
}

#chatbot-ai-button:hover {
    transform: scale(1.05) translateY(-2px);
    box-shadow: 0 12px 40px rgba(59, 130, 246, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.3);
}

#chatbot-ai-button svg {
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* Online Indicator */
.chatbot-online-indicator {
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 14px;
    height: 14px;
    background: #10b981;
    border-radius: 50%;
    border: 3px solid white;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
    animation: pulse-indicator 2s infinite;
}

@keyframes pulse-indicator {
    0%, 100% {
        box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
    }
    50% {
        box-shadow: 0 0 16px rgba(16, 185, 129, 0.8), 0 0 24px rgba(16, 185, 129, 0.4);
    }
}

/* Chat Window */
#chatbot-ai-window {
    position: fixed !important;
    bottom: 100px !important;
    right: 24px !important;
    left: auto !important;
    top: auto !important;
    width: 360px !important;
    height: 600px !important;
    max-height: calc(100vh - 140px);
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border-radius: 28px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(255, 255, 255, 0.2);
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    overflow: hidden;
    animation: slideUpScale 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUpScale {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.chatbot-header {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 20px 20px 16px;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 3px double rgba(100, 100, 120, 0.25);
    position: relative;
    z-index: 10;
    box-shadow: 0 2px 0 rgba(255, 255, 255, 0.5);
}

.chatbot-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar-container {
    position: relative;
}

.chatbot-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    border: 2px solid white;
}

.chatbot-avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #10b981;
    border-radius: 50%;
    border: 2px solid white;
}

.chatbot-header-info {
    display: flex;
    flex-direction: column;
}

.chatbot-header-name {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    line-height: 1.2;
    margin: 0;
}

.chatbot-header-status {
    font-size: 10px;
    font-weight: 500;
    color: #10b981;
    margin: 2px 0 0;
}

.chatbot-header-actions {
    display: flex;
    gap: 8px;
}

/* CRITICAL: Nút close - Đảm bảo hiển thị */
.chatbot-header-btn {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    border: none;
    color: #9ca3af;
    cursor: pointer;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s;
    padding: 0 !important;
    margin: 0 !important;
    opacity: 1 !important;
    visibility: visible !important;
}

.chatbot-header-btn:hover {
    background: rgba(255, 255, 255, 0.8);
    color: #4b5563;
    transform: scale(1.05);
}

/* CRITICAL: SVG trong nút close */
.chatbot-header-btn svg {
    width: 16px !important;
    height: 16px !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Divider */
.chatbot-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px 0;
}

.chatbot-divider-text {
    font-size: 10px;
    font-weight: 600;
    color: #9ca3af;
    letter-spacing: 1.5px;
    background: rgba(255, 255, 255, 0.4);
    padding: 4px 12px;
    border-radius: 12px;
}

/* Messages Area */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    background: transparent;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(203, 213, 225, 0.5);
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(160, 174, 192, 0.7);
}

/* Message */
.chatbot-message {
    display: flex;
    width: 100%;
    margin-bottom: 16px;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chatbot-message.user {
    justify-content: flex-end;
}

.chatbot-message.assistant {
    justify-content: flex-start;
}

.chatbot-message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    font-size: 13px;
    line-height: 1.6;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.chatbot-message.assistant .chatbot-message-bubble {
    background: white;
    color: #374151;
    border-radius: 16px;
    border-top-left-radius: 4px;
}

.chatbot-message.user .chatbot-message-bubble {
    background: #2563eb;
    color: white;
    border-radius: 16px;
    border-top-right-radius: 4px;
}

/* Typing Indicator */
.chatbot-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    border-top-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    width: fit-content;
}

.chatbot-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: typingBounce 1.4s infinite;
}

.chatbot-typing span:nth-child(1) {
    animation-delay: 0s;
}

.chatbot-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chatbot-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Input Area */
.chatbot-input-container {
    padding: 8px 16px 16px !important;
    background: linear-gradient(to top, rgba(255, 255, 255, 0.4), transparent) !important;
}

/* File Preview */
.chatbot-file-preview {
    padding: 12px 16px;
    background: rgba(243, 244, 246, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(229, 231, 235, 0.5);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-file-preview-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

#chatbot-file-preview-img {
    max-width: 80px;
    max-height: 80px;
    border-radius: 8px;
    object-fit: cover;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#chatbot-file-preview-doc {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

#chatbot-file-preview-doc svg {
    color: #3b82f6;
    flex-shrink: 0;
}

#chatbot-file-name {
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chatbot-file-remove {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.1);
    border: none;
    color: #ef4444;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chatbot-file-remove:hover {
    background: #ef4444;
    color: white;
    transform: scale(1.1);
}

/* CRITICAL: Input Wrapper - Fix outline và height */
.chatbot-input-wrapper {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 8px !important;
    background: white !important;
    border: 1px solid rgba(229, 231, 235, 0.5) !important;
    border-radius: 24px !important;
    padding: 4px 4px 4px 16px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05) !important;
    transition: all 0.2s !important;
    outline: none !important;
    min-height: 44px !important;
    max-height: 44px !important;
    height: 44px !important;
    box-sizing: border-box !important;
}

.chatbot-input-wrapper:focus-within {
    border-color: #2563eb !important;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1), 0 2px 8px rgba(0, 0, 0, 0.05) !important;
    outline: none !important;
}

/* CRITICAL: Textarea - Fix height */
#chatbot-input {
    flex: 1 !important;
    min-width: 0 !important;
    background: transparent !important;
    border: none !important;
    outline: none !important;
    font-size: 14px !important;
    color: #374151 !important;
    height: 36px !important;
    min-height: 36px !important;
    max-height: 36px !important;
    resize: none !important;
    font-family: inherit !important;
    margin: 0 !important;
    padding: 0 !important;
    line-height: 36px !important;
    overflow: hidden !important;
}

#chatbot-input::placeholder {
    color: #9ca3af !important;
}

/* Actions Container */
.chatbot-input-actions {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 4px !important;
    padding-right: 4px !important;
    flex-shrink: 0 !important;
}

/* Buttons */
.chatbot-input-btn {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
    max-width: 32px !important;
    max-height: 32px !important;
    border-radius: 50% !important;
    border: none !important;
    background: transparent !important;
    color: #9ca3af !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s !important;
    margin: 0 !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
}

.chatbot-input-btn:hover {
    color: #4b5563 !important;
    background: rgba(243, 244, 246, 0.8) !important;
}

.chatbot-input-btn svg {
    width: 18px !important;
    height: 18px !important;
}

#chatbot-send {
    background: #2563eb !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important;
}

#chatbot-send:hover:not(:disabled) {
    background: #1d4ed8 !important;
    transform: scale(1.05) !important;
}

#chatbot-send:disabled {
    background: #e5e7eb !important;
    color: #9ca3af !important;
    cursor: not-allowed !important;
    box-shadow: none !important;
}

#chatbot-send svg {
    width: 16px !important;
    height: 16px !important;
    transform: translateX(1px) !important;
}

/* Attachment in Message */
.chatbot-attachment {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
}

.chatbot-attachment img {
    width: 100%;
    max-width: 220px;
    max-height: 240px;
    border-radius: 14px;
    cursor: zoom-in;
    object-fit: cover;
    transition: all 0.25s ease;
    box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.chatbot-attachment img:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}

.chatbot-message.assistant .chatbot-attachment img {
    margin-right: auto;
}

.chatbot-message.user .chatbot-attachment img {
    margin-left: auto;
}

.chatbot-attachment-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #f3f4f6;
    border-radius: 12px;
    text-decoration: none;
    color: #111827;
    transition: background 0.2s, transform 0.2s;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.chatbot-attachment-file:hover {
    background: #e5e7eb;
    transform: translateY(-1px);
}

.chatbot-attachment-file-icon {
    font-size: 16px;
}

.chatbot-attachment-file-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Image modal */
#chatbot-image-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999999;
}

.chatbot-image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
}

.chatbot-image-modal-img {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 16px;
    box-shadow: 0 12px 36px rgba(0,0,0,0.4);
    z-index: 1;
}

.chatbot-no-scroll {
    overflow: hidden;
}
/* Footer */
.chatbot-footer {
    padding: 12px 16px 0;
    text-align: center;
}

.chatbot-footer-text {
    font-size: 10px;
    font-weight: 500;
    color: #9ca3af;
}

.chatbot-footer-link {
    color: #2563eb;
    text-decoration: none;
    transition: all 0.2s;
}

.chatbot-footer-link:hover {
    text-decoration: underline;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    #chatbot-ai-widget {
        right: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
    }
    
    #chatbot-ai-button {
        width: 56px !important;
        height: 56px !important;
        position: fixed !important;
        bottom: 16px !important;
        right: 16px !important;
    }
    
    #chatbot-ai-button svg {
        width: 24px !important;
        height: 24px !important;
    }
    
    #chatbot-ai-window {
        width: 100vw !important;
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height - tính cả bàn phím */
        max-height: 100vh !important;
        max-height: 100dvh !important;
        right: 0 !important;
        bottom: 0 !important;
        top: 0 !important;
        left: 0 !important;
        border-radius: 0 !important;
        border: none !important;
    }
    
    .chatbot-header {
        padding: 16px 20px !important;
        border-radius: 0 !important;
        flex-shrink: 0 !important; /* Không co lại */
    }
    
    .chatbot-messages {
        flex: 1 1 auto !important;
        min-height: 0 !important; /* Cho phép shrink khi bàn phím hiện */
        padding-bottom: 80px !important; /* Khoảng trống để input không che tin nhắn cuối */
    }
    
    .chatbot-input-wrapper {
        position: sticky !important; /* Dính ở dưới cùng */
        bottom: 0 !important;
        flex-shrink: 0 !important; /* Không bao giờ co lại */
        z-index: 10 !important;
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
    }
    
    #chatbot-input {
        font-size: 16px !important; /* Tránh iOS zoom khi focus */
        max-height: 100px !important; /* Giới hạn chiều cao khi gõ nhiều */
    }
}

/* Utility */
* {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
