/* ── AI chat widget stylesheet ──────────────────────────────────────────────
   Everything the widget in js/ai-agent.js looks like. Extracted from the site
   it was first built for and made self-contained: no host stylesheet, no
   framework, no build step. Drop it in a <link> and the widget renders.

   REBRANDING. Every colour, font and timing is a custom property defined once
   in the :root block below. Override the ones you want AFTER this file loads
   and nothing else needs touching:

     <link rel="stylesheet" href="/css/ai-agent.css">
     <style>:root{ --ai-accent:#7a2e5c; --ai-font-body:'Inter',sans-serif; }</style>

   The defaults are a neutral slate blue chosen to belong to nobody. They are
   meant to be replaced.

   DARK MODE is not assumed. If your site has a dark theme, redefine the same
   properties under whatever selector switches it - the widget follows
   automatically, because it reads nothing else.

   WHAT THE HTML NEEDS is one button on the page:

     <button class="ai-agent" aria-expanded="false"
             data-label="Ask Ada" data-icon="↑"
             data-skip-paths="/contact,/signup">
       <span class="ai-agent-dot"></span>
       <span class="ai-agent-label">AI</span>
     </button>

   The panel, the guide reader, the teaser bubble and the prompt card are all
   created by the script; none of them belong in your markup. */

:root {
  /* Colour. --ai-accent is the one most worth changing. */
  --ai-accent:          #3d5a80;   /* buttons, links, the user's own messages */
  --ai-ink:             #1a1a1a;   /* body text */
  --ai-ink-soft:        #4a4a4a;   /* secondary text */
  --ai-bg:              #ffffff;   /* panel background */
  --ai-surface:         #eef0f3;   /* the assistant's message bubbles */
  --ai-rule-mid:        #d7dce3;   /* slightly stronger dividers */
  --ai-panel-head-bg:   #e5e8ec;   /* the panel's title bar */

  /* The float button's frosted-glass look. */
  --ai-glass-bg:        rgba(255, 255, 255, 0.62);
  --ai-glass-border:    rgba(61, 90, 128, 0.22);

  /* Type. Inherit the page's own stack by default rather than imposing one. */
  --ai-font-body:       system-ui, -apple-system, "Segoe UI", sans-serif;
  --ai-font-display:    var(--ai-font-body);

  /* Motion. Respect prefers-reduced-motion is handled further down. */
  --ai-duration-fast:   0.15s;
  --ai-duration-mid:    0.3s;
  --ai-ease-out:        cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* ── AI agent float button ── */
.ai-agent {
  position: fixed;
  bottom: 32px;
  right: 32px;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 56px;
  height: 56px;
  background: var(--ai-glass-bg);
  border: 1px solid var(--ai-glass-border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  cursor: pointer;
  transition: border-color var(--ai-duration-fast);
  animation: ai-agent-nudge 8s ease-in-out infinite;
}
.ai-agent:hover { border-color: var(--ai-accent); animation-play-state: paused; }
/* Stop the attract-motion once the panel is open — a bouncing button behind
   an open chat reads as broken, not inviting. */
.ai-agent[aria-expanded="true"] { animation: none; }
@keyframes ai-agent-nudge {
  0%, 92%, 100% { transform: translateY(0) scale(1); }
  94% { transform: translateY(-6px) scale(1.04); }
  96% { transform: translateY(0) scale(1); }
  98% { transform: translateY(-3px) scale(1.02); }
}
@media (prefers-reduced-motion: reduce) {
  .ai-agent { animation: none; }
}
.ai-agent-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ai-accent);
  animation: agent-pulse 2s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes agent-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}
.ai-agent-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ai-ink-soft);
}

