/* K-Bot: khung chat trợ lý AI (nạp khi K-Bot đang bật) */
.kb-nut, .kb-khung { --kb-navy: var(--navy, #0A1428); --kb-navy-2: var(--navy-2, #12233F); --kb-red: var(--red, #E10600); --kb-cyan: var(--cyan, #22D3EE);
    --kb-mat: var(--surface, #F3F6FA); --kb-vien: var(--line, #DCE3EE); --kb-vien-2: var(--line-2, #C7D2E0); --kb-chu: var(--ink, #0A1428); --kb-chu-2: var(--ink-2, #4B5870); --kb-chu-3: var(--ink-3, #74829A);
    font-family: var(--font, "Be Vietnam Pro", "Segoe UI", Roboto, Arial, sans-serif); }
.kb-an { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.kb-nut svg, .kb-khung svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Nút mở: nằm trên nút Zalo ---------- */
.kb-nut { position: fixed; z-index: 41; right: max(16px, env(safe-area-inset-right)); bottom: calc(72px + env(safe-area-inset-bottom));
    display: flex; align-items: center; gap: 5px; min-height: 42px; padding: 7px 10px; border: 0; border-radius: 999px;
    background: var(--kb-navy); color: #fff; font-weight: 600; font-size: .875rem; line-height: 1.2; box-shadow: 0 6px 16px rgba(6, 11, 22, .25), 0 0 0 1px rgba(255, 255, 255, .28); cursor: pointer; }
.kb-nut:hover { background: var(--kb-navy-2); }
.kb-nut__ic { width: 24px; height: 24px; position: relative; flex: none; }
.kb-nut__ic .kb-robot { display: block; width: 100%; height: auto; }
.kb-nut__ai { padding: 2px 6px; border: 1px solid rgba(34, 211, 238, .6); border-radius: 4px; color: var(--kb-cyan); font-size: .6875rem; letter-spacing: .02em; }
.kb-nut[aria-expanded="true"] { visibility: hidden; }
body.co-kbot .totop { bottom: calc(128px + env(safe-area-inset-bottom)); }

/* Chuông báo: chấm đỏ và rung nhẹ khi K-Bot tự chào */
.kb-nut--bao .kb-nut__ic::after { content: ""; position: absolute; z-index: 1; top: -2px; right: -2px; width: 7px; height: 7px; border-radius: 50%; background: var(--kb-red); box-shadow: 0 0 0 2px var(--kb-navy); }
.kb-nut--bao .kb-nut__ic .kb-robot { animation: kb-rung 1.1s ease-in-out 3; transform-origin: 50% 90%; }
@keyframes kb-rung { 0%, 50%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(-14deg); } 20%, 40% { transform: rotate(14deg); } }

/* Lời chào nhỏ trên điện thoại */
.kb-chao { position: fixed; z-index: 42; right: max(10px, env(safe-area-inset-right)); bottom: calc(118px + env(safe-area-inset-bottom));
    display: flex; align-items: flex-start; gap: 2px; width: min(300px, calc(100vw - 20px)); padding: 4px 4px 4px 0; border-radius: 12px; background: #fff;
    box-shadow: 0 12px 32px rgba(6, 11, 22, .26), 0 0 0 1px rgba(10, 20, 40, .08); font-family: var(--font, "Be Vietnam Pro", sans-serif); animation: kb-hien .35s ease-out; }
.kb-chao::after { content: ""; position: absolute; right: 26px; bottom: -6px; width: 12px; height: 12px; background: #fff; transform: rotate(45deg); box-shadow: 3px 3px 6px rgba(6, 11, 22, .08); }
.kb-chao__mo { flex: 1; display: flex; align-items: flex-start; gap: 8px; padding: 10px 6px 10px 10px; border: 0; background: transparent; color: var(--ink, #0A1428); font: inherit; font-size: .875rem; line-height: 1.45; text-align: left; cursor: pointer; }
.kb-chao__anh { width: 46px; height: auto; flex: none; margin-top: -2px; }
.kb-chao__mo strong { display: block; margin-bottom: 2px; color: var(--navy, #0A1428); font-size: .8125rem; }
.kb-chao__dong { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--ink-3, #74829A); font-size: 1rem; cursor: pointer; flex: none; }
.kb-chao__dong svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.kb-chao__dong:hover { background: var(--surface, #F3F6FA); color: var(--ink, #0A1428); }
.kb-chao :focus-visible { outline: 3px solid var(--cyan, #22D3EE); outline-offset: 2px; }
body.kb-co-chao .totop { visibility: hidden; }
@keyframes kb-hien { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Khung chat ---------- */
.kb-khung { position: fixed; z-index: 70; right: max(16px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom));
    width: min(286px, calc(100% - 32px)); height: 400px;
    max-height: calc(100% - 36px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    display: flex; flex-direction: column; overflow: hidden; background: #fff; color: var(--kb-chu); border-radius: 14px;
    box-shadow: 0 24px 60px rgba(6, 11, 22, .32), 0 0 0 1px rgba(10, 20, 40, .06); font-size: .9375rem; line-height: 1.55; }
.kb-khung[hidden] { display: none; }

.kb-dau { display: flex; align-items: center; gap: 10px; padding: 12px 8px 12px 14px; background: var(--kb-navy); color: #fff; }
.kb-dau__anh { position: relative; width: 40px; height: 40px; flex: none; }
.kb-dau__anh .kb-robot { position: absolute; left: -6px; top: -6px; width: 52px; height: auto; max-width: none; }
.kb-dau__ten { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.kb-dau__ten strong { font-family: var(--font-cond, "Chakra Petch", sans-serif); font-size: 1.125rem; font-weight: 700; letter-spacing: .01em; display: flex; align-items: center; gap: 8px; }
.kb-dau__ten > span { color: var(--on-dark-2, #A9B6CB); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kb-the-ai { padding: 1px 6px; border: 1px solid rgba(34, 211, 238, .6); border-radius: 4px; color: var(--kb-cyan); font-family: var(--font, sans-serif); font-size: .6875rem; font-weight: 600; }
.kb-icon { display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 8px; background: transparent; color: #fff; font-size: 1.15rem; cursor: pointer; flex: none; }
.kb-icon:hover { background: rgba(255, 255, 255, .1); }

.kb-xem-thu { margin: 0; padding: 6px 14px; background: #FFF6D6; color: #6B4E00; font-size: .78rem; font-weight: 600; }

/* Gặp kỹ sư: luôn hiện dưới đầu khung */
.kb-ky-su { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 8px 12px; background: var(--kb-mat); border-bottom: 1px solid var(--kb-vien); font-size: .8125rem; }
.kb-ky-su > span { color: var(--kb-chu-2); font-weight: 600; margin-right: 2px; }
.kb-ks { display: inline-flex; align-items: center; gap: 5px; min-height: 30px; padding: 4px 10px; border: 1px solid transparent; border-radius: 999px;
    font: inherit; font-weight: 600; font-size: .8125rem; line-height: 1.2; text-decoration: none; cursor: pointer; }
.kb-ks--goi { background: var(--kb-red); color: #fff; }
.kb-ks--zalo { background: #0068FF; color: #fff; }
.kb-ks--nho { background: #fff; color: var(--kb-navy); border-color: var(--kb-vien-2); }
.kb-ks--chat { background: #0B7A4B; color: #fff; }
.kb-ks--goi:hover, .kb-ks--zalo:hover, .kb-ks--chat:hover { color: #fff; filter: brightness(1.08); }
.kb-ks--nho:hover { border-color: var(--kb-navy); }

/* Tin nhắn */
.kb-tin { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.kb-bong { max-width: 88%; padding: 9px 12px; border-radius: 12px; overflow-wrap: anywhere; }
.kb-bong p { margin: 0 0 .5em; }
.kb-bong p:last-child, .kb-bong ul:last-child, .kb-bong ol:last-child { margin-bottom: 0; }
.kb-bong ul, .kb-bong ol { margin: 0 0 .5em; padding-left: 1.2em; }
.kb-bong li + li { margin-top: 2px; }
.kb-bong--bot { align-self: flex-start; background: var(--kb-mat); border: 1px solid var(--kb-vien); border-bottom-left-radius: 4px; }
.kb-bong--bot a { color: var(--kb-navy-2); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.kb-bong--bot a:hover { color: var(--kb-red); }
.kb-bong--khach { align-self: flex-end; background: var(--kb-navy); color: #fff; border-bottom-right-radius: 4px; white-space: normal; }
.kb-he-thong { align-self: center; max-width: 92%; margin: 0; padding: 6px 10px; border-radius: 8px; background: #EEF8FB; color: var(--kb-chu-2); font-size: .8125rem; text-align: center; }

.kb-dang-go { display: inline-flex; gap: 4px; align-items: center; padding: 12px 14px; }
.kb-dang-go i { width: 7px; height: 7px; border-radius: 50%; background: var(--kb-chu-3); animation: kb-cham 1.2s infinite ease-in-out; }
.kb-dang-go i:nth-child(3) { animation-delay: .15s; }
.kb-dang-go i:nth-child(4) { animation-delay: .3s; }
@keyframes kb-cham { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.kb-goi-y { display: flex; flex-wrap: wrap; gap: 6px; }
.kb-chip { padding: 7px 12px; border: 1px solid var(--kb-vien-2); border-radius: 999px; background: #fff; color: var(--kb-navy); font: inherit; font-size: .8125rem; font-weight: 500; line-height: 1.3; text-align: left; cursor: pointer; }
.kb-chip:hover { border-color: var(--kb-navy); background: var(--kb-mat); }

/* Thẻ gặp kỹ sư trong luồng chat */
.kb-the { align-self: stretch; padding: 10px 12px; border: 1px solid var(--kb-vien); border-left: 3px solid var(--kb-red); border-radius: 10px; background: #fff; }
.kb-the p { margin: 0 0 8px; font-size: .8125rem; font-weight: 600; color: var(--kb-chu-2); }
.kb-the__nut { display: flex; flex-wrap: wrap; gap: 6px; }

/* Form để lại số điện thoại */
.kb-form { align-self: stretch; display: grid; gap: 4px; padding: 12px; border: 1px solid var(--kb-vien-2); border-radius: 10px; background: #fff; }
.kb-form label { font-size: .8125rem; font-weight: 600; color: var(--kb-chu-2); margin-top: 4px; }
.kb-form input, .kb-form textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--kb-vien-2); border-radius: 8px; font: inherit; font-size: .9375rem; color: var(--kb-chu); background: #fff; }
.kb-form textarea { resize: vertical; min-height: 48px; }
.kb-form input:focus, .kb-form textarea:focus { border-color: var(--kb-navy); outline: 2px solid rgba(34, 211, 238, .5); outline-offset: 0; }
.kb-bay { position: absolute !important; left: -9999px !important; width: 1px !important; height: 1px !important; opacity: 0; }
.kb-form__loi { margin: 4px 0 0; color: var(--kb-red); font-size: .8125rem; font-weight: 600; }
.kb-form__dy { margin: 4px 0 0; color: var(--kb-chu-3); font-size: .75rem; }
.kb-form__nut { display: flex; gap: 8px; margin-top: 8px; }
.kb-nut-chinh, .kb-nut-phu { min-height: 38px; padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 600; font-size: .875rem; cursor: pointer; }
.kb-nut-chinh { border: 0; background: var(--kb-red); color: #fff; }
.kb-nut-chinh:hover { background: var(--red-d, #B80500); }
.kb-nut-chinh:disabled { opacity: .6; cursor: progress; }
.kb-nut-phu { border: 1px solid var(--kb-vien-2); background: #fff; color: var(--kb-chu-2); }

/* Ô nhập */
.kb-nhap { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 6px; border-top: 1px solid var(--kb-vien); background: #fff; }
.kb-nhap textarea { flex: 1; min-width: 0; height: 44px; max-height: 120px; padding: 10px 12px; border: 1px solid var(--kb-vien-2); border-radius: 10px; resize: none;
    font: inherit; font-size: 1rem; line-height: 1.4; color: var(--kb-chu); background: #fff; }
.kb-nhap textarea:focus { border-color: var(--kb-navy); outline: 2px solid rgba(34, 211, 238, .5); outline-offset: 0; }
.kb-nhap textarea:disabled { background: var(--kb-mat); }
.kb-gui { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px; background: var(--kb-navy); color: #fff; font-size: 1.25rem; cursor: pointer; flex: none; }
.kb-gui:hover { background: var(--kb-red); }
.kb-gui:disabled { opacity: .45; cursor: default; background: var(--kb-navy); }

.kb-khung :focus-visible, .kb-nut:focus-visible { outline: 3px solid var(--kb-cyan); outline-offset: 2px; }

/* ---------- Điện thoại: khung chat toàn màn hình ---------- */
@media (max-width: 640px) {
    .kb-nut { right: max(10px, env(safe-area-inset-right)); bottom: calc(64px + env(safe-area-inset-bottom)); font-size: .875rem; }
    .kb-nut__ai { display: none; }
    body.co-kbot .totop { bottom: calc(118px + env(safe-area-inset-bottom)); }
    .kb-khung { inset: 0; width: 100%; height: 100%; height: 100dvh; max-height: none; border-radius: 0; padding-bottom: env(safe-area-inset-bottom); }
    html.kb-dang-mo, html.kb-dang-mo body { overflow: hidden; }
    .kb-bong { max-width: 92%; }
    .kb-ky-su { gap: 5px; padding: 8px 10px; }
    .kb-ks { padding: 4px 8px; gap: 4px; }
}
@media (min-width: 641px) {
    .kb-chao { right: max(16px, env(safe-area-inset-right)); bottom: calc(128px + env(safe-area-inset-bottom)); }
    .kb-dau { gap: 6px; padding: 7px 6px 7px 10px; }
    .kb-dau__anh { width: 34px; height: 34px; }
    .kb-dau__anh .kb-robot { width: 46px; }
    .kb-ky-su { gap: 4px; padding: 6px 8px; }
    .kb-ks { gap: 4px; min-height: 28px; padding: 3px 6px; }
    .kb-tin { padding: 9px 9px 6px; }
    .kb-bong { max-width: 94%; }
    .kb-goi-y { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px; }
    .kb-chip { padding: 5px 7px; line-height: 1.25; overflow-wrap: anywhere; }
    .kb-nhap { padding: 6px 8px 4px; }
    .kb-nhap textarea { padding-inline: 8px; }
    .kb-nhap textarea::placeholder { font-size: .9rem; }
}
@media (prefers-reduced-motion: reduce) { .kb-dang-go i, .kb-nut--bao .kb-nut__ic .kb-robot, .kb-chao { animation: none; opacity: 1; } }
@media print { .kb-nut, .kb-khung, .kb-chao { display: none !important; } }
