/* ==========================================================================
   CLE.EDU.VN - AI Chatbot Widget Styles
   Màu sắc chủ đạo: Xanh thương hiệu #155ba0 | Gradient cao cấp | Responsive
   ========================================================================== */

:root {
    --cle-chat-primary: #155ba0;
    --cle-chat-primary-dark: #0d3d6b;
    --cle-chat-primary-light: #eaf3fb;
    --cle-chat-accent: #ff6b35;
    --cle-chat-text-dark: #1e293b;
    --cle-chat-text-muted: #64748b;
    --cle-chat-bg: #ffffff;
    --cle-chat-bot-bubble: #f1f5f9;
    --cle-chat-user-bubble: #155ba0;
    --cle-chat-border: #e2e8f0;
    --cle-chat-shadow: 0 12px 36px rgba(15, 23, 42, 0.16), 0 4px 12px rgba(15, 23, 42, 0.08);
    --cle-chat-radius: 18px;
    --cle-chat-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --------------------------------------------------------------------------
   1. NÚT KÍCH HOẠT NỔI (FLOATING LAUNCHER BUTTON)
   -------------------------------------------------------------------------- */
#cle-chatbot-launcher {
    position: fixed;
    bottom: 140px;
    right: 20px;
    z-index: 99998;
    display: flex;
    align-items: center;
    cursor: pointer;
    font-family: var(--cle-chat-font);
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

#cle-chatbot-launcher:hover {
    transform: translateY(-3px) scale(1.03);
}

.cle-chat-badge-pill {
    background: #ffffff;
    color: var(--cle-chat-primary);
    font-size: 13px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 30px;
    margin-right: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--cle-chat-border);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    animation: cleFloatPill 3s ease-in-out infinite alternate;
}

.cle-chat-badge-pill .cle-pulse-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    animation: clePulse 2s infinite;
}

.cle-chat-btn-circle {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--cle-chat-primary) 0%, #1e40af 100%);
    box-shadow: 0 8px 24px rgba(21, 91, 160, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    position: relative;
    border: 2px solid #ffffff;
}

.cle-chat-btn-circle svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    transition: transform 0.3s ease;
}

.cle-chat-btn-circle .cle-icon-close {
    display: none;
}

#cle-chatbot-launcher.active {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.85);
}

#cle-chatbot-launcher.active .cle-chat-btn-circle .cle-icon-chat {
    display: none;
}

#cle-chatbot-launcher.active .cle-chat-btn-circle .cle-icon-close {
    display: block;
    transform: rotate(90deg);
}

.cle-chat-btn-ring {
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    bottom: -5px;
    border-radius: 50%;
    border: 2px solid var(--cle-chat-primary);
    opacity: 0.5;
    animation: clePulseRing 2.4s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   1b. SẮP XẾP CỘT NÚT NỔI BÊN PHẢI (TRÁNH CHỒNG ICON)
   Thứ tự từ dưới lên (desktop):
     Lên đầu trang (70–120) → Chatbot AI (140–198) → Messenger (215–271)
     → Zalo (295–345, vòng sáng ±10px) → Đăng ký học (370+)
   Tâm các nút căn thẳng hàng tại right ≈ 45px.
   -------------------------------------------------------------------------- */
#cle-chatbot-launcher {
    right: 16px !important;
    bottom: 140px !important;
}

.js-facebook-messenger-box {
    bottom: 215px !important;
    right: 17px !important;
}

.btn-zalo {
    bottom: 295px !important;
    right: 15px !important;
}

a.btn-dangky {
    bottom: 375px !important;
    right: 10px !important;
}

/* --------------------------------------------------------------------------
   2. KHUNG HỘI THOẠI CHAT (CHAT WINDOW)
   -------------------------------------------------------------------------- */
#cle-chatbot-window {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 390px;
    max-width: calc(100vw - 30px);
    height: 580px;
    max-height: calc(100vh - 40px);
    background: var(--cle-chat-bg);
    border-radius: var(--cle-chat-radius);
    box-shadow: var(--cle-chat-shadow);
    display: flex;
    flex-direction: column;
    z-index: 99999;
    overflow: hidden;
    font-family: var(--cle-chat-font);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.3s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.3s;
    border: 1px solid rgba(226, 232, 240, 0.8);
}

#cle-chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.cle-chat-header {
    background: linear-gradient(135deg, var(--cle-chat-primary) 0%, #0d3d6b 100%);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.cle-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.cle-chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.cle-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 50%;
}

.cle-chat-title-group h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
}

.cle-chat-status {
    font-size: 11px;
    color: #dbeafe;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 3px;
}

.cle-chat-status-dot {
    width: 7px;
    height: 7px;
    background: #10b981;
    border-radius: 50%;
    display: inline-block;
}

.cle-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.cle-chat-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.cle-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.28);
    transform: scale(1.08);
}

/* Body / Messages */
.cle-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.cle-chat-body::-webkit-scrollbar {
    width: 5px;
}

.cle-chat-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

/* Tin nhắn chung */
.cle-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: cleMsgFadeIn 0.25s ease-out;
}

.cle-msg-row.bot {
    align-self: flex-start;
    max-width: 86%;
}

.cle-msg-row.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    max-width: 86%;
}

