/* Scoped reset — defeats site-level CSS bleed into our widget. Site themes
   often style header/textarea/button/input globally (background, padding,
   margin, scrollbars). Keep specificity high but avoid !important spam. */
.apex-assistant,
.apex-assistant *,
.apex-assistant *::before,
.apex-assistant *::after {
  box-sizing: border-box;
}
.apex-assistant button,
.apex-assistant textarea,
.apex-assistant input,
.apex-assistant select {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  margin: 0;
  padding: 0;
  outline: 0;
  letter-spacing: normal;
  text-transform: none;
  text-shadow: none;
  box-shadow: none;
  appearance: none;
  -webkit-appearance: none;
}
.apex-assistant .apex-assistant__header,
.apex-assistant .apex-assistant__panel,
.apex-assistant .apex-assistant__bar {
  /* Cancel any global margins/positioning the theme might inject. */
  margin: 0;
  text-align: left;
}
.apex-assistant a {
  text-decoration: underline;
  color: inherit;
}

.apex-assistant {
  --apex-accent: #2563eb;
  --apex-bar-h: 56px;
  --apex-bar-w: 420px;
  --apex-bar-radius: 999px;
  --apex-ease: cubic-bezier(0.65, 0, 0.35, 1);
  --apex-bg-chat: #ffffff;
  --apex-bg-voice: #0d1525;
  --apex-fg-chat: #1f2937;
  --apex-fg-voice: #f1f5f9;
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--apex-fg-chat);
  width: var(--apex-bar-w);
  max-width: calc(100vw - 28px);
  pointer-events: none;
}
.apex-assistant > * { pointer-events: auto; }

/* ---------- Glow (under the bar, breathes in voice mode) ---------- */

.apex-assistant__glow {
  position: absolute;
  inset: -14px -22px;
  border-radius: var(--apex-bar-radius);
  background:
    radial-gradient(ellipse 70% 80% at 50% 50%, rgba(56, 189, 248, 0.55), rgba(34, 211, 238, 0.18) 55%, transparent 78%);
  filter: blur(22px);
  z-index: -1;
  pointer-events: none;
  transform-origin: center;
  will-change: opacity, transform;
}

/* ---------- Morphing pill bar ---------- */

.apex-assistant .apex-assistant__bar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--apex-bar-h);
  padding: 6px 6px 6px 6px;
  border-radius: var(--apex-bar-radius);
  background: var(--apex-bg-chat);
  color: var(--apex-fg-chat);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 10px 28px rgba(15, 23, 42, 0.16),
    0 2px 6px rgba(15, 23, 42, 0.06);
  margin: 0;
  overflow: hidden;
  isolation: isolate;
  will-change: transform;
  transition:
    background 0.6s var(--apex-ease),
    color 0.55s var(--apex-ease),
    box-shadow 0.55s var(--apex-ease),
    padding 0.55s var(--apex-ease);
}

.apex-assistant[data-mode="voice"] .apex-assistant__bar {
  background: var(--apex-bg-voice);
  color: var(--apex-fg-voice);
  padding: 6px 6px 6px 14px;
  box-shadow:
    0 0 0 1px rgba(56, 189, 248, 0.18) inset,
    0 12px 32px rgba(34, 211, 238, 0.28),
    0 0 50px rgba(56, 189, 248, 0.18),
    0 4px 12px rgba(15, 23, 42, 0.18);
}

/* The growing-ink layer — sits behind the bar's content, expands from the
   mic-button center when entering voice mode. */
.apex-assistant .apex-assistant__ink {
  position: absolute;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--apex-bg-voice);
  pointer-events: none;
  z-index: 1;
  transform-origin: center;
  will-change: transform, opacity;
}

/* Bar children sit above the ink. */
.apex-assistant .apex-assistant__mic-btn,
.apex-assistant .apex-assistant__center,
.apex-assistant .apex-assistant__action {
  position: relative;
  z-index: 2;
}

/* ---------- Mic (left) ---------- */

.apex-assistant .apex-assistant__mic-btn {
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--apex-bg-voice);
  color: #ffffff;
  width: 64px;
  height: 44px;
  border-radius: 999px;
  padding: 0;
  transition:
    background 0.6s var(--apex-ease),
    color 0.55s var(--apex-ease),
    width 0.6s var(--apex-ease),
    transform 0.18s ease;
}
.apex-assistant .apex-assistant__mic-btn:hover { transform: scale(1.05); }
.apex-assistant .apex-assistant__mic-btn:active { transform: scale(0.96); }

.apex-assistant[data-mode="voice"] .apex-assistant__mic-btn {
  background: transparent;
  color: var(--apex-fg-voice);
  width: 36px;
  cursor: default;
}
.apex-assistant[data-mode="voice"] .apex-assistant__mic-btn:hover { transform: none; }

/* ---------- Center slot (input + status crossfade) ---------- */

