/* ============================================================
   ai-guide.css — nút micro + khung hội thoại của hướng dẫn viên AI
   ------------------------------------------------------------
   Vị trí: GÓC DƯỚI-PHẢI. Đo thật trên index.htm: góc dưới-trái đã có #fp-fabs
   (2 nút pill "Chỉ đường"/"Điểm đến"), góc trên-phải đã có #st-menu + #st-lang
   (từ 2026-08-05 cùng ở hàng top 15, đè lên cụm chia sẻ/pill "VN" của skin
   3DVista) — dưới-phải là vùng duy nhất còn trống ở cả 4 khổ màn hình.

   z-index 10009: bằng #st-lang và #fp-split-ctl, để không bị #viewer (10005/
   10008 lúc chia đôi màn hình) che mất.

   Khi lớp phủ bản đồ đang mở: ẩn hẳn nếu chưa trò chuyện (bản đồ là một màn hình
   con, đủ chật rồi); ĐANG trò chuyện thì giữ lại một nút tròn ở trên-phải để
   khách luôn tắt được micro — không bao giờ để phiên chạy mà mất nút dừng.
   ============================================================ */

#st-ai {
  position: fixed;
  right: 16px;
  /* --st-ai-lift do js/ai-guide.js ĐO và đặt: khoảng cách cần nâng để không đè
     cụm #fp-fabs. Không đoán bằng con số cố định vì cụm đó xuống hàng nở LÊN
     TRÊN ở màn ≤480px (welcome.css) và số hàng còn đổi theo độ dài nhãn/ngôn ngữ. */
  bottom: calc(var(--st-ai-lift, 16px) + env(safe-area-inset-bottom, 0px));
  z-index: 10009;
  font-family: 'Be Vietnam Pro', system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex;
  /* column-reverse: nút micro luôn nằm DƯỚI CÙNG (đúng thói quen khung chat),
     khung hội thoại mọc lên phía trên nó. */
  flex-direction: column-reverse;
  align-items: flex-end;
  gap: 10px;
}


/* Bản đồ mở TRÊN một trang có nội dung riêng (index.htm có #fp-close) */
body:has(#fp-close):has(#fp-overlay.open) #st-ai {
  display: none;
}

body:has(#fp-close):has(#fp-overlay.open) #st-ai.st-ai-live {
  display: block;
  bottom: auto;
  right: 70px;
  /* chừa #st-lang — lúc bản đồ mở nó tụt về right:16 / top:68 (lang-switch.css) */
  top: calc(68px + env(safe-area-inset-top, 0px));
}

body:has(#fp-close):has(#fp-overlay.open) #st-ai.st-ai-live #st-ai-panel {
  display: none;
}

/* ---------- nút micro ---------- */
#st-ai-fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: #1769ff;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(15, 23, 42, .28);
  transition: background .18s, transform .18s;
}

#st-ai-fab:hover {
  transform: translateY(-1px);
}

#st-ai-fab svg {
  width: 24px;
  height: 24px;
}

#st-ai-fab.on {
  background: #ef4444;
}

#st-ai-fab.on::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(239, 68, 68, .55);
  animation: st-ai-pulse 1.6s ease-out infinite;
  /* Vòng sáng nở tới ~11px ngoài mép nút; không tắt nhận chạm thì nó nuốt cả cú
     chạm nhắm vào thứ nằm cạnh nút. */
  pointer-events: none;
}

@keyframes st-ai-pulse {
  0% {
    transform: scale(.92);
    opacity: .9;
  }

  100% {
    transform: scale(1.25);
    opacity: 0;
  }
}

/* sóng âm khi AI đang nói */
.st-ai-wave {
  display: none;
  position: absolute;
  bottom: 8px;
  gap: 2px;
}

#st-ai-fab.talking .st-ai-wave {
  display: flex;
}

#st-ai-fab.talking svg {
  opacity: .35;
}

