/* ============================================================================
   Favored Assistant - widget styles
   Load AFTER components.css and dark.css so these rules win without !important.

   Tokens are scoped --fa-* and mirror the nav/footer system (nav.css), so the
   assistant reads as part of the site rather than a bolted-on third-party
   product. Light and dark are genuinely separate palettes, not one palette with
   the lightness inverted.

   The old widget's rules live in components.css (.chat, .chat-panel, ...) and
   are NOT reused; these class names are all fa-* to avoid inheriting them.
   ============================================================================ */

:root {
  --fa-brand:      #15356E;   /* brand navy, same as --blue-d in nav.css */
  --fa-brand-2:    #1F4FA3;
  --fa-accent:     #FFD24A;   /* brand yellow, same as --mq-ink */
  --fa-surface:    #FFFFFF;
  --fa-surface-2:  #EDF2FA;
  --fa-line:       #D6E0F0;
  --fa-ink:        #0F1F38;
  --fa-ink-dim:    #4A5D7A;
  --fa-bot-bg:     #FFFFFF;
  --fa-bot-ink:    #0F1F38;
  --fa-user-bg:    #15356E;
  --fa-user-ink:   #FFFFFF;
  --fa-chip-bg:    #FFFFFF;
  --fa-chip-ink:   #15356E;
  --fa-chip-line:  #C3D2E8;
  --fa-err:        #A3161B;
  --fa-shadow:     0 18px 48px rgba(15, 31, 56, .22);
  --fa-radius:     16px;
  --fa-speed:      .22s;
}

[data-theme="dark"] {
  --fa-brand:      #17386F;
  --fa-brand-2:    #2A5FBF;
  --fa-accent:     #FFCB52;
  --fa-surface:    #141D30;
  --fa-surface-2:  #0B1220;
  --fa-line:       #2A3A55;
  --fa-ink:        #E8EEF8;
  --fa-ink-dim:    #CBD8EA;
  --fa-bot-bg:     #1C2740;
  --fa-bot-ink:    #E8EEF8;
  --fa-user-bg:    #2A5FBF;
  --fa-user-ink:   #FFFFFF;
  --fa-chip-bg:    #1C2740;
  --fa-chip-ink:   #D5E0F0;
  --fa-chip-line:  #35486A;
  --fa-err:        #FF8A8F;
  --fa-shadow:     0 18px 48px rgba(0, 0, 0, .55);
}

/* ------------------------------------------------------------------ launcher
   #chatToggle already exists in footer.php. These rules restyle it without
   renaming it, so the PHP does not have to change. */
#chatToggle.chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2147483000;
  width: 60px;
  height: 60px;
  min-width: 60px;
  min-height: 60px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--fa-brand-2), var(--fa-brand));
  color: #fff;
  box-shadow: var(--fa-shadow);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform var(--fa-speed) ease, box-shadow var(--fa-speed) ease;
}
#chatToggle.chat svg { width: 26px; height: 26px; stroke: currentColor; fill: none; }
#chatToggle.chat:hover { transform: translateY(-3px) scale(1.04); }
#chatToggle.chat:focus-visible {
  outline: 3px solid var(--fa-accent);
  outline-offset: 3px;
}

/* -------------------------------------------------------------------- panel
   Two selectors on purpose. [popover] is the modern path and puts the panel in
   the top layer, which ends the z-index fight with the sticky header, the
   Cookiebot banner and the accessibility widget. .fa-panel.on is the fallback
   for browsers without the Popover API, where a plain fixed element is used. */
