/* ==========================
   Barts Chat Widget
   Standalone styles for the AI chat assistant
========================== */

:root {
  --chat-primary: var(--primary, #cc1010);
  --chat-primary-dark: var(--primary-dark, #a50d0d);
  --chat-black: var(--black, #0a0a0a);
  --chat-surface: var(--surface, #141414);
  --chat-card: var(--card, #1c1c1c);
  --chat-text: var(--text, #f0f0f0);
  --chat-muted: var(--text-muted, #9ca3af);
  --chat-border: var(--border, #2a2a2a);
}

#barts-chat-widget {
  position: fixed;
  right: 28px;
  bottom: 28px;
  z-index: 9999;
  font-family: "Inter", sans-serif;
}

.barts-chat {
  position: relative;
}

/* ==========================
   Floating Action Button
========================== */
.barts-chat-fab {
  position: relative;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 999px;
  background: var(--chat-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  transition: transform 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}

.barts-chat-fab:hover,
.barts-chat-fab:focus-visible {
  background: var(--chat-primary-dark);
  transform: translateY(-2px);
}

.barts-chat-fab svg {
  width: 28px;
  height: 28px;
}

.barts-chat-fab::after {
  content: "";
  position: absolute;
  inset: -5px;
  border-radius: 999px;
  border: 2px solid rgba(204, 16, 16, 0.4);
  animation: barts-chat-pulse 2.2s ease-out infinite;
}

@keyframes barts-chat-pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.55;
  }
  70% {
    transform: scale(1.18);
    opacity: 0;
  }
  100% {
    transform: scale(1.18);
    opacity: 0;
  }
}

.barts-chat-tooltip {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: #111;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  padding: 0.42rem 0.7rem;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.barts-chat-fab:hover .barts-chat-tooltip,
.barts-chat-fab:focus-visible .barts-chat-tooltip {
  opacity: 1;
  transform: translateY(-50%) translateX(-2px);
}

.barts-chat-unread {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #ff2a2a;
  border: 2px solid #fff;
}

.barts-chat-unread[hidden] {
  display: none;
}

/* ==========================
   Chat Panel
========================== */
.barts-chat-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 370px;
  height: 520px;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  background: var(--chat-surface);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(204, 16, 16, 0.2);
  overflow: hidden;
  transform: translateY(20px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}

.barts-chat.is-open .barts-chat-panel {
  transform: translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.barts-chat.is-open .barts-chat-fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.85);
}

/* ==========================
   Header
========================== */
.barts-chat-header {
  min-height: 72px;
  background: var(--chat-primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
}

.barts-chat-logo-wrap {
  background: #fff;
  border-radius: 6px;
  padding: 3px 8px;
  flex-shrink: 0;
}

.barts-chat-logo-wrap img {
  height: 32px;
  width: auto;
  display: block;
}

.barts-chat-header-copy {
  min-width: 0;
  flex: 1;
}

.barts-chat-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
  font-weight: 700;
}

.barts-chat-subtitle {
  margin: 0.2rem 0 0;
  font-size: 0.76rem;
  opacity: 0.75;
}

.barts-chat-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 1.45rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.barts-chat-close:hover,
.barts-chat-close:focus-visible {
  background: rgba(255, 255, 255, 0.14);
}

/* ==========================
   Messages Area
========================== */
.barts-chat-messages {
  flex: 1;
  background: var(--chat-black);
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.barts-chat-messages::-webkit-scrollbar {
  width: 10px;
}

.barts-chat-messages::-webkit-scrollbar-track {
  background: #111;
}

.barts-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(204, 16, 16, 0.65);
  border-radius: 999px;
}

.barts-chat-messages {
  scrollbar-color: rgba(204, 16, 16, 0.65) #111;
}

.barts-chat-message {
  display: flex;
  max-width: 100%;
  animation: barts-chat-message-in 0.18s ease both;
}

@keyframes barts-chat-message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.barts-chat-message-bot {
  align-items: flex-start;
  gap: 8px;
  justify-content: flex-start;
}

.barts-chat-message-user {
  justify-content: flex-end;
}

.barts-chat-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--chat-primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
  flex-shrink: 0;
}

.barts-chat-bubble {
  max-width: 80%;
  padding: 0.62rem 0.75rem;
  font-size: 0.92rem;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.barts-chat-message-bot .barts-chat-bubble {
  background: var(--chat-card);
  border: 1px solid var(--chat-border);
  color: var(--chat-text);
  border-radius: 4px 16px 16px 16px;
}

.barts-chat-message-user .barts-chat-bubble {
  background: var(--chat-primary);
  color: #fff;
  border-radius: 16px 4px 16px 16px;
}

.barts-chat-retry {
  margin-top: 0.55rem;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.24rem 0.62rem;
  cursor: pointer;
}

.barts-chat-message-bot .barts-chat-retry {
  color: var(--chat-primary);
  border-color: rgba(204, 16, 16, 0.6);
}

.barts-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.barts-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fff;
  opacity: 0.6;
  animation: barts-chat-dot-bounce 1.1s ease-in-out infinite;
}

.barts-chat-message-bot .barts-chat-typing span {
  background: var(--chat-text);
}

.barts-chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.barts-chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes barts-chat-dot-bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* ==========================
   Quick Replies
========================== */
.barts-chat-quick-replies {
  background: #101010;
  border-top: 1px solid var(--chat-border);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.barts-chat-quick-replies[hidden] {
  display: none;
}

.barts-chat-quick-replies::-webkit-scrollbar {
  height: 6px;
}

.barts-chat-quick-replies::-webkit-scrollbar-thumb {
  background: rgba(204, 16, 16, 0.4);
  border-radius: 999px;
}

.barts-chat-chip {
  border: 1px solid var(--chat-primary);
  background: transparent;
  color: var(--chat-primary);
  border-radius: 999px;
  padding: 0.36rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease;
}

.barts-chat-chip:hover,
.barts-chat-chip:focus-visible {
  background: var(--chat-primary);
  color: #fff;
}

/* ==========================
   Input Area
========================== */
.barts-chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--chat-card);
  border-top: 1px solid var(--chat-border);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
}

.barts-chat-input {
  flex: 1;
  resize: none;
  border: 0;
  border-radius: 10px;
  background: #111;
  color: var(--chat-text);
  min-height: 42px;
  max-height: 96px;
  padding: 0.62rem 0.72rem;
  line-height: 1.35;
  font-size: 0.92rem;
  font-family: inherit;
}

.barts-chat-input::placeholder {
  color: #8a8a8a;
}

.barts-chat-input:focus-visible {
  outline: 2px solid var(--chat-primary);
  outline-offset: 0;
}

.barts-chat-send {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: var(--chat-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
}

.barts-chat-send:hover,
.barts-chat-send:focus-visible {
  background: var(--chat-primary-dark);
  transform: translateY(-1px);
}

.barts-chat-send svg {
  width: 18px;
  height: 18px;
}

.barts-chat.is-loading .barts-chat-input-area {
  opacity: 0.62;
}

/* ==========================
   A11y
========================== */
.barts-chat-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ==========================
   Mobile
========================== */
@media (max-width: 767px) {
  #barts-chat-widget {
    right: 16px;
    bottom: 20px;
  }

  .barts-chat-fab {
    width: 52px;
    height: 52px;
  }

  .barts-chat-fab svg {
    width: 24px;
    height: 24px;
  }

  .barts-chat-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 75vh;
    border-radius: 16px 16px 0 0;
  }

  .barts-chat-bubble {
    max-width: 88%;
  }
}
