/* ==========================================
   BIBU AI CHATBOT
   Clean responsive layout
========================================== */

#bibuChatbot {
  --bibu-accent: #4cc9ff;
  --bibu-purple: #7b61ff;
  --bibu-panel: #111827;
  --bibu-card: #1b2638;
  --bibu-text: #f4f7ff;
  --bibu-muted: #9ba9bd;
  --bibu-border: rgba(255, 255, 255, 0.1);

  position: fixed;
  right: clamp(12px, 2vw, 28px);
  bottom: clamp(12px, 2vw, 28px);
  z-index: 9998;
  font-family: inherit;
  box-sizing: border-box;
}

#bibuChatbot *,
#bibuChatbot *::before,
#bibuChatbot *::after {
  box-sizing: border-box;
}

/* Launcher */

#bibuChatbot .bibu-launcher {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 11px 16px;
  border: none;
  border-radius: 50px;
  background: linear-gradient(135deg, var(--bibu-accent), var(--bibu-purple));
  color: #08111f;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 30px rgba(76, 201, 255, 0.28);
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease;
}

#bibuChatbot .bibu-launcher:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 35px rgba(123, 97, 255, 0.4);
}

#bibuChatbot .bibu-launcher-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  overflow: hidden;
  border-radius: 50%;
}

#bibuChatbot .bibu-avatar-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

#bibuChatbot .bibu-launcher-label {
  white-space: nowrap;
}

/* Chat window */

#bibuChatbot .bibu-window {
  position: absolute;
  right: 0;
  bottom: 72px;
  display: flex;
  flex-direction: column;

  width: min(400px, calc(100vw - 32px));
  height: min(620px, calc(100dvh - 110px));
  min-height: 300px;

  overflow: hidden;
  border: 1px solid var(--bibu-border);
  border-radius: 19px;
  background: var(--bibu-panel);
  color: var(--bibu-text);
  box-shadow: 0 20px 65px rgba(0, 0, 0, 0.4);

  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;

  transition:
    opacity 0.22s ease,
    transform 0.22s ease,
    visibility 0.22s ease;
}

#bibuChatbot.bibu-open .bibu-window {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

/* Header */

#bibuChatbot .bibu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: 0 0 auto;
  min-height: 68px;
  padding: 11px 15px;
  background: linear-gradient(120deg, #182b43, #28204b);
  border-bottom: 1px solid var(--bibu-border);
}

#bibuChatbot .bibu-header-info {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

#bibuChatbot .bibu-avatar {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  overflow: hidden;
  border-radius: 50%;
}

#bibuChatbot .bibu-header h3 {
  margin: 0 0 4px;
  color: #fff;
  font-size: 16px;
}

#bibuChatbot .bibu-status {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #d0d9e8;
  font-size: 11px;
}

#bibuChatbot .bibu-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #35d98b;
  box-shadow: 0 0 8px rgba(53, 217, 139, 0.6);
}

#bibuChatbot .bibu-header-actions {
  display: flex;
  flex-shrink: 0;
  gap: 7px;
}

#bibuChatbot .bibu-header-actions button {
  display: grid;
  place-items: center;
  width: 33px;
  height: 33px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
  color: white;
  font-size: 21px;
  cursor: pointer;
}

/* Messages */

#bibuChatbot .bibu-messages {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: stretch;
  gap: 15px;
  min-height: 0;
  padding: 16px 13px;
  overflow-x: hidden;
  overflow-y: auto;
  text-align: left;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

#bibuChatbot .bibu-message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 92%;
  min-width: 0;
}

#bibuChatbot .bibu-message-bot {
  align-self: flex-start;
  justify-content: flex-start;
}

#bibuChatbot .bibu-message-user {
  align-self: flex-end;
  justify-content: flex-end;
}

#bibuChatbot .bibu-message-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 27px;
  height: 27px;
  flex: 0 0 27px;
  overflow: hidden;
  border-radius: 50%;
}

#bibuChatbot .bibu-message-content {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  max-width: 100%;
  text-align: left;
}

