/* ── PulmoCrit AI Chatbot Widget ─────────────────────────────────────────── */

:root {
  --chat-purple: #7057a5;
  --chat-dark-blue: #1b2c51;
  --chat-green: #28b16d;
  --chat-bg: #ffffff;
  --chat-user-bubble: #28b16d;
  --chat-bot-bubble: #f0f0f0;
  --chat-text-dark: #333333;
  --chat-text-light: #666666;
  --chat-border: #e0e0e0;
  --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  --chat-radius: 16px;
  --chat-z: 9999;
}

/* ── Launcher Button ─────────────────────────────────────────────────────── */

#pulmocrit-chatbot {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: var(--chat-z);
  font-family: 'Montserrat', 'Segoe UI', sans-serif;
}

#chat-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--chat-purple);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(112, 87, 165, 0.45);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  color: #fff;
  font-size: 24px;
}

#chat-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(112, 87, 165, 0.6);
}

#chat-launcher:focus-visible {
  outline: 3px solid var(--chat-dark-blue);
  outline-offset: 3px;
}

#chat-launcher svg {
  width: 28px;
  height: 28px;
  fill: #fff;
}

/* ── Chat Window ─────────────────────────────────────────────────────────── */

#chat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 360px;
  height: 500px;
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--chat-z);
  transform: translateY(20px) scale(0.95);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.25s ease;
}

#chat-window.chat-open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* ── Chat Header ─────────────────────────────────────────────────────────── */

#chat-header {
  background: linear-gradient(135deg, var(--chat-purple), var(--chat-dark-blue));
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#chat-header .chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

#chat-header .chat-title {
  flex: 1;
}

#chat-header .chat-title strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
}

#chat-header .chat-title span {
  font-size: 11px;
  opacity: 0.85;
}

#chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  font-size: 20px;
  opacity: 0.85;
  transition: opacity 0.2s;
}

#chat-close:hover { opacity: 1; }
#chat-close:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ── Disclaimer Banner ───────────────────────────────────────────────────── */

#chat-disclaimer {
  background: #fff8e1;
  border-bottom: 1px solid #ffe082;
  padding: 8px 14px;
  font-size: 11.5px;
  color: #5a4500;
  line-height: 1.45;
  flex-shrink: 0;
}

#chat-disclaimer button {
  background: none;
  border: none;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  float: right;
  color: #5a4500;
  padding: 0 0 0 8px;
}

/* ── Messages Area ───────────────────────────────────────────────────────── */

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

#chat-messages::-webkit-scrollbar { width: 4px; }
#chat-messages::-webkit-scrollbar-track { background: transparent; }
#chat-messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

.chat-message {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
}

.chat-message.bot {
  background: var(--chat-bot-bubble);
  color: var(--chat-text-dark);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.chat-message.user {
  background: var(--chat-user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
  align-self: flex-end;
}

/* ── Typing Indicator ────────────────────────────────────────────────────── */

.chat-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 14px;
  background: var(--chat-bot-bubble);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  width: fit-content;
}

.chat-typing span {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: #aaa;
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }

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

/* ── Input Area ──────────────────────────────────────────────────────────── */

#chat-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--chat-border);
  background: #fafafa;
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  border: 1.5px solid var(--chat-border);
  border-radius: 24px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  background: #fff;
  color: var(--chat-text-dark);
  transition: border-color 0.2s;
  resize: none;
  line-height: 1.4;
}

#chat-input:focus {
  border-color: var(--chat-purple);
}

#chat-send {
  width: 38px;
  height: 38px;
  background: var(--chat-purple);
  border: none;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}

#chat-send:hover { background: var(--chat-dark-blue); }
#chat-send:active { transform: scale(0.92); }
#chat-send:focus-visible {
  outline: 3px solid var(--chat-dark-blue);
  outline-offset: 3px;
}

#chat-send svg {
  width: 18px;
  height: 18px;
  fill: #fff;
}

/* ── Live region for screen readers ─────────────────────────────────────── */

#chat-live-region {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ── Responsive: full-screen on mobile ───────────────────────────────────── */

@media (max-width: 480px) {
  #chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  #pulmocrit-chatbot {
    bottom: 20px;
    right: 20px;
  }
}
