/* ============================================================
   CHATBOT WIDGET
   Floating chat toggle + expandable window (bottom-right).
   Prefixed cb-* to avoid collisions with main site styles.
   ============================================================ */
.cb-container {
  position: fixed;
  bottom: 21px;
  right: 18px;
  z-index: 9999;
  font-family: var(--font-body);
  box-sizing: border-box;
  user-select: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.cb-container.visible {
  opacity: 1;
  visibility: visible;
}

/* Header border gradient shimmer — loops a gold→slate sweep across the chat header bottom border */
@keyframes borderShimmer {
  0% {
    border-bottom: 2px solid var(--bp-gold);
  }

  50% {
    border-bottom: 2px solid #f1dfa0;
  }

  100% {
    border-bottom: 2px solid var(--bp-gold);
  }
}

/* Typing indicator dots — three dots scale up/down in sequence via animation-delay staggering */
@keyframes dot-flashing {

  0%,
  100% {
    background-color: rgba(169, 179, 190, 0);
  }

  50% {
    background-color: var(--bp-slate);
  }
}

/* Typing dots bounce — translateY creates a subtle vertical bounce synced with dot-flashing */
@keyframes typing {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-4px);
  }
}

/* Chat toggle button — fixed bottom-right, animated gradient border, will-change + backface-visibility for GPU-composited transforms */
.cb-toggle {
  user-select: none;
  position: absolute;
  bottom: 0;
  right: 0;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: var(--gradient-bgGray);
  background-size: 400% 400%;
  border: 2px solid var(--bp-acabe);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out, background 0.3s ease-in-out, border-color 0.3s ease-in-out;
  opacity: 1;
  animation: gradientMove 20s ease infinite;
  box-shadow: 0 2px 6px rgba(85, 85, 85, 0.10), 0 6px 16px rgba(85, 85, 85, 0.06);
  will-change: transform;
  backface-visibility: hidden;
}

.cb-toggle:hover {
  transform: scale(1.06);
  background: var(--gradient-bgGold);
  background-size: 400% 400%;
  animation: gradientMove 20s ease infinite;
  border-color: var(--bp-gold);
  box-shadow: 0 2px 8px var(--bp-gold-glow-strong), 0 6px 16px rgba(85, 85, 85, 0.10);
}

.cb-container.active .cb-toggle {
  display: none;
}

.cb-toggle-img {
  image-rendering: -webkit-optimize-contrast;
  position: absolute;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
}

.cb-expand {
  position: absolute;
  right: 40px;
  top: 4px;
  background: none;
  border: none;
  color: var(--bp-acabe);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
}

.cb-expand:hover,
.cb-expand:active {
  color: white;
}

.Touchscreen .cb-expand:hover {
  color: var(--bp-acabe);
}

/* Chat window — anchored above toggle via bottom: calc(100% - 20px), scale(1) translateY(20px) is the open state; closed state scales to 0 and shifts down */
.cb-window {
  width: 310px;
  background: #ffffffd2;
  border-radius: 10px;
  border: 2px solid var(--bp-acabe);
  box-shadow: 0 2px 6px rgba(85, 85, 85, 0.10), 0 6px 16px rgba(85, 85, 85, 0.06);
  opacity: 0;
  transform: scale(1) translateY(20px);
  transition: opacity 0.6s ease, transform 0.6s ease, left 0.6s ease;
  position: absolute;
  bottom: calc(100% - 20px);
  right: -18px;
  visibility: hidden;
  overflow-x: hidden;
}

.cb-container.active .cb-window {
  opacity: 1;
  transform: scale(1) translateY(0);
  visibility: visible;
}

/* Fullscreen mode — slides in from right (left: 100% → left: 0) on mobile, fills viewport */
.cb-window.fullscreen {
  width: 100%;
  height: 100%;
  top: 0;
  left: 100%;
  right: auto;
  bottom: 0;
  border-radius: 0;
  position: fixed;
  transition: left 0.6s ease;
  display: flex;
  flex-direction: column;
}

.cb-container.active .cb-window.fullscreen {
  left: 0;
}

.cb-window.fullscreen .cb-header {
  border-radius: 0;
}

.cb-window.fullscreen .cb-send {
  margin-right: 4px;
}

.cb-window.fullscreen .cb-body {
  flex: 1;
  overflow-y: auto;
  height: auto;
  padding: 15px 15px 20px 15px;
}

.cb-window.fullscreen .cb-input {
  position: sticky;
  bottom: 0;
  left: 0;
  width: 100%;
  padding: 2px;
  background: white;
  box-sizing: border-box;
  border-top: 1px solid var(--bp-content-bg);
}

.cb-window.fullscreen .cb-typing {
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: 45px;
  padding: 5px 5px;
  background: transparent;
  display: none;
  justify-content: center;
  gap: 4px;
}

.cb-header {
  background: var(--bp-bg-deep);
  color: white;
  padding: 4px 10px;
  border-radius: 8px 8px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 2;
  border-bottom: 2px solid var(--bp-gold);
  animation: borderShimmer 6s infinite ease-in-out;
}

.cb-title {
  margin: 0;
  color: var(--bp-acabe);
  font-size: 18px;
  font-weight: 500;
}

.cb-close {
  background: none;
  border: none;
  color: var(--bp-acabe);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
  padding: 4px 0 4px 8px;
}

.cb-close:hover,
.cb-close:active {
  color: white;
}

