/* =============================================
   MABEL CHATBOT — SMKN 15 KOTA BEKASI
   chatbot.css
   Compatible: Mobile & Desktop
   ============================================= */

/* ---- ROOT VARIABLES ---- */
:root {
  --cb-primary: #004aad;
  --cb-primary-dark: #003688;
  --cb-primary-light: #e8f0fd;
  --cb-accent: #f39c12;
  --cb-wa-green: #25D366;
  --cb-wa-dark: #1ebe5d;
  --cb-bot-bubble: #f0f4ff;
  --cb-bot-text: #1a1a2e;
  --cb-user-bubble: #004aad;
  --cb-user-text: #ffffff;
  --cb-bg: #f7f9fc;
  --cb-border: #dde4f0;
  --cb-shadow: 0 8px 40px rgba(0, 74, 173, 0.18);
  --cb-radius: 20px;
  --cb-radius-bubble: 18px;
  --cb-font: 'Poppins', sans-serif;
  --cb-header-h: 64px;
  --cb-footer-h: 64px;
  --cb-win-w: 380px;
  --cb-win-h: 560px;
  --cb-z: 99999;
}

/* =============================================
   FLOATING LAUNCHER BUTTONS
   ============================================= */
#cb-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  z-index: var(--cb-z);
}

/* WhatsApp Button */
#cb-wa-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  background: var(--cb-wa-green);
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(37, 211, 102, 0.4);
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s;
  text-decoration: none;
  position: relative;
}

#cb-wa-btn:hover {
  transform: scale(1.12);
  box-shadow: 0 6px 24px rgba(37, 211, 102, 0.55);
}

#cb-wa-btn svg {
  width: 26px;
  height: 26px;
  fill: white;
}

/* Tooltip WA */
#cb-wa-btn::before {
  content: attr(data-tooltip);
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: rgba(37, 211, 102, 0.95);
  color: white;
  font-family: var(--cb-font);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: 8px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

#cb-wa-btn:hover::before {
  opacity: 1;
}

/* Chat Open Button */
#cb-open-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  background: var(--cb-primary);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 74, 173, 0.45);
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), box-shadow 0.25s;
  position: relative;
  overflow: visible;
}

#cb-open-btn:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(0, 74, 173, 0.6);
}

#cb-open-btn svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s;
  position: absolute;
}

#cb-open-btn .cb-icon-bot {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

#cb-open-btn .cb-icon-close {
  opacity: 0;
  transform: scale(0.6) rotate(-45deg);
}

#cb-open-btn.active .cb-icon-bot {
  opacity: 0;
  transform: scale(0.6) rotate(45deg);
}

#cb-open-btn.active .cb-icon-close {
  opacity: 1;
  transform: scale(1) rotate(0deg);
}

/* Pulse ring on open button */
#cb-open-btn::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid rgba(0, 74, 173, 0.4);
  animation: cb-pulse 2.5s ease-out infinite;
}

@keyframes cb-pulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.7); opacity: 0; }
}

/* =============================================
   CHAT WINDOW
   ============================================= */
#cb-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: var(--cb-win-w);
  height: var(--cb-win-h);
  background: var(--cb-bg);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--cb-z);
  transform-origin: bottom right;
  transition: transform 0.35s cubic-bezier(.34,1.56,.64,1),
              opacity 0.3s ease,
              height 0.4s cubic-bezier(.22,1,.36,1);
  border: 1px solid var(--cb-border);
}

/* States */
#cb-window.cb-closed {
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
}

#cb-window.cb-open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ---- HEADER ---- */
#cb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--cb-header-h);
  background: var(--cb-primary);
  flex-shrink: 0;
  cursor: default;
}

.cb-header-left {
  display: flex;
  align-items: center;
  gap: 11px;
}

.cb-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.35);
  background: white;
  padding: 3px;
  flex-shrink: 0;
}

.cb-header-info {
  display: flex;
  flex-direction: column;
}

