/* =====================================================
   BRIGAMA Chatbot Widget
   ===================================================== */

/* ── Toggle Button ── */
.chatbot-toggle {
  position: fixed;
  bottom: 28px;
  right: 24px; /* Tighter to the corner when at the top */
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-800), var(--blue-700));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(8, 87, 195, 0.40);
  z-index: 2000; /* Stays above navbar (z-1000) */
  transition: right 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
              transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
              box-shadow var(--transition);
  color: #fff;
}

/* Shift left when back-to-top is visible (at About section and below) */
.chatbot-toggle.shifted {
  right: 92px !important;
}

.chatbot-toggle:hover {
  transform: translateY(-2px) scale(1.05);
  box-shadow: 0 8px 28px rgba(8, 87, 195, 0.50);
}

.chatbot-toggle .cb-icon-open,
.chatbot-toggle .cb-icon-close {
  position: absolute;
  transition: opacity var(--transition), transform var(--transition);
}

.chatbot-toggle .cb-icon-close {
  opacity: 0;
  transform: rotate(-90deg) scale(0.8);
}

.chatbot-toggle.is-open .cb-icon-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.8);
}

.chatbot-toggle.is-open .cb-icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Notification dot */
.chatbot-toggle .cb-notif {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  background: var(--gold-400);
  border-radius: 50%;
  border: 2px solid #fff;
  animation: cb-pulse 2s infinite;
}

@keyframes cb-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%       { transform: scale(1.3); opacity: 0.7; }
}

/* ── Chat Panel ── */
.chatbot-panel {
  position: fixed;
  bottom: 100px;
  right: 32px;
  width: 380px;
  max-height: calc(100vh - 120px); /* Ensure it stays within viewport and below navbar */
  background: var(--white);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1999; /* Just below its toggle but above navbar */
  opacity: 0;
  transform: translateY(20px) scale(0.92);
  transform-origin: bottom right; /* Pop from the toggle button corner */
  pointer-events: none;
  transition: opacity 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), 
              transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  border: 1px solid rgba(8, 87, 195, 0.15);
}

.chatbot-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* ── Header ── */
.cb-header {
  background: linear-gradient(135deg, var(--blue-900), var(--blue-800));
  padding: 16px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.cb-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.cb-header-info {
  flex: 1;
  min-width: 0;
}

.cb-header-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.cb-header-status {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}

.cb-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  animation: cb-pulse 2.5s infinite;
}

.cb-header-close {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color var(--transition), background var(--transition);
}

.cb-header-close:hover {
  color: #fff;
  background: rgba(255,255,255,0.12);
}

/* ── Messages Area ── */
.cb-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--gray-50);
  scroll-behavior: smooth;
}

.cb-messages::-webkit-scrollbar { width: 4px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 2px; }

/* Message Bubbles */
.cb-msg {
  display: flex;
  gap: 8px;
  max-width: 90%;
  animation: cb-msg-in 0.2s ease;
}

@keyframes cb-msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cb-msg--bot {
  align-self: flex-start;
}

.cb-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.cb-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.8375rem;
  line-height: 1.55;
  word-break: break-word;
}

.cb-msg--bot .cb-msg-bubble {
  background: var(--white);
  color: var(--gray-800);
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--shadow-sm);
}

.cb-msg--user .cb-msg-bubble {
  background: linear-gradient(135deg, var(--blue-800), var(--blue-700));
  color: #fff;
  border-radius: 16px 4px 16px 16px;
}

/* Markdown-like formatting inside bot bubbles */
.cb-msg--bot .cb-msg-bubble strong {
  font-weight: 600;
  color: var(--blue-800);
}

.cb-msg--bot .cb-msg-bubble ul {
  margin: 6px 0 0 0;
  padding-left: 18px;
}

.cb-msg--bot .cb-msg-bubble li {
  margin-bottom: 3px;
}

.cb-msg--bot .cb-msg-bubble a {
  color: var(--blue-700);
  text-decoration: underline;
  font-weight: 500;
}

/* Typing Indicator */
.cb-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: var(--white);
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--shadow-sm);
  width: fit-content;
  animation: cb-msg-in 0.2s ease;
}

.cb-typing span {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--gray-300);
  animation: cb-bounce 1.2s infinite;
}

.cb-typing span:nth-child(2) { animation-delay: 0.15s; }
.cb-typing span:nth-child(3) { animation-delay: 0.30s; }

@keyframes cb-bounce {
  0%, 60%, 100% { transform: translateY(0); background: var(--gray-300); }
  30%           { transform: translateY(-5px); background: var(--blue-700); }
}

/* ── Suggestions ── */
.cb-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  background: var(--gray-50);
}

.cb-suggestion-chip {
  background: var(--white);
  border: 1px solid rgba(8, 87, 195, 0.20);
  color: var(--blue-800);
  border-radius: 20px;
  padding: 5px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  font-family: var(--font-family);
  white-space: nowrap;
}

.cb-suggestion-chip:hover {
  background: var(--blue-50);
  border-color: var(--blue-700);
}

/* ── Input Area ── */
.cb-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  background: var(--white);
  border-top: 1px solid var(--gray-100);
  flex-shrink: 0;
}

.cb-input {
  flex: 1;
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  padding: 9px 16px;
  font-size: 0.8375rem;
  font-family: var(--font-family);
  color: var(--gray-800);
  background: var(--gray-50);
  resize: none;
  outline: none;
  line-height: 1.4;
  max-height: 100px;
  overflow-y: auto;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.cb-input::placeholder { color: var(--gray-400); }

.cb-input:focus {
  border-color: var(--blue-700);
  box-shadow: 0 0 0 3px rgba(48, 127, 226, 0.12);
  background: var(--white);
}

.cb-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-800), var(--blue-700));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
  transition: transform var(--transition), box-shadow var(--transition), opacity var(--transition);
}

.cb-send:hover:not(:disabled) {
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(8, 87, 195, 0.35);
}

.cb-send:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Mobile ── */
@media (max-width: 420px) {
  .chatbot-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 148px;
  }

  .chatbot-toggle {
    right: 20px;
    bottom: 20px;
  }

  .chatbot-toggle.shifted {
    right: 80px;
  }
}