/* ── AI agent chat panel — rises from just above the S.AI button ── */
.ai-agent-panel {
  position: fixed;
  right: 32px;
  bottom: 100px;
  width: 400px;
  max-width: calc(100vw - 32px);
  /* Deliberately more see-through than the nav's --glass-bg: a 24px blur at
     full glass opacity reads as a flat wash over plain backgrounds rather
     than genuine transparency, so this panel is diluted further and blurred
     less, letting whatever's behind stay recognisable. */
  background: color-mix(in srgb, var(--ai-glass-bg) 45%, transparent);
  border: 1px solid var(--ai-glass-border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.24);
  overflow: hidden;
  z-index: 101;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity var(--ai-duration-mid) var(--ai-ease-out),
              transform var(--ai-duration-mid) var(--ai-ease-out),
              width var(--ai-duration-mid) var(--ai-ease-out);
}
.ai-agent-panel.is-open { opacity: 1; transform: none; pointer-events: auto; }
.ai-agent-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--ai-panel-head-bg);
  border-bottom: 1px solid var(--ai-glass-border);
  color: var(--ai-accent);
}
.ai-agent-panel-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.ai-agent-panel-logo {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  /* Always the brand green, on every arm/theme — the mark, not the accent. */
  color: var(--ai-accent);
}
.ai-agent-panel-title {
  font-family: var(--ai-font-body);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.ai-agent-panel-close {
  background: none;
  border: none;
  color: var(--ai-ink);
  font-size: 15px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity var(--ai-duration-fast);
}
.ai-agent-panel-close:hover { opacity: 1; }
.ai-agent-panel-body {
  width: 400px;
  max-width: 100%;
  height: min(600px, calc(100vh - 190px));
  display: flex;
  flex-direction: column;
  background: transparent;
}
/* In-panel guide reader — opens over the chat log (HelpScout-style) so a
   visitor never actually leaves the conversation to read a guide. Hidden by
   default; shown (and the chat body hidden) only while .is-reading. */
.ai-guide-reader { display: none; }
.ai-agent-panel.is-reading .ai-agent-panel-body { display: none; }
.ai-agent-panel.is-reading .ai-guide-reader {
  display: flex;
  flex-direction: column;
  width: 400px;
  max-width: 100%;
  height: min(600px, calc(100vh - 190px));
}
.ai-guide-reader-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--ai-panel-head-bg);
  border-bottom: 1px solid var(--ai-glass-border);
  flex-shrink: 0;
}
.ai-guide-reader-back {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--ai-accent);
  font-family: var(--ai-font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px 4px 0;
}
.ai-guide-reader-title {
  font-family: var(--ai-font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--ai-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ai-guide-reader-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  scrollbar-width: none;
}
.ai-guide-reader-body::-webkit-scrollbar { display: none; }
/* The guide's own sections carry .reveal, which global.css hides until an
   IntersectionObserver fires on scroll — that observer never runs on content
   injected here, so without this override the reader renders blank. */
.ai-guide-reader-body .reveal { opacity: 1 !important; transform: none !important; }
/* .post-takeaways ("Key takeaways") is genuinely useful summary content, kept
   in the reader — but its background (--bg-panel) has only ever had one,
   permanently-light definition (it's only ever used on the guide's own
   always-light page), so it renders illegibly on the AI arm's dark panel.
   Re-pin it to --bg, which IS theme-aware, matching how the guide-card
   already handles this same panel-vs-page token mismatch. */
.ai-guide-reader-body .post-takeaways { background: var(--ai-bg); }
/* Reading typography — the guide page's own CSS isn't loaded here, so the
   injected fragment needs its own rules. Deliberately plain: a reading
   surface, not the full designed page. */
.ai-guide-reader-body h2 {
  font-family: var(--ai-font-display);
  font-weight: 400;
  font-size: 21px;
  line-height: 1.25;
  color: var(--ai-ink);
  margin: 22px 0 10px;
}
.ai-guide-reader-body h2:first-child { margin-top: 0; }
.ai-guide-reader-body h3 {
  font-family: var(--ai-font-body);
  font-weight: 600;
  font-size: 15px;
  color: var(--ai-ink);
  margin: 18px 0 8px;
}
.ai-guide-reader-body p { font-size: 14px; line-height: 1.65; color: var(--ai-ink); margin-bottom: 12px; }
.ai-guide-reader-body ul,
.ai-guide-reader-body ol { font-size: 14px; line-height: 1.65; color: var(--ai-ink); margin: 0 0 12px 20px; }
.ai-guide-reader-body li { margin-bottom: 6px; }
.ai-guide-reader-body strong { font-weight: 600; }
.ai-guide-reader-body em { font-style: italic; }
.ai-guide-reader-body blockquote {
  border-left: 2px solid var(--ai-accent);
  padding-left: 14px;
  margin: 0 0 12px;
  color: var(--ai-ink-soft);
  font-style: italic;
}
.ai-guide-reader-body a { color: var(--ai-accent); text-decoration: underline; }
.ai-guide-reader-full { margin-top: 8px; font-size: 13px; }
.ai-guide-reader-full a { text-decoration: none; font-weight: 600; }
.ai-guide-reader-error { font-size: 14px; line-height: 1.6; color: var(--ai-ink-soft); margin-bottom: 4px; }
.ai-guide-reader-loading { display: flex; gap: 4px; align-items: center; padding: 8px 0; }
.ai-guide-reader-loading span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ai-ink-soft);
  animation: ai-typing-bounce 1.2s infinite ease-in-out;
}
.ai-guide-reader-loading span:nth-child(2) { animation-delay: 0.15s; }
.ai-guide-reader-loading span:nth-child(3) { animation-delay: 0.3s; }
/* Chat UI */
.ai-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* legacy Edge */
}
.ai-chat-log::-webkit-scrollbar { display: none; } /* Chrome, Safari */
.ai-msg {
  max-width: 82%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  white-space: normal;
  word-wrap: break-word;
}
.ai-msg-assistant {
  align-self: flex-start;
  background: var(--ai-surface, #f0efe9);
  color: var(--ai-ink);
  border-bottom-left-radius: 4px;
}
.ai-msg-user {
  align-self: flex-end;
  background: var(--ai-accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-typing { display: flex; gap: 4px; align-items: center; }
.ai-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--ai-ink-soft);
  animation: ai-typing-bounce 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}
.ai-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.ai-chip {
  border: 1px solid var(--ai-glass-border);
  background: none;
  color: var(--ai-ink);
  font-family: var(--ai-font-body);
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color var(--ai-duration-fast), color var(--ai-duration-fast);
}
.ai-chip:hover { border-color: var(--ai-accent); color: var(--ai-accent); }
/* Guide card — a resource the assistant points to. Deliberately not a bubble and not a
   reply chip: a bordered card with an icon and a "Read guide" affordance, so it
   unmistakably reads as somewhere to go rather than something she said. */
.ai-guide-wrap { display: flex; margin-top: 2px; }
.ai-guide-card {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 92%;
  padding: 11px 13px;
  text-decoration: none;
  color: var(--ai-ink);
  background: var(--ai-bg, #fff);
  border: 1px solid var(--ai-rule-mid, #d9d5c8);
  border-left: 3px solid var(--ai-accent);
  border-radius: 12px;
  transition: border-color var(--ai-duration-fast) var(--ai-ease-out),
              transform var(--ai-duration-fast) var(--ai-ease-out),
              box-shadow var(--ai-duration-fast) var(--ai-ease-out);
}
.ai-guide-card:hover {
  border-color: var(--ai-accent);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
}
.ai-guide-icon {
  flex-shrink: 0;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--ai-accent);
  color: #fff;
}
.ai-guide-icon svg { width: 18px; height: 18px; }
.ai-guide-text { display: flex; flex-direction: column; min-width: 0; }
.ai-guide-kicker {
  font-size: 10px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--ai-accent);
}
.ai-guide-title { font-size: 13.5px; font-weight: 600; line-height: 1.3; color: var(--ai-ink); }
.ai-guide-cta { font-size: 12px; color: var(--ai-ink-soft); margin-top: 2px; }
.ai-guide-arrow { margin-left: auto; align-self: center; color: var(--ai-accent); font-size: 16px; }
/* AI arm — orange accents, works in both light and dark (bg/ink flip per theme) */

/* ── CTA card — the second, bigger nudge, carrying the quick-reply chips
   so one click starts a real conversation. Styled to match the chat panel it
   opens into (same glass, border, radius and shadow), so it reads as a preview
   of the panel rather than a separate advert. Held slightly more opaque than
   the panel (65% vs 45%) because it sits over arbitrary page content and the
   outlined chips inside it have to stay legible. ── */
.ai-cta {
  position: fixed;
  right: 32px;
  bottom: 100px;
  width: 340px;
  max-width: calc(100vw - 32px);
  padding: 18px 18px 16px;
  background: color-mix(in srgb, var(--ai-glass-bg) 65%, transparent);
  border: 1px solid var(--ai-glass-border);
  border-radius: 14px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.24);
  cursor: pointer;
  z-index: 100;
  opacity: 0;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity var(--ai-duration-mid) var(--ai-ease-out),
              transform var(--ai-duration-mid) var(--ai-ease-out);
}
.ai-cta.is-open { opacity: 1; transform: none; pointer-events: auto; }
.ai-cta-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.ai-cta-logo { width: 18px; height: 18px; flex-shrink: 0; color: var(--ai-accent); }
.ai-cta-name {
  font-family: var(--ai-font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ai-accent);
}
.ai-cta-title {
  font-family: var(--ai-font-display);
  font-size: 19px;
  font-weight: 400;
  line-height: 1.25;
  color: var(--ai-ink);
  margin-bottom: 6px;
}
.ai-cta-line {
  font-family: var(--ai-font-body);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ai-ink-soft);
  margin-bottom: 14px;
}
.ai-cta-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.ai-cta-close {
  position: absolute;
  top: 8px;
  right: 10px;
  background: none;
  border: none;
  color: var(--ai-ink-soft);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
  opacity: 0.7;
  transition: opacity var(--ai-duration-fast);
}
.ai-cta-close:hover { opacity: 1; }
/* Mobile: a bottom sheet using a reasonable slice of the screen, NOT a
   full-screen overlay — a large interstitial over the content is both hostile
   and an SEO risk on mobile. */
