/* Self-contained tokens with hex fallbacks so this renders even without app.css */
:root {
  --chat-teal: #004d40;
  --chat-white: #FFFFFF;
  --chat-brass: #B08D57;
  --chat-online: #34c77b;
  --chat-muted: rgba(0, 77, 64, 0.45);
  --chat-hairline: rgba(0, 77, 64, 0.14);
  --chat-warm-tint: rgba(176, 141, 87, 0.07);
  --chat-brass-glow: rgba(176, 141, 87, 0.35);
  --chat-radius-lg: 22px;
  --chat-radius-md: 14px;
  --chat-radius-sm: 9px;
  --chat-shadow-card: 0 14px 34px -14px rgba(0, 77, 64, 0.32);
  --chat-shadow-soft: 0 3px 10px -4px rgba(0, 77, 64, 0.18);
  --chat-ease: cubic-bezier(0.16, 0.84, 0.44, 1);
}

/* Speech-bubble launcher: mostly round, one flattened corner reads as the tail */
#chatbot-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50% 50% 50% 6px;
  background: var(--chat-teal, #004d40);
  color: var(--chat-white, #FFFFFF);
  display: flex;
  justify-content: center;
  align-items: center;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: grab;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  box-shadow: var(--chat-shadow-card, 0 14px 34px -14px rgba(0, 77, 64, 0.32));
  transition: box-shadow 0.25s var(--chat-ease, ease), transform 0.15s var(--chat-ease, ease), filter 0.2s var(--chat-ease, ease);
  z-index: 1000;
}
#chatbot-button:hover {
  filter: brightness(1.08);
  box-shadow: var(--chat-shadow-card, 0 14px 34px -14px rgba(0, 77, 64, 0.32)), 0 0 0 4px var(--chat-brass-glow, rgba(176, 141, 87, 0.35));
  transform: translateY(-2px);
}
#chatbot-button:active,
#chatbot-button.dragging {
  cursor: grabbing;
  transform: scale(0.97);
  transition: none;
}

/* Mobile: bottom sheet. Desktop: docked panel. Scrim stays opaque so the widget never blends into the host page. */
.chatbot-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 77, 64, 0.45);
  justify-content: center;
  align-items: flex-end;
  z-index: 1000;
}
.chatbot-modal.show {
  display: flex;
}

