/* Floating chat widget. Injected on every page by scripts/apply-chat.mjs.
   Uses the site's existing design tokens (--navy, --gold, --blue…) so it
   inherits the palette rather than hardcoding a second one. */

.apc {
  position: fixed;
  right: clamp(14px, 2vw, 24px);
  bottom: clamp(14px, 2vw, 24px);
  z-index: 9000;
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* ---------------------------------------------------------------- teaser */

.apc__teaser {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(310px, calc(100vw - 40px));
}
.apc__teaser[hidden] { display: none; }

.apc__bubble {
  position: relative;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px 16px 5px 16px;
  box-shadow: var(--shadow-lg);
  padding: 13px 34px 13px 15px;
  font-size: .93rem;
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  animation: apc-pop .45s var(--ease) both;
}
.apc__bubble strong { font-family: var(--font-display); display: block; margin-bottom: 2px; }
.apc__bubble:hover { border-color: var(--blue-100); }

.apc__bubble-x {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 0;
  background: none;
  color: var(--muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0;
}
.apc__bubble-x:hover { background: var(--bg-soft-2); color: var(--ink); }

.apc__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: flex-end;
}
.apc__chip {
  font-family: var(--font-body);
  font-size: .85rem;
  font-weight: 600;
  color: var(--blue-700);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 13px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform .16s var(--ease), border-color .16s var(--ease);
  animation: apc-pop .45s var(--ease) both;
}
.apc__chip:hover { border-color: var(--blue); transform: translateY(-1px); }

/* ---------------------------------------------------------------- launcher */

.apc__launcher {
  position: relative;
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--gold), var(--gold-600));
  color: #3a2600;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease);
}
.apc__launcher:hover { transform: translateY(-2px) scale(1.04); }
.apc__launcher:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }
.apc__launcher svg { width: 27px; height: 27px; }
.apc__launcher .apc__icon-close { display: none; }
.apc.is-open .apc__launcher .apc__icon-open { display: none; }
.apc.is-open .apc__launcher .apc__icon-close { display: block; }

/* Pulse ring — draws the eye once without animating forever. */
.apc__launcher:after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--gold);
  animation: apc-ring 2.4s var(--ease) 3;
}
.apc.is-open .apc__launcher:after,
.apc__launcher:hover:after { animation: none; opacity: 0; }

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

.apc__panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: min(392px, calc(100vw - 28px));
  height: min(600px, calc(100vh - 120px));
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform-origin: bottom right;
}
.apc__panel[hidden] { display: none; }

/* Only when the visitor opens it themselves. A panel restored mid-visit on the
   next page should look like it never went away, not slide in again. */
.apc__panel--anim { animation: apc-open .28s var(--ease) both; }