@media (max-width: 600px) {
  .ai-cta {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    max-height: 60vh;
    overflow-y: auto;
    border-radius: 16px 16px 0 0;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transform-origin: bottom center;
  }
  .ai-cta.is-open { transform: none; }
}

/* ── Teaser bubble — a one-off, stronger nudge than the button's ambient
   bounce. Solid (not glass): it needs to catch the eye, not blend in. ── */
.ai-agent-teaser {
  position: fixed;
  right: 32px;
  bottom: 100px;
  max-width: 240px;
  background: var(--ai-accent);
  color: #fff;
  padding: 14px 32px 14px 16px;
  border-radius: 16px;
  border-bottom-right-radius: 4px;
  font-family: var(--ai-font-body);
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  z-index: 99;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
  transform-origin: bottom right;
  pointer-events: none;
  transition: opacity var(--ai-duration-mid) var(--ai-ease-out), transform var(--ai-duration-mid) var(--ai-ease-out);
}
.ai-agent-teaser.is-open { opacity: 1; transform: none; pointer-events: auto; }
.ai-agent-teaser p { margin: 0; }
.ai-agent-teaser-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  padding: 6px;
}
.ai-agent-teaser-close:hover { color: #fff; }
@media (max-width: 480px) {
  .ai-agent-teaser { right: 16px; left: 16px; max-width: none; bottom: 92px; }
}
.ai-chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  background: var(--ai-panel-head-bg);
  border-top: 1px solid var(--ai-glass-border);
}
.ai-chat-input textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--ai-glass-border);
  border-radius: 12px;
  padding: 9px 12px;
  font-family: var(--ai-font-body);
  font-size: 14px;
  line-height: 1.4;
  background: var(--ai-bg);
  color: var(--ai-ink);
  max-height: 96px;
  scrollbar-width: none; /* Firefox */
}
.ai-chat-input textarea::-webkit-scrollbar { display: none; } /* Chrome, Safari */
.ai-chat-input textarea:focus { outline: none; border-color: var(--ai-accent); }
.ai-chat-input button {
  flex-shrink: 0;
  width: 40px; height: 40px;
  border: none;
  border-radius: 50%;
  background: #fff;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.14);
  transition: transform var(--ai-duration-fast);
}
/* The send button carries a text glyph (data-icon on the host button), not an
   image asset - a product cannot depend on one customer's file being present. */
.ai-send-glyph { font-size: 17px; line-height: 1; display: block; }
.ai-chat-input button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-chat-input button:hover { transform: scale(1.06); }
/* Mobile: full-screen rather than a floating box — the 68vh panel used to
   sit oddly, part-covering the page beneath it with an awkward gap below. */
@media (max-width: 600px) {
  .ai-agent-panel {
    inset: 0; right: 0; left: 0; top: 0; bottom: 0;
    width: 100%; max-width: none;
    border-radius: 0;
    display: flex; flex-direction: column;
    /* Above every other fixed layer on the page — site header (900), the
       hamburger trigger and AI theme bulb (949-950), even the nav overlay
       itself (1000) — otherwise "full-screen" still has some of the page's
       own chrome painted over the top of it. */
    z-index: 1010;
  }
  .ai-agent-panel-body { width: 100%; height: auto; flex: 1; min-height: 0; }
  .ai-agent-panel.is-reading .ai-guide-reader { width: 100%; height: auto; flex: 1; min-height: 0; }
}
/* Desktop only: widen while reading a guide. Explicitly scoped above the
   mobile breakpoint so it never fights the full-screen rule above. */
@media (min-width: 601px) {
  .ai-agent-panel.is-reading { width: 520px; }
}
