/* frameworx — apex assistant
   ---------------------------------------------------------------------------
   Self-contained. Removing this file and assets/apex.js takes the bot out
   completely and restores .fx-fab to its original corner position.

   Colours, fonts and radii come from the tokens in styles.css rather than
   being hard-coded, so a brand change flows through here for free. */

:root {
  --apex-size:  64px;                    /* launcher square */
  --apex-inset: clamp(14px, 3vw, 26px);  /* matches .fx-fab's own inset */
  --apex-gap:   18px;                    /* clear air between bot and CTA */
}

/* The assessment CTA and the launcher both used to claim the bottom-right
   corner, with .fx-fab (z-index 80) painting straight over the bot. Lift the
   pill above the launcher instead. */
.fx-fab { bottom: calc(var(--apex-inset) + var(--apex-size) + var(--apex-gap)); }

/* While the panel is open or the nudge is up, the pill would crowd or overlap
   them — hide it exactly the way the mobile menu already does. */
body.apex-engaged .fx-fab {
  opacity: 0; visibility: hidden; transform: translateY(14px); pointer-events: none;
}

.apex, .apex *, .apex *::before, .apex *::after { box-sizing: border-box; }

/* ---------------------------------------------------------------- character */
/* Pure CSS, no assets. Authored at 72x60 and scaled per placement. transform
   doesn't shrink the layout box, so each slot centres it absolutely. */
.apex-face {
  position: absolute; left: 50%; top: 50%;
  width: 72px; height: 60px;
  transform: translate(-50%, -50%) scale(var(--apex-scale, 1));
  animation: apexBob 3.8s ease-in-out infinite;
}
.apex-head {
  position: absolute; inset: 0;
  background: #fff; border: 1.5px solid var(--line);
  border-radius: 22px;
}
.apex-visor {
  position: absolute; inset: 9px 8px;
  background: var(--ink); border-radius: 15px; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
}
.apex-eyes { display: flex; gap: 12px; }
.apex-eye {
  width: 9px; height: 11px; border-radius: 4px;
  background: linear-gradient(180deg, var(--pink), var(--orange));
  transition: transform .2s ease;
  animation: apexBlink 5s ease-in-out infinite;
}
.apex-mouth {
  width: 10px; height: 3px; border-radius: 2px;
  background: rgba(255,162,62,.85);
  transition: width .2s ease;
}
.apex-antenna {
  position: absolute; left: 50%; top: -13px; width: 2px; height: 13px;
  background: var(--line-dark); opacity: .35; transform: translateX(-50%);
}
.apex-antenna::after {
  content: ""; position: absolute; left: 50%; top: -7px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--grad);
  transform: translateX(-50%); animation: apexAntenna 2.2s ease-in-out infinite;
}
.apex-ear {
  position: absolute; top: 22px; width: 5px; height: 16px; border-radius: 3px;
  background: rgba(255,90,82,.5);
}
.apex-ear.l { left: -5px; }
.apex-ear.r { right: -5px; }
.apex-scan {
  position: absolute; left: 0; right: 0; height: 8px;
  background: linear-gradient(rgba(255,90,82,.4), transparent);
  animation: apexScan 3.2s linear infinite;
}

/* the four faces */
.apex-face[data-mood="listening"] .apex-eye { transform: scaleY(1.15) translateY(-1px); animation: none; }
.apex-face[data-mood="listening"] .apex-mouth { width: 6px; }
.apex-face[data-mood="thinking"]  .apex-eye { transform: scaleY(.34); animation: apexThink 1s ease-in-out infinite; }
.apex-face[data-mood="thinking"]  .apex-mouth { width: 8px; }
.apex-face[data-mood="talking"]   .apex-mouth { animation: apexTalk .42s ease-in-out infinite; }
.apex-face[data-mood="happy"]     .apex-eye { transform: scaleY(.45) translateY(-2px); animation: none; }
.apex-face[data-mood="happy"]     .apex-mouth { width: 18px; }

@keyframes apexBob   { 0%,100% { transform: translate(-50%,-50%) scale(var(--apex-scale,1)) translateY(0) rotate(-.6deg); }
                        50%    { transform: translate(-50%,-50%) scale(var(--apex-scale,1)) translateY(-4px) rotate(.6deg); } }
