/* FoxAI Chatbot Modern Styles with Fullscreen & Effects */
.foxai-chatbot {
    position: fixed;
    z-index: 10000;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    letter-spacing: 0.01em;
}

.foxai-chatbot.bottom-right {
    bottom: 80px;
    right: 10px;
}

.foxai-chatbot.bottom-left {
    bottom: 80px;
    left: 24px;
}

#foxai-chat-button {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: transparent;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    /* box-shadow: 0 8px 32px rgba(0, 124, 186, 0.18);
    transition: transform 0.18s cubic-bezier(.4,2,.6,1), box-shadow 0.18s; */
    font-size: 28px;
    border: none;
    outline: none;
    position: relative;
    overflow: hidden;
}

#foxai-chat-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255,255,255,0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

#foxai-chat-button:hover {
    transform: scale(1.08) rotate(-3deg);
    box-shadow: 0 12px 36px rgba(0, 124, 186, 0.22);
    background: linear-gradient(135deg, #00c6fb 60%, #007cba 100%);
}

#foxai-chat-button:hover::before {
    width: 100%;
    height: 100%;
}

#foxai-chat-window {
    width: 370px;
    height: 540px;
    background: rgba(255,255,255,0.98);
    border-radius: 18px;
    box-shadow: 0 8px 40px rgba(0, 124, 186, 0.18);
    position: absolute;
    bottom: 84px;
    right: 0;
    overflow: hidden;
    border: none;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(4px);
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#foxai-chat-window.show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

#foxai-chat-window.fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    z-index: 10001;
}

.foxai-chatbot.bottom-left #foxai-chat-window {
    right: auto;
    left: 0;
}

.foxai-chat-header {
    background: linear-gradient(90deg, #007cba 60%, #00c6fb 100%);
    color: #fff;
    padding: 18px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(0,124,186,0.08);
    position: relative;
    /* Đảm bảo header luôn ở đúng vị trí */
    flex-shrink: 0;
}

.foxai-chat-logo-header {
    display: flex;
    align-items: center;
    gap: 5px;
}

.foxai-chat-close {
    display: flex;
    gap: 5px;
    align-items: center;
    justify-content: center;
}

#foxai-close-chat {
    all: unset;
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.18s;
}

#foxai-close-chat:hover {
    background: rgba(0,0,0,0.08);
    opacity: 0.9;
    transform: rotate(90deg);
}

/* Nút fullscreen */
#foxai-fullscreen-toggle {
    all: unset;
    background: rgba(255,255,255,0.12);
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.18s;
    margin-right: 8px;
}

#foxai-fullscreen-toggle:hover {
    background: rgba(0,0,0,0.08);
    transform: scale(1.1);
}

.foxai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px 16px 20px;
    background: linear-gradient(135deg, #f8fafd 80%, #eaf6fb 100%);
    scrollbar-width: thin;
    scrollbar-color: #b3e0fc #f1f1f1;
    position: relative;
    /* Đảm bảo messages có thể cuộn khi bàn phím xuất hiện */
    min-height: 0;
}

.foxai-message {
    margin-bottom: 18px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    opacity: 0;
    transform: translateY(20px);
    animation: foxai-message-slide-in 0.4s ease-out forwards;
}

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

.foxai-message.bot {
    justify-content: flex-start;
}

@keyframes foxai-message-slide-in {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.foxai-message-content {
    max-width: 75%;
    padding: 14px 18px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(0,124,186,0.06);
    transition: all 0.18s;
    position: relative;
    overflow: hidden;
}

.foxai-message-content::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.6s;
}

.foxai-message-content:hover::before {
    left: 100%;
}

