/* 💬 KHUNG HỖ TRỢ (chatbot AI + gặp admin) — thiết kế 2026-11-16 kiểu chat chăm sóc khách hiện đại.
   Dùng chung App + landing (landing nhận bản chép qua landing/tools/build_seo.py).
   Sáng mặc định; Tối khi <html data-theme="dark"> mà không có .theme-sale (App) — landing cũng đặt data-theme.
   Icon là SVG nội tuyến (landing không có sprite chung). Điện thoại: khung phủ toàn màn hình, ô nhập 16px. */
.ht {
    --ht-a: #2f6fed; --ht-a-h: #255ed1; --ht-a-soft: #eaf1ff; --ht-bg: #ffffff; --ht-soft: #f4f6fb; --ht-line: #e4e8f0;
    --ht-text: #141a26; --ht-body: #2b3242; --ht-muted: #5d6576; --ht-ok: #0f9d74; --ht-ok-soft: #dcf5ec;
    --ht-red: #e5484d; --ht-warn-soft: #fff4d6; --ht-warn: #8a5a00;
    --ht-shadow: 0 24px 64px -16px rgba(20, 26, 38, .28), 0 4px 14px -6px rgba(20, 26, 38, .12);
    --ht-r: 18px;
    position: fixed; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom));
    z-index: 2147483000; color: var(--ht-text); max-width: calc(100vw - 16px);
    transform: translateY(calc(-1 * var(--ht-nang, 0px))); transition: transform .2s ease;
    font: 400 14px/1.55 Inter, 'Nunito Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}
.ht *, .ht *::before, .ht *::after { box-sizing: border-box; }
.ht [hidden] { display: none !important; }
.ht button { font: inherit; cursor: pointer; color: inherit; }
.ht svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ht :focus-visible { outline: 2px solid var(--ht-a); outline-offset: 2px; }
.ht .ht-input textarea:focus-visible { outline: none; }   /* viền đã nằm ở cả viên nhập */

/* ---------- nút tròn mở chat ---------- */
.ht-fab {
    position: relative; width: 60px; height: 60px; border: 0; border-radius: 50%; color: #fff; background: var(--ht-a);
    display: grid; place-items: center; box-shadow: 0 14px 32px -10px rgba(47, 111, 237, .7);
    transition: transform .25s cubic-bezier(.2, .8, .2, 1), background .2s;
}
.ht-fab:hover { background: var(--ht-a-h); transform: translateY(-2px); }
.ht-fab svg { width: 26px; height: 26px; transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .2s; }
.ht-fab .ht-fab-x { position: absolute; opacity: 0; transform: rotate(-90deg) scale(.6); }
.ht.open .ht-fab .ht-fab-i { opacity: 0; transform: rotate(90deg) scale(.6); }
.ht.open .ht-fab .ht-fab-x { opacity: 1; transform: none; }
.ht-badge {
    position: absolute; top: -3px; right: -3px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
    background: var(--ht-red); color: #fff; font: 800 11.5px/18px inherit; text-align: center; border: 2px solid var(--ht-bg);
}

/* lời chào nhỏ cạnh nút (hiện 1 lần / trình duyệt) */
.ht-teaser {
    position: absolute; right: 0; bottom: 74px; width: max-content; max-width: min(280px, calc(100vw - 40px));
    display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border-radius: 16px 16px 4px 16px;
    background: var(--ht-bg); color: var(--ht-body); border: 1px solid var(--ht-line); box-shadow: var(--ht-shadow);
    font-size: 13.5px; cursor: pointer; animation: ht-in .35s cubic-bezier(.2, .8, .2, 1);
}
.ht-teaser b { display: block; color: var(--ht-text); font-weight: 700; margin-bottom: 2px; }
.ht-teaser-x { margin: -6px -8px 0 0; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--ht-muted); display: grid; place-items: center; }
.ht-teaser-x:hover { background: var(--ht-soft); }
.ht-teaser-x svg { width: 14px; height: 14px; }

/* ---------- khung chat ---------- */
.ht-panel {
    position: absolute; right: 0; bottom: 76px; width: min(400px, calc(100vw - 40px)); height: min(640px, calc(100dvh - 120px));
    background: var(--ht-bg); border-radius: 22px; border: 1px solid var(--ht-line); box-shadow: var(--ht-shadow);
    display: flex; flex-direction: column; overflow: hidden; transform-origin: bottom right;
    animation: ht-in .3s cubic-bezier(.2, .8, .2, 1);
}
@keyframes ht-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }

