/**
 * AI Chatbot Widget Styles - Modern Design
 */

:root {
    --ai-chatbot-primary: #667eea;
    --ai-chatbot-primary-dark: #5a67d8;
    --ai-chatbot-secondary: #764ba2;
    --ai-chatbot-bg: #ffffff;
    --ai-chatbot-text: #1a202c;
    --ai-chatbot-text-light: #718096;
    --ai-chatbot-border: #e2e8f0;
    --ai-chatbot-user-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --ai-chatbot-bot-bg: #f7fafc;
    --ai-chatbot-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    --ai-chatbot-shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Wrapper */
#ai-chatbot-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    line-height: 1.5;
}

/* Chat Button */
.ai-chatbot-button {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-secondary) 100%);
    border: none;
    cursor: pointer;
    box-shadow: var(--ai-chatbot-shadow);
    z-index: 99999;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: button-bounce 2s ease-in-out infinite, pulse-ring 2s cubic-bezier(0.455, 0.03, 0.515, 0.955) infinite;
}

.ai-chatbot-button::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: inherit;
    animation: pulse-dot 2s cubic-bezier(0.455, 0.03, 0.515, 0.955) infinite;
    z-index: -1;
}

/* Tooltip bubble - Chat với chúng tôi */
.ai-chatbot-tooltip {
    position: fixed;
    bottom: 95px;
    right: 24px;
    background: #ffffff;
    color: var(--ai-chatbot-text);
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 99998;
    animation: tooltip-bounce 3s ease-in-out infinite;
    white-space: nowrap;
}

.ai-chatbot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 28px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #ffffff;
}

.ai-chatbot-tooltip.hidden {
    display: none;
}

/* Notification dot */
.ai-chatbot-button .notification-dot {
    position: absolute;
    top: 0;
    right: 0;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    border: 3px solid #ffffff;
    animation: notification-pulse 1.5s ease-in-out infinite;
}

@keyframes notification-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@keyframes button-bounce {
    0%, 20%, 50%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-8px); }
    60% { transform: translateY(-4px); }
}

@keyframes tooltip-bounce {
    0%, 100% { transform: translateY(0); opacity: 1; }
    50% { transform: translateY(-5px); opacity: 0.9; }
}

@keyframes pulse-ring {
    0% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.5); }
    70% { box-shadow: 0 0 0 20px rgba(102, 126, 234, 0); }
    100% { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0); }
}

@keyframes pulse-dot {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.ai-chatbot-button:hover {
    transform: scale(1.1);
    animation: none;
}

.ai-chatbot-button.open {
    animation: none;
    transform: rotate(0deg);
}

.ai-chatbot-button.open::before {
    animation: none;
}

.ai-chatbot-button.open .notification-dot {
    display: none;
}

.ai-chatbot-button svg {
    width: 28px;
    height: 28px;
    fill: #ffffff;
    transition: transform 0.3s ease;
}

.ai-chatbot-button.open svg.chat-icon {
    display: none;
}

.ai-chatbot-button.open svg.close-icon {
    display: block;
    transform: rotate(90deg);
}

.ai-chatbot-button svg.close-icon {
    display: none;
}

/* Chat Container */
.ai-chatbot-container {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 600px;
    max-height: calc(100vh - 140px);
    background: var(--ai-chatbot-bg);
    border-radius: 24px;
    box-shadow: var(--ai-chatbot-shadow);
    z-index: 99998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(30px) scale(0.9);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-chatbot-container.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.ai-chatbot-header {
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-secondary) 100%);
    color: #ffffff;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    position: relative;
    overflow: hidden;
}

.ai-chatbot-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 100%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 60%);
    pointer-events: none;
}

