/* ===========================================================================
   Afterdesk demo chat widget — styling
   Self-contained, scoped under #ad-widget-root to avoid colliding with the
   host page. Pulls the same CSS custom properties already defined on :root
   in style.css (--bg, --accent-1/2/3, --gradient, etc.) so it stays in sync
   with the live site palette rather than hardcoding a parallel set of colors.
   =========================================================================== */

#ad-widget-root {
  --ad-accent-1: var(--accent-1, #a855f7);
  --ad-accent-2: var(--accent-2, #ec4899);
  --ad-accent-3: var(--accent-3, #6366f1);
  --ad-accent-dark: #7c2fd4; /* ~15% darker than accent-1, for the bubble gradient */
  --ad-bg-elevated: var(--bg-elevated, #12121a);
  --ad-border: var(--border, rgba(255,255,255,0.08));
  --ad-text: var(--text, #f2f2f5);
  --ad-text-dim: var(--text-dim, #9a9aa8);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

#ad-widget-root * {
  box-sizing: border-box;
}

/* ---------------------------------------------------------------------- */
/* Launcher bubble                                                        */
/* ---------------------------------------------------------------------- */

.ad-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--ad-accent-3), var(--ad-accent-1), var(--ad-accent-2), var(--ad-accent-3));
  background-size: 300% 300%;
  animation: ad-launcher-gradient 6s ease infinite, ad-launcher-idle-pulse 3s ease-in-out infinite;
  box-shadow: 0 2px 8px rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

@keyframes ad-launcher-gradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

@keyframes ad-launcher-idle-pulse {
  0%, 100% { border-radius: 50%; transform: scale(1); box-shadow: 0 2px 8px rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.2); }
  50% { border-radius: 47% 53% 51% 49% / 51% 49% 53% 47%; transform: scale(1.05); box-shadow: 0 2px 8px rgba(0,0,0,.15), 0 8px 24px rgba(0,0,0,.2), 0 0 18px rgba(236,72,153,0.4); }
}

.ad-launcher:hover {
  transform: scale(1.06);
  box-shadow: 0 2px 10px rgba(0,0,0,.18), 0 10px 28px rgba(0,0,0,.26);
}

.ad-launcher.ad-open {
  animation: ad-launcher-gradient 6s ease infinite;
}

.ad-launcher svg {
  width: 26px;
  height: 26px;
  display: block;
}

.ad-launcher .ad-icon-chat,
.ad-launcher .ad-icon-close {
  position: absolute;
  transition: opacity 180ms ease, transform 180ms ease;
}

.ad-launcher .ad-icon-chat {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

.ad-launcher .ad-icon-close {
  opacity: 0;
  transform: rotate(-45deg) scale(0.6);
}

.ad-launcher.ad-open .ad-icon-chat {
  opacity: 0;
  transform: rotate(45deg) scale(0.6);
}

.ad-launcher.ad-open .ad-icon-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* ---------------------------------------------------------------------- */
/* Panel                                                                   */
/* ---------------------------------------------------------------------- */

.ad-panel {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  background: linear-gradient(rgba(18,18,26,0.82), rgba(18,18,26,0.82)) padding-box,
              linear-gradient(135deg, var(--ad-accent-3), var(--ad-accent-1), var(--ad-accent-2)) border-box;
  border: 1px solid transparent;
  border-radius: 20px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 2px 8px rgba(0,0,0,.2), 0 16px 48px rgba(0,0,0,.4), 0 0 24px rgba(168,85,247,0.25);
  animation: ad-panel-glow 4s ease-in-out infinite;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.ad-panel.ad-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

@keyframes ad-panel-glow {
  0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,.2), 0 16px 48px rgba(0,0,0,.4), 0 0 24px rgba(168,85,247,0.25); }
  50% { box-shadow: 0 2px 8px rgba(0,0,0,.2), 0 16px 48px rgba(0,0,0,.4), 0 0 36px rgba(236,72,153,0.35); }
}

/* header */
.ad-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  background: var(--ad-bg-elevated);
  border-bottom: 1px solid var(--ad-border);
  flex-shrink: 0;
}

.ad-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--ad-accent-3), var(--ad-accent-1), var(--ad-accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ad-avatar.ad-talking {
  animation: ad-orb-morph 0.9s ease-in-out infinite;
  box-shadow: 0 0 24px rgba(236,72,153,0.7);
}

.ad-avatar.ad-listening {
  animation: ad-orb-pulse 1.1s ease-in-out infinite;
  box-shadow: 0 0 24px rgba(99,102,241,0.7);
}

@keyframes ad-orb-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

@keyframes ad-orb-morph {
  0%, 100% { border-radius: 50%; transform: scale(1); }
  25% { border-radius: 38% 62% 55% 45% / 58% 42% 60% 40%; transform: scale(1.18); }
  50% { border-radius: 62% 38% 42% 58% / 40% 60% 38% 62%; transform: scale(0.85); }
  75% { border-radius: 45% 55% 60% 40% / 50% 50% 45% 55%; transform: scale(1.1); }
}

.ad-header-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.ad-header-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ad-text);
  letter-spacing: -0.01em;
}