#bibuChatbot .bibu-message-bubble {
  display: block;
  width: fit-content;
  max-width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--bibu-border);
  border-radius: 14px 14px 14px 4px;
  background: var(--bibu-card);
  color: var(--bibu-text);
  font-size: 13px;
  line-height: 1.6;
  text-align: left;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

#bibuChatbot .bibu-message-user .bibu-message-bubble {
  border: none;
  border-radius: 14px 14px 4px 14px;
  background: linear-gradient(135deg, #287fb2, #6751c5);
  color: #fff;
}

#bibuChatbot .bibu-message-time {
  display: block;
  padding: 0 3px;
  color: var(--bibu-muted);
  font-size: 10px;
  text-align: left;
}

#bibuChatbot .bibu-message-user .bibu-message-time {
  text-align: right;
}

/* Typing indicator */

#bibuChatbot .bibu-typing {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 5px;
  padding: 0 17px 10px;
  color: var(--bibu-muted);
}

#bibuChatbot .bibu-typing[hidden] {
  display: none;
}

#bibuChatbot .bibu-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bibu-accent);
  animation: bibuTyping 1s infinite ease-in-out;
}

#bibuChatbot .bibu-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

#bibuChatbot .bibu-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

#bibuChatbot .bibu-typing small {
  margin-left: 5px;
  font-size: 11px;
}

@keyframes bibuTyping {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }
  30% {
    opacity: 1;
    transform: translateY(-4px);
  }
}

/* Input */

#bibuChatbot .bibu-input-area {
  display: flex;
  align-items: flex-end;
  flex: 0 0 auto;
  gap: 9px;
  width: 100%;
  margin: 0;
  padding: 11px 12px 7px;
  border-top: 1px solid var(--bibu-border);
  background: var(--bibu-panel);
}

#bibuChatbot .bibu-input-area textarea {
  flex: 1 1 auto;
  width: 0;
  min-width: 0;
  max-height: 120px;
  resize: none;
  padding: 10px 12px;
  border: 1px solid var(--bibu-border);
  border-radius: 12px;
  outline: none;
  background: var(--bibu-card);
  color: var(--bibu-text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
}

#bibuChatbot .bibu-input-area textarea:focus {
  border-color: var(--bibu-accent);
}

#bibuChatbot .bibu-input-area textarea::placeholder {
  color: var(--bibu-muted);
}

#bibuChatbot .bibu-input-area button {
  display: grid;
  place-items: center;
  flex: 0 0 41px;
  width: 41px;
  height: 41px;
  padding: 0;
  border: none;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--bibu-accent), var(--bibu-purple));
  color: #08111f;
  font-size: 19px;
  cursor: pointer;
}

#bibuChatbot .bibu-input-area button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* Turnstile */

#bibuChatbot #bibuTurnstile {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 0 0 auto;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

/* Disclaimer */

#bibuChatbot .bibu-disclaimer {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  margin: 0;
  padding: 8px 12px 10px;
  background: var(--bibu-panel);
  color: var(--bibu-muted);
  font-size: 10px;
  line-height: 1.45;
  text-align: center;
  overflow-wrap: anywhere;
}

/* Theme compatibility */

body.light #bibuChatbot,
body.light-mode #bibuChatbot {
  --bibu-panel: #ffffff;
  --bibu-card: #f0f3f9;
  --bibu-text: #172033;
  --bibu-muted: #69758a;
  --bibu-border: rgba(20, 35, 60, 0.12);
}

body.light #bibuChatbot .bibu-header,
body.light-mode #bibuChatbot .bibu-header {
  background: linear-gradient(120deg, #dff5ff, #eee7ff);
}

body.light #bibuChatbot .bibu-header h3,
body.light-mode #bibuChatbot .bibu-header h3 {
  color: #172033;
}

body.light #bibuChatbot .bibu-status,
body.light-mode #bibuChatbot .bibu-status {
  color: #536176;
}

body.light #bibuChatbot .bibu-header-actions button,
body.light-mode #bibuChatbot .bibu-header-actions button {
  color: #172033;
  border-color: rgba(20, 35, 60, 0.12);
  background: rgba(255, 255, 255, 0.55);
}