.apc__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  background: linear-gradient(120deg, var(--navy), var(--navy-3));
  color: #fff;
  flex: none;
}
.apc__avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: #ffffff1f;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.apc__avatar img { width: 100%; height: 100%; object-fit: cover; }
.apc__head-txt { flex: 1; min-width: 0; }
.apc__head-txt strong {
  font-family: var(--font-display);
  font-size: .98rem;
  display: block;
  color: #fff;
}
.apc__head-txt span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .79rem;
  color: #b9cde8;
}
.apc__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  box-shadow: 0 0 0 3px #4ade8033;
}
.apc__close {
  width: 32px;
  height: 32px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: #ffffff1a;
  color: #fff;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 0;
}
.apc__close:hover { background: #ffffff33; }

.apc__call {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  background: var(--gold-100);
  border-bottom: 1px solid #f2d9a6;
  color: #7a4b00;
  font-size: .85rem;
  font-weight: 600;
  flex: none;
}
.apc__call a { color: #7a4b00; text-decoration: underline; font-weight: 800; }
.apc__call svg { width: 15px; height: 15px; }

.apc__log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  background: var(--bg-soft);
  scroll-behavior: smooth;
}

.apc__msg {
  max-width: 86%;
  padding: 11px 14px;
  border-radius: 15px;
  font-size: .93rem;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: apc-pop .3s var(--ease) both;
}
.apc__msg--bot {
  align-self: flex-start;
  background: #fff;
  color: var(--body);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.apc__msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--blue), var(--blue-700));
  color: #fff;
  border-bottom-right-radius: 5px;
}
.apc__msg--err {
  align-self: flex-start;
  background: #fff4f4;
  border: 1px solid #f6d5d5;
  color: #98383f;
  border-bottom-left-radius: 5px;
}
.apc__msg a { color: var(--blue-600); text-decoration: underline; font-weight: 600; }
.apc__msg--user a { color: #fff; }
.apc__msg strong { font-weight: 700; color: var(--ink); }
.apc__msg--user strong { color: #fff; }

/* Typing dots, shown while waiting for the first token. */
.apc__typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.apc__typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: apc-blink 1.3s infinite ease-in-out both;
}
.apc__typing i:nth-child(2) { animation-delay: .16s; }
.apc__typing i:nth-child(3) { animation-delay: .32s; }

/* Suggested questions + the CTA row the bot's answer earns. */
.apc__suggest {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 2px 16px 14px;
  background: var(--bg-soft);
  flex: none;
}
.apc__suggest[hidden] { display: none; }
.apc__suggest-lbl {
  font-family: var(--font-display);
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1px;
}
.apc__q {
  text-align: left;
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  color: var(--blue-700);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 10px 13px;
  cursor: pointer;
  transition: border-color .16s var(--ease), transform .16s var(--ease);
}
.apc__q:hover { border-color: var(--blue); transform: translateX(2px); }

.apc__cta {
  display: flex;
  gap: 8px;
  padding: 0 16px 12px;
  background: var(--bg-soft);
  flex: none;
}
.apc__cta[hidden] { display: none; }
.apc__cta a {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-family: var(--font-display);
  font-size: .87rem;
  font-weight: 700;
  padding: 11px 10px;
  border-radius: 11px;
  text-decoration: none;
  text-align: center;
}
.apc__cta svg { width: 15px; height: 15px; }
.apc__cta-call { background: linear-gradient(135deg, var(--gold), var(--gold-600)); color: #3a2600; }
.apc__cta-call:hover { color: #3a2600; filter: brightness(1.04); }
.apc__cta-quote { background: var(--navy); color: #fff; }
.apc__cta-quote:hover { color: #fff; background: var(--navy-3); }

.apc__form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 11px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
  flex: none;
}
.apc__input {
  flex: 1;
  font: inherit;
  font-size: .93rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 13px;
  resize: none;
  max-height: 108px;
  line-height: 1.45;
  background: var(--bg-soft);
}
.apc__input:focus { outline: none; border-color: var(--blue); background: #fff; }
.apc__input::placeholder { color: var(--muted); }

.apc__send {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--blue), var(--blue-700));
  color: #fff;
  cursor: pointer;
  transition: opacity .16s var(--ease);
}
.apc__send svg { width: 18px; height: 18px; }
.apc__send:disabled { opacity: .45; cursor: not-allowed; }

.apc__legal {
  padding: 0 14px 10px;
  font-size: .7rem;
  color: var(--muted);
  text-align: center;
  background: #fff;
  flex: none;
}

/* ---------------------------------------------------------------- motion */

@keyframes apc-open {
  from { opacity: 0; transform: translateY(14px) scale(.96); }
  to   { opacity: 1; transform: none; }
}
@keyframes apc-pop {
  from { opacity: 0; transform: translateY(7px); }
  to   { opacity: 1; transform: none; }
}
@keyframes apc-ring {
  0%   { opacity: .85; transform: scale(1); }
  70%  { opacity: 0; transform: scale(1.45); }
  100% { opacity: 0; transform: scale(1.45); }
}
@keyframes apc-blink {
  0%, 80%, 100% { opacity: .28; transform: translateY(0); }
  40%           { opacity: 1; transform: translateY(-3px); }
}

@media (prefers-reduced-motion: reduce) {
  .apc__panel, .apc__panel--anim, .apc__msg, .apc__chip, .apc__bubble { animation: none; }
  .apc__launcher:after { animation: none; opacity: 0; }
  .apc__log { scroll-behavior: auto; }
}

/* On a phone the panel takes the screen — a 392px card floating over content
   is unusable at 360px wide. */
@media (max-width: 480px) {
  .apc__panel {
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
    border: 0;
  }
  .apc.is-open .apc__launcher,
  .apc.is-open .apc__teaser { display: none; }
}

/* Below 768px the site shows .mobile-callbar — a fixed, full-width gold call
   bar pinned to the bottom. Lift the launcher clear of it, including the
   safe-area inset it already accounts for. */
@media (max-width: 768px) {
  .apc { bottom: calc(84px + env(safe-area-inset-bottom)); }
}