.foxai-message.user .foxai-message-content {
    background: linear-gradient(135deg, #007cba 80%, #00c6fb 100%);
    color: #fff;
    border-bottom-right-radius: 8px;
    border-top-right-radius: 4px;
    transform: translateX(0);
    animation: foxai-message-user-slide 0.4s ease-out;
}

.foxai-message.bot .foxai-message-content {
    background: #fff;
    color: #222;
    border: 1px solid #e1e5e9;
    border-bottom-left-radius: 8px;
    border-top-left-radius: 4px;
    transform: translateX(0);
    animation: foxai-message-bot-slide 0.4s ease-out;
}

@keyframes foxai-message-user-slide {
    0% {
        transform: translateX(30px);
        opacity: 0;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes foxai-message-bot-slide {
    0% {
        transform: translateX(-30px);
        opacity: 0;
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

.foxai-message-time {
    font-size: 11px;
    color: #8ca0b3;
    margin-top: 4px;
    text-align: center;
}

.foxai-chat-input-container {
    padding: 16px 20px;
    background: #f8fafd;
    border-top: 1px solid #e1e5e9;
    display: flex;
    gap: 12px;
    align-items: center;
    position: relative;
    /* Đảm bảo input container luôn ở đúng vị trí */
    flex-shrink: 0;
}

.foxai-chat-input-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, #00c6fb, transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.foxai-chat-input-container.active::before {
    opacity: 1;
}

#foxai-chat-input {
    all: unset;
    flex: 1;
    padding: 0px 20px;
    border: 1.5px solid #e1e5e9;
    border-radius: 28px;
    outline: none;
    font-size: 15px;
    background: #f4f8fb;
    transition: all 0.18s;
    position: relative;
    resize: none;
    overflow-y: auto;
    min-height: 44px;
    max-height: 100px;
    line-height: 1.4;
}

#foxai-chat-input:focus {
    border-color: #00c6fb;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(0, 198, 251, 0.1);
    transform: translateY(-1px);
}

#foxai-send-message {
    all: unset;
    padding: 10px 24px;
    background: linear-gradient(135deg, #007cba 60%, #00c6fb 100%);
    color: #fff;
    border: none;
    border-radius: 28px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: all 0.18s;
    box-shadow: 0 2px 8px rgba(0,124,186,0.08);
    position: relative;
    overflow: hidden;
}

#foxai-send-message::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255,255,255,0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

#foxai-send-message:hover {
    background: linear-gradient(135deg, #00c6fb 60%, #007cba 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,124,186,0.16);
}

#foxai-send-message:hover::before {
    width: 100%;
    height: 100%;
}

#foxai-send-message:active {
    transform: translateY(0);
}

#foxai-send-message:disabled {
    background: #e1e5e9;
    color: #b0b8c1;
    cursor: not-allowed;
    transform: none;
}

.foxai-typing-indicator {
    display: flex;
    align-items: center;
    padding: 13px 18px;
    background: #fff;
    border: 1px solid #e1e5e9;
    border-radius: 20px;
    border-bottom-left-radius: 8px;
    max-width: 75%;
    box-shadow: 0 2px 8px rgba(0,124,186,0.06);
    opacity: 0;
    transform: translateY(20px);
    animation: foxai-typing-appear 0.3s ease-out forwards;
}

@keyframes foxai-typing-appear {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.foxai-typing-dots {
    display: flex;
    gap: 5px;
}

.foxai-typing-dots span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007cba 60%, #00c6fb 100%);
    animation: foxai-typing 1.4s infinite;
}

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

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

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

/* Hiệu ứng pulse cho button khi có tin nhắn mới */
.foxai-new-message-pulse {
    animation: foxai-pulse 1s infinite;
}

@keyframes foxai-pulse {
    0% {
        box-shadow: 0 8px 32px rgba(0, 124, 186, 0.18);
    }
    50% {
        box-shadow: 0 8px 32px rgba(0, 124, 186, 0.4), 0 0 0 8px rgba(0, 124, 186, 0.1);
    }
    100% {
        box-shadow: 0 8px 32px rgba(0, 124, 186, 0.18);
    }
}

/* Hiệu ứng gõ phím */
@keyframes foxai-input-typing {
    0% { border-color: #00c6fb; }
    50% { border-color: #007cba; }
    100% { border-color: #00c6fb; }
}

.foxai-input-typing {
    animation: foxai-input-typing 1s infinite;
}

/* Responsive với sửa lỗi bàn phím mobile */
@media (max-width: 480px) {
    #foxai-chat-window {
        width: 100vw;
        height: 100vh;
        /* Sử dụng viewport units tương thích với bàn phím */
        height: 100dvh; /* Dynamic viewport height */
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        box-shadow: none;
    }
    
    #foxai-chat-window.fullscreen {
        transform: none !important;
        height: 100dvh !important;
    }
    
    .foxai-chat-messages {
        /* Tính toán chiều cao chính xác để tránh bàn phím che */
        height: calc(100dvh - 130px); /* 70px cho header + 60px cho input container */
        max-height: calc(100dvh - 130px);
        min-height: calc(100dvh - 130px);
        padding: 18px 8px 12px 8px;
        overflow-y: auto;
        /* Thêm scroll behavior mượt mà */
        -webkit-overflow-scrolling: touch;
    }
    
    .foxai-chat-header {
        height: 70px;
        padding: 16px 12px;
        /* Đảm bảo header có chiều cao cố định */
        flex-shrink: 0;
    }
    
    .foxai-chat-input-container {
        height: 60px;
        min-height: 60px;
        padding: 12px 12px;
        /* Đảm bảo input container có chiều cao cố định */
        flex-shrink: 0;
        /* Đảm bảo input container luôn hiển thị */
        position: relative;
        background: #f8fafd;
        border-top: 1px solid #e1e5e9;
    }
    
    #foxai-chat-input {
        min-height: 36px;
        max-height: 36px;
        font-size: 16px; /* Ngăn zoom trên iOS */
    }
    
    #foxai-send-message {
        min-height: 36px;
        padding: 8px 16px;
        font-size: 14px;
    }
    
    .foxai-message-content {
        max-width: 85%;
        font-size: 14px;
    }
}

