/* ==================== QHUN22 AI CHATBOT WIDGET ==================== */

:root {
    --qh-chat-primary: var(--qh-primary, #b91c1c);
    --qh-chat-soft: var(--qh-primary-light, #fee2e2);
    --qh-chat-primary-dark: var(--qh-primary-hover, #991b1b);
}

.qh-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--qh-chat-primary), var(--qh-chat-primary-dark));
    border: none;
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(5, 150, 105, .45);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s, box-shadow .2s;
}

.qh-chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(5, 150, 105, .6);
}

.qh-chat-fab .qh-chat-fab-close {
    display: none;
}

.qh-chat-fab.active .qh-chat-fab-open {
    display: none;
}

.qh-chat-fab.active .qh-chat-fab-close {
    display: inline;
}

/* ── Chat Window ─────────────────────────────────────────── */
.qh-chat-window {
    position: fixed;
    bottom: 75px;
    right: 10px;
    width: 380px;
    max-height: 540px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, .15);
    z-index: 9999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: qhChatSlideUp .25s ease-out;
}

.qh-chat-window.open {
    display: flex;
}

@keyframes qhChatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Header ──────────────────────────────────────────────── */
.qh-chat-header {
    background: linear-gradient(135deg, #224560, #047857);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.qh-chat-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, .65);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.qh-chat-bot-image {
    width: 70%;
    height: 70%;
    object-fit: contain;
    display: block;
}

.qh-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.qh-chat-header-btn {
    border: 1px solid #059669;
    background: #d1fae5;
    color: #059669;
    font-size: 13px;
    font-weight: 600;
    font-family: 'Signika', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    border-radius: 999px;
    padding: 5px 14px;
    line-height: 1.1;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s, transform .15s, box-shadow .15s;
}

.qh-chat-header-btn:hover {
    background: #059669;
    color: #d1fae5;
    border-color: #059669;
    box-shadow: 0 2px 8px rgba(5, 150, 105, .22);
    transform: translateY(-1px);
}

.qh-chat-header-btn--ghost {
    background: #d1fae5;
}

.qh-chat-header-info {
    flex: 1;
}

.qh-chat-header-info h6 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    font-family: 'Signika', sans-serif;
}

.qh-chat-header-info small {
    font-size: 11px;
    opacity: .85;
}

.qh-chat-header-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    opacity: .8;
    transition: opacity .15s;
    padding: 0;
    line-height: 1;
}

.qh-chat-header-close:hover {
    opacity: 1;
}

/* ── Messages area ───────────────────────────────────────── */
.qh-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 280px;
    max-height: 360px;
}

/* ── Message bubble ──────────────────────────────────────── */
.qh-chat-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: qhMsgFade .2s ease-out;
}

@keyframes qhMsgFade {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.qh-chat-msg.bot {
    align-self: flex-start;
}

.qh-chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.qh-chat-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.qh-chat-msg.bot .qh-chat-msg-avatar {
    background: #fff;
    border: 1px solid #d7f3e7;
}

.qh-chat-msg-avatar--bot {
    background: #fff;
    border: 1px solid #d7f3e7;
}

.qh-chat-msg.user .qh-chat-msg-avatar {
    background: #e8e8e8;
    color: #666;
}

.qh-chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    word-wrap: break-word;
    font-family: 'Signika', sans-serif;
}

.qh-chat-msg.bot .qh-chat-msg-bubble {
    background: #fff;
    color: #333;
    border: 1px solid #e8ecf0;
    border-top-left-radius: 4px;
}

.qh-chat-msg.user .qh-chat-msg-bubble {
    background: var(--qh-chat-primary);
    color: #fff;
    border-top-right-radius: 4px;
}

/* ── Markdown in bot messages ────────────────────────────── */
.qh-chat-msg.bot .qh-chat-msg-bubble strong,
.qh-chat-msg.bot .qh-chat-msg-bubble b {
    font-weight: 600;
    color: #222;
}

/* ── Suggestions ─────────────────────────────────────────── */
.qh-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.qh-chat-suggestion-btn {
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    color: #374151;
    border-radius: 20px;
    padding: 5px 14px;
    font-size: 12.5px;
    cursor: pointer;
    transition: all .15s;
    font-family: 'Signika', sans-serif;
    white-space: nowrap;
}

.qh-chat-suggestion-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
    color: #1f2937;
}

/* ── Product cards in bot responses ─────────────────────── */
.qh-chat-cards {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.qh-chat-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f7faf9;
    border: 1px solid #d8ebe3;
    border-radius: 10px;
    padding: 8px;
}

.qh-chat-card-thumb {
    width: 54px;
    height: 54px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #d8ebe3;
    background: #fff;
    flex-shrink: 0;
}

.qh-chat-card-meta {
    min-width: 0;
}

.qh-chat-card-title {
    font-size: 13px;
    line-height: 1.3;
    font-weight: 600;
    color: #1f2937;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qh-chat-card-subtitle {
    margin-top: 2px;
    font-size: 12px;
    color: #4b5563;
    line-height: 1.35;
}

/* ── Typing indicator ────────────────────────────────────── */
.qh-chat-typing {
    display: none;
    align-self: flex-start;
    align-items: center;
    gap: 8px;
    max-width: 88%;
}

.qh-chat-typing.show {
    display: flex;
}

.qh-chat-typing-dots {
    background: #fff;
    border: 1px solid #e8ecf0;
    border-radius: 14px;
    border-top-left-radius: 4px;
    padding: 12px 18px;
    display: flex;
    gap: 4px;
}

.qh-chat-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #bbb;
    animation: qhTyping 1.2s infinite;
}

.qh-chat-typing-dots span:nth-child(2) {
    animation-delay: .2s;
}

