/* Live chat widget */
.chat-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 56;
  width: 60px;
  height: 60px;
  border-radius: 20px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #fff;
  border: 1px solid rgba(16, 42, 70, 0.16);
  box-shadow: 0 14px 30px rgba(16, 42, 70, 0.28);
  transition: transform 200ms var(--ease), border-radius 200ms var(--ease), background 200ms ease;
  -webkit-tap-highlight-color: transparent;
}
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab:active { transform: scale(0.92); }
.chat-fab svg,
.chat-fab img { grid-area: 1 / 1; transition: opacity 180ms ease, transform 220ms var(--ease); }
.chat-fab-open { width: 40px; height: 40px; border-radius: 12px; object-fit: contain; }
.chat-fab-close { opacity: 0; transform: rotate(-90deg) scale(0.6); }
.bi-chat.is-open .chat-fab-open { opacity: 0; transform: rotate(90deg) scale(0.6); }
.bi-chat.is-open .chat-fab-close { opacity: 1; transform: none; }
.bi-chat.is-open .chat-fab { border-radius: 50%; border-color: transparent; background: linear-gradient(145deg, #1D4068, #0B1F35); }
.chat-fab-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid #fff;
}
.chat-fab-dot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  background: #22C55E;
  animation: chatPulse 1.8s ease-out infinite;
}
.bi-chat.is-seen .chat-fab-dot::after,
.bi-chat.is-open .chat-fab-dot { display: none; }
@keyframes chatPulse { from { transform: scale(1); opacity: 0.6; } to { transform: scale(2.4); opacity: 0; } }

.chat-nudge {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 56;
  max-width: 250px;
  padding: 12px 14px;
  border-radius: 16px 16px 4px 16px;
  background: #fff;
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.45;
  text-align: left;
  box-shadow: 0 14px 34px rgba(11, 35, 70, 0.18);
  border: 1px solid var(--border);
  animation: chatIn 320ms var(--ease);
}
.chat-nudge strong { color: var(--gold); }
.chat-nudge[hidden] { display: none; }

.chat-panel {
  position: fixed;
  right: 24px;
  bottom: 96px;
  z-index: 65;
  width: 384px;
  height: min(640px, calc(100vh - 128px));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #F6F6F3;
  border: 1px solid rgba(16, 42, 70, 0.08);
  border-radius: 24px;
  box-shadow: 0 24px 60px rgba(11, 35, 70, 0.24);
  transform-origin: bottom right;
  animation: chatIn 280ms var(--ease);
}
.chat-panel[hidden] { display: none; }
@keyframes chatIn { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 14px 16px;
  color: #fff;
  background: linear-gradient(135deg, #102A46, #0B1F35);
}
.chat-avatar {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: #fff;
}
.chat-avatar img { width: 30px; height: 30px; border-radius: 9px; object-fit: contain; }
.chat-avatar i {
  position: absolute;
  right: -2px;
  bottom: -2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22C55E;
  border: 2px solid #102A46;
}
.chat-title { flex: 1; min-width: 0; line-height: 1.25; }
.chat-title strong { display: block; font-size: 15px; font-weight: 600; }
.chat-title small { font-size: 12px; opacity: 0.85; }
.chat-head-btn {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  transition: background var(--t);
}
.chat-head-btn:hover { background: rgba(255, 255, 255, 0.26); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-msg { display: flex; flex-direction: column; max-width: 86%; animation: chatIn 220ms var(--ease); }
.chat-msg.is-user { align-self: flex-end; align-items: flex-end; }
.chat-msg.is-assistant { align-self: flex-start; }
.chat-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.is-assistant .chat-bubble {
  background: #fff;
  color: var(--ink);
  border: 1px solid rgba(16, 42, 70, 0.07);
  border-bottom-left-radius: 6px;
  box-shadow: 0 2px 6px rgba(16, 42, 70, 0.04);
}
.is-user .chat-bubble {
  background: linear-gradient(135deg, #1D4068, #102A46);
  color: #fff;
  border-bottom-right-radius: 6px;
}
.is-error .chat-bubble { background: #FFF5F5; border-color: #F5D0D0; }
.chat-bubble p { margin: 0; }
.chat-bubble ul { margin: 4px 0; padding-left: 18px; list-style: disc; }
.chat-bubble li { margin: 2px 0; }
.chat-bubble strong { font-weight: 600; }
.chat-bubble a { color: var(--gold); font-weight: 500; text-decoration: underline; text-underline-offset: 2px; }
.is-user .chat-bubble a { color: #fff; }
.chat-gap { display: block; height: 6px; }
.chat-time { margin: 4px 6px 0; font-size: 10.5px; color: var(--gray); }

.chat-typing .chat-bubble { display: flex; gap: 5px; padding: 14px 16px; }
.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9AA8BA;
  animation: chatDot 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatDot { 0%, 60%, 100% { transform: translateY(0); opacity: 0.5; } 30% { transform: translateY(-5px); opacity: 1; } }

.chat-chips {
  display: flex;
  gap: 8px;
  padding: 4px 14px 10px;
  overflow-x: auto;
  scrollbar-width: none;
}
.chat-chips::-webkit-scrollbar { display: none; }
.chat-chips[hidden] { display: none; }
.chat-chips button {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid rgba(16, 42, 70, 0.28);
  background: #fff;
  color: var(--gold);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.chat-chips button:hover { background: #FFF4E0; }

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 12px;
  padding: 6px 6px 6px 14px;
  background: #fff;
  border: 1px solid rgba(16, 42, 70, 0.12);
  border-radius: 22px;
  transition: border-color var(--t), box-shadow var(--t);
}
.chat-form:focus-within { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(16, 42, 70, 0.12); }
.chat-form textarea {
  flex: 1;
  min-height: 36px;
  max-height: 120px;
  padding: 8px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  font-size: 14.5px;
  line-height: 1.4;
}
.chat-form button {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--gold);
  transition: opacity var(--t), transform 160ms ease;
}
.chat-form button:active { transform: scale(0.9); }
.chat-form button:disabled { opacity: 0.5; }
.chat-foot {
  margin: 0;
  padding: 8px 14px 12px;
  font-size: 11px;
  color: var(--gray);
  text-align: center;
}
.chat-foot button { color: var(--gold); font-size: 11px; font-weight: 500; text-decoration: underline; }

/* WhatsApp sits above the chat button on desktop */
.whatsapp-float { bottom: 98px; right: 29px; width: 50px; height: 50px; }

@media (max-width: 767px) {
  .chat-fab {
    right: 14px;
    bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 10px);
    width: 54px;
    height: 54px;
    border-radius: 18px;
  }
  .whatsapp-float { display: none; }
  .chat-nudge { right: 14px; bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 74px); }
  .chat-panel {
    inset: 0;
    width: auto;
    height: auto;
    border: 0;
    border-radius: 0;
    animation: chatSheet 300ms var(--ease);
  }
  @keyframes chatSheet { from { transform: translateY(100%); } to { transform: none; } }
  .chat-head { padding-top: calc(12px + env(safe-area-inset-top)); }
  .chat-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .chat-form textarea { font-size: 16px; }
  html.chat-open, html.chat-open body { overflow: hidden; }
  html.chat-open .chat-fab, html.chat-open .mobile-bottom-nav { display: none; }
}