/* Mobile */

@media (max-width: 600px) {
  #bibuChatbot {
    right: 12px;
    bottom: 12px;
  }

  #bibuChatbot .bibu-window {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: auto;
    height: min(650px, calc(100dvh - 100px - env(safe-area-inset-bottom)));
    max-height: calc(100dvh - 100px - env(safe-area-inset-bottom));
    min-height: 260px;
    border-radius: 18px;
    transform-origin: bottom center;
  }

  #bibuChatbot .bibu-header {
    min-height: 62px;
    padding: 9px 12px;
  }

  #bibuChatbot .bibu-messages {
    padding: 13px 10px;
    gap: 12px;
  }

  #bibuChatbot .bibu-message {
    max-width: 96%;
  }

  #bibuChatbot .bibu-message-bubble {
    font-size: 13px;
    padding: 10px 11px;
  }

  #bibuChatbot .bibu-input-area {
    padding: 9px 9px 5px;
  }

  #bibuChatbot .bibu-disclaimer {
    padding: 5px 9px 8px;
    font-size: 9px;
  }

  #bibuChatbot .bibu-launcher {
    padding: 10px 14px;
  }
}

@media (max-width: 360px) {
  #bibuChatbot .bibu-window {
    left: 6px;
    right: 6px;
    bottom: calc(70px + env(safe-area-inset-bottom));
    height: calc(100dvh - 88px - env(safe-area-inset-bottom));
    max-height: calc(100dvh - 88px - env(safe-area-inset-bottom));
  }

  #bibuChatbot .bibu-header-actions {
    gap: 5px;
  }

  #bibuChatbot .bibu-header-actions button {
    width: 30px;
    height: 30px;
  }

  #bibuChatbot .bibu-launcher {
    font-size: 12px;
  }
}

/* Reduced motion */

@media (prefers-reduced-motion: reduce) {
  #bibuChatbot .bibu-window,
  #bibuChatbot .bibu-launcher {
    transition: none;
  }

  #bibuChatbot .bibu-typing span {
    animation: none;
  }
}

/* Correct chatbot bottom positioning */

#bibuChatbot .bibu-window {
  position: absolute;
  display: flex;
  flex-direction: column;
  padding-bottom: 0 !important;
}

#bibuChatbot .bibu-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

#bibuChatbot .bibu-input-area {
  flex: 0 0 auto;
  margin-bottom: 0 !important;
}

#bibuChatbot #bibuTurnstile {
  flex: 0 0 auto;
  margin: 0 !important;
  padding: 0 !important;
}

#bibuChatbot .bibu-disclaimer {
  position: relative;
  flex: 0 0 auto;
  display: block;
  width: 100%;
  margin: 0 !important;
  padding: 7px 10px 8px !important;
  text-align: center;
  line-height: 1.4;
  background: var(--bibu-panel);
  box-sizing: border-box;
}

/* Mobile chatbot sizing */
@media (max-width: 600px) {
  #bibuChatbot .bibu-window {
    position: fixed;
    left: auto;
    right: 12px;
    bottom: calc(75px + env(safe-area-inset-bottom));

    width: min(360px, calc(100vw - 24px));
    height: min(480px, calc(100dvh - 110px));
    max-height: calc(100dvh - 110px);
    min-height: 320px;

    border-radius: 18px;
    overflow: hidden;
  }

  #bibuChatbot .bibu-messages {
    flex: 1 1 auto;
    min-height: 0;
    padding: 11px;
  }

  #bibuChatbot .bibu-input-area {
    padding: 8px 9px 5px;
  }

  #bibuChatbot .bibu-disclaimer {
    padding: 6px 8px 8px !important;
    font-size: 9px;
  }
}

/* Very small screens */
@media (max-width: 380px) {
  #bibuChatbot .bibu-window {
    width: calc(100vw - 24px);
    height: min(430px, calc(100dvh - 105px));
    min-height: 300px;
  }
}
