/* ============================================================
   CHATBOT.CSS — Bhanu's Portfolio AI Assistant Widget
   Matches noir / matcha dossier aesthetic
   ============================================================ */

/* ── FLOATING ORB TRIGGER ──────────────────────────────────── */
.chatbot-fab {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9998;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: 1.5px solid var(--border-hover);
  background: var(--gradient-btn);
  color: var(--text-on-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-glow), 0 6px 24px rgba(0,0,0,0.5);
  transition: transform 0.35s cubic-bezier(.34,1.56,.64,1), box-shadow 0.3s ease, opacity 0.3s ease;
  animation: chatbot-fab-pulse 3s ease-in-out infinite;
}
.chatbot-fab:hover {
  transform: scale(1.12) rotate(-8deg);
  box-shadow: var(--shadow-glow), 0 8px 36px rgba(0,0,0,0.6);
}
.chatbot-fab.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.5);
}
.chatbot-fab svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

@keyframes chatbot-fab-pulse {
  0%, 100% { box-shadow: var(--shadow-glow), 0 6px 24px rgba(0,0,0,0.5); }
  50%      { box-shadow: 0 0 40px var(--accent-glow), 0 6px 24px rgba(0,0,0,0.5); }
}

/* Notification badge */
.chatbot-fab .fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #e74c3c;
  border: 2px solid var(--bg-primary);
  animation: chatbot-badge-pop 0.4s cubic-bezier(.34,1.56,.64,1);
}
@keyframes chatbot-badge-pop {
  0%   { transform: scale(0); }
  100% { transform: scale(1); }
}

/* ── POPUP SPEECH BUBBLE (TEASER ON LOAD) ──────────────────── */
.chatbot-bubble {
  position: fixed;
  bottom: 2.2rem;
  right: calc(2rem + 68px);
  z-index: 9997;
  max-width: 310px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 0.85rem 1rem;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform-origin: right bottom;
  transform: translateX(20px) scale(0.6);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
  user-select: none;
  position: fixed;
  overflow: visible;
}

/* Shimmer border glow on reveal */
.chatbot-bubble::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: 16px;
  background: linear-gradient(135deg, transparent 25%, var(--accent-glow) 50%, transparent 75%);
  pointer-events: none;
  opacity: 0;
  z-index: 0;
}

.chatbot-bubble.visible {
  opacity: 1;
  pointer-events: auto;
  animation: chatbot-bubble-reveal 0.6s cubic-bezier(.34, 1.56, .64, 1) forwards;
}

.chatbot-bubble.visible::before {
  animation: chatbot-bubble-shimmer 1.2s ease-out 0.2s forwards;
}

.chatbot-bubble.pop-off {
  animation: chatbot-bubble-pop-off 0.45s cubic-bezier(.34, 1.56, .64, 1) forwards !important;
  pointer-events: none;
}

@keyframes chatbot-bubble-pop-off {
  0% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0px);
  }
  30% {
    opacity: 0.95;
    transform: translateX(-4px) scale(1.02);
  }
  100% {
    opacity: 0;
    transform: translateX(24px) scale(0.55);
    filter: blur(4px);
  }
}

@keyframes chatbot-bubble-reveal {
  0% {
    opacity: 0;
    transform: translateX(24px) scale(0.55);
    filter: blur(6px);
  }
  65% {
    opacity: 1;
    transform: translateX(-4px) scale(1.03);
    filter: blur(0px);
  }
  100% {
    opacity: 1;
    transform: translateX(0) scale(1);
    filter: blur(0px);
  }
}

@keyframes chatbot-bubble-shimmer {
  0% {
    opacity: 0;
    transform: scale(0.95);
  }
  40% {
    opacity: 1;
    transform: scale(1.02);
  }
  100% {
    opacity: 0;
    transform: scale(1);
  }
}

.chatbot-bubble:hover {
  border-color: var(--border-hover);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.65), 0 0 24px var(--accent-glow);
  transform: translateX(-3px) scale(1.02);
}

/* Triangle speech pointer (pointing right toward FAB) */
.chatbot-bubble::after {
  content: '';
  position: absolute;
  right: -7px;
  bottom: 18px;
  width: 12px;
  height: 12px;
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  transform: rotate(45deg);
  transition: border-color 0.25s ease;
  z-index: 1;
}
.chatbot-bubble:hover::after {
  border-color: var(--border-hover);
}

.chatbot-bubble-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--gradient-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-accent);
  font-weight: 800;
  font-size: 0.78rem;
  font-family: 'Outfit', sans-serif;
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--accent-glow);
  position: relative;
  z-index: 2;
}

.chatbot-bubble.visible .chatbot-bubble-avatar {
  animation: chatbot-avatar-pop 0.55s cubic-bezier(.34, 1.56, .64, 1) 0.15s both;
}

@keyframes chatbot-avatar-pop {
  0% {
    transform: scale(0) rotate(-25deg);
    opacity: 0;
  }
  100% {
    transform: scale(1) rotate(0deg);
    opacity: 1;
  }
}

