/* Modern AI Chatbot Widget (Bootstrap-friendly)
   - Uses Bootstrap CSS variables when available
   - Namespaced with .ai-chatbot* to avoid collisions
*/

.ai-chatbot {
  position: fixed;
  right: 16px;
  bottom: 16px;
  /* Keep below Bootstrap modal/backdrop (1050/1055) */
  z-index: 1039;
  pointer-events: none;
}

.ai-chatbot__launcher,
.ai-chatbot__panel {
  pointer-events: auto;
}

.ai-chatbot__launcher {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

/* Attention nudge (speech bubble) */
.ai-chatbot__nudge {
  position: absolute;
  right: 0;
  bottom: 64px;
  pointer-events: none;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 160ms ease, transform 180ms ease;
}

.ai-chatbot__nudge-bubble {
  max-width: min(260px, calc(100vw - 32px));
  background: var(--bs-body-bg, #fff);
  color: var(--bs-body-color, #212529);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.18);
  line-height: 1.2;
  font-size: 0.9rem;
}

.ai-chatbot__nudge-bubble::after {
  content: '';
  position: absolute;
  right: 18px;
  bottom: -8px;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-top: 8px solid var(--bs-body-bg, #fff);
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.12));
}

.ai-chatbot[data-state="open"] .ai-chatbot__nudge {
  opacity: 0;
  transform: translateY(6px);
}

/* Heartbeat launcher (closed state only) */
.ai-chatbot[data-state="closed"] .ai-chatbot__launcher {
  animation: aiChatbotHeartbeat 1.6s ease-in-out infinite;
  transform-origin: bottom right;
}

@keyframes aiChatbotHeartbeat {
  0%, 100% { transform: scale(1); }
  12% { transform: scale(1.06); }
  24% { transform: scale(1); }
  36% { transform: scale(1.08); }
  52% { transform: scale(1); }
}

.ai-chatbot__launcher-icon {
  display: inline-flex;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-content: center;
}

.ai-chatbot__panel {
  position: absolute;
  right: 0;
  bottom: 56px;
  width: min(420px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 140px));
  background: var(--bs-body-bg, #fff);
  color: var(--bs-body-color, #212529);
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 16px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.28);
  overflow: hidden;

  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 160ms ease, transform 180ms cubic-bezier(0.2, 0.9, 0.2, 1);
  pointer-events: none;
}

/* Desktop maximize mode (mobile already uses fullscreen panel) */
@media (min-width: 768px) {
  .ai-chatbot[data-size="max"] .ai-chatbot__panel {
    position: fixed;
    right: 2.5vw;
    bottom: 2.5vh;
    width: 95vw;
    height: 95vh;
    max-width: 95vw;
    max-height: 95vh;
  }
}

.ai-chatbot[data-state="open"] .ai-chatbot__panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.ai-chatbot[data-state="open"] .ai-chatbot__launcher {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
}

.ai-chatbot__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px;
  background: linear-gradient(135deg, rgba(13, 110, 253, 0.15), rgba(13, 110, 253, 0.03));
  border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.ai-chatbot__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ai-chatbot__brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bs-primary, #0d6efd);
  color: #fff;
}

.ai-chatbot__name {
  font-weight: 700;
  line-height: 1.1;
}

.ai-chatbot__status {
  font-size: 12px;
  color: var(--bs-secondary-color, #6c757d);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.ai-chatbot__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bs-success, #198754);
  box-shadow: 0 0 0 0 rgba(25, 135, 84, 0.35);
  animation: aiChatbotPulse 1.8s ease-out infinite;
}

@keyframes aiChatbotPulse {
  0% { box-shadow: 0 0 0 0 rgba(25, 135, 84, 0.35); }
  70% { box-shadow: 0 0 0 10px rgba(25, 135, 84, 0); }
  100% { box-shadow: 0 0 0 0 rgba(25, 135, 84, 0); }
}

.ai-chatbot__icon-btn {
  border-radius: 10px;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.ai-chatbot__body {
  display: flex;
  flex-direction: column;
  height: calc(100% - 56px);
}

.ai-chatbot__messages {
  flex: 1;
  overflow: auto;
  padding: 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, rgba(13, 110, 253, 0.03), rgba(0, 0, 0, 0));
}

.ai-chatbot__msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: aiChatbotMsgIn 180ms ease-out;
}

@keyframes aiChatbotMsgIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.ai-chatbot__msg--user {
  justify-content: flex-end;
}

.ai-chatbot__bubble {
  max-width: 85%;
  padding: 9px 11px;
  border-radius: 14px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
}

.ai-chatbot__msg--user .ai-chatbot__bubble {
  background: var(--bs-primary, #0d6efd);
  color: #fff;
  border-color: rgba(13, 110, 253, 0.4);
  border-bottom-right-radius: 6px;
}

.ai-chatbot__msg--bot .ai-chatbot__bubble {
  background: var(--bs-body-bg, #fff);
  color: var(--bs-body-color, #212529);
  border-bottom-left-radius: 6px;
}

.ai-chatbot__bubble p:last-child {
  margin-bottom: 0;
}

.ai-chatbot__typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 14px;
}

.ai-chatbot__typing span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  animation: aiChatbotDots 1.1s infinite;
}

.ai-chatbot__typing span:nth-child(2) { animation-delay: 120ms; }
.ai-chatbot__typing span:nth-child(3) { animation-delay: 240ms; }

@keyframes aiChatbotDots {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.ai-chatbot__quick {
  padding: 10px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: var(--bs-body-bg, #fff);

  /* Smooth "tenggelam" hide animation */
  max-height: 160px;
  opacity: 1;
  transform: translateY(0);
  overflow: hidden;
  transition: max-height 300ms ease, opacity 270ms ease, transform 300ms ease, padding 300ms ease;
  will-change: max-height, opacity, transform;
}

.ai-chatbot__quick.ai-chatbot__quick--hidden {
  opacity: 0;
  transform: translateY(10px);
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  pointer-events: none;
}

.ai-chatbot__chip {
  border-radius: 999px;
}

/* Chip shape variants (no color/token changes) */
.ai-chatbot__chip--pill {
  border-radius: 999px;
}

.ai-chatbot__chip--cut {
  border-radius: 10px;
}

.ai-chatbot__composer {
  padding: 10px 12px 12px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: #fff;
}

/* Keep input group white even if global theme toggles */
.ai-chatbot__composer .input-group,
.ai-chatbot__composer .form-control {
  background: #fff;
}

.ai-chatbot__composer .form-control {
  color: #212529;
}

.ai-chatbot__composer .form-control:focus {
  background: #fff;
  color: #212529;
}

.ai-chatbot__composer .form-control::placeholder {
  color: rgba(33, 37, 41, 0.6);
}

.ai-chatbot__hint {
  font-size: 12px;
  margin-top: 6px;
}

/* Mobile safe-area + positioning */
@supports (padding: max(0px)) {
  .ai-chatbot {
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
  }
}

/* Mobile: make chat panel fullscreen for usability */
@media (max-width: 576px) {
  .ai-chatbot__panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    right: 0;
    bottom: 0;
    transform-origin: center;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .ai-chatbot__panel,
  .ai-chatbot__msg,
  .ai-chatbot__dot,
  .ai-chatbot__typing span,
  .ai-chatbot__launcher {
    transition: none !important;
    animation: none !important;
  }
}