/* Responsive cho tablet */
@media (max-width: 768px) and (min-width: 481px) {
    #foxai-chat-window {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        border-radius: 0;
        box-shadow: none;
    }
    
    .foxai-chat-messages {
        height: calc(100dvh - 140px);
        padding: 16px 12px;
        -webkit-overflow-scrolling: touch;
    }
    
    .foxai-chat-header {
        padding: 16px 16px;
        height: 70px;
        flex-shrink: 0;
    }
    
    .foxai-chat-input-container {
        padding: 12px 16px;
        height: 70px;
        flex-shrink: 0;
    }
    
    #foxai-chat-input {
        font-size: 16px; /* Ngăn zoom trên iOS */
    }
    
    .foxai-message-content {
        max-width: 85%;
        font-size: 14px;
    }
}

/* Xử lý đặc biệt cho iOS để tránh bàn phím che */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        #foxai-chat-window {
            height: 100vh;
            height: -webkit-fill-available;
        }
        
        .foxai-chat-messages {
            height: calc(100vh - 140px);
            height: calc(-webkit-fill-available - 140px);
        }
        
        /* Khi input được focus, cuộn messages lên */
        .foxai-chat-input-focused .foxai-chat-messages {
            height: calc(100vh - 140px);
            height: calc(-webkit-fill-available - 140px);
            padding-bottom: 60px;
        }
    }
}

/* Scrollbar styling */
.foxai-chat-messages::-webkit-scrollbar {
    width: 7px;
}

.foxai-chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.foxai-chat-messages::-webkit-scrollbar-thumb {
    background: #b3e0fc;
    border-radius: 4px;
    transition: background 0.2s;
}

.foxai-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #7fd8f9;
}

/* Backdrop cho fullscreen */
.foxai-fullscreen-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s;
}

.foxai-fullscreen-backdrop.show {
    opacity: 1;
}

/* Hiệu ứng shine cho tin nhắn mới */
@keyframes foxai-message-shine {
    0% {
        background-position: -200px 0;
    }
    100% {
        background-position: 200px 0;
    }
}

.foxai-message-shine {
    background-image: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    background-size: 200px 100%;
    background-repeat: no-repeat;
    animation: foxai-message-shine 1.5s ease-out;
}

/* Smooth transitions for all interactive elements */
* {
    -webkit-tap-highlight-color: transparent;
}

/* Loading state for send button */
#foxai-send-message.loading {
    pointer-events: none;
    opacity: 0.7;
}

#foxai-send-message.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid transparent;
    border-top: 2px solid #fff;
    border-radius: 50%;
    animation: foxai-spin 1s linear infinite;
}

@keyframes foxai-spin {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* Focus states for accessibility */
#foxai-chat-button:focus,
#foxai-close-chat:focus,
#foxai-fullscreen-toggle:focus {
    outline: 2px solid #00c6fb;
    outline-offset: 2px;
}

#foxai-chat-input:focus {
    outline: none;
}

/* Message timestamps */
.foxai-message-time {
    font-size: 10px;
    color: #8ca0b3;
    margin-top: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.foxai-message:hover .foxai-message-time {
    opacity: 1;
}

/* Print styles */
@media print {
    .foxai-chatbot {
        display: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    #foxai-chat-button {
        border: 2px solid #000;
    }
    
    .foxai-message-content {
        border: 1px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support (if needed) */
@media (prefers-color-scheme: dark) {
    .foxai-chat-messages {
        background: linear-gradient(135deg, #1a1a1a 80%, #2d2d2d 100%);
    }
    
    .foxai-message.bot .foxai-message-content {
        background: #2d2d2d;
        color: #fff;
        border-color: #444;
    }
    
    .foxai-chat-input-container {
        background: #1a1a1a;
        border-color: #444;
    }
    
    #foxai-chat-input {
        background: #2d2d2d;
        color: #fff;
        border-color: #444;
    }
}

/* Thêm class để xử lý khi input được focus trên mobile */
.foxai-mobile-keyboard-active {
    /* Có thể thêm styles đặc biệt khi bàn phím xuất hiện */
}

/* Safe area cho các thiết bị có notch */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .foxai-chat-header {
            padding-top: max(16px, env(safe-area-inset-top));
        }
        
        .foxai-chat-input-container {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
    }
}