/* ==========================================================================
   Chatbot Widget — Diego Cuevas Main Website
   Modern floating chat with avatar integration
   ========================================================================== */

/* ── Floating Character (BonziBuddy-style, no circle) ───── */

/* Avatar always visible — compact size by default, Diego sprite shows */
.dc-chatbot-btn {
  position: fixed;
  bottom: 10px;
  right: 14px;
  width: 95px;
  height: 150px;
  border-radius: 0;
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  z-index: 99990;
  box-shadow: none;
  transition: transform 0.25s ease;
  pointer-events: auto;
  overflow: visible;
  filter: drop-shadow(0 8px 12px rgba(0, 0, 0, 0.45));
}
.dc-chatbot-btn:hover { transform: scale(1.04) translateY(-2px); }
.dc-chatbot-btn:active { transform: scale(0.97); }
/* Optional big-avatar mode (backward compat — not used by default now) */
.dc-chatbot-btn.avatar-big {
  width: 140px;
  height: 220px;
}

.dc-chatbot-btn:hover {
  transform: scale(1.06) translateY(-2px);
}

.dc-chatbot-btn:active {
  transform: scale(0.98);
}

.dc-chatbot-btn-avatar {
  position: absolute;
  inset: 0;
  background-image: url('retro/assets/avatars/pixel/diego-wave.png');
  background-repeat: no-repeat;
  background-position: center bottom;
  /* auto 100% keeps the character HEIGHT constant across poses —
     different sprites have different aspect ratios, but Diego always
     stands at the same visible height. */
  background-size: auto 100%;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  pointer-events: none;
  border-radius: 0;
}

.dc-chatbot-btn.hidden {
  display: none;
}

/* Subtle idle bob */
@keyframes dcAvatarBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-3px); }
}
.dc-chatbot-btn:not(.hidden) .dc-chatbot-btn-avatar {
  animation: dcAvatarBounce 2.6s ease-in-out infinite;
}

/* ── BonziBuddy-style Speech Bubble ──────────────────────── */
.dc-chatbot-bubble {
  position: absolute;
  bottom: calc(100% + 12px);
  right: 0;
  min-width: 180px;
  max-width: 260px;
  padding: 10px 14px;
  background: #ffffff;
  color: #111118;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35),
              0 0 0 1px rgba(43, 125, 233, 0.25);
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  pointer-events: none;
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  text-align: left;
  white-space: normal;
  z-index: 1;
}
.dc-chatbot-bubble.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
  animation: dcBubbleWobble 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);
}
/* (idle bubble CSS preserved — always allowed now that avatar is default) */
.dc-chatbot-bubble::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 20px;
  width: 14px;
  height: 14px;
  background: #ffffff;
  transform: rotate(45deg);
  box-shadow: 1px 1px 0 rgba(43, 125, 233, 0.25);
  z-index: -1;
}
@keyframes dcBubbleWobble {
  0%   { transform: translateY(8px) scale(0.85) rotate(-2deg); }
  60%  { transform: translateY(-2px) scale(1.05) rotate(1.5deg); }
  100% { transform: translateY(0) scale(1) rotate(0); }
}
@media (max-width: 480px) {
  .dc-chatbot-bubble { min-width: 140px; max-width: 210px; font-size: 12px; padding: 8px 12px; }
}

/* ── Chat Panel ──────────────────────────────────────────── */

.dc-chatbot-panel {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 360px;
  height: 520px;
  max-height: calc(100vh - 48px);
  background: var(--black-light, #111118);
  border: 1px solid rgba(43, 125, 233, 0.3);
  border-radius: 16px;
  z-index: 99999;
  display: none;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6),
              0 0 30px rgba(43, 125, 233, 0.1);
  animation: chatPanelIn 0.3s ease-out;
  resize: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
/* Messages + input still selectable (typing/copying) */
.dc-chatbot-panel .dc-chatbot-messages,
.dc-chatbot-panel .dc-chatbot-input {
  user-select: text;
  -webkit-user-select: text;
}

.dc-chatbot-panel.open {
  display: flex;
}

@keyframes chatPanelIn {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ── Header ──────────────────────────────────────────────── */

.dc-chatbot-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--blue-dark, #0d3a7a), var(--blue, #1a5fb4));
  border-bottom: 1px solid rgba(43, 125, 233, 0.3);
  flex-shrink: 0;
}

.dc-chatbot-header-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: rgba(255, 255, 255, 0.1);
  background-repeat: no-repeat;
  background-position: center 4px;
  background-size: 82% auto;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  overflow: hidden;
  flex-shrink: 0;
  transition: background-image 0.25s ease, transform 0.15s ease;
}
/* While the bot is speaking (TTS playing), animate the avatar like it's
   talking: subtle bob + halo pulse. */
.dc-chatbot-header-avatar.speaking {
  animation: dcTalkBob 0.38s ease-in-out infinite alternate;
  box-shadow: 0 0 0 3px rgba(43, 125, 233, 0.35);
}
@keyframes dcTalkBob {
  0%   { transform: translateY(0)    scale(1); }
  100% { transform: translateY(-2px) scale(1.04); }
}

