/* CM AI Chatbot – khung chat frontend. Tông màu: vàng #FFCB04 + đen #333333 (đổi được trong admin). */
.hd-chatbot-root {
    --hd-chat-color: #FFCB04;      /* màu chủ đạo */
    --hd-chat-dark: #333333;       /* màu phụ: tiêu đề, chữ, viền mascot */
    --hd-chat-on-color: #333333;   /* chữ đặt trên màu chủ đạo */
    --hd-chat-on-dark: #ffffff;    /* chữ đặt trên màu phụ */
    --hd-chat-bg: #ffffff;
    --hd-chat-muted: #7a7a7a;
    --hd-chat-bubble: #f4f4f4;
    --hd-chat-border: #e6e6e6;
    --hd-chat-radius: 16px;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 99999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--hd-chat-dark);
}
.hd-chatbot-root--left { right: auto; left: 20px; }
.hd-chatbot-root *, .hd-chatbot-root *::before, .hd-chatbot-root *::after { box-sizing: border-box; }

/* Mascot robot AI */
.hd-mascot { display: block; overflow: visible; }
.hd-mascot .m-d { fill: var(--hd-chat-dark); }
.hd-mascot .m-w { fill: #fff; }
.hd-mascot .m-y { fill: var(--hd-chat-color); }
.hd-mascot .m-ds { stroke: var(--hd-chat-dark); }
.hd-mascot .m-ys { fill: none; stroke: var(--hd-chat-color); }
.hd-mascot__eyes { transform-box: fill-box; transform-origin: center; animation: hd-mascot-blink 4.5s infinite; }
@keyframes hd-mascot-blink { 0%, 92%, 100% { transform: scaleY(1); } 95%, 97% { transform: scaleY(.1); } }
@keyframes hd-mascot-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }

/* Nút mở */
.hd-chat-toggle {
    position: relative;
    width: 64px; height: 64px; border-radius: 50%; cursor: pointer; padding: 0;
    background: var(--hd-chat-color); color: var(--hd-chat-on-color);
    border: 0; outline: none;
    /* Không viền: dùng hai lớp bóng mềm để nút vẫn tách khỏi nền sáng */
    box-shadow: 0 10px 28px rgba(0,0,0,.20), 0 2px 6px rgba(0,0,0,.14);
    display: flex; align-items: center; justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
}
.hd-chat-toggle:hover { transform: scale(1.06); box-shadow: 0 14px 34px rgba(0,0,0,.26), 0 3px 8px rgba(0,0,0,.16); }
.hd-chat-toggle:focus-visible { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--hd-chat-dark); }

/* Không để outline/viền focus dính lại sau khi click hay chạm. Dùng !important vì CSS của theme hoặc plugin khác
   có thể đặt outline cho button:focus. Người dùng bàn phím vẫn có vòng focus riêng qua :focus-visible ở trên. */
.hd-chatbot-root button,
.hd-chatbot-root button:focus,
.hd-chatbot-root button:active,
.hd-chatbot-root button:focus-visible {
    outline: none !important;
    -webkit-tap-highlight-color: transparent;
}
.hd-chatbot-root button::-moz-focus-inner { border: 0; }
.hd-chatbot-root button { -webkit-appearance: none; appearance: none; text-decoration: none; }
.hd-chat-header__btn:focus-visible, .hd-chat-send:focus-visible, .hd-chat-suggestion:focus-visible { box-shadow: 0 0 0 2px var(--hd-chat-color); }
.hd-chat-toggle__open, .hd-chat-toggle__close { display: flex; }
.hd-chat-toggle__open .hd-mascot { width: 44px; height: 44px; animation: hd-mascot-float 3s ease-in-out infinite; }
.hd-chat-toggle__close svg { width: 26px; height: 26px; fill: currentColor; }
.hd-chat-toggle__close { display: none; }
.hd-chatbot-root.is-open .hd-chat-toggle__open { display: none; }
.hd-chatbot-root.is-open .hd-chat-toggle__close { display: flex; }
.hd-chat-toggle__badge {
    position: absolute; top: 0; right: 0; width: 16px; height: 16px; border-radius: 50%;
    background: #ef4444; border: 2px solid #fff;
}
.hd-chatbot-root.is-open .hd-chat-toggle__badge, .hd-chatbot-root.is-seen .hd-chat-toggle__badge { display: none; }

