/*
 * Web chat widget (Session 6).
 * Floating action button + slide-up chat panel. Fully theme-variable driven
 * (matches each clinic's brand) and RTL-aware: the FAB/panel sit bottom-right in
 * LTR (Turkish) and flip to bottom-left in RTL (Arabic). On small screens the
 * panel becomes a full-height sheet.
 */

.chatbot-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  font-family: var(--font-body, var(--font-latin, sans-serif));
}
[dir="rtl"] .chatbot-root {
  right: auto;
  left: 24px;
}

/* ---- Floating action button ---- */
.chatbot-fab {
  width: 60px;
  height: 60px;
  border-radius: var(--radius-pill, 999px);
  border: none;
  cursor: pointer;
  background: var(--color-primary, #2563eb);
  color: #fff;
  box-shadow: var(--shadow-lg, 0 10px 30px rgba(0, 0, 0, 0.2));
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}
.chatbot-fab:hover {
  transform: translateY(-2px) scale(1.04);
}
.chatbot-fab:active {
  transform: scale(0.96);
}
.chatbot-fab svg {
  width: 28px;
  height: 28px;
}
.chatbot-root.is-open .chatbot-fab {
  opacity: 0;
  pointer-events: none;
}

/* ---- Panel ---- */
.chatbot-panel {
  position: absolute;
  bottom: 74px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 110px);
  display: flex;
  flex-direction: column;
  background: var(--color-surface, #fff);
  color: var(--color-text, #1a1a1a);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-lg, 18px);
  box-shadow: var(--shadow-lg, 0 18px 50px rgba(0, 0, 0, 0.22));
  overflow: hidden;
  transform-origin: bottom right;
  transform: translateY(12px) scale(0.96);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.2, 0.8, 0.3, 1), opacity 0.2s ease;
}
[dir="rtl"] .chatbot-panel {
  right: auto;
  left: 0;
  transform-origin: bottom left;
}
.chatbot-root.is-open .chatbot-panel {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: auto;
}

/* ---- Header ---- */
.chatbot-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--color-primary, #2563eb);
  color: #fff;
  flex-shrink: 0;
}
.chatbot-header-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-pill, 999px);
  object-fit: cover;
  background: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}
.chatbot-header-meta {
  flex: 1;
  min-width: 0;
}
.chatbot-header-name {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chatbot-header-status {
  font-size: 0.72rem;
  opacity: 0.85;
}
.chatbot-header-btn {
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm, 8px);
  opacity: 0.85;
  display: flex;
  align-items: center;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.chatbot-header-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
}
.chatbot-header-btn svg {
  width: 18px;
  height: 18px;
}

/* ---- Messages ---- */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-bg-alt, #f7f8fa);
  scroll-behavior: smooth;
}
.chatbot-msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
}
.chatbot-msg-bubble {
  padding: 9px 13px;
  border-radius: var(--radius-md, 14px);
  font-size: 0.9rem;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.chatbot-msg-time {
  font-size: 0.66rem;
  color: var(--color-text-muted, #8a8f98);
  margin-top: 3px;
  padding: 0 4px;
}
.chatbot-msg.bot {
  align-self: flex-start;
  align-items: flex-start;
}
.chatbot-msg.bot .chatbot-msg-bubble {
  background: var(--color-surface, #fff);
  color: var(--color-text, #1a1a1a);
  border: 1px solid var(--color-border, #e5e7eb);
  border-bottom-left-radius: 4px;
}
[dir="rtl"] .chatbot-msg.bot .chatbot-msg-bubble {
  border-bottom-left-radius: var(--radius-md, 14px);
  border-bottom-right-radius: 4px;
}
.chatbot-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}
.chatbot-msg.user .chatbot-msg-bubble {
  background: var(--color-primary, #2563eb);
  color: #fff;
  border-bottom-right-radius: 4px;
}
[dir="rtl"] .chatbot-msg.user .chatbot-msg-bubble {
  border-bottom-right-radius: var(--radius-md, 14px);
  border-bottom-left-radius: 4px;
}
.chatbot-msg.error .chatbot-msg-bubble {
  background: var(--color-danger-light, #fde8e8);
  color: var(--color-danger, #c0392b);
  border: 1px solid var(--color-danger, #c0392b);
}

/* ---- Typing indicator ---- */
.chatbot-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 11px 14px;
  background: var(--color-surface, #fff);
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 14px);
  border-bottom-left-radius: 4px;
}
.chatbot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-text-muted, #9aa0a8);
  animation: chatbot-bounce 1.3s infinite ease-in-out;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.18s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes chatbot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- Input row ---- */
.chatbot-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 12px;
  border-top: 1px solid var(--color-border, #e5e7eb);
  background: var(--color-surface, #fff);
  flex-shrink: 0;
}
.chatbot-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border, #e5e7eb);
  border-radius: var(--radius-md, 14px);
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  max-height: 100px;
  color: var(--color-text, #1a1a1a);
  background: var(--color-bg, #fff);
  outline: none;
  transition: border-color 0.15s ease;
}
.chatbot-input:focus {
  border-color: var(--color-primary, #2563eb);
}
.chatbot-send {
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-pill, 999px);
  background: var(--color-primary, #2563eb);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.chatbot-send:hover { transform: scale(1.06); }
.chatbot-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.chatbot-send svg { width: 20px; height: 20px; }
[dir="rtl"] .chatbot-send svg { transform: scaleX(-1); }

/* ---- Mobile: full-height sheet ---- */
@media (max-width: 480px) {
  .chatbot-root { bottom: 16px; right: 16px; }
  [dir="rtl"] .chatbot-root { left: 16px; right: auto; }
  .chatbot-panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: none;
  }
}
