/* ==========================================================================
   INFBLE CHATBOT — Isolated, self-contained styling for the AI bot launcher,
   quick-action chips, and modal. Uses tokens from style.css only.
   Loaded on every page; renders nothing until chat.js injects its DOM.
   All selectors namespaced under .infble-bot-* to avoid collisions.
   ========================================================================== */

/* ===== Launcher (bottom-right floating button — bare mascot, no container) ===== */
.infble-bot-launcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 84px;
  height: 84px;
  background: transparent;
  border: none;
  box-shadow: none;
  cursor: pointer;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: visible;
  transition: transform var(--transition-normal);
  /* Continuous bob + periodic wiggle to catch the visitor's eye. Runs on
     the button (not the inner img) so hover overrides both cleanly. */
  animation: infbleBotAttention 8s ease-in-out infinite;
}
.infble-bot-launcher:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 4px; border-radius: 12px; }
.infble-bot-launcher:hover {
  animation: none;
  transform: translateY(-4px) scale(1.06);
}
.infble-bot-launcher img,
.infble-bot-launcher svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  /* Glow lives on the mascot itself, following its silhouette. Filter is
     animated separately so it pulses independently of the bob/wiggle. */
  filter: drop-shadow(0 6px 22px rgba(56, 189, 248, 0.45))
          drop-shadow(0 0 10px rgba(129, 140, 248, 0.25));
  animation: infbleBotGlow 3s ease-in-out infinite;
}
.infble-bot-launcher:hover img,
.infble-bot-launcher:hover svg { animation-play-state: paused; }
.infble-bot-launcher.is-hidden { display: none; }

@keyframes infbleBotAttention {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  10%      { transform: translateY(-4px) rotate(0deg); }
  20%      { transform: translateY(0) rotate(0deg); }
  30%      { transform: translateY(-4px) rotate(0deg); }
  40%      { transform: translateY(0) rotate(0deg); }
  /* Attention wiggle in the last ~12% — a friendly "hi over here" */
  85%      { transform: translateY(-2px) rotate(0deg); }
  88%      { transform: translateY(-3px) rotate(-9deg); }
  91%      { transform: translateY(-3px) rotate(7deg); }
  94%      { transform: translateY(-2px) rotate(-4deg); }
  97%      { transform: translateY(-1px) rotate(0deg); }
}
@keyframes infbleBotGlow {
  0%, 100% {
    filter: drop-shadow(0 6px 22px rgba(56, 189, 248, 0.4))
            drop-shadow(0 0 10px rgba(129, 140, 248, 0.22));
  }
  50% {
    filter: drop-shadow(0 8px 30px rgba(56, 189, 248, 0.75))
            drop-shadow(0 0 18px rgba(129, 140, 248, 0.45));
  }
}

@media (prefers-reduced-motion: reduce) {
  .infble-bot-launcher { transition: none; animation: none; }
  .infble-bot-launcher:hover { transform: none; }
  .infble-bot-launcher img,
  .infble-bot-launcher svg { animation: none; }
}

/* ===== Quick-action chips (above the launcher when modal is closed) ===== */
.infble-bot-chips {
  position: fixed;
  bottom: 100px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  z-index: 999;
  max-width: calc(100vw - 48px);
}
.infble-bot-chip {
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-default);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: border-color var(--transition-fast), transform var(--transition-fast);
  white-space: nowrap;
}
.infble-bot-chip:hover,
.infble-bot-chip:focus-visible {
  border-color: var(--border-accent);
  transform: translateX(-2px);
  outline: none;
}
.infble-bot-chips.is-hidden { display: none; }

