/* ─── CHATBOT WIDGET — AI Systems Advisor ────────────────────────────────────
 * Azure-blue / violet glassmorphism — abdialamir.com
 * Toggle pill: violet glow  ·  Panel: dark glass, azure-blue accents
 * ─────────────────────────────────────────────────────────────────────────── */

/* ── Container ───────────────────────────────────────────────────────────── */
#chatbot-widget {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 16px;
  transition: bottom 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Raise widget when video player controls are visible */
#chatbot-widget.video-active {
  bottom: 140px;
}

/* ── Floating toggle — premium AI pill ──────────────────────────────────── */
#chatbot-toggle {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 62px;
  padding: 10px 28px 10px 10px;
  border: 1px solid rgba(124, 58, 237, 0.50);
  border-radius: 50px;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  background: rgba(8, 8, 20, 0.92);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  box-shadow:
    0 0 0 1px rgba(124, 58, 237, 0.24),
    0 0 32px rgba(109, 40, 217, 0.32),
    0 14px 44px rgba(0, 0, 0, 0.64),
    0 24px 68px rgba(109, 40, 217, 0.16);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
}

#chatbot-toggle:hover {
  transform: scale(1.03);
  border-color: rgba(139, 92, 246, 0.72);
  box-shadow:
    0 0 0 1px rgba(139, 92, 246, 0.38),
    0 0 50px rgba(109, 40, 217, 0.52),
    0 14px 44px rgba(0, 0, 0, 0.68),
    0 28px 76px rgba(109, 40, 217, 0.26);
}

@keyframes ai-pill-glow {
  0%, 100% {
    box-shadow:
      0 0 0 1px rgba(124, 58, 237, 0.24),
      0 0 32px rgba(109, 40, 217, 0.32),
      0 14px 44px rgba(0, 0, 0, 0.64),
      0 24px 68px rgba(109, 40, 217, 0.16);
    transform: scale(1);
  }
  50% {
    box-shadow:
      0 0 0 1px rgba(139, 92, 246, 0.38),
      0 0 48px rgba(109, 40, 217, 0.48),
      0 14px 44px rgba(0, 0, 0, 0.66),
      0 28px 76px rgba(109, 40, 217, 0.24);
    transform: scale(1.018);
  }
}

#chatbot-toggle[aria-expanded="false"] {
  animation: ai-pill-glow 4s ease-in-out infinite;
}
#chatbot-toggle[aria-expanded="true"] {
  animation: none;
  transform: scale(1);
}

/* ── AI orb ──────────────────────────────────────────────────────────────── */
.chatbot-orb {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  background: radial-gradient(
    circle at 38% 36%,
    rgba(255, 255, 255, 0.90) 0%,
    rgba(196, 181, 253, 0.85) 18%,
    rgba(139, 92, 246, 0.88) 40%,
    rgba(79, 70, 229, 0.92) 65%,
    rgba(30, 27, 90, 0.96) 100%
  );
  box-shadow:
    0 0 14px rgba(139, 92, 246, 0.60),
    0 0 28px rgba(109, 40, 217, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
  animation: orb-breathe 3.2s ease-in-out infinite;
}

@keyframes orb-breathe {
  0%, 100% {
    box-shadow: 0 0 14px rgba(139,92,246,0.55), 0 0 28px rgba(109,40,217,0.28), inset 0 1px 0 rgba(255,255,255,0.28);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 0 22px rgba(139,92,246,0.85), 0 0 44px rgba(109,40,217,0.50), inset 0 1px 0 rgba(255,255,255,0.35);
    transform: scale(1.05);
  }
}

/* ── Vertical divider ────────────────────────────────────────────────────── */
.chatbot-divider {
  width: 1px;
  height: 22px;
  background: rgba(255, 255, 255, 0.13);
  flex-shrink: 0;
}

/* ── Label ───────────────────────────────────────────────────────────────── */
.chatbot-label {
  font-size: 1.0rem;
  font-weight: 520;
  color: rgba(248, 250, 252, 0.97);
  letter-spacing: 0.012em;
  line-height: 1;
}

/* ── Online indicator ────────────────────────────────────────────────────── */
.chatbot-online-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  box-shadow: 0 0 10px rgba(34, 197, 94, 0.85), 0 0 20px rgba(34, 197, 94, 0.42);
  animation: pulse-dot 2.2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.70; transform: scale(0.88); }
}