.ht-head {
    position: relative; display: flex; align-items: center; gap: 12px; padding: 16px 14px 14px 18px; color: #fff;
    background: linear-gradient(135deg, #2a62d9 0%, #1d4fbf 100%);
}
.ht-ava { position: relative; width: 42px; height: 42px; flex: none; border-radius: 14px; display: grid; place-items: center;
    background: rgba(255, 255, 255, .18); border: 1px solid rgba(255, 255, 255, .28); }
.ht-ava svg { width: 22px; height: 22px; }
.ht-ava::after { content: ''; position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%;
    background: #34d399; border: 2px solid #2f6fed; }
.ht-head-t { min-width: 0; flex: 1; }
.ht-head-t b { display: block; font-size: 16px; font-weight: 800; letter-spacing: -.01em; line-height: 1.3; }
.ht-head-t span { display: block; font-size: 12.5px; color: #e8efff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ht-iconbtn { width: 40px; height: 40px; flex: none; border: 0; border-radius: 11px; display: grid; place-items: center;
    background: rgba(255, 255, 255, .14); color: #fff; transition: background .15s; }
.ht-iconbtn:hover { background: rgba(255, 255, 255, .26); }

/* tab dạng nút phân đoạn */
.ht-tabs { display: flex; gap: 4px; margin: 12px 14px 0; padding: 4px; border-radius: 14px; background: var(--ht-soft); border: 1px solid var(--ht-line); }
.ht-tabs button { flex: 1; min-width: 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0;
    background: transparent; min-height: 40px; padding: 8px 6px; border-radius: 10px; font-size: 12.5px; font-weight: 700; color: var(--ht-muted);
    white-space: nowrap; transition: background .15s, color .15s; }
.ht-tabs button svg { width: 15px; height: 15px; }
.ht-tabs button span { overflow: hidden; text-overflow: ellipsis; }
.ht-tabs button:hover { color: var(--ht-text); }
.ht-tabs button.on { background: var(--ht-bg); color: var(--ht-a); box-shadow: 0 1px 4px rgba(20, 26, 38, .08); }
.ht-mini { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--ht-red); color: #fff; font: 800 10.5px/18px inherit; }

.ht-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ht-msgs, .ht-scroll { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 12px;
    overscroll-behavior: contain; scrollbar-width: thin; }

/* màn chào khi chưa nhắn */
.ht-hello { padding: 4px 4px 2px; }
.ht-hello h4 { margin: 0 0 4px; font-size: 19px; line-height: 1.3; font-weight: 800; letter-spacing: -.015em; color: var(--ht-text); }
.ht-hello p { margin: 0; color: var(--ht-muted); font-size: 13.5px; }
.ht-quick { display: grid; gap: 8px; }
.ht-quick button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 11px 12px; border-radius: 14px;
    border: 1px solid var(--ht-line); background: var(--ht-bg); color: var(--ht-body); font-size: 13.5px; font-weight: 600;
    transition: border-color .15s, background .15s, transform .15s; }
.ht-quick button:hover { border-color: var(--ht-a); background: var(--ht-a-soft); transform: translateY(-1px); }
.ht-quick button > i { width: 32px; height: 32px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--ht-a-soft); color: var(--ht-a); }
.ht-quick button > span { flex: 1; min-width: 0; }
.ht-quick button > svg { color: var(--ht-muted); width: 16px; height: 16px; }

/* tin nhắn */
.ht-m { display: flex; gap: 8px; align-items: flex-end; max-width: 100%; }
.ht-m-ava { width: 28px; height: 28px; flex: none; border-radius: 9px; display: grid; place-items: center; background: var(--ht-a-soft); color: var(--ht-a); }
.ht-m-ava svg { width: 15px; height: 15px; }
.ht-adm .ht-m-ava { background: var(--ht-ok-soft); color: var(--ht-ok); }
.ht-m-col { min-width: 0; max-width: calc(100% - 44px); display: flex; flex-direction: column; gap: 4px; }
.ht-m small { font-size: 11.5px; color: var(--ht-muted); font-weight: 700; padding: 0 2px; }
.ht-bub { padding: 10px 13px; border-radius: 16px; color: var(--ht-body); background: var(--ht-soft); border-bottom-left-radius: 5px;
    overflow-wrap: anywhere; }
.ht-bub p { margin: 0; }
.ht-bub p + p, .ht-bub p + ul, .ht-bub ul + p { margin-top: 6px; }
.ht-bub ul { margin: 0; padding-left: 18px; }
.ht-bub li + li { margin-top: 3px; }
.ht-bub a { color: var(--ht-a); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.ht-adm .ht-bub { background: var(--ht-ok-soft); }
.ht-me { justify-content: flex-end; }
.ht-me .ht-m-col { align-items: flex-end; max-width: 84%; }
.ht-me .ht-bub { background: var(--ht-a); color: #fff; border-radius: 16px; border-bottom-right-radius: 5px; }
.ht-me .ht-bub a { color: #fff; }
.ht-need { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--ht-a); background: var(--ht-bg);
    color: var(--ht-a); border-radius: 11px; padding: 7px 11px; font-size: 12.5px; font-weight: 700; text-align: left; }
.ht-need:hover { background: var(--ht-a-soft); }
.ht-need svg { width: 14px; height: 14px; }
.ht-typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.ht-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--ht-muted); animation: ht-b 1.2s infinite; }
.ht-typing i:nth-child(2) { animation-delay: .15s; } .ht-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ht-b { 0%, 60%, 100% { transform: translateY(0); opacity: .35; } 30% { transform: translateY(-4px); opacity: 1; } }

/* ô nhập dạng viên */
.ht-input { padding: 10px 12px 12px; border-top: 1px solid var(--ht-line); background: var(--ht-bg); }
.ht-input-row { display: flex; align-items: flex-end; gap: 6px; padding: 5px 5px 5px 14px; border-radius: 22px; background: var(--ht-soft);
    border: 1px solid var(--ht-line); transition: border-color .15s, box-shadow .15s, background .15s; }
.ht-input-row:focus-within { border-color: var(--ht-a); background: var(--ht-bg); box-shadow: 0 0 0 3px rgba(47, 111, 237, .15); }
.ht-input textarea { flex: 1; min-width: 0; resize: none; border: 0; background: transparent; padding: 8px 0; font: inherit; font-size: 14px;
    line-height: 1.45; max-height: 120px; outline: none; color: var(--ht-text); }
.ht-input textarea::placeholder { color: var(--ht-muted); }
.ht-send { width: 40px; height: 40px; flex: none; border: 0; border-radius: 50%; display: grid; place-items: center; background: var(--ht-a); color: #fff;
    transition: background .15s, opacity .15s, transform .15s; }
.ht-send:hover { background: var(--ht-a-h); }
.ht-send:disabled { opacity: .4; cursor: default; transform: none; }
.ht-send svg { width: 17px; height: 17px; }
.ht-foot { margin: 0; padding: 0 14px 10px; background: var(--ht-bg); text-align: center; font-size: 11px; line-height: 1.4; color: var(--ht-muted); }
.ht-input:has(+ .ht-foot) { padding-bottom: 8px; }

/* tab Gặp admin */
.ht-lbl { margin: 0; font-size: 11.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--ht-muted); }
.ht-chs { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; }
.ht-ch { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 10px 12px; border: 1px solid var(--ht-line); border-radius: 14px;
    text-decoration: none; color: var(--ht-text); background: var(--ht-bg); transition: border-color .15s, transform .15s; }