.fa-panel {
  position: fixed;
  inset: auto 20px 92px auto;
  width: min(380px, calc(100vw - 32px));
  height: min(560px, calc(100vh - 130px));
  margin: 0;
  padding: 0;
  border: 1px solid var(--fa-line);
  border-radius: var(--fa-radius);
  background: var(--fa-surface-2);
  color: var(--fa-ink);
  box-shadow: var(--fa-shadow);
  overflow: hidden;
  display: none;
  flex-direction: column;
  font: 400 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
.fa-panel:popover-open,
.fa-panel.on { display: flex; }

/* Entry and exit. Top-layer elements toggle `display`, so `display` and
   `overlay` must both be transitioned with allow-discrete or the panel is
   clipped out of the top layer before the animation finishes. */
.fa-panel {
  opacity: 0;
  transform: translateY(12px) scale(.97);
  transition-property: opacity, transform, display, overlay;
  transition-duration: var(--fa-speed);
  transition-timing-function: cubic-bezier(.2, .8, .3, 1);
  transition-behavior: allow-discrete;
}
.fa-panel:popover-open,
.fa-panel.on {
  opacity: 1;
  transform: translateY(0) scale(1);
}
@starting-style {
  .fa-panel:popover-open,
  .fa-panel.on {
    opacity: 0;
    transform: translateY(12px) scale(.97);
  }
}

/* --------------------------------------------------------------------- head */
.fa-head {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 13px 14px;
  background: linear-gradient(135deg, var(--fa-brand-2), var(--fa-brand));
  color: #fff;
  flex-shrink: 0;
}
.fa-av {
  width: 38px; height: 38px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--fa-accent);
  color: #15356E;
  display: grid; place-items: center;
  font: 700 17px/1 Sora, system-ui, sans-serif;
}
.fa-head-t { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.fa-head-t b {
  font: 700 15px/1.25 Sora, system-ui, sans-serif;
  color: #fff;
}
.fa-status {
  display: flex; align-items: center; gap: 6px;
  font-size: .78rem;
  color: rgba(255, 255, 255, .88);
}
.fa-status::before {
  content: "";
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #4ADE80;
  box-shadow: 0 0 0 3px rgba(74, 222, 128, .28);
  flex-shrink: 0;
}
.fa-x {
  width: 44px; height: 44px;      /* 2.5.5 minimum target */
  flex-shrink: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 10px;
  background: rgba(255, 255, 255, .12);
  color: #fff;
  cursor: pointer;
  transition: background var(--fa-speed) ease;
}
.fa-x svg { width: 17px; height: 17px; }
.fa-x:hover { background: rgba(255, 255, 255, .24); }
.fa-x:focus-visible { outline: 3px solid var(--fa-accent); outline-offset: -2px; }

/* ---------------------------------------------------------------------- log */
.fa-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: var(--fa-surface-2);
  /* keeps the newest message in view when content is appended */
  overflow-anchor: auto;
}
.fa-msg {
  max-width: 84%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: .92rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.fa-bot {
  align-self: flex-start;
  background: var(--fa-bot-bg);
  color: var(--fa-bot-ink);
  border: 1px solid var(--fa-line);
  border-bottom-left-radius: 5px;
}
.fa-user {
  align-self: flex-end;
  background: var(--fa-user-bg);
  color: var(--fa-user-ink);
  border-bottom-right-radius: 5px;
}

/* -------------------------------------------------------------------- chips */
.fa-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.fa-chip {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--fa-chip-line);
  border-radius: 99px;
  background: var(--fa-chip-bg);
  color: var(--fa-chip-ink);
  font: 600 .84rem/1 Inter, system-ui, sans-serif;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--fa-speed) ease, border-color var(--fa-speed) ease,
              transform var(--fa-speed) ease;
}
.fa-chip:hover {
  background: var(--fa-brand);
  border-color: var(--fa-brand);
  color: #fff;
  transform: translateY(-1px);
}
.fa-chip:focus-visible { outline: 3px solid var(--fa-brand-2); outline-offset: 2px; }

/* ------------------------------------------------------------------- typing */
.fa-typing { display: flex; gap: 5px; align-items: center; padding: 13px; }
.fa-typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--fa-ink-dim);
  animation: fa-bounce 1.3s infinite ease-in-out;
}
.fa-typing span:nth-child(2) { animation-delay: .17s; }
.fa-typing span:nth-child(3) { animation-delay: .34s; }
@keyframes fa-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .45; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* --------------------------------------------------------------- composer */
.fa-foot {
  display: flex;
  gap: 8px;
  padding: 11px;
  background: var(--fa-surface);
  border-top: 1px solid var(--fa-line);
  flex-shrink: 0;
}
.fa-input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--fa-line);
  border-radius: 99px;
  background: var(--fa-surface-2);
  color: var(--fa-ink);
  font: 400 .92rem/1.4 Inter, system-ui, sans-serif;
}
.fa-input::placeholder { color: var(--fa-ink-dim); opacity: 1; }
.fa-input:focus-visible {
  outline: 3px solid var(--fa-brand-2);
  outline-offset: 1px;
  border-color: var(--fa-brand-2);
}
.fa-send {
  width: 44px; height: 44px;
  flex-shrink: 0;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: linear-gradient(135deg, var(--fa-brand-2), var(--fa-brand));
  color: #fff;
  cursor: pointer;
  transition: transform var(--fa-speed) ease, filter var(--fa-speed) ease;
}
.fa-send svg { width: 19px; height: 19px; }
.fa-send:hover { transform: scale(1.07); }
.fa-send:focus-visible { outline: 3px solid var(--fa-accent); outline-offset: 2px; }
.fa-send:disabled, .fa-input:disabled { opacity: .55; cursor: not-allowed; }
.fa-send:disabled:hover { transform: none; }