@keyframes apexBlink { 0%,92%,100% { transform: scaleY(1); } 95% { transform: scaleY(.12); } }
@keyframes apexThink { 0%,100% { transform: scaleY(.34) translateY(0); } 50% { transform: scaleY(.34) translateY(-2px); } }
@keyframes apexTalk  { 0%,100% { width: 8px; height: 3px; } 35% { width: 16px; height: 7px; } 70% { width: 11px; height: 4px; } }
@keyframes apexAntenna { 0%,100% { opacity: .4; transform: translateX(-50%) scale(.82); } 50% { opacity: 1; transform: translateX(-50%) scale(1.1); } }
@keyframes apexScan  { 0% { transform: translateY(-8px); opacity: 0; } 40% { opacity: .55; } 100% { transform: translateY(22px); opacity: 0; } }
@keyframes apexPulse { 0% { box-shadow: 0 0 0 0 rgba(255,90,82,.30); } 70% { box-shadow: 0 0 0 18px rgba(255,90,82,0); } 100% { box-shadow: 0 0 0 0 rgba(255,90,82,0); } }
@keyframes apexIn    { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes apexDot   { 0%,60%,100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

/* ----------------------------------------------------------------- launcher */
.apex-launcher {
  position: fixed; z-index: 82;
  right: var(--apex-inset); bottom: var(--apex-inset);
  width: var(--apex-size); height: var(--apex-size);
  padding: 0; border-radius: 20px; cursor: pointer;
  background: #fff; border: 1px solid var(--line);
  box-shadow: 0 14px 34px rgba(20,20,26,.16);
  transition: border-color .2s, transform .25s cubic-bezier(.2,.8,.2,1);
}
.apex-launcher.pulse { animation: apexPulse 3.4s ease-out 1.2s 3; }
.apex-launcher:hover { border-color: rgba(255,90,82,.55); transform: translateY(-2px); }
.apex-launcher:focus-visible { outline: 2px solid var(--orange); outline-offset: 3px; }
.apex-launcher .apex-face { --apex-scale: .6; }
.apex-launcher-x {
  display: none; font-family: var(--mono); font-size: 20px; color: var(--muted-2);
}
.apex-launcher[aria-expanded="true"] .apex-face { display: none; }
.apex-launcher[aria-expanded="true"] .apex-launcher-x { display: block; }
body.menu-open .apex-launcher { opacity: 0; visibility: hidden; pointer-events: none; }

/* -------------------------------------------------------------------- nudge */
.apex-nudge {
  position: fixed; z-index: 82;
  right: var(--apex-inset);
  bottom: calc(var(--apex-inset) + var(--apex-size) + 14px);
  display: flex; align-items: flex-start; gap: 6px;
  animation: apexIn .26s ease;
}
.apex-nudge-body {
  max-width: 272px; text-align: left; cursor: pointer;
  background: #fff; border: 1px solid var(--line);
  border-radius: 18px 18px 4px 18px; padding: 14px 16px;
  font-family: var(--sans); font-size: 13.5px; line-height: 1.5; color: var(--ink-soft);
  box-shadow: 0 14px 36px rgba(20,20,26,.12);
  transition: border-color .2s;
}
.apex-nudge-body:hover { border-color: rgba(255,90,82,.5); }
.apex-nudge-x {
  flex: none; width: 24px; height: 24px; padding: 0; cursor: pointer;
  border: 0; border-radius: 50%; background: var(--paper); color: var(--muted);
  font-size: 15px; line-height: 1; display: grid; place-items: center;
  box-shadow: 0 4px 14px -4px rgba(20,20,26,.45), 0 0 0 1px var(--line);
}
.apex-nudge-x:hover { color: var(--ink); }

/* -------------------------------------------------------------------- panel */
.apex-panel {
  position: fixed; z-index: 84;
  right: var(--apex-inset);
  bottom: calc(var(--apex-inset) + var(--apex-size) + 14px);
  width: 386px; height: min(566px, calc(100vh - 120px));
  display: grid; grid-template-rows: auto 1fr auto;
  background: #fff; border: 1px solid var(--line); border-radius: 22px;
  box-shadow: 0 28px 70px rgba(20,20,26,.16);
  overflow: hidden; animation: apexIn .22s ease;
  font-family: var(--sans);
}
/* display:grid would otherwise beat the UA's [hidden] rule on equal specificity. */
.apex-panel[hidden] { display: none; }
.apex-head-bar {
  display: flex; align-items: center; gap: 11px;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.apex-avatar { position: relative; width: 40px; height: 40px; flex: none; }
.apex-avatar .apex-face { --apex-scale: .44; }
.apex-id { flex: 1; min-width: 0; }
.apex-id strong {
  display: block; font-family: var(--mono); font-size: 14px; font-weight: 500; letter-spacing: -.02em;
}
.apex-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted-2); margin-top: 2px;
}
.apex-status::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex: none;
}
.apex-close {
  flex: none; border: 0; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--muted-2); padding: 0 2px;
}
.apex-close:hover { color: var(--ink); }

