/* Container above everything, but pass clicks through by default */
#chatbox-container {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 2147483647;
  isolation: isolate;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  pointer-events: none;
}

/* Layer order inside the container */
#chat-overlay { z-index: 1; }
#chatbox      { z-index: 2; }
#chat-toggle  { z-index: 3; }

/* Panel */
#chatbox {
  position: fixed;
  left: 20px;
  bottom: 90px;
  width: 360px;
  height: 460px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  visibility: hidden;
  opacity: 0;
  transition: visibility 0s, opacity 0.25s ease;
  pointer-events: none;
}
#chatbox.open { visibility: visible; opacity: 1; pointer-events: auto; }

/* Backdrop overlay (mobile-only; under the chatbox) */
#chat-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
#chat-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }
@media (min-width: 769px) { #chat-overlay { display: none !important; } }

/* Header */
#chat-header {
  background: #265cdc;
  color: #fff;
  padding: 10px 12px;
  border-radius: 12px 12px 0 0;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.chat-brand { display: inline-flex; align-items: center; gap: 10px; }
.chat-logo { width: 40px; height: 40px; border-radius: 50%; object-fit: contain; }
.chat-title { display: inline-block; line-height: 1; }
#close-button { background: none; border: none; color: #fff; font-size: 18px; cursor: pointer; padding: 6px; }

/* Messages area: make it a proper iOS momentum scroller */
#chat-messages {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
  background: #f9fafb;

  display: flex;
  flex-direction: column;
  gap: 8px;

  /* ✅ reliable inner scrolling on iOS */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}

/* Bubbles */
.message {
  display: inline-block;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: normal;
  max-width: 85%;
}

.user-message { align-self: flex-end; background: #265cdc; color: #fff; text-align: left; }
.bot-message  { align-self: flex-start; background: #e5e7eb; color: #111827; }

/* Links inside bot bubble */
.bot-message a { color: #1f3db5; text-decoration: underline; font-weight: 600; word-break: break-word; }

/* Typing indicator */
.typing { align-self: flex-start; background: #e5e7eb; color: #111827; }
.typing .dot { width: 6px; height: 6px; background: #6b7280; border-radius: 50%; display: inline-block; animation: blink 1.2s infinite ease-in-out; margin-right: 4px; }
.typing .dot:nth-child(2) { animation-delay: 0.15s; }
.typing .dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink { 0%,80%,100%{opacity:.2;} 40%{opacity:1;} }

/* Input row */
#chat-input { display: flex; padding: 12px; background: #fff; border-top: 1px solid #e5e7eb; border-radius: 0 0 12px 12px; gap: 8px; }
#user-input { flex: 1; padding: 10px 12px; border: 1px solid #d1d5db; border-radius: 8px; outline: none; font-size: 14px; margin-bottom: 0 !important; }
#send-button { padding: 10px 16px; background: #265cdc; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; }
#send-button:hover { background: #1e4ab8; }

/* Toggle button — only this and the open chat can receive clicks */
#chat-toggle {
  position: fixed;
  left: 20px;
  bottom: 20px;
  width: 60px;
  height: 60px;
  background: #265cdc;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  margin-top: 10px;
  pointer-events: auto;
}
#chat-toggle img { width: 28px; height: 28px; }

/* Mobile layout tweaks */
@media (max-width: 420px) {
  #chatbox {
    left: 4vw;
    width: 92vw;
    height: 62vh;
    bottom: 88px;
  }
  #user-input { font-size: 16px; line-height: 1.4; } /* prevent iOS zoom */
  #send-button { font-size: 16px; }
}

/* iOS text-size adjustments */
#chatbox-container, #chatbox { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
