/* ==========================================================================
   Ishara Care Assistant — chat panel
   ========================================================================== */

.chatbot-panel {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1100;
  width: 400px;
  max-width: calc(100vw - 36px);
  height: min(620px, calc(100vh - 40px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px);
  transition: opacity .25s var(--ease), transform .25s var(--ease), visibility .25s;
}
.chatbot-panel.active { opacity: 1; visibility: visible; transform: none; }

/* Header */
.chatbot-header {
  background: var(--navy-800);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chatbot-avatar {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--teal-600); color: #fff;
  display: grid; place-items: center; flex-shrink: 0;
  font-family: var(--font-display); font-size: 1.1rem; line-height: 1;
  border: 1px solid rgba(255,255,255,.28);
}
.chatbot-identity { flex: 1; min-width: 0; }
.chatbot-identity h2 {
  font-family: var(--font-ui); font-size: 1rem; font-weight: 600;
  color: #fff; margin: 0; line-height: 1.3;
}
.chatbot-status { font-size: 0.82rem; color: #B7C9D5; display: flex; align-items: center; gap: 7px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #62C08E; flex-shrink: 0; }
.chatbot-close {
  background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff;
  width: 38px; height: 38px; border-radius: var(--r-sm); cursor: pointer;
  display: grid; place-items: center; flex-shrink: 0;
}
.chatbot-close:hover { background: rgba(255,255,255,.12); }

/* Disclaimer strip */
.chatbot-disclaimer {
  background: var(--warning-bg);
  border-bottom: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 0.79rem;
  line-height: 1.45;
  padding: 9px 16px;
  flex-shrink: 0;
}
.chatbot-disclaimer strong { color: var(--text); }

/* Message list */
.chatbot-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overscroll-behavior: contain;
}
.chat-row { display: flex; gap: 10px; align-items: flex-end; max-width: 100%; }
.chat-row.user { flex-direction: row-reverse; }
.chat-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font-size: 0.72rem;
  background: var(--navy-800); color: #fff;
}
.chat-row.user .chat-avatar { background: var(--teal-600); }
.chat-bubble {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md) var(--r-md) var(--r-md) 2px;
  padding: 11px 14px;
  font-size: 0.94rem;
  line-height: 1.55;
  max-width: 82%;
  overflow-wrap: anywhere;
}
.chat-row.user .chat-bubble {
  background: var(--navy-800);
  border-color: var(--navy-800);
  color: #fff;
  border-radius: var(--r-md) var(--r-md) 2px var(--r-md);
}
[data-theme="dark"] .chat-row.user .chat-bubble { background: var(--teal-700); border-color: var(--teal-700); }
.chat-bubble p { margin: 0 0 8px; max-width: none; }
.chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul { padding-left: 18px; list-style: disc; margin: 6px 0; }
.chat-bubble a { color: var(--link); }
.chat-row.user .chat-bubble a { color: #CFE3F2; }
.chat-time { font-size: 0.72rem; color: var(--text-muted); margin-top: 5px; display: block; }
.chat-row.user .chat-time { color: rgba(255,255,255,.7); text-align: right; }

/* Typing indicator */
.typing-indicator { display: none; gap: 5px; padding: 4px 0 0 40px; }
.typing-indicator.show { display: flex; }
.typing-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--slate-500);
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* Quick actions */
.chatbot-quick {
  display: flex; flex-wrap: wrap; gap: 7px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  flex-shrink: 0;
}
.quick-action {
  background: var(--surface-alt);
  border: 1px solid var(--line-strong);
  border-radius: 100px;
  padding: 7px 14px;
  font-size: 0.86rem;
  cursor: pointer;
  color: var(--heading);
  min-height: 36px;
  transition: background-color .2s var(--ease), border-color .2s var(--ease);
}
.quick-action:hover { background: var(--navy-800); border-color: var(--navy-800); color: #fff; }
.quick-action--accent { border-color: var(--accent); color: var(--accent-text); }

/* Escalation card inside the transcript */
.escalation-card {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: var(--surface);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  padding: 13px 14px;
  font-size: 0.9rem;
}
.escalation-card h4 { margin: 0 0 8px; font-size: 0.95rem; font-family: var(--font-ui); font-weight: 600; }
.escalation-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.escalation-actions .btn { padding: 8px 14px; min-height: 38px; font-size: 0.87rem; }

/* Emergency callout */
.chat-bubble--urgent { border-left: 3px solid var(--danger); background: var(--danger-bg); }

/* Input */
.chatbot-input {
  display: flex; gap: 9px; padding: 12px 16px;
  border-top: 1px solid var(--line); background: var(--surface); flex-shrink: 0;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.chatbot-input input { min-height: 46px; }
.chatbot-input button {
  background: var(--navy-800); border: none; color: #fff; border-radius: var(--r-sm);
  width: 48px; min-height: 46px; cursor: pointer; flex-shrink: 0;
}
.chatbot-input button:hover { background: var(--navy-700); }
[data-theme="dark"] .chatbot-input button { background: var(--teal-600); }

/* Mobile: near full screen */
@media (max-width: 620px) {
  .chatbot-panel {
    right: 0; left: 0; bottom: 0; top: 0;
    width: 100%; max-width: 100%; height: 100%;
    border-radius: 0; border: none;
  }
  .chat-bubble { max-width: 86%; }
}

@media (prefers-reduced-motion: reduce) {
  .typing-dot { animation: none; opacity: .6; }
}