.apex-thread {
  padding: 18px; overflow-y: auto; background: var(--paper);
  display: flex; flex-direction: column; gap: 14px;
}
.apex-msg { max-width: 85%; }
.apex-msg.bot {
  align-self: flex-start;
  background: #fff; border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px; padding: 12px 15px;
  font-size: 14px; line-height: 1.6; color: var(--ink-soft);
}
.apex-msg.me {
  align-self: flex-end; background: var(--grad); color: #fff;
  border-radius: 16px 16px 4px 16px; padding: 12px 15px;
  font-size: 14px; line-height: 1.6;
}
.apex-link {
  display: inline-block; margin-top: 9px;
  font-family: var(--mono); font-size: 12px; color: var(--accent);
  border-bottom: 1px solid rgba(255,90,82,.35);
}
.apex-link:hover { color: var(--ink); border-bottom-color: var(--ink); }
.apex-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.apex-chip {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 14px; font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft);
  box-shadow: 0 2px 8px rgba(20,20,26,.04);
  transition: border-color .2s, color .2s;
}
.apex-chip::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); flex: none;
}
.apex-chip:hover { border-color: rgba(255,90,82,.55); color: var(--accent); }
.apex-typing {
  align-self: flex-start; display: flex; gap: 4px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 16px 16px 16px 4px; padding: 13px 15px;
}
.apex-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted-2); animation: apexDot 1.1s infinite; }
.apex-typing i:nth-child(2) { animation-delay: .15s; }
.apex-typing i:nth-child(3) { animation-delay: .3s; }

.apex-email {
  display: flex; flex-direction: column; gap: 10px;
  background: #fff; border: 1px solid rgba(255,90,82,.3);
  border-radius: 16px; padding: 14px;
}
.apex-email p { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0; }
.apex-email input {
  background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; font-family: var(--sans); font-size: 13.5px; color: var(--ink); outline: none;
}
.apex-email input:focus { border-color: rgba(255,90,82,.55); }
.apex-email button {
  background: var(--grad); color: #fff; border: 0; border-radius: 999px;
  padding: 12px; font-family: var(--mono); font-size: 13px; cursor: pointer;
}
.apex-email .apex-err { color: var(--accent); font-size: 12px; margin: 0; }

.apex-composer { padding: 11px 13px; border-top: 1px solid var(--line); background: #fff; }
.apex-pill {
  display: flex; align-items: center;
  background: var(--paper); border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 4px 4px 16px;
}
.apex-pill input {
  flex: 1; min-width: 0; border: 0; background: none; outline: none;
  font-family: var(--sans); font-size: 14px; color: var(--ink); padding: 8px 0;
}
.apex-send {
  flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%;
  background: var(--grad); color: #fff; cursor: pointer; font-size: 15px;
}
.apex-send:disabled { opacity: .45; cursor: default; }
.apex-disclaimer {
  text-align: center; font-family: var(--mono); font-size: 10.5px;
  color: var(--muted-2); margin: 8px 0 2px;
}

/* --------------------------------------------------------------- responsive */
@media (max-width: 640px) {
  :root { --apex-size: 48px; }
  .apex-panel {
    right: 0; left: 0; bottom: 0; width: auto;
    height: 92vh; border-radius: 22px 22px 0 0;
  }
  .apex-nudge { max-width: calc(100vw - 2 * var(--apex-inset)); }
}

@media (prefers-reduced-motion: reduce) {
  /* Ambient motion goes; the face states stay — they carry information. */
  .apex-face, .apex-antenna::after, .apex-scan, .apex-launcher.pulse,
  .apex-panel, .apex-nudge { animation: none !important; }
  .apex-face { transform: translate(-50%, -50%) scale(var(--apex-scale, 1)); }
  .apex-eye { animation: none !important; }
}
