/* Step 9.3 — AI chat widget (REQ-AI-01/04/05).
   Nút nổi + panel chat, màu theo palette site: palette-1-base #f38181
   (nút Confirm/header), light #fef2f2 (bong bóng khách). Font kế thừa
   Roboto của style.css. Không framework — cùng khuôn booking.js/booking.css. */
#aichat-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 9998;
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: #f38181; color: #fff; box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
  display: flex; align-items: center; justify-content: center;
}
#aichat-fab:hover { background: #ef6c6c; }
#aichat-fab svg { width: 26px; height: 26px; fill: currentColor; }
#aichat-fab[hidden] { display: none; }

#aichat-panel {
  position: fixed; right: 20px; bottom: 90px; z-index: 9999;
  width: 360px; max-width: calc(100vw - 24px); height: 480px; max-height: calc(100vh - 120px);
  background: #fff; border-radius: 12px; overflow: hidden;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
  display: flex; flex-direction: column; font-family: Roboto, Arial, sans-serif;
}
#aichat-panel[hidden] { display: none; }

#aichat-head {
  background: #f38181; color: #fff; padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 700; font-size: 16px;
}
#aichat-head button {
  background: none; border: none; color: #fff; font-size: 20px;
  line-height: 1; cursor: pointer; padding: 2px 6px;
}
.aichat-head-btns { display: flex; align-items: center; gap: 2px; }
.aichat-restart { font-size: 18px; }
#aichat-log {
  flex: 1; overflow-y: auto; padding: 14px; background: #faf7f5;
  display: flex; flex-direction: column; gap: 10px;
}
.aichat-row { display: flex; }
.aichat-row.user { justify-content: flex-end; }
.aichat-row.ai { justify-content: flex-start; }
.aichat-bubble {
  max-width: 85%; padding: 9px 12px; border-radius: 12px;
  font-size: 14px; line-height: 1.45; white-space: pre-wrap;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.aichat-row.user .aichat-bubble { background: #fef2f2; color: #3a2a2a; border-bottom-right-radius: 3px; }
.aichat-row.ai .aichat-bubble { background: #fff; color: #333; border: 1px solid #eee; border-bottom-left-radius: 3px; }
.aichat-row.note { justify-content: center; }
.aichat-note { font-size: 12px; color: #999; font-style: italic; text-align: center; }

/* Thẻ nháp confirm (draft card) */
.aichat-card {
  max-width: 92%; border: 1px solid #f38181; border-radius: 10px;
  background: #fff; padding: 10px 12px; font-size: 14px; color: #333;
}
.aichat-card .aichat-card-title { font-weight: 700; margin-bottom: 6px; }
.aichat-card .aichat-card-err { color: #b3261e; margin: 6px 0 0; font-size: 13px; }
.aichat-card .aichat-card-ok { color: #1b7a43; margin: 0; font-weight: 700; }
.aichat-card .aichat-card-guest { margin: 6px 0 0; font-size: 13px; }
/* Fix 9.3 F-09: dòng tóm tắt giao dịch trên thẻ Confirm */
.aichat-card-sum { border-top: 1px dashed #eee; margin-top: 6px; padding-top: 6px; }
.aichat-card-sumrow { display: flex; gap: 8px; font-size: 13px; line-height: 1.5; }
.aichat-card-sumkey { color: #999; min-width: 58px; }
.aichat-card-sumval { color: #333; overflow-wrap: anywhere; }
/* User 14/10: ghi chú "giá tối thiểu, extra tính thêm" trước nút Confirm */
.aichat-card .aichat-card-note { color: #8a5a00; background: #fff7e6; border-radius: 6px; padding: 6px 8px; margin-top: 6px; font-size: 12px; line-height: 1.45; }
.aichat-card-btns { display: flex; gap: 8px; margin-top: 8px; }
.aichat-btn {
  border: 1px solid #f38181; border-radius: 6px; padding: 6px 14px;
  font-size: 14px; cursor: pointer; background: #f38181; color: #fff;
}
.aichat-btn.secondary { background: #fff; color: #f38181; }
.aichat-btn:disabled { opacity: .5; cursor: default; }

/* Typing */
.aichat-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.aichat-typing i {
  width: 7px; height: 7px; border-radius: 50%; background: #f38181;
  opacity: .35; animation: aichat-blink 1s infinite;
}
.aichat-typing i:nth-child(2) { animation-delay: .2s; }
.aichat-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes aichat-blink { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* Input */
#aichat-input-row { display: flex; gap: 8px; padding: 10px; border-top: 1px solid #eee; background: #fff; }
#aichat-input {
  flex: 1; border: 1px solid #ddd; border-radius: 8px; padding: 9px 11px;
  font: inherit; font-size: 14px; resize: none; max-height: 96px;
}
#aichat-input:focus { outline: 2px solid #f38181; border-color: transparent; }
#aichat-send { border: none; border-radius: 8px; padding: 0 16px; font-size: 14px; cursor: pointer; background: #f38181; color: #fff; }
#aichat-send:disabled { opacity: .5; cursor: default; }

@media (max-width: 480px) {
  #aichat-panel { right: 8px; left: 8px; bottom: 78px; width: auto; height: calc(100vh - 96px); max-height: none; }
  #aichat-fab { right: 14px; bottom: 14px; }
}