.apex-assistant__center {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.apex-assistant__input {
  flex: 1;
  font-size: 14.5px;
  resize: none;
  padding: 4px 4px;
  height: 24px;
  max-height: 120px;
  line-height: 1.4;
  text-align: center;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.apex-assistant__input::-webkit-scrollbar { display: none; width: 0; height: 0; }
.apex-assistant__input::placeholder { color: #9ca3af; font-weight: 400; opacity: 1; }

.apex-assistant__status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14.5px;
  letter-spacing: 0.005em;
  pointer-events: none;
  color: inherit;
}

/* ---------- Right action slot (send / pause crossfade) ---------- */

/* Action slot mirrors the mic button — chat-mode send and voice-mode pause
   share size + radius (64 × 44 pill). Send is now a solid dark pill in chat
   mode so both ends of the bar feel anchored. */
.apex-assistant .apex-assistant__action {
  position: relative;
  width: 64px;
  height: 44px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.apex-assistant .apex-assistant__send,
.apex-assistant .apex-assistant__pause {
  position: absolute;
  inset: 0;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  width: 64px;
  height: 44px;
}

.apex-assistant .apex-assistant__send {
  background: var(--apex-bg-voice);
  color: #ffffff;
  transition: transform 0.18s ease, background 0.2s ease;
}
.apex-assistant .apex-assistant__send:hover {
  transform: scale(1.05);
}
.apex-assistant .apex-assistant__send:active { transform: scale(0.96); }

.apex-assistant .apex-assistant__pause {
  background: #ffffff;
  color: var(--apex-bg-voice);
  transition: transform 0.18s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.apex-assistant .apex-assistant__pause:hover { transform: scale(1.05); }
.apex-assistant .apex-assistant__pause:active { transform: scale(0.96); }

/* ---------- Conversation panel ---------- */

.apex-assistant__panel {
  position: absolute;
  bottom: calc(var(--apex-bar-h) + 12px);
  left: 0;
  right: 0;
  width: 100%;
  height: auto;
  max-height: min(520px, calc(100vh - 130px));
  min-height: 0;
  display: none;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-radius: 22px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 22px 54px rgba(15, 23, 42, 0.22),
    0 4px 12px rgba(15, 23, 42, 0.06);
  overflow: hidden;
  will-change: transform, opacity;
  color: #1f2937;
}

.apex-assistant .apex-assistant__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.05);
  flex-shrink: 0;
}
.apex-assistant .apex-assistant__title {
  font-weight: 600;
  font-size: 13.5px;
  color: #111827;
  letter-spacing: 0;
}
.apex-assistant__close {
  background: transparent;
  border: none;
  color: #6b7280;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.18s ease, color 0.18s ease;
}
.apex-assistant__close:hover { background: rgba(15, 23, 42, 0.06); color: #111827; }

.apex-assistant__notice {
  margin: 0 16px 8px;
  padding: 7px 11px;
  background: rgba(239, 68, 68, 0.08);
  color: #991b1b;
  border-radius: 10px;
  font-size: 12.5px;
}

.apex-assistant__log {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.apex-assistant__log:empty { display: none; }

.apex-assistant__msg { display: flex; }
.apex-assistant__msg--user { justify-content: flex-end; }
.apex-assistant__msg-bubble {
  max-width: 84%;
  padding: 9px 13px;
  border-radius: 14px;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.07);
  word-wrap: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  font-size: 13.5px;
}
.apex-assistant__msg--user .apex-assistant__msg-bubble {
  background: var(--apex-bg-voice);
  color: #ffffff;
  border-color: transparent;
  border-bottom-right-radius: 6px;
}
.apex-assistant__msg--assistant .apex-assistant__msg-bubble {
  border-bottom-left-radius: 6px;
}
.apex-assistant__msg-bubble code {
  background: rgba(15, 23, 42, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
  font-size: 12px;
}
.apex-assistant__msg-bubble a { color: inherit; text-decoration: underline; }

.apex-assistant__typing .apex-assistant__msg-bubble {
  display: inline-flex;
  gap: 4px;
  padding: 11px 13px;
}
.apex-assistant__typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9ca3af;
  animation: apex-bounce 1.2s infinite;
}
.apex-assistant__typing span:nth-child(2) { animation-delay: 0.15s; }
.apex-assistant__typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes apex-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-3px); opacity: 1; }
}

@media (max-width: 600px) {
  .apex-assistant {
    width: calc(100vw - 24px);
    bottom: 14px;
    --apex-bar-h: 52px;
  }
  .apex-assistant .apex-assistant__panel {
    max-height: min(72vh, calc(100vh - 100px));
    border-radius: 18px;
  }
  .apex-assistant .apex-assistant__mic-btn { width: 56px; height: 40px; }
  .apex-assistant .apex-assistant__send,
  .apex-assistant .apex-assistant__pause { width: 56px; height: 40px; }
  .apex-assistant .apex-assistant__action { width: 56px; height: 40px; }
}