.ai-chatbot-avatar {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.ai-chatbot-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-chatbot-avatar svg {
    width: 28px;
    height: 28px;
    fill: #ffffff;
}

.ai-chatbot-info {
    flex: 1;
    min-width: 0;
}

.ai-chatbot-name {
    font-weight: 700;
    font-size: 18px;
    margin: 0 0 2px 0;
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.ai-chatbot-status {
    font-size: 13px;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-chatbot-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #68d391;
    border-radius: 50%;
    box-shadow: 0 0 8px #68d391;
    animation: status-pulse 2s infinite;
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.ai-chatbot-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 8px;
    border-radius: 12px;
    transition: all 0.2s ease;
    backdrop-filter: blur(10px);
}

.ai-chatbot-close:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: rotate(90deg);
}

.ai-chatbot-close svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    display: block;
}

/* Messages Area */
.ai-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}

.ai-chatbot-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 20px;
    line-height: 1.6;
    font-size: 14px;
    word-wrap: break-word;
    position: relative;
    animation: message-in 0.3s ease-out;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chatbot-message.user {
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-secondary) 100%);
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.ai-chatbot-message.assistant {
    background: #ffffff;
    color: var(--ai-chatbot-text);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: var(--ai-chatbot-shadow-sm);
    border: 1px solid var(--ai-chatbot-border);
}

.ai-chatbot-message a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ai-chatbot-message.user a {
    color: #ffffff;
}

/* Typing Indicator */
.ai-chatbot-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 16px 20px;
    background: #ffffff;
    border-radius: 20px;
    border-bottom-left-radius: 6px;
    align-self: flex-start;
    box-shadow: var(--ai-chatbot-shadow-sm);
    border: 1px solid var(--ai-chatbot-border);
    animation: message-in 0.3s ease-out;
}

.ai-chatbot-typing span {
    width: 8px;
    height: 8px;
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-secondary) 100%);
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out;
}

.ai-chatbot-typing span:nth-child(1) { animation-delay: 0s; }
.ai-chatbot-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-chatbot-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* Input Area */
.ai-chatbot-input-area {
    padding: 16px 20px;
    background: #ffffff;
    border-top: 1px solid var(--ai-chatbot-border);
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.ai-chatbot-input {
    flex: 1;
    border: 2px solid var(--ai-chatbot-border);
    border-radius: 24px;
    padding: 12px 20px;
    font-size: 14px;
    resize: none;
    max-height: 120px;
    outline: none;
    transition: all 0.3s ease;
    font-family: inherit;
    background: #f7fafc;
}

.ai-chatbot-input:focus {
    border-color: var(--ai-chatbot-primary);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
}

.ai-chatbot-input::placeholder {
    color: var(--ai-chatbot-text-light);
}

.ai-chatbot-send {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-secondary) 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.ai-chatbot-send:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.ai-chatbot-send:active {
    transform: scale(0.95);
}

.ai-chatbot-send:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.ai-chatbot-send svg {
    width: 22px;
    height: 22px;
    fill: #ffffff;
    margin-left: 2px;
}

/* Scrollbar */
.ai-chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chatbot-messages::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--ai-chatbot-primary) 0%, var(--ai-chatbot-secondary) 100%);
    border-radius: 3px;
}