/* Cửa sổ */
.hd-chat-window {
    position: absolute; bottom: 80px; right: 0;
    width: 380px; max-width: calc(100vw - 40px); height: 560px; max-height: calc(100vh - 120px);
    background: var(--hd-chat-bg); border-radius: var(--hd-chat-radius);
    box-shadow: 0 16px 48px rgba(0,0,0,.28);
    display: flex; flex-direction: column; overflow: hidden;
    opacity: 0; visibility: hidden; transform: translateY(12px) scale(.98);
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
}
.hd-chatbot-root--left .hd-chat-window { right: auto; left: 0; }
.hd-chatbot-root.is-open .hd-chat-window { opacity: 1; visibility: visible; transform: none; }

/* Tiêu đề: nền đen, viền dưới vàng */
.hd-chat-header {
    background: var(--hd-chat-dark); color: var(--hd-chat-on-dark); padding: 12px 14px;
    border-bottom: 3px solid var(--hd-chat-color);
    display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.hd-chat-header__avatar {
    width: 44px; height: 44px; border-radius: 50%; background: var(--hd-chat-color);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.hd-chat-header__avatar .hd-mascot { width: 32px; height: 32px; }
.hd-chat-header__title { font-weight: 700; font-size: 15px; color: var(--hd-chat-color); }
.hd-chat-header__status { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 5px; }
.hd-chat-header__status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #4ade80; }
.hd-chat-header__actions { margin-left: auto; display: flex; gap: 4px; }
.hd-chat-header__btn {
    background: transparent; border: 0; color: inherit; cursor: pointer; padding: 6px; border-radius: 8px; opacity: .8;
    display: flex; transition: background .15s, color .15s, opacity .15s;
}
.hd-chat-header__btn:hover { background: var(--hd-chat-color); color: var(--hd-chat-on-color); opacity: 1; }
.hd-chat-header__btn svg { width: 18px; height: 18px; fill: currentColor; }

/* Nút gặp nhân viên, ngay dưới tiêu đề */
.hd-chat-contacts {
    display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 8px 12px; flex-shrink: 0;
    background: #fafafa; border-bottom: 1px solid var(--hd-chat-border); font-size: 12px;
}
.hd-chat-contacts__label { color: var(--hd-chat-muted); margin-right: 2px; }
.hd-chat-contact {
    display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
    background: #fff; border: 1.5px solid var(--hd-chat-dark); color: var(--hd-chat-dark) !important;
    text-decoration: none !important; font-weight: 600; line-height: 1.3; transition: background .15s, border-color .15s;
}
.hd-chat-contact:hover, .hd-chat-contact:focus-visible { background: var(--hd-chat-color); border-color: var(--hd-chat-color); color: var(--hd-chat-on-color) !important; outline: none; }
.hd-chat-contact svg { width: 13px; height: 13px; fill: currentColor; flex-shrink: 0; }

/* Vùng chỉ dành cho trình đọc màn hình */
.hd-chat-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* Tin nhắn */
.hd-chat-messages {
    flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px;
    scroll-behavior: smooth; -webkit-overflow-scrolling: touch; background: var(--hd-chat-bg);
}
.hd-chat-msg { max-width: 85%; padding: 10px 14px; border-radius: 14px; word-wrap: break-word; white-space: pre-wrap; }
.hd-chat-msg--bot { align-self: flex-start; background: var(--hd-chat-bubble); color: var(--hd-chat-dark); border-bottom-left-radius: 4px; }
.hd-chat-msg--user { align-self: flex-end; background: var(--hd-chat-color); color: var(--hd-chat-on-color); border-bottom-right-radius: 4px; }
.hd-chat-msg--error { align-self: center; background: #fef2f2; color: #b91c1c; font-size: 13px; text-align: center; }
.hd-chat-msg a { color: inherit; text-decoration: underline; text-decoration-color: var(--hd-chat-color); text-decoration-thickness: 2px; }
.hd-chat-msg--user a { text-decoration-color: currentColor; }
.hd-chat-msg strong { font-weight: 700; }
.hd-chat-msg ul { margin: 4px 0 0; padding-left: 18px; white-space: normal; }
.hd-chat-msg li { margin: 2px 0; }
.hd-chat-msg li::marker { color: var(--hd-chat-dark); }
.hd-chat-msg--typing { display: flex; gap: 4px; padding: 14px; }
.hd-chat-msg--typing span {
    width: 7px; height: 7px; border-radius: 50%; background: var(--hd-chat-dark); opacity: .4;
    animation: hd-chat-blink 1.2s infinite;
}
.hd-chat-msg--typing span:nth-child(2) { animation-delay: .2s; }
.hd-chat-msg--typing span:nth-child(3) { animation-delay: .4s; }
@keyframes hd-chat-blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.hd-chat-cursor::after { content: "▍"; animation: hd-chat-blink .8s infinite; color: var(--hd-chat-color); }

/* Câu hỏi gợi ý */
.hd-chat-suggestions { display: flex; flex-wrap: wrap; gap: 6px; align-self: flex-start; max-width: 95%; }
.hd-chat-suggestion {
    background: #fff; border: 1.5px solid var(--hd-chat-dark); color: var(--hd-chat-dark);
    border-radius: 999px; padding: 6px 12px; font-size: 13px; cursor: pointer; font-family: inherit;
    transition: background .15s, border-color .15s;
}
.hd-chat-suggestion:hover { background: var(--hd-chat-color); border-color: var(--hd-chat-color); color: var(--hd-chat-on-color); }

/* Ô nhập */
.hd-chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--hd-chat-border); flex-shrink: 0; background: var(--hd-chat-bg); }
.hd-chat-input {
    flex: 1; resize: none; border: 1.5px solid var(--hd-chat-border); border-radius: 12px; padding: 10px 12px;
    font: inherit; color: var(--hd-chat-dark); max-height: 120px; min-height: 42px; line-height: 1.4; outline: none; background: #fff;
    transition: border-color .15s, box-shadow .15s;
    overflow-y: hidden; /* chat.js bật lại khi nội dung vượt chiều cao tối đa */
    box-shadow: none; -webkit-appearance: none; appearance: none; margin: 0; height: 42px;
}
/* Thanh cuộn mảnh cho ô nhập và danh sách tin nhắn */
.hd-chat-input, .hd-chat-messages { scrollbar-width: thin; scrollbar-color: #c9c9c9 transparent; }
.hd-chat-input::-webkit-scrollbar, .hd-chat-messages::-webkit-scrollbar { width: 6px; }
.hd-chat-input::-webkit-scrollbar-track, .hd-chat-messages::-webkit-scrollbar-track { background: transparent; }
.hd-chat-input::-webkit-scrollbar-thumb, .hd-chat-messages::-webkit-scrollbar-thumb { background: #c9c9c9; border-radius: 3px; }
.hd-chat-input::-webkit-scrollbar-thumb:hover, .hd-chat-messages::-webkit-scrollbar-thumb:hover { background: var(--hd-chat-dark); }
.hd-chat-input::placeholder { color: var(--hd-chat-muted); }
.hd-chat-input:focus { border-color: var(--hd-chat-color); box-shadow: 0 0 0 3px rgba(255, 203, 4, .25); }
.hd-chat-send {
    width: 42px; height: 42px; border-radius: 12px; border: 0; cursor: pointer;
    background: var(--hd-chat-color); color: var(--hd-chat-on-color);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
    transition: background .15s, color .15s;
}
.hd-chat-send:hover:not(:disabled) { background: var(--hd-chat-dark); color: var(--hd-chat-color); }
.hd-chat-send:disabled { opacity: .5; cursor: default; }
.hd-chat-send svg { width: 20px; height: 20px; fill: currentColor; }
.hd-chat-footer { font-size: 11px; line-height: 1.4; color: var(--hd-chat-muted); text-align: center; padding: 0 12px 8px; background: var(--hd-chat-bg); }
.hd-chat-footer__consent { margin-bottom: 2px; }
.hd-chat-footer a { color: inherit; text-decoration: underline; }

/* Lời mời chat cạnh nút mở */
.hd-chat-teaser {
    position: absolute; bottom: 12px; right: 76px; display: flex; align-items: center; gap: 2px;
    background: #fff; color: var(--hd-chat-dark); border-radius: 14px; border-bottom-right-radius: 4px;
    box-shadow: 0 8px 24px rgba(0,0,0,.18), 0 1px 4px rgba(0,0,0,.12); padding: 4px 4px 4px 12px;
    white-space: nowrap; max-width: calc(100vw - 110px); animation: hd-chat-teaser-in .35s ease both;
}
.hd-chatbot-root--left .hd-chat-teaser { right: auto; left: 76px; border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }
.hd-chat-teaser[hidden], .hd-chatbot-root.is-open .hd-chat-teaser { display: none; }
.hd-chat-teaser__text {
    background: none; border: 0; padding: 6px 2px; margin: 0; cursor: pointer; font: inherit; font-size: 14px; font-weight: 600;
    color: inherit; overflow: hidden; text-overflow: ellipsis;
}
.hd-chat-teaser__close { background: none; border: 0; padding: 6px; margin: 0; cursor: pointer; color: var(--hd-chat-muted); display: flex; border-radius: 50%; }
.hd-chat-teaser__close:hover { background: var(--hd-chat-bubble); color: var(--hd-chat-dark); }
.hd-chat-teaser__close svg { width: 12px; height: 12px; fill: currentColor; }
@keyframes hd-chat-teaser-in { from { opacity: 0; transform: translateY(6px) scale(.96); } to { opacity: 1; transform: none; } }
/* Khung chat được mở lại sau khi chuyển trang thì không chạy lại hiệu ứng mở */
.hd-chatbot-root.is-restored .hd-chat-window { transition: none; }

/* Vuốt tới cuối danh sách tin nhắn không kéo theo trang nền */
.hd-chat-messages { overscroll-behavior: contain; }
/* chat.js gắn lớp này khi khung chat mở toàn màn hình trên điện thoại */
html.hd-chat-lock, html.hd-chat-lock body { overflow: hidden !important; }

/* iOS Safari tự phóng to trang khi focus vào ô nhập có cỡ chữ dưới 16px */
@media (hover: none) and (pointer: coarse) {
    .hd-chat-input { font-size: 16px; }
}
@media (max-width: 480px) {
    .hd-chatbot-root { bottom: 12px; right: 12px; }
    .hd-chatbot-root--left { left: 12px; }
    .hd-chat-window {
        position: fixed; inset: 0; width: 100%; max-width: none; max-height: none; border-radius: 0;
        height: 100%; height: 100dvh; /* chat.js chỉnh lại theo visualViewport khi bàn phím ảo bật */
    }
    .hd-chat-input { font-size: 16px; }
    .hd-chat-footer { padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }
    .hd-chatbot-root.is-open .hd-chat-toggle { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .hd-mascot__eyes, .hd-chat-toggle__open .hd-mascot, .hd-chat-teaser { animation: none; }
}