/* Message area — semi-transparent background, thin custom scrollbar, flex column for bottom-anchored auto-scroll */
.cb-body {
  height: 355px;
  overflow-y: auto;
  padding: 15px 15px 20px 15px;
  background: rgba(239, 239, 239, 0.85);
  overflow-x: hidden;
  word-wrap: break-word;
  white-space: normal;
  scrollbar-width: thin;
  scrollbar-color: var(--bp-slate) var(--bp-content-bg);
}

.cb-body::-webkit-scrollbar {
  width: 8px;
}

.cb-body::-webkit-scrollbar-track {
  background: var(--bp-content-bg);
  border-radius: 10px;
}

.cb-body::-webkit-scrollbar-thumb {
  background: var(--bp-slate);
  border-radius: 10px;
}

.cb-body::-webkit-scrollbar-thumb:hover {
  background: var(--bp-gold);
}

/* Chat messages — flex row with avatar + text; .cb-message-user reverses flex-direction so user messages align right */
.cb-message {
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
}

.cb-message.user {
  flex-direction: row-reverse;
  padding-right: 15px;
}

.cb-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  outline: 2.5px solid var(--bp-slate-light, #c8c8d6);
  outline-offset: -2px;
}

.cb-content {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.4;
  transition: opacity 0.6s ease, transform 0.6s ease, left 0.6s ease;
}

.cb-message.bot .cb-content {
  background: white;
  color: var(--bp-bg-deep);
  border: 1px solid var(--bp-acabe);
}

.cb-message.user .cb-content {
  background: var(--bp-bg-deep);
  color: white;
}

.cb-input {
  display: flex;
  padding: 2px;
  gap: 6px;
  background: white;
  border-top: 1px solid var(--bp-content-bg);
  padding-right: 6px;
}

.cb-input-field {
  flex: 1;
  padding: 2px 2px;
  border: 1px solid var(--bp-acabe);
  border-radius: 20px;
  font-size: 14px !important;
  outline: none;
  transition: border-color 0.3s ease;
}

.cb-input-field:focus {
  border-color: var(--bp-gold);
}

.cb-send {
  background: var(--bp-bg-deep);
  color: var(--bp-acabe);
  border: none;
  border-radius: 10px;
  cursor: pointer;
  padding: 2px;
  height: 30px;
  width: 35px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: auto;
}

.cb-send:hover,
.cb-send:active {
  color: white;
  background: var(--bp-bg-deep);
}

.Touchscreen .cb-send:hover {
  color: var(--bp-acabe);
  background: var(--bp-bg-deep);
}

/* Typing indicator — three dots with dual animations (dot-flashing + typing) staggered at 0s/0.2s/0.4s delays for a wave effect */
.cb-typing {
  display: none;
  position: absolute;
  left: 15px;
  right: 15px;
  bottom: 45px;
  padding: 5px 5px;
  justify-content: center;
  gap: 4px;
  background: transparent;
}

.cb-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: rgba(205, 176, 122, 0);
  animation: dot-flashing 1.2s infinite ease-in-out, typing 1.2s infinite ease-in-out;
}

.cb-typing span:nth-child(1) {
  animation-delay: 0s, 0s;
}

.cb-typing span:nth-child(2) {
  animation-delay: 0.4s, 0.4s;
}

.cb-typing span:nth-child(3) {
  animation-delay: 0.8s, 0.8s;
}

/* Bubble messages */
.cb-bubble {
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  line-height: 1.2;
  height: 100%;
  position: absolute;
  right: 76px;
  bottom: 15px;
  background: #fffffff2;
  color: var(--bp-bg-deep);
  border: 1px solid rgba(239, 239, 239, 0.46);
  padding: 4px 6px;
  border-radius: 20px;
  font-size: 11px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  opacity: 0;
  min-width: 140px;
  min-height: 40px;
  max-height: 350px;
  max-width: 260px;
  pointer-events: none;
  z-index: 9998;
  transform: translateX(10px);
  visibility: hidden;
  white-space: pre-line;
  overflow-wrap: break-word;
  word-break: break-word;
  overflow: hidden;
}

.cb-bubble-small {
  line-height: 0;
  width: 10px;
  height: 10px;
  min-width: 10px;
  min-height: 10px;
  max-width: 100px;
  max-height: 100px;
  position: absolute;
  right: calc(100px - 36px);
  background: #fffffff2;
  color: #fffffff2;
  border: 1px solid rgba(169, 179, 190, 0.46);
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  padding: 0;
  border-radius: 50%;
  font-size: 6px;
  opacity: 0;
  pointer-events: none;
  z-index: 9997;
  transform: translateX(11px);
}

.cb-bubble, .cb-bubble-small {
  transition: opacity 0.6s ease, visibility 0s linear 0.6s;
}

/* Responsive — 1024px: smaller toggle + window; 480px: fullscreen-only chat window */
@media only screen and (max-width: 1024px) {
  .cb-container {
    right: 10px;
    bottom: 45px;
  }

  .cb-window {
    width: 310px;
    bottom: calc(100% - 45px);
    right: -8px;
  }

  .cb-body {
    height: 300px;
    padding: 10px 10px 20px 10px;
  }

  .cb-title {
    font-size: 14px;
  }

  .cb-content {
    font-size: 12px;
  }

  .cb-input-field {
    font-size: 12px;
    padding: 4px 6px;
  }

}

@media only screen and (max-width: 480px) {
  .cb-window.fullscreen .cb-input {
    padding-bottom: max(2px, env(safe-area-inset-bottom));
  }
  .cb-bubble {
    right: 66px;
    min-width: 100px;
    max-width: 220px;
    font-size: 10px;
  }
  .cb-bubble-small {
    right: calc(100px - 44px);
  }
}

