/* HUD E-Brochure | Chatbot AI | Khung chat (theo sổ tay thương hiệu HUD: đỏ #ED1C24, font Cambria) */
.hudcb {
  --hudcb-red: #ED1C24;
  --hudcb-red-deep: #C4161C;
  --hudcb-gold: #B8893A;
  --hudcb-ink: #1E1F21;
  --hudcb-gray: #58595B;
  --hudcb-ground: #F1F2F2;
  --hudcb-line: #DCDDDE;
  font-family: Cambria, "Noto Serif", Georgia, "Times New Roman", serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--hudcb-ink);
  -webkit-font-smoothing: antialiased;
}
.hudcb *, .hudcb *::before, .hudcb *::after { box-sizing: border-box; }
.hudcb button, .hudcb input { font-family: inherit; letter-spacing: normal; text-transform: none; }
.hudcb p, .hudcb ul, .hudcb h2, .hudcb h3 { margin: 0; padding: 0; }
.hudcb [hidden] { display: none !important; }
.hudcb-sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hudcb svg { display: block; flex-shrink: 0; }

/* Nút mở chat */
.hudcb-launcher {
  position: fixed; right: 24px; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 2147483000;
  display: flex; align-items: center; gap: 12px; height: 60px; padding: 0 24px 0 8px; margin: 0;
  border: 0; border-radius: 999px; background: var(--hudcb-red); color: #fff;
  font-size: 17px; font-weight: 700; line-height: 1; cursor: pointer;
  box-shadow: 0 12px 26px rgba(196, 22, 28, .32);
}
.hudcb-launcher:hover { background: var(--hudcb-red-deep); }
.hudcb.is-open .hudcb-launcher { display: none; }
.hudcb-ico {
  width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .16);
  display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0;
}
.hudcb-ico img { width: 100%; height: 100%; object-fit: cover; }
.hudcb-head .hudcb-ico { width: 42px; height: 42px; }