/* ── Chat panel ──────────────────────────────────────────────────────────── */
#chatbot-panel {
  position: absolute;
  bottom: calc(100% + 16px);
  right: 0;
  width: 400px;
  display: flex;
  flex-direction: column;
  background: rgba(6, 6, 14, 0.97);
  backdrop-filter: blur(32px);
  -webkit-backdrop-filter: blur(32px);
  border: 1px solid rgba(59, 130, 246, 0.22);
  border-radius: 24px;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.032),
    0 16px 60px rgba(0, 0, 0, 0.78),
    0  0  80px rgba(59, 130, 246, 0.08),
    0  0  40px rgba(124, 58, 237, 0.06);
  overflow: hidden;

  /* Closed state */
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition:
    opacity   0.28s ease,
    transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

#chatbot-panel.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(59, 130, 246, 0.12);
  background: linear-gradient(
    180deg,
    rgba(59, 130, 246, 0.07) 0%,
    rgba(124, 58, 237, 0.04) 60%,
    transparent 100%
  );
  flex-shrink: 0;
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chatbot-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.72);
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}

.chatbot-header-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.chatbot-title {
  font-size: 0.9rem;
  font-weight: 650;
  color: #f1f5f9;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.chatbot-subtitle {
  font-size: 0.69rem;
  color: rgba(148, 163, 184, 0.60);
  line-height: 1.2;
  letter-spacing: 0.005em;
}

#chatbot-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(148, 163, 184, 0.55);
  padding: 0;
  border-radius: 6px;
  transition: color 0.16s ease, background 0.16s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

#chatbot-close:hover {
  color: #f1f5f9;
  background: rgba(255, 255, 255, 0.07);
}

/* ── Starter prompt chips ────────────────────────────────────────────────── */
.chatbot-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 14px 16px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.045);
  flex-shrink: 0;
}

.chatbot-chips.hidden {
  display: none;
}

.chatbot-chip {
  background: rgba(59, 130, 246, 0.07);
  border: 1px solid rgba(59, 130, 246, 0.20);
  border-radius: 10px;
  color: rgba(148, 163, 184, 0.80);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.765rem;
  font-weight: 450;
  line-height: 1.35;
  padding: 9px 12px;
  text-align: left;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.chatbot-chip:hover {
  background: rgba(59, 130, 246, 0.14);
  border-color: rgba(59, 130, 246, 0.40);
  color: rgba(226, 232, 240, 0.95);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.10);
}

/* ── Dynamic follow-up chips (injected after GPT reply) ─────────────────── */
.chatbot-followups {
  display: flex;
  flex-direction: column;
  gap: 5px;
  align-self: flex-start;
  width: 82%;
  animation: chat-msg-in 0.28s ease both;
  animation-delay: 0.12s;
}

.chatbot-followup-chip {
  background: rgba(59, 130, 246, 0.05);
  border: none;
  border-left: 2px solid rgba(59, 130, 246, 0.32);
  border-radius: 0 8px 8px 0;
  color: rgba(96, 165, 250, 0.68);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.775rem;
  line-height: 1.4;
  padding: 7px 12px;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.chatbot-followup-chip:hover {
  background: rgba(59, 130, 246, 0.12);
  border-left-color: rgba(59, 130, 246, 0.65);
  color: rgba(147, 197, 253, 0.92);
}

/* ── Messages area ───────────────────────────────────────────────────────── */
#chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 200px;
  max-height: 380px;
  scroll-behavior: smooth;
}

#chatbot-messages::-webkit-scrollbar { width: 3px; }
#chatbot-messages::-webkit-scrollbar-track  { background: transparent; }
#chatbot-messages::-webkit-scrollbar-thumb  {
  background: rgba(59, 130, 246, 0.25);
  border-radius: 4px;
}

/* ── Message bubbles ─────────────────────────────────────────────────────── */
.chat-msg {
  max-width: 86%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.865rem;
  line-height: 1.52;
  animation: chat-msg-in 0.22s ease both;
}

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

.chat-msg--assistant {
  background: rgba(20, 20, 34, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.07);
  color: rgba(226, 232, 240, 0.92);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  white-space: pre-wrap;
}