.cle-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid var(--cle-chat-border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.cle-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.cle-msg-bubble {
    padding: 11px 15px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.cle-msg-row.bot .cle-msg-bubble {
    background: #ffffff;
    color: var(--cle-chat-text-dark);
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.cle-msg-row.user .cle-msg-bubble {
    background: var(--cle-chat-user-bubble);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

/* Định dạng Markdown trong câu trả lời bot */
.cle-msg-bubble p {
    margin: 0 0 8px 0;
}

.cle-msg-bubble p:last-child {
    margin-bottom: 0;
}

.cle-msg-bubble ul, .cle-msg-bubble ol {
    margin: 4px 0 8px 18px;
    padding: 0;
}

.cle-msg-bubble li {
    margin-bottom: 4px;
}

.cle-msg-bubble strong {
    color: var(--cle-chat-primary-dark);
}

.cle-msg-row.user .cle-msg-bubble strong {
    color: #ffffff;
}

.cle-msg-bubble a {
    color: var(--cle-chat-primary);
    text-decoration: underline;
    font-weight: 600;
}

.cle-msg-row.user .cle-msg-bubble a {
    color: #ffffff;
}

/* Quick Prompts Chips */
.cle-quick-prompts-wrapper {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cle-quick-prompt-title {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--cle-chat-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.cle-quick-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cle-prompt-chip {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: var(--cle-chat-primary);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.cle-prompt-chip:hover {
    background: var(--cle-chat-primary-light);
    border-color: var(--cle-chat-primary);
    transform: translateY(-1px);
}

/* Fast Action Bar (Hotline & Zalo) */
.cle-chat-fast-actions {
    background: #ffffff;
    border-top: 1px solid var(--cle-chat-border);
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    gap: 8px;
}

.cle-fast-btn {
    flex: 1;
    padding: 6px 10px;
    border-radius: 8px;
    text-decoration: none !important;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: opacity 0.2s, transform 0.2s;
}

.cle-fast-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.cle-fast-btn.call {
    background: #e0f2fe;
    color: #0284c7;
}

.cle-fast-btn.zalo {
    background: #0068ff;
    color: #ffffff;
}

.cle-fast-btn.lead {
    background: #fef3c7;
    color: #d97706;
}

/* Typing Indicator */
.cle-typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #ffffff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--cle-chat-border);
}

.cle-typing-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: cleBlink 1.4s infinite both;
}

.cle-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.cle-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

/* Quick Lead Form Card */
.cle-lead-card {
    background: #ffffff;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 12px 14px;
    margin-top: 8px;
    box-shadow: 0 2px 8px rgba(21, 91, 160, 0.08);
}

.cle-lead-card-header {
    font-size: 13px;
    font-weight: 700;
    color: var(--cle-chat-primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.cle-lead-input {
    width: 100%;
    padding: 8px 10px;
    font-size: 12.5px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    margin-bottom: 8px;
    box-sizing: border-box;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.cle-lead-input:focus {
    border-color: var(--cle-chat-primary);
}

.cle-lead-submit {
    width: 100%;
    background: var(--cle-chat-primary);
    color: #ffffff;
    border: none;
    padding: 8px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s;
}

.cle-lead-submit:hover {
    background: var(--cle-chat-primary-dark);
}

/* Chat Footer / Input */
.cle-chat-footer {
    background: #ffffff;
    border-top: 1px solid var(--cle-chat-border);
    padding: 10px 14px 12px;
}

.cle-chat-input-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    padding: 4px 6px 4px 14px;
    transition: border-color 0.2s, background 0.2s;
}

.cle-chat-input-box:focus-within {
    border-color: var(--cle-chat-primary);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(21, 91, 160, 0.12);
}

.cle-chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 8px 0;
    font-size: 13px;
    font-family: inherit;
    color: var(--cle-chat-text-dark);
    outline: none;
}

.cle-chat-input::placeholder {
    color: #94a3b8;
}

.cle-chat-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--cle-chat-primary);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.15s, background 0.2s, opacity 0.2s;
}

.cle-chat-send-btn:hover {
    background: var(--cle-chat-primary-dark);
    transform: scale(1.05);
}

.cle-chat-send-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    transform: none;
}

.cle-chat-disclaimer {
    font-size: 10px;
    color: #94a3b8;
    text-align: center;
    margin-top: 6px;
}

/* --------------------------------------------------------------------------
   3. ANIMATIONS
   -------------------------------------------------------------------------- */
@keyframes clePulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.6); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

@keyframes clePulseRing {
    0% { transform: scale(0.85); opacity: 0.8; }
    50% { transform: scale(1.2); opacity: 0.2; }
    100% { transform: scale(1.4); opacity: 0; }
}

@keyframes cleFloatPill {
    0% { transform: translateY(0); }
    100% { transform: translateY(-4px); }
}

@keyframes cleMsgFadeIn {
    0% { opacity: 0; transform: translateY(6px); }
    100% { opacity: 1; transform: translateY(0); }
}

@keyframes cleBlink {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.1); }
}

/* --------------------------------------------------------------------------
   4. RESPONSIVE MOBILE TỐI ƯU
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    #cle-chatbot-launcher {
        bottom: 95px !important;
        right: 14px !important;
    }

    .cle-chat-badge-pill {
        display: none !important; /* Ẩn pill trên màn hình nhỏ để tránh che nội dung */
    }

    .cle-chat-btn-circle {
        width: 52px;
        height: 52px;
    }

    .js-facebook-messenger-box {
        bottom: 162px !important;
        right: 14px !important;
    }

    .btn-zalo {
        bottom: 230px !important;
        right: 12px !important;
    }

    a.btn-dangky {
        bottom: 300px !important;
        right: 8px !important;
    }

    #cle-chatbot-window {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        border: none;
    }

    .cle-chat-header {
        padding: 12px 14px;
        border-radius: 0;
    }

    .cle-chat-body {
        padding: 12px;
    }
}