.dc-chatbot-header-avatar svg {
  width: 34px;
  height: 34px;
}

.dc-chatbot-header-info {
  flex: 1;
}

.dc-chatbot-header-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
}

.dc-chatbot-header-status {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
}

.dc-chatbot-header-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  background: #4ade80;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.dc-chatbot-lang {
  display: inline-flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}
.dc-chatbot-lang button {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: rgba(255, 255, 255, 0.65);
  background: transparent;
  border: none;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.dc-chatbot-lang button:hover { color: #ffffff; }
.dc-chatbot-lang button.active {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.dc-chatbot-voice, .dc-chatbot-summon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
  opacity: 0.55;
}
.dc-chatbot-voice:hover, .dc-chatbot-summon:hover { background: rgba(255, 255, 255, 0.2); opacity: 1; }
.dc-chatbot-voice.active, .dc-chatbot-summon.active { opacity: 1; background: rgba(43, 125, 233, 0.45); color: #ffffff; }

.dc-chatbot-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #ffffff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  flex-shrink: 0;
}

.dc-chatbot-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ── Messages Area ───────────────────────────────────────── */

.dc-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: var(--blue, #1a5fb4) transparent;
}

.dc-chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.dc-chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--blue, #1a5fb4);
  border-radius: 4px;
}

/* ── Message Bubbles ─────────────────────────────────────── */

.dc-chatbot-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
}

.dc-chatbot-msg.bot {
  align-self: flex-start;
  background: rgba(43, 125, 233, 0.15);
  color: #e0e0ee;
  border-bottom-left-radius: 4px;
}

.dc-chatbot-msg.user {
  align-self: flex-end;
  background: var(--blue, #1a5fb4);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.dc-chatbot-msg-time {
  display: block;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.35);
  margin-top: 4px;
  text-align: right;
}

.dc-chatbot-msg.bot .dc-chatbot-msg-time {
  text-align: left;
}

/* ── Input Area ──────────────────────────────────────────── */

.dc-chatbot-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-top: 1px solid rgba(43, 125, 233, 0.15);
  flex-shrink: 0;
}

.dc-chatbot-input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(43, 125, 233, 0.2);
  background: rgba(255, 255, 255, 0.05);
  color: #ffffff;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s;
}

.dc-chatbot-input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

.dc-chatbot-input:focus {
  border-color: var(--blue-glow, #2b7de9);
}

.dc-chatbot-mic {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(43,125,233,0.25);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, transform 0.1s;
  flex-shrink: 0;
  position: relative;
}
.dc-chatbot-mic:hover { background: rgba(255,255,255,0.16); }
/* Voice-mode ON — persistent visual state (even when not actively listening) */
.dc-chatbot-mic.voice-on {
  background: #1a5fb4;
  border-color: #2b7de9;
  color: #fff;
  box-shadow: 0 0 0 3px rgba(43,125,233,0.25);
}
/* Actively listening */
.dc-chatbot-mic.recording {
  background: #e5484d;
  color: #fff;
  border-color: #e5484d;
  animation: dcMicPulse 1.2s infinite;
}
@keyframes dcMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,72,77,0.6); }
  50%      { box-shadow: 0 0 0 8px rgba(229,72,77,0); }
}

.dc-chatbot-send {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--blue, #1a5fb4);
  border: none;
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.1s;
  flex-shrink: 0;
}

.dc-chatbot-send:hover {
  background: var(--blue-glow, #2b7de9);
}

.dc-chatbot-send:active {
  transform: scale(0.9);
}

.dc-chatbot-send svg {
  width: 18px;
  height: 18px;
  fill: #ffffff;
}

/* ── Mobile Responsive ───────────────────────────────────── */

@media (max-width: 480px) {
  .dc-chatbot-panel {
    width: calc(100vw - 16px);
    /* Use small viewport height (svh) and dynamic viewport height (dvh) to
       stay inside iOS Chrome/Safari URL-bar region — fixes "buttons fall
       outside the frame". Fallbacks handle older browsers. */
    height: min(75svh, 560px);
    max-height: calc(100dvh - 16px);
    bottom: 8px;
    right: 8px;
    border-radius: 16px;
    /* Hard cap: can never exceed viewport */
    max-width: calc(100vw - 16px);
  }
  /* Header tightens on very narrow screens so nothing overflows */
  .dc-chatbot-header { padding: 10px 12px; gap: 8px; }
  .dc-chatbot-header-avatar { width: 40px; height: 40px; }
  .dc-chatbot-lang button { padding: 3px 6px; font-size: 10px; }
  .dc-chatbot-voice, .dc-chatbot-close { width: 30px; height: 30px; }

  /* Avatar 50% bigger than before (was 52x52 — now ~140x180) */
  .dc-chatbot-btn {
    bottom: 10px;
    right: 10px;
    width: 120px;
    height: 170px;
    z-index: 99990;
  }
  .dc-chatbot-btn.avatar-big {
    width: 140px;
    height: 200px;
    bottom: 8px;
    right: 8px;
  }
  .dc-chatbot-btn-avatar {
    transform: translateZ(0);
  }
}
@media (max-width: 768px) {
  .dc-chatbot-btn { z-index: 99990; }
}