.qh-chat-typing-dots span:nth-child(3) {
    animation-delay: .4s;
}

@keyframes qhTyping {

    0%,
    60%,
    100% {
        opacity: .3;
        transform: scale(.8);
    }

    30% {
        opacity: 1;
        transform: scale(1);
    }
}

/* ── Input area ──────────────────────────────────────────── */
.qh-chat-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid #eee;
    background: #fff;
    flex-shrink: 0;
}

.qh-chat-input {
    flex: 1;
    border: 1px solid #dde2e8;
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 13.5px;
    outline: none;
    font-family: 'Signika', sans-serif;
    transition: border-color .15s;
    background: #f8f9fc;
}

.qh-chat-input:focus {
    border-color: var(--qh-chat-primary);
    background: #fff;
}

.qh-chat-input::placeholder {
    color: #aaa;
}

.qh-chat-send {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    padding: 0;
    background: linear-gradient(135deg, var(--qh-chat-primary), var(--qh-chat-primary-dark));
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s, opacity .15s;
    flex-shrink: 0;
}

.qh-chat-send i {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transform: translateX(1px);
}

.qh-chat-send:hover {
    transform: scale(1.06);
}

.qh-chat-send:disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
}

/* ==================== CHATBOT MOBILE DRAWER (≤768px) ====================
   Build riêng cho mobile — y hệt qh-advanced-filter-drawer + qh-compare-bar
   PC (>768px) KHÔNG bị ảnh hưởng — không đụng vào bất kỳ rule nào ở trên
   ====================================================================== */
@media (max-width: 768px) {

    /* 1. Biến chat window thành right drawer, dùng transform thay display toggle */
    .qh-chat-window {
        /* Ghi đè hoàn toàn vị trí floating window */
        bottom: unset !important;
        top: 0;
        right: 0;
        width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        /* Luôn là flex nhưng ẩn bằng transform — giống qh-advanced-filter-drawer */
        display: flex !important;
        transform: translateX(100%);
        transition: transform 0.24s ease, visibility 0s ease 0.24s;
        animation: none;
        z-index: 12002;
        pointer-events: none;
        visibility: hidden;
    }

    .qh-chat-window.open {
        transform: translateX(0);
        pointer-events: auto;
        visibility: visible;
        box-shadow: -12px 0 28px rgba(15, 23, 42, 0.16);
        transition: transform 0.24s ease, visibility 0s ease 0s;
    }

    /* 2. Header — giống .qh-advanced-filter-head / .qh-compare-bar-head */
    .qh-chat-header {
        background: #fff;
        color: #1f2937;
        padding: 14px 14px;
        padding-top: max(14px, env(safe-area-inset-top));
        border-bottom: 1px solid #eef2f7;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        flex-shrink: 0;
    }

    /* Avatar: nhỏ lại như icon kế tiêu đề */
    .qh-chat-avatar {
        width: 28px;
        height: 28px;
        border-radius: 50%;
        border: 1.5px solid #e5e7eb;
        background: #f9fafb;
        overflow: hidden;
        flex-shrink: 0;
    }

    .qh-chat-bot-image {
        width: 100%;
        height: 100%;
        object-fit: contain;
    }

    /* Tiêu đề — giống .qh-advanced-filter-head h3 */
    .qh-chat-header-info {
        flex: 1;
        min-width: 0;
    }

    .qh-chat-header-info h6 {
        margin: 0;
        font-size: 16px;
        font-weight: 700;
        color: #1f2937;
        letter-spacing: 0.3px;
    }

    .qh-chat-header-info small {
        display: none;
    }

    /* Actions wrapper */
    .qh-chat-header-actions {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }

    /* Reset button: pill nhẹ */
    .qh-chat-header-btn--ghost {
        border: 1px solid #d1d5db;
        background: #f9fafb;
        color: #374151;
        font-size: 12px;
        font-weight: 600;
        padding: 5px 12px;
        border-radius: 999px;
        transition: background 0.15s;
    }

    .qh-chat-header-btn--ghost:hover {
        background: #e5e7eb;
        color: #1f2937;
        border-color: #d1d5db;
        transform: none;
        box-shadow: none;
    }

    /* Đóng button — giống .qh-advanced-filter-close */
    .qh-chat-header-btn:not(.qh-chat-header-btn--ghost) {
        width: 34px;
        height: 34px;
        border: 1px solid #d1d5db;
        border-radius: 999px;
        background: #f9fafb;
        color: #334155;
        font-size: 14px;
        font-weight: 700;
        line-height: 1;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        padding: 0;
        transition: background 0.15s;
    }

    .qh-chat-header-btn:not(.qh-chat-header-btn--ghost):hover {
        background: #e5e7eb;
        transform: none;
        box-shadow: none;
    }

    /* 3. Messages area — giống .qh-advanced-filter-body (scrollable flex body) */
    .qh-chat-messages {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 14px;
        min-height: 0;
        max-height: none;
    }

    /* Typing indicator */
    .qh-chat-typing {
        padding: 0 14px 8px;
        flex-shrink: 0;
    }

    /* 4. Input area — giống .qh-advanced-filter-foot (footer ghim dưới) */
    .qh-chat-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        border-top: 1px solid #eef2f7;
        background: #fff;
        flex-shrink: 0;
        gap: 8px;
    }

    /* Input field */
    .qh-chat-input {
        height: 44px;
        font-size: 14px;
        border-radius: 8px;
        padding: 0 14px;
        background: #f9fafb;
    }

    .qh-chat-input:focus {
        border-color: var(--qh-primary);
        background: #fff;
    }

    /* Send button — hình vuông bo góc giống filter apply button */
    .qh-chat-send {
        width: 44px;
        height: 44px;
        border-radius: 8px;
        flex-shrink: 0;
    }
}