.cb-bot-name {
  color: white;
  font-family: var(--cb-font);
  font-weight: 700;
  font-size: 15px;
  line-height: 1.2;
  letter-spacing: 0.3px;
}

.cb-bot-status {
  color: rgba(255,255,255,0.75);
  font-family: var(--cb-font);
  font-size: 11.5px;
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cb-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #5dff9b;
  display: inline-block;
  animation: cb-blink 2s ease-in-out infinite;
}

@keyframes cb-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.cb-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cb-header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 8px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  color: white;
  font-size: 15px;
}

.cb-header-btn:hover {
  background: rgba(255,255,255,0.28);
}

.cb-header-btn svg {
  width: 16px;
  height: 16px;
  fill: white;
}

/* ---- SEARCH BAR ---- */
#cb-search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: white;
  border-bottom: 1px solid var(--cb-border);
  transform: translateY(-100%);
  opacity: 0;
  height: 0;
  overflow: hidden;
  transition: all 0.3s ease;
}

#cb-search-bar.cb-visible {
  transform: translateY(0);
  opacity: 1;
  height: 48px;
}

#cb-search-input {
  flex: 1;
  border: 1px solid var(--cb-border);
  border-radius: 10px;
  padding: 6px 12px;
  font-family: var(--cb-font);
  font-size: 13px;
  outline: none;
  color: var(--cb-bot-text);
  background: var(--cb-bg);
  transition: border-color 0.2s;
}

#cb-search-input:focus {
  border-color: var(--cb-primary);
}

#cb-search-clear {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: #888;
  padding: 4px;
}

/* ---- BODY / MESSAGES ---- */
#cb-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  background: var(--cb-bg);
}

/* Scrollbar */
#cb-body::-webkit-scrollbar {
  width: 4px;
}
#cb-body::-webkit-scrollbar-track {
  background: transparent;
}
#cb-body::-webkit-scrollbar-thumb {
  background: var(--cb-border);
  border-radius: 4px;
}

/* Date divider */
.cb-date-divider {
  text-align: center;
  font-family: var(--cb-font);
  font-size: 11px;
  color: #aaa;
  padding: 4px 0 2px;
  position: relative;
}

.cb-date-divider::before,
.cb-date-divider::after {
  content: '';
  display: inline-block;
  height: 1px;
  background: var(--cb-border);
  width: 28%;
  vertical-align: middle;
  margin: 0 8px;
}

/* Message row */
.cb-msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: cb-msg-in 0.35s cubic-bezier(.22,1,.36,1) both;
}

@keyframes cb-msg-in {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.cb-msg-row.cb-user {
  flex-direction: row-reverse;
}

/* Mini avatar in messages */
.cb-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: white;
  padding: 2px;
  border: 1px solid var(--cb-border);
  flex-shrink: 0;
}

.cb-msg-row.cb-user .cb-msg-avatar {
  display: none;
}

/* Bubble wrapper */
.cb-bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 100%;
}

.cb-msg-row.cb-user .cb-bubble-wrap {
  align-items: flex-end;
}

/* Bubble */
.cb-bubble {
  padding: 10px 14px;
  border-radius: var(--cb-radius-bubble);
  font-family: var(--cb-font);
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
  position: relative;
  width: fit-content;
  max-width: 100%;
  white-space: normal;
}

/* Bot bubble */
.cb-msg-row.cb-bot .cb-bubble {
  background: white;
  color: var(--cb-bot-text);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--cb-border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

/* User bubble */
.cb-msg-row.cb-user .cb-bubble {
  background: var(--cb-user-bubble);
  color: var(--cb-user-text);
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 74, 173, 0.25);
}