.st-ai-wave i {
  width: 3px;
  height: 10px;
  border-radius: 2px;
  background: #fff;
  animation: st-ai-bar .9s ease-in-out infinite;
}

.st-ai-wave i:nth-child(2) {
  animation-delay: .15s;
}

.st-ai-wave i:nth-child(3) {
  animation-delay: .3s;
}

@keyframes st-ai-bar {

  0%,
  100% {
    height: 6px;
  }

  50% {
    height: 18px;
  }
}

/* ---------- khung hội thoại ---------- */
#st-ai-panel {
  width: min(360px, calc(100vw - 32px));
  max-height: min(62vh, 520px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 16px;
  background: #fff;
  color: #0f172a;
  box-shadow: 0 18px 48px rgba(15, 23, 42, .3);
}

#st-ai-panel[hidden] {
  display: none;
}

#st-ai-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 8px 12px 14px;
  border-bottom: 1px solid #e2e8f0;
}

.st-ai-title {
  font-family: inherit;
  font-weight: 800;
  font-size: 14px;
  line-height: 1.2;
}

#st-ai-status {
  flex: 1;
  font-family: inherit;
  font-weight: 600;
  font-size: 12px;
  line-height: 1.2;
  color: #64748b;
}

#st-ai-status.talking {
  color: #1769ff;
}

#st-ai-status.retry,
#st-ai-status.error {
  color: #b45309;
}

#st-ai-x {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #475569;
  font-family: inherit;
  font-weight: 400;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

#st-ai-x:hover {
  background: #f1f5f9;
}

#st-ai-log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.st-ai-hint {
  font-family: inherit;
  font-weight: 400;
  font-size: 12.5px;
  line-height: 1.5;
  color: #94a3b8;
  text-align: center;
  padding: 12px 6px;
}

.st-ai-msg p {
  margin: 0;
  padding: 8px 12px;
  border-radius: 14px;
  font-family: inherit;
  font-weight: 400;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.st-ai-who {
  display: block;
  margin-bottom: 3px;
  font-family: inherit;
  font-weight: 700;
  font-size: 11px;
  line-height: 1;
  color: #94a3b8;
}

.st-ai-you {
  align-self: flex-end;
  max-width: 88%;
  text-align: right;
}

.st-ai-you p {
  background: #1769ff;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.st-ai-ai {
  align-self: flex-start;
  max-width: 92%;
}

.st-ai-ai p {
  background: #f1f5f9;
  border-bottom-left-radius: 4px;
}

/* dòng thông báo của hệ thống (đang chuyển cảnh, lỗi micro…) */
.st-ai-sys p {
  background: #fff7ed;
  color: #9a3412;
  font-size: 12.5px;
  text-align: center;
}

#st-ai-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid #e2e8f0;
}

#st-ai-mic,
#st-ai-send {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: #f1f5f9;
  color: #475569;
  cursor: pointer;
}

#st-ai-mic svg,
#st-ai-send svg {
  width: 19px;
  height: 19px;
}

#st-ai-mic.on {
  background: #fee2e2;
  color: #dc2626;
}

#st-ai-send {
  background: #1769ff;
  color: #fff;
}

#st-ai-input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  background: #fff;
  color: #0f172a;
  font-family: inherit;
  font-weight: 400;
  font-size: 13.5px;
  line-height: 1;
}

#st-ai-input:focus {
  outline: none;
  border-color: #1769ff;
}

@media (max-width:700px) {
  #st-ai-panel {
    max-height: 56vh;
  }
}

/* Chừa riêng cột phải cho nút AI để giữ đúng vị trí 16px từ đáy/phải.
   Chỉ áp dụng portrait: màn ngang đã có luật #fp-fabs riêng ở floorplan.css. */
@media (max-width:640px) and (orientation: portrait) {
  body #fp-fabs {
    width: calc(100vw - 88px);
    max-width: calc(100vw - 16px - 88px);
  }
}