.ad-header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ad-text-dim);
}

.ad-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34,197,94,0.7);
  flex-shrink: 0;
}

.ad-call-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: #22c55e;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s;
  animation: ad-call-ring 1.4s ease-in-out infinite;
}

.ad-call-btn:hover { transform: scale(1.06); }

.ad-call-btn svg {
  width: 16px;
  height: 16px;
}

@keyframes ad-call-ring {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
}

.ad-call-view {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #05050a;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.ad-call-view:not([hidden]) {
  display: flex;
}

.ad-call-video {
  width: 100%;
  flex: 1;
  object-fit: cover;
  background: #05050a;
}

.ad-call-status {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.5);
  color: var(--ad-text);
  font-size: 0.85rem;
  padding: 6px 16px;
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.ad-call-end {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: #ef4444;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(239,68,68,0.5);
}

.ad-call-end svg {
  width: 22px;
  height: 22px;
}

.ad-header-close {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--ad-text-dim);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.ad-header-close:hover {
  color: var(--ad-text);
  background: rgba(255,255,255,0.06);
}

/* message list */
.ad-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ad-messages::-webkit-scrollbar {
  width: 6px;
}
.ad-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
}

.ad-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.ad-msg p { margin: 0 0 8px; }
.ad-msg p:last-child { margin-bottom: 0; }
.ad-msg ul { margin: 4px 0 8px 18px; padding: 0; }
.ad-msg li { margin-bottom: 4px; }
.ad-msg strong { font-weight: 700; color: var(--ad-text); }

.ad-msg-bot {
  align-self: flex-start;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--ad-border);
  color: var(--ad-text);
  border-bottom-left-radius: 4px;
}

.ad-msg-user {
  align-self: flex-end;
  background: var(--ad-gradient, linear-gradient(120deg, var(--ad-accent-3), var(--ad-accent-1), var(--ad-accent-2)));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ad-caret {
  display: inline-block;
  width: 2px;
  height: 0.95em;
  margin-left: 1px;
  background: currentColor;
  vertical-align: text-bottom;
  animation: ad-caret-blink 0.8s step-end infinite;
}

@keyframes ad-caret-blink {
  0%, 50% { opacity: 1; }
  50.01%, 100% { opacity: 0; }
}

.ad-msg-error {
  align-self: flex-start;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.35);
  color: #fca5a5;
  border-bottom-left-radius: 4px;
}

.ad-msg-system {
  align-self: center;
  background: transparent;
  color: var(--ad-text-dim);
  font-size: 0.8rem;
  text-align: center;
  padding: 4px 10px;
}

/* typing indicator */
.ad-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--ad-border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}

.ad-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ad-text-dim);
  animation: ad-typing-bounce 1.2s infinite ease-in-out;
}
.ad-typing span:nth-child(2) { animation-delay: 0.15s; }
.ad-typing span:nth-child(3) { animation-delay: 0.3s; }

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

/* input row */
.ad-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--ad-border);
  background: var(--ad-bg-elevated);
  flex-shrink: 0;
}

.ad-input {
  flex: 1;
  resize: none;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--ad-border);
  border-radius: 12px;
  color: var(--ad-text);
  font-family: inherit;
  font-size: 16px; /* iOS Safari auto-zooms on focus below 16px */
  padding: 10px 12px;
  max-height: 100px;
  outline: none;
  transition: border-color 0.15s;
}

.ad-input:focus {
  border-color: var(--ad-accent-1);
}

.ad-input::placeholder {
  color: var(--ad-text-dim);
}

.ad-mic {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--ad-border);
  background: rgba(255,255,255,0.06);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, background 0.15s, box-shadow 0.15s;
}

.ad-mic:hover:not(:disabled) {
  background: rgba(255,255,255,0.12);
}

.ad-mic:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ad-mic svg {
  width: 16px;
  height: 16px;
}

.ad-mic-active {
  background: linear-gradient(135deg, var(--ad-accent-3), var(--ad-accent-1));
  box-shadow: 0 0 16px rgba(99,102,241,0.6);
  animation: ad-mic-pulse 1.1s ease-in-out infinite;
}

@keyframes ad-mic-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.ad-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--ad-accent-1), var(--ad-accent-dark));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
}

.ad-send:hover:not(:disabled) {
  transform: scale(1.06);
}

.ad-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ad-send svg {
  width: 16px;
  height: 16px;
}

/* offline / connection banner */
.ad-offline-banner {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(239,68,68,0.12);
  border-top: 1px solid rgba(239,68,68,0.3);
  color: #fca5a5;
  font-size: 0.78rem;
  flex-shrink: 0;
}
.ad-offline-banner.ad-show { display: flex; }

/* mobile responsiveness */
@media (max-width: 480px) {
  .ad-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 88px;
    height: calc(100vh - 160px);
  }
  .ad-launcher {
    right: 14px;
    bottom: 14px;
    width: 48px;
    height: 48px;
  }
  .ad-launcher svg {
    width: 20px;
    height: 20px;
  }
}