/* Bubble with list */
.cb-bubble ul {
  list-style: none;
  margin: 6px 0 2px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.cb-bubble ul li {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 6px 10px;
  background: var(--cb-primary-light);
  border-radius: 10px;
  font-size: 13px;
  color: var(--cb-bot-text);
  line-height: 1.45;
}

.cb-bubble ul li::before {
  content: '›';
  color: var(--cb-primary);
  font-weight: 700;
  font-size: 16px;
  line-height: 1.2;
  flex-shrink: 0;
}

/* Bubble para intro text above list */
.cb-bubble .cb-intro {
  margin-bottom: 8px;
  font-weight: 500;
  color: #444;
  font-size: 13.5px;
}

/* Error fallback bubble */
.cb-bubble.cb-error {
  background: #fff8f0;
  border-color: #fde8c8;
}

.cb-bubble.cb-error .cb-err-title {
  font-weight: 600;
  color: #c0392b;
  margin-bottom: 6px;
  font-size: 13px;
}

.cb-err-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.cb-err-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  font-family: var(--cb-font);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
  transition: transform 0.2s, box-shadow 0.2s;
  color: white;
}

.cb-err-link:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.cb-err-link.cb-google {
  background: #4285F4;
}

.cb-err-link.cb-wa {
  background: var(--cb-wa-green);
}

.cb-err-link.cb-web {
  background: var(--cb-primary);
}

.cb-err-link svg {
  width: 16px;
  height: 16px;
  fill: white;
  flex-shrink: 0;
}

/* Message timestamp */
.cb-time {
  font-size: 10.5px;
  color: #bbb;
  margin-top: 4px;
  font-family: var(--cb-font);
}

.cb-msg-row.cb-user .cb-time {
  text-align: right;
}

/* Highlighted search match */
.cb-highlight {
  background: rgba(243, 156, 18, 0.3);
  border-radius: 3px;
  padding: 0 2px;
}

/* ---- QUICK REPLY BUTTONS ---- */
.cb-quick-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 4px;
  animation: cb-msg-in 0.4s 0.2s cubic-bezier(.22,1,.36,1) both;
}

.cb-quick-btn {
  background: white;
  border: 1.5px solid var(--cb-primary);
  color: var(--cb-primary);
  border-radius: 20px;
  padding: 6px 13px;
  font-family: var(--cb-font);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(.34,1.56,.64,1);
  white-space: nowrap;
}

.cb-quick-btn:hover {
  background: var(--cb-primary);
  color: white;
  transform: scale(1.05);
}

.cb-quick-btn:active {
  transform: scale(0.97);
}

/* Interactive button inside bubble */
.cb-bubble .cb-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--cb-primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 7px 14px;
  font-family: var(--cb-font);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  margin: 4px 4px 0 0;
  text-decoration: none;
  transition: background 0.2s, transform 0.2s;
}

.cb-bubble .cb-action-btn:hover {
  background: var(--cb-primary-dark);
  transform: translateY(-1px);
}

/* ---- TYPING INDICATOR ---- */
.cb-typing-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: cb-msg-in 0.3s ease both;
}

.cb-typing-bubble {
  background: white;
  border: 1px solid var(--cb-border);
  border-radius: var(--cb-radius-bubble);
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.cb-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aac4f0;
  animation: cb-typing 1.3s ease-in-out infinite;
}

.cb-dot:nth-child(2) { animation-delay: 0.15s; }
.cb-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes cb-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ---- FOOTER ---- */
#cb-footer {
  background: white;
  border-top: 1px solid var(--cb-border);
  padding: 10px 12px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Collapse input row button */
#cb-collapse-row {
  display: flex;
  justify-content: center;
  height: 0;
  overflow: hidden;
  transition: height 0.3s ease, opacity 0.3s;
  opacity: 0;
}

#cb-collapse-row.cb-visible {
  height: 30px;
  opacity: 1;
}

#cb-collapse-input-btn {
  background: none;
  border: 1px solid var(--cb-border);
  border-radius: 20px;
  padding: 3px 14px;
  font-family: var(--cb-font);
  font-size: 11px;
  color: #888;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.2s;
}

