/* ═══════════════════════════════════════════════════════════
   AI Chatbot Widget — manojmadhavan.com
   Floating bubble → modal chat window
   ═══════════════════════════════════════════════════════════ */

/* ── Bubble ── */
.cb-bubble {
  position: fixed; bottom: 24px; right: 24px; z-index: 9998;
  width: 60px; height: 60px; border-radius: 50%;
  background: linear-gradient(135deg, #F0B429, #D4991A);
  box-shadow: 0 4px 20px rgba(240,180,41,0.35);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform 0.2s, box-shadow 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.cb-bubble:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(240,180,41,0.45); }
.cb-bubble:active { transform: scale(0.95); }
.cb-bubble svg { width: 28px; height: 28px; fill: #0D1117; }

/* Pulse ring */
.cb-bubble::before {
  content: ''; position: absolute; inset: -4px;
  border-radius: 50%; border: 2px solid rgba(240,180,41,0.4);
  animation: cbPulse 2s ease-out infinite;
}
@keyframes cbPulse {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}
.cb-bubble.cb-bubble--seen::before { display: none; }

/* Unread badge */
.cb-badge {
  position: absolute; top: -2px; right: -2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #EF4444; color: #fff; font-size: 0.6rem; font-weight: 700;
  display: none; align-items: center; justify-content: center;
  border: 2px solid #0D1117;
}
.cb-badge.visible { display: flex; }

/* Tooltip */
.cb-tooltip {
  position: absolute; right: 72px; top: 50%; transform: translateY(-50%);
  background: #1C2128; color: #E6EDF3; font-size: 0.78rem; font-weight: 600;
  padding: 8px 14px; border-radius: 8px; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.cb-tooltip::after {
  content: ''; position: absolute; right: -6px; top: 50%; transform: translateY(-50%);
  border: 6px solid transparent; border-left-color: #1C2128;
}
.cb-bubble:not(.cb-bubble--seen):hover .cb-tooltip { opacity: 1; }

/* Hide bubble when modal open */
.cb-bubble.cb-hidden { transform: scale(0); pointer-events: none; opacity: 0; }

/* ── Modal ── */
.cb-modal {
  position: fixed; z-index: 9999;
  bottom: 24px; right: 24px;
  width: 400px; height: 580px;
  max-height: calc(100vh - 48px); max-width: calc(100vw - 32px);
  background: #0D1117; border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 12px 48px rgba(0,0,0,0.5);
  display: flex; flex-direction: column;
  transform: scale(0.5) translateY(20px); opacity: 0;
  transform-origin: bottom right;
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s;
  pointer-events: none; overflow: hidden;
}
.cb-modal.cb-open {
  transform: scale(1) translateY(0); opacity: 1; pointer-events: all;
}

/* ── Header ── */
.cb-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; background: #161B22;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0; cursor: default;
}
.cb-header__avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #F0B429, #D4991A);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 800; color: #0D1117; flex-shrink: 0;
}
.cb-header__info { flex: 1; min-width: 0; }
.cb-header__name { font-size: 0.88rem; font-weight: 700; color: #fff; margin: 0; }
.cb-header__status {
  font-size: 0.68rem; color: #22C55E;
  display: flex; align-items: center; gap: 4px;
}
.cb-header__dot {
  width: 6px; height: 6px; border-radius: 50%; background: #22C55E; display: inline-block;
}
.cb-header__actions { display: flex; gap: 4px; }
.cb-header__btn {
  width: 32px; height: 32px; border-radius: 8px; border: none;
  background: transparent; color: #8B949E; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.cb-header__btn:hover { background: rgba(255,255,255,0.06); color: #E6EDF3; }

/* ── Messages ── */
.cb-messages {
  flex: 1; overflow-y: auto; padding: 16px 14px 8px;
  -webkit-overflow-scrolling: touch; scroll-behavior: smooth;
}
.cb-messages::-webkit-scrollbar { width: 4px; }
.cb-messages::-webkit-scrollbar-track { background: transparent; }
.cb-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 2px; }

/* Messages */
.cb-msg {
  display: flex; gap: 8px; margin-bottom: 12px;
  animation: cbMsgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  max-width: 85%;
}
.cb-msg--bot { align-self: flex-start; }
.cb-msg--user { align-self: flex-end; flex-direction: row-reverse; margin-left: auto; }
@keyframes cbMsgIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.cb-msg__avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, #F0B429, #D4991A);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.58rem; font-weight: 800; color: #0D1117; margin-top: 2px;
}
.cb-msg__bubble {
  padding: 10px 14px; border-radius: 16px; font-size: 0.84rem; line-height: 1.5;
  word-wrap: break-word;
}
.cb-msg__bubble p { margin: 0 0 6px; }
.cb-msg__bubble p:last-child { margin-bottom: 0; }
.cb-msg--bot .cb-msg__bubble { background: #1C2128; color: #E6EDF3; border-bottom-left-radius: 4px; }
.cb-msg--user .cb-msg__bubble { background: #1A3A5C; color: #E6EDF3; border-bottom-right-radius: 4px; }
.cb-msg__time { font-size: 0.55rem; color: rgba(255,255,255,0.2); margin-top: 3px; display: block; }
.cb-msg--user .cb-msg__time { text-align: right; }

/* Typing */
.cb-typing { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.cb-typing__dots {
  display: flex; gap: 4px; padding: 12px 16px;
  background: #1C2128; border-radius: 16px; border-bottom-left-radius: 4px;
}
.cb-typing__dot {
  width: 6px; height: 6px; border-radius: 50%; background: #4A5568;
  animation: cbTypePulse 1.4s infinite;
}
.cb-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.cb-typing__dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes cbTypePulse { 0%,60%,100% { opacity:0.3; transform:scale(0.8); } 30% { opacity:1; transform:scale(1); } }

/* Quick replies */
.cb-replies { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 0 10px; }
.cb-reply {
  padding: 8px 14px; border-radius: 18px; font-size: 0.78rem; font-weight: 600;
  border: 1.5px solid rgba(240,180,41,0.3); background: rgba(240,180,41,0.05);
  color: #F0B429; cursor: pointer; transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cb-reply:hover { background: rgba(240,180,41,0.15); }
.cb-reply:active { transform: scale(0.96); }
.cb-reply--primary { background: linear-gradient(135deg, #F0B429, #D4991A); color: #0D1117; border-color: transparent; }

/* ── Input ── */
.cb-input {
  display: flex; padding: 10px 12px;
  background: #161B22; border-top: 1px solid rgba(255,255,255,0.06);
  gap: 8px; align-items: flex-end; flex-shrink: 0;
}
.cb-input textarea {
  flex: 1; padding: 10px 14px; border-radius: 22px;
  background: #0D1117; border: 1px solid rgba(255,255,255,0.08);
  color: #fff; font-size: 0.84rem; font-family: inherit;
  resize: none; outline: none; max-height: 100px; min-height: 40px; line-height: 1.4;
}
.cb-input textarea:focus { border-color: rgba(240,180,41,0.4); }
.cb-input textarea::placeholder { color: rgba(255,255,255,0.25); }
.cb-send {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: linear-gradient(135deg, #F0B429, #D4991A);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: opacity 0.15s;
}
.cb-send:disabled { opacity: 0.3; pointer-events: none; }
.cb-send svg { width: 18px; height: 18px; fill: #0D1117; }

/* Offline bar */
.cb-offline {
  display: none; padding: 5px 10px; background: rgba(239,68,68,0.12);
  text-align: center; font-size: 0.68rem; color: #EF4444; flex-shrink: 0;
}
.cb-offline.visible { display: block; }

/* Powered-by */
.cb-powered {
  text-align: center; padding: 4px; font-size: 0.58rem; color: rgba(255,255,255,0.15);
  background: #161B22; flex-shrink: 0;
}
.cb-powered a { color: rgba(255,255,255,0.25); text-decoration: none; }

/* ── Mobile overrides ── */
@media (max-width: 767px) {
  .cb-bubble { display: none; } /* No bubble on mobile — "Book" nav button opens chat */

  .cb-modal {
    bottom: 0; right: 0; left: 0; top: 0;
    width: 100%; height: 100vh; height: 100dvh;
    max-height: none; max-width: 100vw; border-radius: 0;
    transform-origin: bottom center;
  }

  /* When keyboard is open, modal height is set via JS on .cb-modal directly.
     Ensure input area stays pinned at bottom with safe-area padding. */
  .cb-input {
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .cb-powered {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .cb-bubble::before { animation: none; }
  .cb-msg, .cb-modal { animation: none; transition: none; }
  .cb-typing__dot { animation: none; opacity: 0.5; }
}