/* ===== Modal (chat window) ===== */
.infble-bot-modal {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 130px);
  background: var(--glass-bg-strong);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 1001;
  font-family: var(--font-body);
  color: var(--color-text-primary);
}
.infble-bot-modal.is-open { display: flex; animation: infbleBotSlideIn 0.25s ease-out; }
@keyframes infbleBotSlideIn {
  from { transform: translateY(12px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .infble-bot-modal.is-open { animation: none; }
}

/* ===== Modal header ===== */
.infble-bot-header {
  /* Explicit resets — the site's global `header {}` rule sets position: fixed
     for the navbar, which would otherwise leak into the modal's <header>. */
  position: static;
  top: auto;
  left: auto;
  right: auto;
  width: auto;
  transform: none;
  background: linear-gradient(180deg, rgba(20, 32, 60, 0.92), rgba(13, 22, 44, 0.88));
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-default);
  flex-shrink: 0;
  z-index: 2;
}
.infble-bot-header-avatar {
  width: 40px;
  height: 40px;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.infble-bot-header-avatar img,
.infble-bot-header-avatar svg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(56, 189, 248, 0.35));
}
.infble-bot-header-title {
  flex: 1;
  min-width: 0;
}
.infble-bot-header-title strong {
  display: block;
  font-family: var(--font-display);
  font-size: 0.95rem;
  color: var(--color-text-primary);
  font-weight: 600;
}
.infble-bot-header-title span {
  display: block;
  font-size: 0.72rem;
  color: var(--color-text-secondary);
}
.infble-bot-header-title span::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-success);
  margin-right: 6px;
  vertical-align: middle;
}
.infble-bot-close {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--color-text-secondary);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color var(--transition-fast);
}
.infble-bot-close:hover { border-color: var(--border-accent); color: var(--color-text-primary); }

/* ===== Message log ===== */
.infble-bot-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.infble-bot-log::-webkit-scrollbar { width: 6px; }
.infble-bot-log::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}

/* Every row is [avatar][bubble] — avatars stay on the left for both speakers
   so the log reads as one ordered column; only the bubble side changes.
   System notes are bare and centred — they get no avatar. */
.infble-bot-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 94%;
}
.infble-bot-row.is-bot  { align-self: flex-start; }
.infble-bot-row.is-user { align-self: flex-end; }

/* Both speakers share one glass tile of identical size, so neither side reads
   heavier than the other. The mascot PNG carries its own transparent margin —
   it's scaled past 100% here so its visible mark fills the ring like the
   visitor glyph does, instead of floating in dead space. */
.infble-bot-avatar {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid var(--border-accent);
  box-shadow: var(--glass-highlight);
  color: var(--color-accent-light);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 2px;
}
.infble-bot-avatar.is-bot img,
.infble-bot-avatar.is-bot svg {
  width: 128%;
  height: 128%;
  object-fit: contain;
  filter: drop-shadow(0 0 5px rgba(56, 189, 248, 0.35));
}
.infble-bot-avatar.is-user svg { width: 13px; height: 13px; }

.infble-bot-msg {
  max-width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.infble-bot-msg.is-bot {
  background: rgba(13, 22, 44, 0.55);
  border: 1px solid var(--border-default);
  color: var(--color-text-primary);
  border-bottom-left-radius: 4px;
}
/* Transparent glass tile, not a filled gradient — the accent lives in the
   tint and the border so the bubble reads as part of the site surface. */
.infble-bot-msg.is-user {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12) 0%, rgba(129, 140, 248, 0.1) 100%);
  border: 1px solid var(--border-accent);
  /* Accent-light text — differentiates the visitor's voice from the bot's
     neutral copy without going back to a filled bubble. */
  color: var(--color-accent-light);
  box-shadow: var(--glass-highlight);
  border-bottom-right-radius: 4px;
}
.infble-bot-msg.is-user strong { color: var(--color-white); }

/* Rich bot copy. renderRich() emits real <p>/<ul>/<ol>, so bot bubbles opt out
   of the pre-wrap above — keeping both would double every gap. User and system
   bubbles stay pre-wrap because they render as plain text. */
.infble-bot-msg.is-bot { white-space: normal; }
.infble-bot-msg.is-bot > :first-child { margin-top: 0; }
.infble-bot-msg.is-bot > :last-child { margin-bottom: 0; }
.infble-bot-msg.is-bot p { margin: 0 0 0.65em; }
.infble-bot-msg.is-bot ul,
.infble-bot-msg.is-bot ol {
  margin: 0 0 0.65em;
  padding-left: 1.15em;
}
.infble-bot-msg.is-bot li { margin: 0 0 0.3em; }
.infble-bot-msg.is-bot li:last-child { margin-bottom: 0; }
/* Accent marker is the one bit of colour in the list — it reads as a bullet,
   not as emphasis competing with the bolded terms. */
