/* ============================================================
   Chat Widget — Phase 1 (direct OpenAI)
   ============================================================ */

/* --- Bubble trigger ---------------------------------------- */
#chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9000;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background-color: var(--color-primary, #2563eb);
  color: #fff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 200ms ease, box-shadow 200ms ease;
}

#chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 18px rgba(0,0,0,0.22);
}

#chat-bubble.chat-open {
  display: none;
}

/* --- Panel ------------------------------------------------- */
#chat-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9001;
  width: 360px;
  height: 480px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16), 0 0 0 1px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chat-slide-up 220ms ease;
}

#chat-panel[hidden] {
  display: none !important;
}

@keyframes chat-slide-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Header ------------------------------------------------ */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background-color: var(--color-primary, #2563eb);
  color: #fff;
  flex-shrink: 0;
}

#chat-header-title {
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

#chat-header-title span.chat-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}

#chat-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  line-height: 1;
  transition: background 150ms;
}

#chat-close:hover {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* --- Messages area ----------------------------------------- */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.chat-msg {
  max-width: 80%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  word-break: break-word;
}

.chat-msg.ai {
  background: #f1f5f9;
  color: #1e293b;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.chat-msg.user {
  background-color: var(--color-primary, #2563eb);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.chat-msg.error {
  background: #fef2f2;
  color: #b91c1c;
  align-self: flex-start;
  font-size: 13px;
}

/* typing indicator */
.chat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: #f1f5f9;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: chat-bounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes chat-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

/* --- WhatsApp CTA ------------------------------------------ */
#chat-human-cta {
  padding: 8px 14px;
  border-top: 1px solid #f1f5f9;
  flex-shrink: 0;
}

#chat-human-cta a {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background 150ms;
}

#chat-human-cta a:hover {
  background: #dbeafe;
}

/* --- Input form -------------------------------------------- */
#chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid #e2e8f0;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 14px;
  outline: none;
  background: #f8fafc;
  color: #0f172a;
  transition: border-color 150ms;
}

#chat-input:focus {
  border-color: var(--color-primary, #2563eb);
  background: #fff;
}

#chat-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#chat-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background-color: var(--color-primary, #2563eb);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 150ms, transform 150ms;
}

#chat-send:hover:not(:disabled) {
  opacity: 0.88;
  transform: scale(1.05);
}

#chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#chat-send svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

/* --- Mobile ------------------------------------------------ */
@media (max-width: 400px) {
  #chat-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 70vh;
    border-radius: 16px 16px 0 0;
  }

  #chat-bubble {
    bottom: 24px;
    right: 16px;
  }
}