.ht-ch:hover { border-color: var(--ht-a); transform: translateY(-1px); }
.ht-ch > i { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--ht-a-soft); color: var(--ht-a); }
.ht-ch > span { min-width: 0; display: flex; flex-direction: column; }
.ht-ch b { font-size: 13.5px; font-weight: 700; }
.ht-ch small { color: var(--ht-muted); font-size: 11.5px; overflow-wrap: anywhere; }   /* số điện thoại / email phải đọc đủ, không "…" */
.ht-or { display: flex; align-items: center; gap: 10px; margin: 2px 0; font-size: 12px; color: var(--ht-muted); }
.ht-or::before, .ht-or::after { content: ''; flex: 1; height: 1px; background: var(--ht-line); }
.ht-form { display: flex; flex-direction: column; gap: 10px; }
.ht-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 700; color: var(--ht-body); }
.ht-form input, .ht-form textarea { width: 100%; border: 1px solid var(--ht-line); border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 14px;
    background: var(--ht-soft); outline: none; color: var(--ht-text); resize: vertical; transition: border-color .15s, background .15s, box-shadow .15s; }
.ht-form input:focus, .ht-form textarea:focus { border-color: var(--ht-a); background: var(--ht-bg); box-shadow: 0 0 0 3px rgba(47, 111, 237, .15); }
.ht-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; border: 0; border-radius: 12px; padding: 10px 14px;
    font-weight: 800; color: #fff; background: var(--ht-a); transition: background .15s; }