/* Tablet Responsive */
@media (max-width: 768px) {
    .ai-chatbot-container {
        width: 360px;
        height: 550px;
        bottom: 90px;
    }
    
    .ai-chatbot-button {
        width: 58px;
        height: 58px;
        bottom: 20px;
        right: 20px;
    }
    
    .ai-chatbot-tooltip {
        bottom: 85px;
        right: 20px;
        font-size: 13px;
        padding: 10px 14px;
    }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ai-chatbot-tooltip {
        display: none !important;
    }
    
    .ai-chatbot-container {
        position: fixed;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        max-height: 100% !important;
        border-radius: 0 !important;
        transform: translateY(100%);
    }
    
    .ai-chatbot-container.open {
        transform: translateY(0);
    }
    
    /* Ẩn nút toggle khi chat mở trên mobile */
    .ai-chatbot-button.open {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        pointer-events: none !important;
    }
    
    .ai-chatbot-button {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    
    .ai-chatbot-button svg {
        width: 24px;
        height: 24px;
    }
    
    .ai-chatbot-header {
        padding: 16px;
        border-radius: 0;
        padding-top: max(16px, env(safe-area-inset-top));
        flex-shrink: 0;
    }
    
    .ai-chatbot-avatar {
        width: 40px;
        height: 40px;
        border-radius: 12px;
    }
    
    .ai-chatbot-name {
        font-size: 16px;
    }
    
    .ai-chatbot-status {
        font-size: 12px;
    }
    
    .ai-chatbot-messages {
        padding: 12px;
        gap: 12px;
        flex: 1;
        min-height: 0;
    }
    
    .ai-chatbot-message {
        max-width: 88%;
        padding: 12px 14px;
        font-size: 15px;
        line-height: 1.5;
    }
    
    .ai-chatbot-typing {
        padding: 14px 18px;
    }
    
    .ai-chatbot-input-area {
        padding: 12px 12px;
        padding-bottom: max(16px, calc(env(safe-area-inset-bottom) + 8px));
        gap: 10px;
        flex-shrink: 0;
        display: flex;
        align-items: center;
        background: #ffffff;
        border-top: 1px solid var(--ai-chatbot-border);
    }
    
    .ai-chatbot-input {
        flex: 1;
        padding: 12px 16px;
        font-size: 16px; /* Prevent zoom on iOS */
        border-radius: 20px;
        min-height: 44px;
        max-height: 100px;
        box-sizing: border-box;
    }
    
    .ai-chatbot-send {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
        flex-shrink: 0;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    .ai-chatbot-send svg {
        width: 20px;
        height: 20px;
    }
    
    .ai-chatbot-close {
        padding: 10px;
    }
}

/* Position Left */
.ai-chatbot-position-left .ai-chatbot-button {
    right: auto;
    left: 24px;
}

.ai-chatbot-position-left .ai-chatbot-tooltip {
    right: auto;
    left: 24px;
}

.ai-chatbot-position-left .ai-chatbot-tooltip::after {
    right: auto;
    left: 28px;
}

.ai-chatbot-position-left .ai-chatbot-container {
    right: auto;
    left: 24px;
}

@media (max-width: 480px) {
    .ai-chatbot-position-left .ai-chatbot-button {
        left: 16px;
    }
    
    .ai-chatbot-position-left .ai-chatbot-container {
        left: 0 !important;
        right: 0 !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --ai-chatbot-bg: #1a202c;
        --ai-chatbot-text: #f7fafc;
        --ai-chatbot-text-light: #a0aec0;
        --ai-chatbot-border: #2d3748;
        --ai-chatbot-bot-bg: #2d3748;
    }
    
    .ai-chatbot-messages {
        background: linear-gradient(180deg, #1a202c 0%, #2d3748 100%);
    }
    
    .ai-chatbot-message.assistant {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .ai-chatbot-typing {
        background: #2d3748;
        border-color: #4a5568;
    }
    
    .ai-chatbot-input-area {
        background: #1a202c;
    }
    
    .ai-chatbot-input {
        background: #2d3748;
        border-color: #4a5568;
        color: #f7fafc;
    }
    
    .ai-chatbot-input:focus {
        background: #2d3748;
    }
}

/* Fix for iOS keyboard */
@supports (-webkit-touch-callout: none) {
    .ai-chatbot-container.open {
        height: 100%;
        height: -webkit-fill-available;
    }
}

/* Ensure send button is always visible on mobile */
@media (max-width: 480px) {
    .ai-chatbot-container.open {
        z-index: 100000;
    }
    
    .ai-chatbot-input-area {
        position: relative;
        z-index: 100001;
    }
    
    .ai-chatbot-send {
        position: relative;
        z-index: 100002;
    }
}