.chat-msg--user {
  background: linear-gradient(135deg, #2563eb 0%, #3b82f6 100%);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 16px rgba(59, 130, 246, 0.28);
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
.chat-typing {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 12px 14px;
  background: rgba(20, 20, 34, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  max-width: 62px;
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.75);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.chat-typing span:nth-child(2) { animation-delay: 0.20s; }
.chat-typing span:nth-child(3) { animation-delay: 0.40s; }

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.82); }
  30%            { opacity: 1;   transform: scale(1.15); }
}

/* ── Input row ───────────────────────────────────────────────────────────── */
.chatbot-input-row {
  display: flex;
  gap: 8px;
  padding: 12px 16px 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.055);
  flex-shrink: 0;
  background: rgba(0, 0, 0, 0.18);
}

#chatbot-input {
  flex: 1;
  background: rgba(14, 14, 26, 0.90);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: #f1f5f9;
  font-family: inherit;
  font-size: 0.875rem;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
  min-width: 0;
}

#chatbot-input::placeholder { color: rgba(148, 163, 184, 0.32); }

#chatbot-input:focus {
  border-color: rgba(59, 130, 246, 0.42);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
}

#chatbot-send {
  background: linear-gradient(135deg, #2563eb 0%, #6366f1 100%);
  border: none;
  border-radius: 10px;
  color: #fff;
  cursor: pointer;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease, box-shadow 0.18s ease;
  box-shadow: 0 2px 14px rgba(59, 130, 246, 0.32);
}

#chatbot-send:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 22px rgba(59, 130, 246, 0.55);
}

#chatbot-send svg { pointer-events: none; }

/* ── Mobile — full-width bottom sheet ───────────────────────────────────── */
@media (max-width: 480px) {
  #chatbot-widget {
    bottom: 0;
    right: 0;
    gap: 0;
    align-items: stretch;
  }

  #chatbot-widget.video-active {
    bottom: 0;
  }

  /* Toggle pill: anchored bottom-right corner */
  #chatbot-toggle {
    position: fixed;
    bottom: 20px;
    right: 16px;
    height: 56px;
    padding: 8px 22px 8px 8px;
    gap: 12px;
    z-index: 9001;
  }
  .chatbot-orb   { width: 38px; height: 38px; }
  .chatbot-label { font-size: 0.9375rem; }

  /* Panel: bottom sheet */
  #chatbot-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 82vh;
    border-radius: 24px 24px 0 0;
    border-bottom: none;
    transform: translateY(100%) scale(1);
    transition:
      opacity   0.30s ease,
      transform 0.30s cubic-bezier(0.16, 1, 0.3, 1);
  }

  #chatbot-panel.open {
    transform: translateY(0) scale(1);
    opacity: 1;
  }

  #chatbot-messages {
    max-height: 45vh;
  }

  .chatbot-chips {
    grid-template-columns: 1fr 1fr;
  }
}

/* ── Input lock state (during API call) ──────────────────────────────────── */
#chatbot-input:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

#chatbot-send:disabled {
  opacity: 0.40;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

/* ── Streaming text reveal — block cursor blink ──────────────────────────── */
.chat-msg--streaming::after {
  content: '▋';
  font-size: 0.72em;
  color: rgba(59, 130, 246, 0.60);
  animation: cursor-blink 0.60s step-end infinite;
  margin-left: 1px;
  vertical-align: middle;
}

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

/* ── Error bubble ────────────────────────────────────────────────────────── */
.chat-msg--error {
  background: rgba(18, 6, 6, 0.95);
  border: 1px solid rgba(239, 68, 68, 0.24);
  color: rgba(252, 165, 165, 0.80);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-retry-btn {
  align-self: flex-start;
  background: none;
  border: 1px solid rgba(239, 68, 68, 0.30);
  border-radius: 6px;
  color: rgba(248, 113, 113, 0.75);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.70rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 11px;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.chat-retry-btn:hover {
  background: rgba(239, 68, 68, 0.10);
  border-color: rgba(239, 68, 68, 0.55);
  color: rgba(252, 165, 165, 0.95);
}

/* ── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #chatbot-toggle[aria-expanded="false"] { animation: none; transform: scale(1); }
  #chatbot-panel  { transition: opacity 0.01s; }
  .chat-msg       { animation: none; }
  .chat-msg--streaming::after { animation: none; }
  .chat-typing span { animation: none; opacity: 0.6; }
  .chatbot-dot    { animation: none; }
  .chatbot-orb    { animation: none; }
  .chatbot-online-dot { animation: none; }
}