.chatbot-container {
  position: relative; /* anchors the mobile drag-handle below */
  width: 100%;
  max-width: 780px;
  height: 88vh;
  max-height: 680px;
  background: var(--chat-white, #FFFFFF);
  border-radius: 28px 28px 0 0;
  box-shadow: 0 -22px 60px rgba(0, 22, 18, 0.38);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.38s var(--chat-ease, ease);
}
/* Native-feeling bottom-sheet grabber. Sits on top of the header (z-index
   beats the header's auto stacking) so it reads as "part of the sheet
   chrome" rather than another header element. */
.chatbot-container::before {
  content: "";
  position: absolute;
  top: 9px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.55);
  z-index: 5;
  pointer-events: none;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (min-width: 768px) {
  .chatbot-modal {
    justify-content: flex-end;
    align-items: flex-end;
    padding: 24px;
    background: rgba(0, 77, 64, 0.25);
  }
  .chatbot-container {
    width: 380px;
    max-width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    border-radius: var(--chat-radius-lg, 22px);
    box-shadow: var(--chat-shadow-card, 0 14px 34px -14px rgba(0, 77, 64, 0.32)), 0 30px 70px -20px rgba(0, 77, 64, 0.35);
    animation: panelIn 0.3s var(--chat-ease, ease);
  }
  .chatbot-container::before {
    display: none; /* the drag handle is a mobile-sheet affordance only */
  }
  @keyframes panelIn {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }
}

/* =========================================================================
 * Header — WhatsApp-style contact bar: photo, name, live status, close.
 * Background is always the flat brand teal (#004d40): the only overlay is a
 * subtle white radial sheen for depth, never a darkening filter.
 * ========================================================================= */
.chatbot-header {
  position: relative;
  background: var(--chat-teal, #004d40);
  color: var(--chat-white, #FFFFFF);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08), 0 6px 16px -8px rgba(0, 77, 64, 0.45);
}
.chatbot-header::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(120% 160% at 12% -30%, rgba(255, 255, 255, 0.14), transparent 55%);
  pointer-events: none;
}
.chatbot-header > * {
  position: relative;
}

.chatbot-avatar-btn {
  flex-shrink: 0;
  position: relative;
  width: 42px;
  height: 42px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s var(--chat-ease, ease);
}
.chatbot-avatar-btn:hover {
  transform: scale(1.06);
}
.chatbot-avatar-btn:active {
  transform: scale(0.96);
}
.chatbot-avatar-btn:focus-visible {
  outline: 2px solid var(--chat-brass, #B08D57);
  outline-offset: 2px;
}
.chatbot-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--chat-brass, #B08D57);
  display: block;
}
.chatbot-online-dot {
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--chat-online, #34c77b);
  border: 2.5px solid var(--chat-teal, #004d40);
}

.chatbot-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chatbot-header-info h3 {
  margin: 0;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--chat-white, #FFFFFF);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chatbot-status {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.1px;
  color: rgba(255, 255, 255, 0.82);
}
.chatbot-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chat-online, #34c77b);
  flex-shrink: 0;
}
.chatbot-status.is-typing .chatbot-status-dot {
  background: var(--chat-brass, #B08D57);
  animation: statusPulse 1s infinite ease-in-out;
}
@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.chatbot-close-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  border-radius: 50%;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  color: var(--chat-white, #FFFFFF);
  opacity: 0.8;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.2s, background 0.2s;
}
.chatbot-close-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.14);
}

/* =========================================================================
 * Avatar viewer — a "contact card" modal opened by tapping the header
 * photo. Tapping the photo again opens the full-size lightbox below. Sits
 * above the chat panel; the scrim is the brand teal at partial opacity
 * (matches the existing chat backdrop pattern), not black.
 * ========================================================================= */
.chatbot-avatar-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 77, 64, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1100;
}
.chatbot-avatar-modal.show {
  display: flex;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.chatbot-avatar-modal-inner {
  position: relative;
  width: 100%;
  max-width: 340px;
  background: var(--chat-white, #FFFFFF);
  border-radius: var(--chat-radius-lg, 22px);
  padding: 34px 26px 26px;
  text-align: center;
  box-shadow: 0 30px 80px -20px rgba(0, 30, 25, 0.5);
  animation: avatarPop 0.25s var(--chat-ease, ease);
}
@keyframes avatarPop {
  from { opacity: 0; transform: scale(0.92) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.chatbot-avatar-modal-photo-btn {
  position: relative;
  display: block;
  width: 208px;
  height: 208px;
  margin: 0 auto 18px;
  padding: 0;
  border: none;
  background: none;
  border-radius: 50%;
  cursor: zoom-in;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.2s var(--chat-ease, ease);
}
.chatbot-avatar-modal-photo-btn:hover:not(:disabled) {
  transform: scale(1.03);
}
.chatbot-avatar-modal-photo-btn:active:not(:disabled) {
  transform: scale(0.98);
}
.chatbot-avatar-modal-photo-btn:disabled {
  cursor: default;
}
.chatbot-avatar-modal-img {
  display: block;
  width: 208px;
  height: 208px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid var(--chat-brass, #B08D57);
  box-shadow: var(--chat-shadow-card, 0 14px 34px -14px rgba(0, 77, 64, 0.32));
}
.chatbot-avatar-modal-zoom {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--chat-teal, #004d40);
  border: 2.5px solid var(--chat-white, #FFFFFF);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--chat-white, #FFFFFF);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
  pointer-events: none;
}
.chatbot-avatar-modal-zoom svg {
  width: 16px;
  height: 16px;
}
.chatbot-avatar-modal-photo-btn:disabled .chatbot-avatar-modal-zoom {
  display: none;
}
.chatbot-avatar-modal-caption h4 {
  margin: 0 0 2px;
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--chat-teal, #004d40);
}
.chatbot-avatar-modal-caption p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--chat-muted, rgba(0, 77, 64, 0.45));
}
.chatbot-avatar-modal-caption .chatbot-avatar-modal-hint {
  margin-top: 8px;
  font-size: 0.74rem;
  font-style: italic;
  color: var(--chat-brass, #B08D57);
}
.chatbot-avatar-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--chat-warm-tint, rgba(176, 141, 87, 0.07));
  color: var(--chat-teal, #004d40);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s;
}
.chatbot-avatar-modal-close:hover {
  background: var(--chat-brass-glow, rgba(176, 141, 87, 0.35));
}

/* =========================================================================
 * Lightbox — true full-size photo view, opened by a second tap on the
 * avatar-modal photo. Dark, edge-to-edge, no brand chrome: this is a photo
 * viewer, not another "card", so it deliberately reads differently from
 * every other layer in the widget.
 * ========================================================================= */
.chatbot-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  align-items: center;
  justify-content: center;
  padding: 32px;
  z-index: 1200;
}
.chatbot-lightbox.show {
  display: flex;
  animation: fadeIn 0.2s ease;
}
.chatbot-lightbox-img {
  max-width: 92vw;
  max-height: 82vh;
  object-fit: contain;
  border-radius: 18px;
  box-shadow: 0 30px 90px -20px rgba(0, 0, 0, 0.7);
  animation: avatarPop 0.25s var(--chat-ease, ease);
}
.chatbot-lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: var(--chat-white, #FFFFFF);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s;
}
.chatbot-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* =========================================================================
 * Messages
 * ========================================================================= */
.chatbot-messages {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background-color: var(--chat-warm-tint, rgba(176, 141, 87, 0.07));
  background-image:
    radial-gradient(circle at 9px 9px, rgba(0, 77, 64, 0.05) 1.4px, transparent 1.6px),
    radial-gradient(circle at 27px 27px, rgba(176, 141, 87, 0.06) 1.4px, transparent 1.6px);
  background-size: 36px 36px;
  display: flex;
  flex-direction: column;
}
.chatbot-message {
  display: flow-root; /* keeps the floated timestamp inside the bubble even when it wraps to its own line */
  margin: 0 4px 14px;
  padding: 11px 15px 9px;
  border-radius: var(--chat-radius-md, 14px);
  line-height: 1.48;
  max-width: 80%;
  word-wrap: break-word;
  font-size: 0.93rem;
  box-shadow: var(--chat-shadow-soft, 0 3px 10px -4px rgba(0, 77, 64, 0.18));
  animation: msgIn 0.25s var(--chat-ease, ease);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.chatbot-message.bot {
  background:
    linear-gradient(180deg, rgba(0, 77, 64, 0.035), rgba(0, 77, 64, 0) 45%),
    var(--chat-white, #FFFFFF);
  color: var(--chat-teal, #004d40);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chatbot-message.user {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0) 45%),
    var(--chat-teal, #004d40);
  color: var(--chat-white, #FFFFFF);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 3px 10px -5px rgba(0, 77, 64, 0.4);
}
/* Consecutive bubbles from the same sender read as one "run": the run's
   earlier bubbles lose their tail corner and sit closer together, and only
   the last bubble in the run keeps the tail — the way WhatsApp/iMessage
   group messages instead of repeating a tail on every line. */
.chatbot-message.grouped-follow {
  margin-top: -10px;
}
.chatbot-message.grouped-lead.bot {
  border-bottom-left-radius: var(--chat-radius-md, 14px);
}
.chatbot-message.grouped-lead.user {
  border-bottom-right-radius: var(--chat-radius-md, 14px);
}
.chatbot-msg-content {
  display: inline;
}
.chatbot-msg-content a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chatbot-msg-content code {
  background: rgba(0, 77, 64, 0.08);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.88em;
}
.chatbot-message.user .chatbot-msg-content code {
  background: rgba(255, 255, 255, 0.18);
}
/* Floats after the text so it tucks into the end of the last line, the way
   WhatsApp's in-bubble timestamp does, and wraps to its own line only when
   the message is too short/wide to leave room next to it. */
.chatbot-msg-time {
  float: right;
  margin: 4px 0 -2px 10px;
  font-size: 0.66rem;
  font-weight: 500;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.chatbot-message.bot .chatbot-msg-time {
  color: var(--chat-muted, rgba(0, 77, 64, 0.45));
}
.chatbot-message.user .chatbot-msg-time {
  color: rgba(255, 255, 255, 0.72);
}

.typing-indicator {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--chat-white, #FFFFFF);
  border-radius: var(--chat-radius-md, 14px);
  border-bottom-left-radius: 4px;
  width: fit-content;
  box-shadow: var(--chat-shadow-soft, 0 3px 10px -4px rgba(0, 77, 64, 0.18));
}
.typing-indicator span {
  display: inline-block;
  width: 7px;
  height: 7px;
  background-color: var(--chat-muted, rgba(0, 77, 64, 0.45));
  border-radius: 50%;
  margin: 0 3px;
  animation: bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* =========================================================================
 * Quick-reply chips (styles used to be injected from chatbot.js at runtime;
 * consolidated here so they share the exact same design tokens as the rest
 * of the widget instead of a second, slightly different brass value).
 * ========================================================================= */
.chatbot-quickreplies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 2px 4px 14px;
}
.chatbot-chip {
  background: var(--chat-white, #FFFFFF);
  color: var(--chat-teal, #004d40);
  border: 1px solid var(--chat-hairline, rgba(0, 77, 64, 0.14));
  border-radius: 999px;
  padding: 9px 16px;
  min-height: 40px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.1px;
  line-height: 1.3;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 2px 8px -3px rgba(0, 77, 64, 0.2);
  transition: background 0.15s var(--chat-ease, ease), color 0.15s var(--chat-ease, ease),
              transform 0.15s var(--chat-ease, ease), box-shadow 0.15s var(--chat-ease, ease);
}
.chatbot-chip:hover,
.chatbot-chip:focus-visible {
  background: var(--chat-teal, #004d40);
  color: #fff;
  outline: none;
  box-shadow: 0 4px 14px -4px rgba(0, 77, 64, 0.4);
}
.chatbot-chip:active {
  transform: scale(0.96);
}
.chatbot-chip:disabled {
  opacity: 0.5;
  cursor: default;
  box-shadow: none;
  transform: none;
}
.chatbot-chip.brass {
  border-color: var(--chat-brass, #B08D57);
  color: var(--chat-brass, #B08D57);
}
.chatbot-chip.brass:hover,
.chatbot-chip.brass:focus-visible {
  background: var(--chat-brass, #B08D57);
  color: #fff;
}

/* =========================================================================
 * Input area
 * ========================================================================= */
.chatbot-input-area {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--chat-hairline, rgba(0, 77, 64, 0.14));
  background: var(--chat-white, #FFFFFF);
  box-shadow: 0 -6px 16px -13px rgba(0, 77, 64, 0.3);
  flex-shrink: 0;
}
#chatbot-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--chat-hairline, rgba(0, 77, 64, 0.14));
  border-radius: 999px;
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--chat-teal, #004d40);
  background: var(--chat-warm-tint, rgba(176, 141, 87, 0.07));
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
#chatbot-input::placeholder {
  color: var(--chat-muted, rgba(0, 77, 64, 0.45));
}
#chatbot-input:focus {
  outline: none;
  border-color: var(--chat-teal, #004d40);
  background: var(--chat-white, #FFFFFF);
  box-shadow: 0 0 0 3px var(--chat-brass-glow, rgba(176, 141, 87, 0.35));
}
#chatbot-send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--chat-teal, #004d40);
  color: var(--chat-white, #FFFFFF);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.2s var(--chat-ease, ease), transform 0.15s var(--chat-ease, ease), opacity 0.2s;
}
#chatbot-send svg {
  width: 18px;
  height: 18px;
  margin-left: 1px; /* optical centering for the triangular glyph */
}
#chatbot-send:hover:not(:disabled) {
  filter: brightness(1.08);
}
#chatbot-send:active:not(:disabled) {
  transform: scale(0.92);
}
#chatbot-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (prefers-reduced-motion: reduce) {
  #chatbot-button,
  .chatbot-container,
  .chatbot-message,
  .chatbot-avatar-modal-inner,
  .chatbot-lightbox-img,
  .chatbot-status-dot,
  .chatbot-avatar-btn,
  .chatbot-avatar-modal-photo-btn,
  .chatbot-chip {
    animation: none !important;
    transition: none !important;
  }
}