/* Lời mời */
.hudcb-invite {
  position: fixed; right: 24px; bottom: calc(100px + env(safe-area-inset-bottom, 0px)); z-index: 2147483000;
  width: 300px; display: flex; gap: 4px; padding: 14px 6px 14px 16px;
  background: #fff; border: 1px solid var(--hudcb-line); border-radius: 14px;
  box-shadow: 0 12px 28px rgba(30, 31, 33, .14);
}
.hudcb-invite-text { flex: 1; min-width: 0; background: none; border: 0; padding: 0; text-align: left; color: #3D3E40; font-size: 14.5px; line-height: 1.55; cursor: pointer; }
.hudcb-invite-text strong { display: block; color: var(--hudcb-ink); font-size: 15px; margin-bottom: 2px; }
.hudcb-invite-close { width: 40px; height: 40px; margin-top: -8px; border: 0; background: transparent; color: var(--hudcb-gray); display: flex; align-items: center; justify-content: center; cursor: pointer; border-radius: 8px; }
.hudcb.is-open .hudcb-invite { display: none; }

/* Khung chat */
.hudcb-panel {
  overscroll-behavior: contain;
  position: fixed; right: 24px; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 2147483001;
  width: 400px; height: min(720px, calc(100vh - 48px));
  display: flex; flex-direction: column;
  filter: drop-shadow(0 16px 36px rgba(30, 31, 33, .24));
  animation: hudcb-in .22s ease-out;
}
@keyframes hudcb-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* Đầu khung: mái nhà đỏ, viền vàng */
.hudcb-head {
  display: flex; align-items: center; gap: 12px; padding: 30px 8px 14px 16px;
  background: var(--hudcb-red); color: #fff;
  clip-path: polygon(0 18px, 50% 0, 100% 18px, 100% 100%, 0 100%);
  border-bottom: 3px solid var(--hudcb-gold);
}
.hudcb-title { flex: 1; min-width: 0; }
.hudcb-title h2 { font-size: 17px; font-weight: 700; line-height: 1.3; color: #fff; }
.hudcb-status { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 1.4; }
.hudcb-online { width: 7px; height: 7px; border-radius: 50%; background: #7EE2AE; }
.hudcb-hbtn { width: 44px; height: 44px; border: 0; border-radius: 8px; background: transparent; color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.hudcb-hbtn:hover { background: rgba(255, 255, 255, .14); }

/* Thân */
.hudcb-body {
  position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
  background: #fff; padding: 16px 16px 12px; display: flex; flex-direction: column; gap: 14px;
}
.hudcb-msgs { margin-top: auto; display: flex; flex-direction: column; gap: 12px; }
.hudcb-welcome { display: flex; flex-direction: column; gap: 14px; }
.hudcb-msg { display: flex; flex-direction: column; gap: 8px; max-width: 88%; align-self: flex-start; align-items: flex-start; }
.hudcb-msg.is-user { align-self: flex-end; align-items: flex-end; max-width: 82%; }
.hudcb-bubble { padding: 10px 14px; font-size: 15px; line-height: 1.6; word-wrap: break-word; overflow-wrap: anywhere; }
.hudcb-msg.is-bot .hudcb-bubble { background: var(--hudcb-ground); border-radius: 4px 14px 14px 14px; }
.hudcb-msg.is-user .hudcb-bubble { background: var(--hudcb-red-deep); color: #fff; border-radius: 14px 4px 14px 14px; }
.hudcb-bubble p + p, .hudcb-bubble p + ul, .hudcb-bubble ul + p { margin-top: 6px; }
.hudcb-bubble ul { padding-left: 18px; }
.hudcb-bubble li + li { margin-top: 2px; }
.hudcb-bubble strong { font-weight: 700; }

.hudcb-links { display: flex; flex-wrap: wrap; gap: 6px; }
.hudcb-link {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 4px 12px; margin: 0;
  border: 1px solid var(--hudcb-line); border-radius: 999px; background: #fff;
  font-size: 13.5px; line-height: 1.35; color: var(--hudcb-red-deep); text-decoration: none; text-align: left; cursor: pointer;
}
.hudcb-link:hover { border-color: var(--hudcb-red-deep); color: var(--hudcb-red-deep); text-decoration: none; }

.hudcb-contact { display: flex; gap: 8px; width: 100%; min-width: 280px; }
.hudcb-contact a {
  flex: 1 1 0; display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 6px 10px;
  border-radius: 10px; font-size: 14.5px; font-weight: 700; text-decoration: none; text-align: center;
}
.hudcb-contact .is-call { background: var(--hudcb-red-deep); color: #fff; }
.hudcb-contact .is-mail { background: #fff; color: var(--hudcb-red-deep); border: 1px solid #9D9FA2; }

.hudcb-section { display: flex; flex-direction: column; gap: 8px; }
.hudcb-section h3 { font-size: 14px; font-weight: 700; color: var(--hudcb-gray); line-height: 1.4; }
.hudcb-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hudcb-chip {
  display: inline-flex; align-items: center; min-height: 36px; padding: 4px 14px; margin: 0;
  border: 1px solid #E8B4B6; border-radius: 999px; background: #fff;
  font-size: 14px; line-height: 1.35; color: var(--hudcb-red-deep); text-align: left; cursor: pointer;
}
.hudcb-chip:hover { background: #FDECEC; }
.hudcb-faq { border: 1px solid var(--hudcb-line); border-radius: 12px; overflow: hidden; }
.hudcb-faq button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 46px;
  padding: 8px 14px; margin: 0; border: 0; border-bottom: 1px solid #ECEDED; background: #fff;
  font-size: 15px; line-height: 1.4; color: var(--hudcb-ink); text-align: left; cursor: pointer;
}
.hudcb-faq button:last-child { border-bottom: 0; }
.hudcb-faq button:hover { background: #FAFAFA; }
.hudcb-faq svg { color: var(--hudcb-gray); }

.hudcb-typing { display: flex; gap: 5px; padding: 14px 16px; background: var(--hudcb-ground); border-radius: 4px 14px 14px 14px; align-self: flex-start; }
.hudcb-typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--hudcb-gray); animation: hudcb-dot 1.2s infinite ease-in-out; }
.hudcb-typing span:nth-child(2) { animation-delay: .15s; }
.hudcb-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes hudcb-dot { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }

/* Chân */
.hudcb-foot { background: #fff; border-top: 1px solid #ECEDED; border-radius: 0 0 16px 16px; padding: 8px 14px 10px; display: flex; flex-direction: column; gap: 8px; }
.hudcb-help { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0; border: 0; background: none; font-size: 13.5px; color: var(--hudcb-gray); cursor: pointer; }
.hudcb-help:hover { color: var(--hudcb-red-deep); }
.hudcb-form { position: relative; display: flex; gap: 8px; align-items: center; margin: 0; }
.hudcb-input {
  flex: 1; min-width: 0; height: 44px; margin: 0; padding: 0 14px;
  border: 1px solid #9D9FA2; border-radius: 10px; background: #FAFAFA;
  font-size: 15px; color: var(--hudcb-ink); box-shadow: none; outline: none;
}
.hudcb-input:focus { border-color: var(--hudcb-red-deep); background: #fff; }
.hudcb-send { width: 44px; height: 44px; flex-shrink: 0; border: 0; border-radius: 10px; background: var(--hudcb-red-deep); color: #fff; display: flex; align-items: center; justify-content: center; cursor: pointer; padding: 0; }
.hudcb-send:disabled { opacity: .55; cursor: default; }
.hudcb-note { font-size: 12.5px; line-height: 1.4; color: var(--hudcb-gray); text-align: center; }

/* Viền khi dùng bàn phím */
.hudcb button:focus-visible, .hudcb a:focus-visible, .hudcb-input:focus-visible { outline: 2px solid var(--hudcb-red-deep); outline-offset: 2px; }
.hudcb-head button:focus-visible, .hudcb-launcher:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }

/* Điện thoại: khung chat toàn màn hình */
@media (max-width: 640px) {
  /* Điện thoại: nút nở kèm chữ lúc mới vào, 3 giây sau thu thành hình tròn */
  .hudcb-launcher {
    right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    height: 56px; font-size: 16px; padding: 0 20px 0 6px; gap: 8px;
    max-width: 80vw; overflow: hidden;
    transition: padding .35s ease, gap .35s ease;
  }
  /* Chỉ ẩn thẻ chữ, KHÔNG đụng vào thẻ ảnh trợ lý (.hudcb-ico cũng là span) */
  .hudcb-launcher > span:not(.hudcb-ico) { white-space: nowrap; transition: opacity .25s ease, max-width .35s ease; max-width: 60vw; }
  .hudcb-launcher.is-compact { width: 56px; padding: 0; gap: 0; justify-content: center; }
  .hudcb-launcher.is-compact > span:not(.hudcb-ico) { opacity: 0; max-width: 0; overflow: hidden; }
  .hudcb-launcher.is-compact .hudcb-ico { width: 44px; height: 44px; opacity: 1; }
  .hudcb-invite { right: 16px; left: 16px; width: auto; bottom: calc(86px + env(safe-area-inset-bottom, 0px)); }
  .hudcb-panel { inset: 0; right: 0; bottom: 0; width: 100%; height: 100%; height: 100dvh; filter: none; padding-top: env(safe-area-inset-top, 0px); background: #3D3E40; }
  .hudcb-foot { border-radius: 0; padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .hudcb-input { font-size: 16px; }
  .hudcb-contact { min-width: 0; }
  html.hudcb-lock, html.hudcb-lock body { overflow: hidden !important; }
}

@media (prefers-reduced-motion: reduce) {
  .hudcb-panel { animation: none; }
  .hudcb-typing span { animation: none; opacity: .7; }
}
.hudcb-i { display: inline-flex; align-items: center; }
.hudcb-related { width: 100%; }
.hudcb-related h3 { font-size: 13.5px; }