.chatbot-bubble-body {
  flex: 1;
  min-width: 0;
  position: relative;
  z-index: 2;
}

.chatbot-bubble-header {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
}

.chatbot-bubble-author {
  font-family: 'Outfit', sans-serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.chatbot-bubble-status {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.55rem;
  letter-spacing: 0.8px;
  color: #4ade80;
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.3);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  font-weight: 600;
  text-transform: uppercase;
}

.chatbot-bubble.visible .chatbot-bubble-status {
  animation: chatbot-status-fade 0.4s ease 0.25s both;
}

@keyframes chatbot-status-fade {
  0% { opacity: 0; transform: translateY(-3px); }
  100% { opacity: 1; transform: translateY(0); }
}

.chatbot-bubble-text {
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--text-primary);
  opacity: 0.95;
  min-height: 2.3em;
}

.chatbot-bubble-cursor {
  display: inline-block;
  margin-left: 2px;
  color: var(--accent-primary);
  font-weight: 700;
  font-size: 0.9em;
  animation: chatbot-cursor-blink 0.65s infinite alternate;
}

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

.chatbot-bubble-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 0.2rem;
  margin: -0.25rem -0.25rem 0 0;
  opacity: 0.65;
  transition: opacity 0.2s ease, color 0.2s ease, transform 0.2s ease;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
}
.chatbot-bubble-close:hover {
  opacity: 1;
  color: var(--text-primary);
  transform: scale(1.15);
}

/* FAB alert nod on reveal */
.chatbot-fab.notifying {
  animation: chatbot-fab-alert 0.7s cubic-bezier(.34, 1.56, .64, 1) !important;
}
@keyframes chatbot-fab-alert {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.18) rotate(-10deg); }
  50%  { transform: scale(1.12) rotate(8deg); }
  75%  { transform: scale(1.06) rotate(-4deg); }
  100% { transform: scale(1) rotate(0deg); }
}

/* ── CHAT WINDOW ───────────────────────────────────────────── */
.chatbot-window {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9999;
  width: 400px;
  max-width: calc(100vw - 2rem);
  height: 560px;
  max-height: calc(100vh - 4rem);
  border-radius: 20px;
  border: 1px solid var(--border-color);
  background: var(--bg-secondary);
  box-shadow: 0 24px 80px rgba(0,0,0,0.65), 0 0 0 1px rgba(255,255,255,0.04) inset;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: pan-y;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(.34,1.56,.64,1);
}
.chatbot-window.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── HEADER ────────────────────────────────────────────────── */
.chatbot-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--gradient-card);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}
.chatbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-on-accent);
  font-weight: 800;
  font-size: 0.85rem;
  font-family: 'Outfit', sans-serif;
  flex-shrink: 0;
  box-shadow: 0 0 12px var(--accent-glow);
}
.chatbot-header-info {
  flex: 1;
  min-width: 0;
}
.chatbot-header-name {
  font-family: 'Outfit', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  line-height: 1.2;
}
.chatbot-header-status {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.65rem;
  color: var(--accent-secondary);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.chatbot-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 8px rgba(74,222,128,0.5);
  animation: chatbot-status-blink 2s ease-in-out infinite;
}
@keyframes chatbot-status-blink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.4; }
}
.chatbot-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s ease;
  flex-shrink: 0;
}
.chatbot-close-btn:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
  background: var(--bg-card-hover);
}

/* ── MESSAGES AREA ─────────────────────────────────────────── */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) transparent;
}
.chatbot-messages::-webkit-scrollbar {
  width: 5px;
}
.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 8px;
  transition: background 0.25s ease, box-shadow 0.25s ease;
}
.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--accent-secondary);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ── MESSAGE BUBBLES ───────────────────────────────────────── */
.chatbot-msg {
  max-width: 88%;
  padding: 0.7rem 1rem;
  border-radius: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  line-height: 1.55;
  color: var(--text-primary);
  animation: chatbot-msg-in 0.35s cubic-bezier(.34,1.56,.64,1);
  word-wrap: break-word;
}
@keyframes chatbot-msg-in {
  0%   { opacity: 0; transform: translateY(8px) scale(0.96); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.chatbot-msg.bot {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}
.chatbot-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-tertiary), var(--accent-primary));
  color: var(--text-on-accent);
  border-bottom-right-radius: 4px;
  font-weight: 500;
}
.chatbot-msg a {
  color: var(--accent-secondary);
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: color 0.2s ease;
}
.chatbot-msg a:hover {
  color: var(--accent-primary);
}
.chatbot-msg.user a {
  color: var(--text-on-accent);
  opacity: 0.9;
}
.chatbot-msg strong {
  color: var(--accent-secondary);
  font-weight: 700;
}
.chatbot-msg.user strong {
  color: var(--text-on-accent);
}

