/* ==========================================================================
   Bizmatch Chat Bot AI
   Màu chủ đạo lấy từ --bizmatch-brand-color (cài trong Admin).
   ========================================================================== */

.bizmatch-launcher,
.bizmatch-box {
    --bz-brand: var(--bizmatch-brand-color, #0068ff);
    --bz-on-brand: var(--bizmatch-on-brand, #fff);
    --bz-link: var(--bizmatch-link-color, var(--bizmatch-brand-color, #0068ff));
    --bz-ink: #1f2430;
    --bz-ink-soft: #5b6270;
    --bz-line: #e6e8ee;
    --bz-surface: #ffffff;
    --bz-bot-bg: #f2f4f8;
    --bz-radius: 18px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    box-sizing: border-box;
}
.bizmatch-launcher *,
.bizmatch-box * { box-sizing: border-box; }

/* ---------- Nút mở chat ---------- */
.bizmatch-launcher {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 999999;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 13px 20px;
    background: var(--bz-brand);
    color: var(--bz-on-brand);
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    user-select: none;
    box-shadow: 0 6px 20px rgba(15, 23, 42, .22), 0 1px 3px rgba(15, 23, 42, .18);
    transition: transform .18s ease, box-shadow .18s ease;
}
.bizmatch-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(15, 23, 42, .26), 0 1px 3px rgba(15, 23, 42, .18);
}
.bizmatch-bot-icon { display: block; flex-shrink: 0; }

/* ---------- Khung chat ---------- */
.bizmatch-box {
    position: fixed;
    bottom: 84px;
    right: 20px;
    z-index: 999999;
    width: 372px;
    max-width: calc(100vw - 24px);
    height: 540px;
    max-height: calc(100vh - 110px);
    flex-direction: column;
    background: var(--bz-surface);
    border-radius: var(--bz-radius);
    overflow: hidden;
    color: var(--bz-ink);
    box-shadow: 0 24px 60px rgba(15, 23, 42, .28), 0 2px 8px rgba(15, 23, 42, .12);
    transform-origin: bottom right;
    animation: bizmatch-pop .22s cubic-bezier(.2, .8, .2, 1);
}
.bizmatch-box.pos-left,
.bizmatch-launcher.pos-left { right: auto; left: 20px; }
.bizmatch-box.pos-left { transform-origin: bottom left; }

@keyframes bizmatch-pop {
    from { opacity: 0; transform: translateY(10px) scale(.97); }
    to   { opacity: 1; transform: none; }
}

/* ---------- Header ---------- */
.bizmatch-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 14px 14px 16px;
    color: var(--bz-on-brand);
    background-color: var(--bz-brand);
    /* lớp phủ tạo chiều sâu, vẫn ăn theo màu thương hiệu */
    background-image: linear-gradient(135deg, rgba(255,255,255,.14), rgba(0,0,0,.14));
}
.bizmatch-header-title {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}
.bizmatch-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(127, 127, 127, .22);
    box-shadow: inset 0 0 0 1px rgba(127, 127, 127, .35);
}
.bizmatch-title-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.bizmatch-title-text strong {
    font-size: 16px;
    font-weight: 650;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bizmatch-title-text small {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    line-height: 1;
    opacity: .88;
}
.bizmatch-title-text small::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, .28);
}
#bizmatch-chat-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--bz-on-brand);
    cursor: pointer;
    transition: background .15s ease;
}
#bizmatch-chat-close:hover { background: rgba(127, 127, 127, .25); }

/* ---------- Danh sách tin nhắn ---------- */
.bizmatch-messages {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 16px 14px;
    overflow-y: auto;
    background: #fafbfd;
    font-size: 14.5px;
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #cfd4de transparent;
}
.bizmatch-messages::-webkit-scrollbar { width: 6px; }
.bizmatch-messages::-webkit-scrollbar-thumb { background: #cfd4de; border-radius: 6px; }

.b-msg {
    max-width: 86%;
    padding: 10px 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.b-msg.bot {
    align-self: flex-start;
    background: var(--bz-bot-bg);
    color: var(--bz-ink);
    border-radius: 4px 16px 16px 16px;
    box-shadow: inset 0 0 0 1px var(--bz-line);
}
.b-msg.user {
    align-self: flex-end;
    background: var(--bz-brand);
    color: var(--bz-on-brand);
    border-radius: 16px 16px 4px 16px;
    white-space: pre-wrap;
}
.b-msg a {
    color: var(--bz-link);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-word;
}
.b-msg a:hover { text-decoration-thickness: 2px; }
.b-msg strong { font-weight: 650; }

/* ---------- Đang trả lời (3 chấm) ---------- */
.b-msg.typing { padding: 14px 16px; }
.b-dots { display: inline-flex; align-items: center; gap: 5px; }
.b-dots i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--bz-ink-soft);
    opacity: .4;
    animation: bizmatch-dot 1.1s infinite ease-in-out;
}
.b-dots i:nth-child(2) { animation-delay: .15s; }
.b-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bizmatch-dot {
    0%, 70%, 100% { transform: translateY(0); opacity: .4; }
    35%           { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Ô nhập ---------- */
.bizmatch-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px 12px;
    background: var(--bz-surface);
    border-top: 1px solid var(--bz-line);
}
#bizmatch-chat-input {
    flex: 1;
    min-width: 0;
    height: 42px;
    padding: 0 16px;
    border: 1px solid var(--bz-line);
    border-radius: 999px;
    background: #f6f7fa;
    color: var(--bz-ink);
    font: inherit;
    font-size: 14.5px;
    outline: none;
    box-shadow: none;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
#bizmatch-chat-input::placeholder { color: #8b92a0; }
#bizmatch-chat-input:focus {
    background: #fff;
    border-color: var(--bz-brand);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, .06);
}
#bizmatch-chat-send {
    flex-shrink: 0;
    height: 42px;
    padding: 0 20px;
    border: 0;
    border-radius: 999px;
    background: var(--bz-brand);
    color: var(--bz-on-brand);
    font: inherit;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    transition: filter .15s ease, transform .15s ease;
}
#bizmatch-chat-send:hover:not(:disabled) { filter: brightness(1.1); }
#bizmatch-chat-send:active:not(:disabled) { transform: scale(.97); }
#bizmatch-chat-send:disabled,
#bizmatch-chat-input:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Focus bàn phím ---------- */
.bizmatch-launcher:focus-visible,
#bizmatch-chat-send:focus-visible,
#bizmatch-chat-close:focus-visible {
    outline: 3px solid rgba(255, 255, 255, .85);
    outline-offset: 2px;
    box-shadow: 0 0 0 5px var(--bz-brand);
}

/* ---------- Mobile ---------- */
@media (max-width: 480px) {
    .bizmatch-box,
    .bizmatch-box.pos-left {
        left: 12px;
        right: 12px;
        bottom: 76px;
        width: auto;
        max-width: none;
        height: 72vh;
    }
    .bizmatch-launcher { right: 12px; bottom: 12px; }
    .bizmatch-launcher.pos-left { left: 12px; right: auto; }
}

@media (prefers-reduced-motion: reduce) {
    .bizmatch-box, .b-dots i { animation: none; }
    .bizmatch-launcher, #bizmatch-chat-send { transition: none; }
    .bizmatch-messages { scroll-behavior: auto; }
}