.infble-bot-msg.is-bot li::marker { color: var(--color-accent); }
.infble-bot-msg.is-bot strong {
  color: var(--color-white);
  font-weight: 600;
}
.infble-bot-msg.is-bot em { font-style: italic; color: var(--color-text-secondary); }
.infble-bot-msg.is-bot code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  padding: 0.1em 0.36em;
  border-radius: var(--radius-sm);
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid var(--border-default);
  color: var(--color-accent-light);
  white-space: nowrap;
}
.infble-bot-msg.is-bot a {
  color: var(--color-accent-light);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 1px;
}
.infble-bot-msg.is-bot a:hover { color: var(--color-white); }
.infble-bot-msg.is-system {
  max-width: 82%;
  align-self: center;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
  color: #fbbf24;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: var(--radius-full);
}

/* Typing indicator (sits inside a .infble-bot-row.is-bot, so no self-align) */
.infble-bot-typing {
  background: rgba(13, 22, 44, 0.55);
  border: 1px solid var(--border-default);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
}
.infble-bot-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  animation: infbleBotBlink 1.2s infinite ease-in-out;
}
.infble-bot-typing span:nth-child(2) { animation-delay: 0.15s; }
.infble-bot-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes infbleBotBlink {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .infble-bot-typing span { animation: none; opacity: 0.6; }
}

/* Inline quick-replies inside the log */
.infble-bot-replies {
  align-self: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  /* Indent by avatar width + row gap so chips line up under the bot bubble */
  margin: 2px 0 4px 34px;
}
.infble-bot-reply {
  background: transparent;
  border: 1px solid var(--border-accent);
  color: var(--color-accent-light);
  padding: 6px 10px;
  border-radius: var(--radius-full);
  font-size: 0.78rem;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background var(--transition-fast);
}
.infble-bot-reply:hover { background: var(--color-accent-muted); }

/* ===== Composer ===== */
.infble-bot-composer {
  border-top: 1px solid var(--border-default);
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: rgba(3, 5, 9, 0.4);
  flex-shrink: 0;
}
.infble-bot-input {
  flex: 1;
  min-height: 38px;
  max-height: 96px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: rgba(13, 22, 44, 0.55);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  resize: none;
  line-height: 1.4;
  outline: none;
  transition: border-color var(--transition-fast);
}
.infble-bot-input:focus { border-color: var(--border-accent); }
.infble-bot-input::placeholder { color: var(--color-text-tertiary); }

/* Glass tile like the mic, one step brighter so send still reads primary. */
.infble-bot-btn {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid var(--border-accent);
  color: var(--color-accent-light);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--glass-highlight);
  transition: transform var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}
.infble-bot-btn:hover {
  transform: scale(1.05);
  background: rgba(56, 189, 248, 0.18);
  border-color: var(--color-accent);
}
.infble-bot-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.infble-bot-mic {
  background: transparent;
  border: 1px solid var(--border-default);
  color: var(--color-text-secondary);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}
.infble-bot-mic:hover { border-color: var(--border-accent); color: var(--color-accent-light); }
.infble-bot-mic.is-recording {
  border-color: var(--color-error);
  color: var(--color-error);
  animation: infbleBotMicPulse 1.2s ease-in-out infinite;
}
@keyframes infbleBotMicPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.4); }
  50%      { box-shadow: 0 0 0 6px rgba(248, 113, 113, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .infble-bot-mic.is-recording { animation: none; }
}
.infble-bot-mic.is-unsupported { display: none; }

/* Footer note */
.infble-bot-foot {
  padding: 6px 12px;
  text-align: center;
  font-size: 0.68rem;
  color: var(--color-text-tertiary);
  border-top: 1px solid var(--border-default);
  background: rgba(3, 5, 9, 0.4);
  flex-shrink: 0;
}
.infble-bot-foot a { color: var(--color-accent-light); text-decoration: none; }

/* ===== Mobile ===== */
@media (max-width: 640px) {
  .infble-bot-launcher { width: 72px; height: 72px; bottom: 14px; right: 14px; }
  .infble-bot-chips { bottom: 96px; right: 14px; }
  .infble-bot-modal {
    right: 8px;
    left: 8px;
    bottom: 8px;
    top: 8px;
    width: auto;
    height: auto;
    max-height: none;
  }
}