#cb-collapse-input-btn:hover {
  background: var(--cb-bg);
  color: var(--cb-primary);
  border-color: var(--cb-primary);
}

#cb-collapse-input-btn svg {
  width: 12px;
  height: 12px;
}

/* Input row */
#cb-input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

/* Textarea */
#cb-input {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  border-radius: 14px;
  padding: 9px 14px;
  font-family: var(--cb-font);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--cb-bot-text);
  background: var(--cb-bg);
  resize: none;
  outline: none;
  max-height: 110px;
  overflow-y: auto;
  transition: border-color 0.2s, box-shadow 0.2s;
  scrollbar-width: thin;
}

#cb-input:focus {
  border-color: var(--cb-primary);
  box-shadow: 0 0 0 3px rgba(0, 74, 173, 0.1);
  background: white;
}

#cb-input::placeholder {
  color: #b0b8c8;
}

/* Send button */
#cb-send {
  width: 42px;
  height: 42px;
  background: var(--cb-primary);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.2s cubic-bezier(.34,1.56,.64,1);
  box-shadow: 0 2px 8px rgba(0, 74, 173, 0.3);
}

#cb-send:hover {
  background: var(--cb-primary-dark);
  transform: scale(1.07);
}

#cb-send:active {
  transform: scale(0.95);
}

#cb-send svg {
  width: 18px;
  height: 18px;
  fill: white;
  transform: translateX(1px);
}

#cb-send:disabled {
  background: #c0cce0;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* =============================================
   MINIMIZED BAR (header minimize → bottom bar)
   ============================================= */
#cb-mini-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--cb-primary);
  color: white;
  border-radius: 40px;
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 4px 20px rgba(0, 74, 173, 0.4);
  cursor: pointer;
  z-index: var(--cb-z);
  font-family: var(--cb-font);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.45s cubic-bezier(.34,1.56,.64,1),
              opacity 0.35s ease;
  max-width: 272px;
}

#cb-mini-bar.cb-visible {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: all;
}

#cb-mini-bar img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.4);
  background: white;
  padding: 2px;
  flex-shrink: 0;
}

.cb-mini-info {
  display: flex;
  flex-direction: column;
}

.cb-mini-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
}

.cb-mini-sub {
  font-size: 10.5px;
  opacity: 0.75;
}

.cb-mini-restore {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  color: white;
  font-family: var(--cb-font);
  font-size: 11.5px;
  padding: 4px 12px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
  white-space: nowrap;
}

.cb-mini-restore:hover {
  background: rgba(255,255,255,0.35);
}

/* Notification badge on launcher */
#cb-notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: var(--cb-accent);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--cb-font);
  border: 2px solid white;
  animation: cb-bounce 0.5s cubic-bezier(.34,1.56,.64,1);
}

@keyframes cb-bounce {
  from { transform: scale(0); }
  to   { transform: scale(1); }
}

/* =============================================
   RESPONSIVE — MOBILE
   ============================================= */
@media (max-width: 480px) {
  #cb-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    transform-origin: center bottom;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  #cb-window.cb-closed {
    transform: scale(0.95) translateY(30px);
  }

  #cb-launcher {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }

  #cb-mini-bar {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    width: calc(100% - 32px);
    max-width: 272px;
  }

  .cb-bubble-wrap {
    max-width: 100%;
  }

  #cb-body {
    padding: 14px 12px;
  }
}

/* =============================================
   UTILITY
   ============================================= */
.cb-hidden {
  display: none !important;
}

/* Shake animation for send on empty */
@keyframes cb-shake {
  0%, 100% { transform: translateX(0); }
  20%  { transform: translateX(-4px); }
  40%  { transform: translateX(4px); }
  60%  { transform: translateX(-3px); }
  80%  { transform: translateX(3px); }
}
.cb-shake {
  animation: cb-shake 0.35s ease;
}