.ht-btn:hover { background: var(--ht-a-h); }
.ht-btn:disabled { opacity: .55; cursor: wait; }
.ht-err { margin: 0; color: var(--ht-red); font-size: 12.5px; }
.ht-ok { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 10px 12px; border-radius: 12px; background: var(--ht-ok-soft); color: var(--ht-ok); font-size: 13px; font-weight: 600; }
.ht-hours { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 0; font-size: 12px; color: var(--ht-muted); text-align: center; }
.ht-hours svg { width: 14px; height: 14px; }

/* tab Yêu cầu của tôi */
.ht-empty { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; color: var(--ht-muted); padding: 24px 12px; }
.ht-empty i { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; background: var(--ht-soft); color: var(--ht-muted); }
.ht-empty i svg { width: 24px; height: 24px; }
.ht-tk { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; text-align: left; padding: 12px 14px;
    border: 1px solid var(--ht-line); border-radius: 14px; background: var(--ht-bg); color: var(--ht-text); transition: border-color .15s; }
.ht-tk:hover { border-color: var(--ht-a); }
.ht-tk b { font-weight: 700; overflow: hidden; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ht-tk small { grid-column: 1 / -1; color: var(--ht-muted); font-size: 11.5px; }
.ht-st { justify-self: start; font-size: 11px; font-weight: 800; padding: 3px 9px; border-radius: 999px; background: var(--ht-warn-soft); color: var(--ht-warn); white-space: nowrap; }
.ht-st-da_tra_loi { background: var(--ht-a-soft); color: var(--ht-a); }
.ht-st-dong { background: var(--ht-ok-soft); color: var(--ht-ok); }
.ht-back { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; color: var(--ht-a); font-weight: 700; padding: 4px 0; }
.ht-back svg { width: 16px; height: 16px; }
.ht-thread { display: flex; flex-direction: column; gap: 12px; }

/* ---------- điện thoại: phủ toàn màn hình ---------- */
/* điện thoại: ô nhập 16px (iPhone không tự phóng to) — mốc 640px theo chuẩn chung */
@media (max-width: 640px) {
    .ht-input textarea, .ht-form input, .ht-form textarea { font-size: 16px; }
    .ht-tabs button { min-height: 44px; }
}
@media (max-width: 520px) {
    .ht { right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); }
    .ht-fab { width: 56px; height: 56px; }
    .ht.open { transform: none; }
    .ht-panel { position: fixed; inset: 0; width: 100%; max-width: 100vw; height: 100dvh; border-radius: 0; border: 0;
        padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }
    .ht-head { padding-top: 14px; }
    .ht.open .ht-fab { display: none; }
    .ht-input textarea, .ht-form input, .ht-form textarea { font-size: 16px; }   /* iPhone không tự phóng to */
    .ht-tabs button { padding: 10px 4px; }
    .ht-teaser { display: none !important; }   /* điện thoại: lời chào nhỏ che nội dung trang (landing hero) ⇒ ẩn */
}
@media (prefers-reduced-motion: reduce) {
    .ht-panel, .ht-teaser, .ht-typing i, .ht-fab svg { animation: none; transition: none; }
}

/* ---------- 🌙 TỐI ---------- */
html[data-theme="dark"]:not(.theme-sale) .ht {
    --ht-a: #4b82f7; --ht-a-h: #6393fa; --ht-a-soft: rgba(75, 130, 247, .16); --ht-bg: #17181c; --ht-soft: #212328; --ht-line: #2d3038;
    --ht-text: #f1f2f5; --ht-body: #d9dce3; --ht-muted: #a1a6b1; --ht-ok: #4ade80; --ht-ok-soft: rgba(74, 222, 128, .13);
    --ht-red: #f87171; --ht-warn-soft: rgba(251, 191, 36, .14); --ht-warn: #fcd34d;
    --ht-shadow: 0 24px 64px -16px rgba(0, 0, 0, .75), 0 4px 14px -6px rgba(0, 0, 0, .5);
    color-scheme: dark;
}
html[data-theme="dark"]:not(.theme-sale) .ht-me .ht-bub { background: #3a6fe0; }
html[data-theme="dark"]:not(.theme-sale) .ht-ava::after { border-color: #2f6fed; }

/* 🛡️ ô xác minh chống robot (captcha.js) — hiện khi máy chủ yêu cầu, dưới tin nhắn / trên nút gửi phiếu */
.ht .ht-cap { margin: 0 12px 8px; max-width: calc(100% - 24px); }
.ht .ht-form .ht-cap { margin: 0 0 10px; max-width: 100%; }
.ht .ht-cap[hidden] { display: none; }