/* Typing indicator */
.chatbot-typing {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 0.8rem 1.2rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}
.chatbot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: chatbot-dot-bounce 1.4s ease-in-out infinite;
}
.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* Quick action chips */
.chatbot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.chatbot-chip {
  display: inline-block;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  border: 1px solid var(--tag-border);
  background: var(--tag-bg);
  color: var(--tag-color);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.25s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.chatbot-chip:hover {
  background: var(--accent-primary);
  color: var(--text-on-accent);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

/* ── INPUT AREA ────────────────────────────────────────────── */
.chatbot-input-area {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
  flex-shrink: 0;
}
.chatbot-input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}
.chatbot-input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}
.chatbot-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.chatbot-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-btn);
  color: var(--text-on-accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
}
.chatbot-send-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-btn);
}
.chatbot-send-btn:active {
  transform: scale(0.95);
}
.chatbot-send-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  transform: rotate(45deg);
}

/* ── POWERED BY FOOTER ─────────────────────────────────────── */
.chatbot-footer {
  text-align: center;
  padding: 0.35rem;
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 0.55rem;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  border-top: 1px solid var(--border-card);
}

/* ── RESPONSIVE ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chatbot-window {
    width: 360px;
    max-width: calc(100vw - 2rem);
    height: 520px;
    max-height: calc(100vh - 3rem);
    right: 1.5rem;
    bottom: 1.5rem;
  }
  .chatbot-fab {
    right: 1.5rem;
    bottom: 1.5rem;
  }
  .chatbot-bubble {
    right: 1.5rem;
    bottom: calc(1.5rem + 68px);
    max-width: calc(100vw - 3rem);
  }
}

@media (max-width: 480px) {
  .chatbot-window {
    bottom: 0;
    right: 0;
    width: 100%;
    width: 100vw;
    max-width: 100vw;
    height: 85vh;
    height: 85dvh;
    max-height: 85dvh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    border-left: none;
    border-right: none;
  }
  .chatbot-header {
    padding: 0.85rem 1rem;
  }
  .chatbot-messages {
    padding: 0.85rem;
  }
  .chatbot-input-area {
    padding: 0.65rem 0.85rem;
    padding-bottom: max(0.65rem, env(safe-area-inset-bottom, 0.65rem));
  }
  .chatbot-chips {
    gap: 0.35rem;
  }
  .chatbot-chip {
    padding: 0.3rem 0.6rem;
    font-size: 0.65rem;
  }
  .chatbot-fab {
    bottom: 1.2rem;
    right: 1.2rem;
    width: 52px;
    height: 52px;
  }
  .chatbot-bubble {
    right: 1.2rem;
    bottom: calc(1.2rem + 60px);
    max-width: min(310px, calc(100vw - 2.4rem));
    transform-origin: right bottom;
    transform: translateY(20px) scale(0.65);
    padding: 0.65rem 0.85rem;
  }
  .chatbot-bubble-text {
    font-size: 0.78rem;
    line-height: 1.35;
    min-height: auto;
  }
  .chatbot-bubble.visible {
    animation: chatbot-bubble-reveal-mobile 0.55s cubic-bezier(.34, 1.56, .64, 1) forwards;
  }
  .chatbot-bubble.pop-off {
    animation: chatbot-bubble-pop-off-mobile 0.45s cubic-bezier(.34, 1.56, .64, 1) forwards !important;
  }
  @keyframes chatbot-bubble-reveal-mobile {
    0% {
      opacity: 0;
      transform: translateY(20px) scale(0.65);
      filter: blur(5px);
    }
    65% {
      opacity: 1;
      transform: translateY(-4px) scale(1.02);
      filter: blur(0px);
    }
    100% {
      opacity: 1;
      transform: translateY(0) scale(1);
      filter: blur(0px);
    }
  }
  @keyframes chatbot-bubble-pop-off-mobile {
    0% {
      opacity: 1;
      transform: translateY(0) scale(1);
      filter: blur(0px);
    }
    30% {
      opacity: 0.95;
      transform: translateY(-4px) scale(1.02);
    }
    100% {
      opacity: 0;
      transform: translateY(20px) scale(0.65);
      filter: blur(4px);
    }
  }
  .chatbot-bubble::after {
    right: 20px;
    bottom: -6px;
    border-top: none;
    border-right: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    border-left: none;
    transform: rotate(45deg);
  }
}

@media (max-width: 360px) {
  .chatbot-fab {
    width: 46px;
    height: 46px;
    bottom: 1rem;
    right: 1rem;
  }
  .chatbot-fab svg {
    width: 22px;
    height: 22px;
  }
  .chatbot-bubble {
    right: 1rem;
    bottom: calc(1rem + 56px);
    padding: 0.7rem;
    max-width: calc(100vw - 2rem);
  }
  .chatbot-bubble-avatar {
    width: 28px;
    height: 28px;
    font-size: 0.7rem;
  }
  .chatbot-bubble-text {
    font-size: 0.75rem;
  }
  .chatbot-input {
    font-size: 0.8rem;
    padding: 0.5rem 0.65rem;
  }
  .chatbot-send-btn {
    width: 34px;
    height: 34px;
  }
}