.fa-note {
  margin: 0;
  padding: 7px 13px 10px;
  background: var(--fa-surface);
  color: var(--fa-ink-dim);
  font-size: .69rem;
  line-height: 1.4;
  text-align: center;
  flex-shrink: 0;
}
.fa-ts { padding: 0 11px; flex-shrink: 0; }
.fa-ts:empty { display: none; }

/* ------------------------------------------------------------------ lead form */
.fa-lead { width: 100%; }
.fa-lead fieldset {
  margin: 0;
  padding: 13px;
  border: 1px solid var(--fa-line);
  border-radius: 13px;
  background: var(--fa-surface);
}
.fa-lead legend {
  padding: 0 6px;
  font: 700 .88rem/1 Sora, system-ui, sans-serif;
  color: var(--fa-ink);
}
.fa-row { margin-bottom: 9px; }
.fa-row label {
  display: block;
  margin-bottom: 4px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--fa-ink);
}
.fa-row input, .fa-row textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--fa-line);
  border-radius: 9px;
  background: var(--fa-surface-2);
  color: var(--fa-ink);
  font: 400 .88rem/1.4 Inter, system-ui, sans-serif;
}
.fa-row textarea { resize: vertical; min-height: 56px; }
.fa-row input:focus-visible, .fa-row textarea:focus-visible {
  outline: 3px solid var(--fa-brand-2);
  outline-offset: 1px;
}
.fa-row input[aria-invalid="true"] { border-color: var(--fa-err); }
.fa-err {
  margin: 4px 0 0;
  font-size: .74rem;
  font-weight: 600;
  color: var(--fa-err);
  min-height: 0;
}
.fa-err:empty { display: none; }
.fa-hint { margin: 4px 0 0; font-size: .72rem; color: var(--fa-ink-dim); }
.fa-disclose {
  margin-top: 9px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--fa-surface-2);
  border: 1px solid var(--fa-line);
}
.fa-submit {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  border: 0;
  border-radius: 99px;
  background: linear-gradient(135deg, var(--fa-brand-2), var(--fa-brand));
  color: #fff;
  font: 700 .88rem/1 Sora, system-ui, sans-serif;
  cursor: pointer;
  transition: transform var(--fa-speed) ease;
}
.fa-submit:hover:not(:disabled) { transform: translateY(-1px); }
.fa-submit:focus-visible { outline: 3px solid var(--fa-accent); outline-offset: 2px; }
.fa-submit:disabled { opacity: .6; cursor: progress; }
.fa-result {
  margin: 8px 0 0;
  font-size: .78rem;
  font-weight: 600;
  color: var(--fa-err);
}
.fa-result:empty { display: none; }

/* Honeypot: removed from sight AND from the accessibility tree, so no screen
   reader user is ever offered a field that would silently discard their
   enquiry. Not display:none, which some bots detect and skip. */
.fa-hp {
  position: absolute !important;
  left: -9999px !important;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Screen-reader-only label */
.fa-sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------- responsive */
@media (max-width: 480px) {
  .fa-panel {
    inset: auto 8px 82px 8px;
    width: auto;
    height: min(74vh, calc(100vh - 110px));
  }
  /* min-width/min-height must be restated. The base rule sets both to 60px as
     a floor against the old components.css sizing, and a floor beats a smaller
     width, so overriding width alone silently did nothing here. */
  #chatToggle.chat {
    right: 14px; bottom: 14px;
    width: 56px; height: 56px;
    min-width: 56px; min-height: 56px;
  }
  .fa-msg { max-width: 90%; }
}

/* Short viewports, e.g. a phone in landscape with the keyboard open */
@media (max-height: 520px) {
  .fa-panel { height: calc(100vh - 96px); }
  .fa-note { display: none; }
}

/* ----------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  .fa-panel {
    transform: none;
    transition-duration: .01ms;
  }
  @starting-style {
    .fa-panel:popover-open,
    .fa-panel.on { transform: none; }
  }
  #chatToggle.chat:hover,
  .fa-chip:hover,
  .fa-send:hover,
  .fa-submit:hover:not(:disabled) { transform: none; }
  .fa-typing span { animation: none; opacity: .6; }
}

/* ------------------------------------------------------------- forced colors */
@media (forced-colors: active) {
  .fa-panel { border: 1px solid CanvasText; }
  .fa-chip, .fa-input, .fa-row input, .fa-row textarea { border: 1px solid CanvasText; }
  .fa-status::before { background: CanvasText; }
}
