/* ============================================================
   Newport agents — the conversational widget shared by Finn
   (candidates) and Beacon (employers). Built on the design
   system tokens in styles.css; an agent should read as part of
   the site, not as a bolted-on chatbot.

   Per-agent accents hang off [data-agent] near the bottom.
   ============================================================ */

.agent-launcher {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: calc(clamp(14px, 3vw, 28px) + env(safe-area-inset-bottom, 0px));
  z-index: 80;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 1.15rem 0.7rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  background: var(--navy-900);
  color: #fff;
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 16px 40px -14px rgba(10, 17, 36, 0.6);
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease;
}
.agent-launcher:hover { transform: translateY(-2px); background: var(--navy-800); }
.agent-launcher:focus-visible { outline: 2px solid var(--blue-bright); outline-offset: 3px; }
.agent-launcher[hidden] { display: none; }
.agent-launcher__avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 50%;
  background: radial-gradient(120% 100% at 50% 25%, #ffffff, #dde5f1 75%);
  color: var(--blue-btn); flex: none;
}
.agent-launcher__avatar svg { width: 21px; height: 21px; }
.agent-launcher__avatar img,
.agent-panel__avatar img,
.agent-cta__avatar img {
  width: 100%; height: 100%; object-fit: cover; object-position: 50% 36%;
  border-radius: inherit;
}
.agent-launcher__label { white-space: nowrap; }
.agent-launcher__dot {
  width: 7px; height: 7px; border-radius: 50%; background: #3ddc97; flex: none;
}
@media (max-width: 520px) {
  .agent-launcher__label { display: none; }
  .agent-launcher { padding: 0.55rem; }
}

/* ---- Contextual CTA (in-page invitation) ---- */
.agent-cta {
  display: flex; align-items: center; gap: 1.1rem; flex-wrap: wrap;
  padding: clamp(1.1rem, 2.4vw, 1.6rem);
  border: 1px solid var(--line-dark);
  border-radius: var(--radius);
  background: var(--paper-2);
}
.section--dark .agent-cta { background: var(--navy-800); border-color: var(--line); }
.agent-cta__avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 52px; height: 52px; border-radius: 14px; flex: none;
  background: radial-gradient(120% 100% at 50% 25%, #ffffff, #dde5f1 75%);
  color: var(--blue);
}
.agent-cta__avatar svg { width: 30px; height: 30px; }
.agent-cta__avatar { overflow: hidden; }
.agent-cta__body { flex: 1 1 280px; }
.agent-cta__body h3 { margin: 0 0 .2rem; font-size: 1.12rem; }
.agent-cta__body p { margin: 0; color: var(--steel-500); font-size: 0.97rem; }
.section--dark .agent-cta__body p { color: var(--steel-300); }

/* ---- Panel ---- */
.agent-panel {
  position: fixed;
  right: clamp(14px, 3vw, 28px);
  bottom: calc(clamp(14px, 3vw, 28px) + env(safe-area-inset-bottom, 0px));
  z-index: 90;
  width: min(418px, calc(100vw - 2 * clamp(14px, 3vw, 28px)));
  max-height: min(680px, calc(100vh - 2 * clamp(14px, 3vw, 28px)));
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line-dark);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 80px -24px rgba(10, 17, 36, 0.55);
}
.agent-panel[hidden] { display: none; }
html.anim .agent-panel { animation: finn-rise .22s ease both; }
@keyframes finn-rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  html.anim .agent-panel { animation: none; }
  .agent-launcher, .agent-panel * { transition: none !important; }
}
@media (max-width: 560px) {
  .agent-panel {
    right: 0; left: 0; bottom: 0;
    width: 100%;
    max-height: 88vh;
    max-height: 88dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

.agent-panel__head {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: var(--navy-900); color: #fff;
  flex: none; position: relative; z-index: 1;
  box-shadow: 0 6px 14px -8px rgba(10, 17, 36, .55);
}
.agent-panel__avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%; flex: none;
  background: radial-gradient(120% 100% at 50% 25%, #ffffff, #dde5f1 75%);
  color: var(--blue-btn);
}
.agent-panel__avatar svg { width: 23px; height: 23px; }
.agent-panel__avatar, .agent-launcher__avatar { overflow: hidden; }
.agent-panel__id { flex: 1; min-width: 0; line-height: 1.25; }
.agent-panel__name { font-weight: 700; font-size: 1rem; }
.agent-panel__role { font-size: 0.78rem; color: var(--steel-300); }
.agent-panel__close {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.18); background: transparent; color: #fff;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.agent-panel__close:hover { background: rgba(255,255,255,.1); }
.agent-panel__close:focus-visible,
.agent-panel button:focus-visible,
.agent-panel a:focus-visible,
.agent-panel textarea:focus-visible { outline: 2px solid var(--agent-accent, var(--blue-btn)); outline-offset: 2px; }
.agent-panel__close:focus-visible { outline-color: #fff; }
.agent-panel__close svg { width: 16px; height: 16px; }

.agent-panel__body {
  flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain;
  padding: 1rem 0.95rem 1.1rem; display: flex; flex-direction: column; gap: 0.7rem;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { .agent-panel__body { scroll-behavior: auto; } }

.agent-welcome h3 { margin: 0 0 .35rem; font-size: 1.18rem; letter-spacing: -.015em; }
.agent-welcome p { margin: 0; color: var(--steel-500); font-size: 0.92rem; line-height: 1.55; }

.agent-msg { max-width: 90%; font-size: 0.92rem; line-height: 1.6; overflow-wrap: anywhere; }
.agent-msg p { margin: 0 0 .6rem; }
.agent-msg p:last-child { margin-bottom: 0; }
.agent-msg ul { margin: .2rem 0 .55rem; padding-left: 1.1rem; }
.agent-msg li { margin-bottom: .25rem; }
.agent-msg--agent {
  align-self: flex-start;
  margin-bottom: .1rem;
  background: var(--paper-2);
  border: 1px solid var(--line-dark);
  border-radius: 14px 14px 14px 4px;
  padding: 0.75rem 0.9rem;
}
.agent-msg--user {
  align-self: flex-end;
  margin-top: .3rem;
  background: var(--navy-900); color: #fff;
  border-radius: 14px 14px 4px 14px;
  padding: 0.75rem 0.9rem;
}
.agent-msg--error {
  align-self: stretch; max-width: 100%;
  background: #fff5f5; border: 1px solid #f3c9c9; color: #8a2a2a;
  border-radius: 12px; padding: 0.75rem 0.9rem;
}
.agent-msg__cites { margin-top: .5rem; display: flex; flex-wrap: wrap; gap: .4rem; }
.agent-msg__cite {
  font-size: .78rem; font-weight: 600; color: var(--blue);
  border: 1px solid rgba(47,123,255,.3); border-radius: 999px; padding: .2rem .6rem;
}
.agent-msg__cite:hover { background: rgba(47,123,255,.08); }

.agent-typing { display: inline-flex; gap: 4px; align-items: center; height: 1.2em; }
.agent-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--steel-300);
  animation: finn-blink 1.1s infinite ease-in-out;
}
.agent-typing span:nth-child(2) { animation-delay: .18s; }
.agent-typing span:nth-child(3) { animation-delay: .36s; }
@keyframes finn-blink { 0%, 80%, 100% { opacity: .3; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .agent-typing span { animation: none; opacity: .6; } }

.agent-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: .15rem; }
.agent-chip {
  font-family: var(--font); font-size: 0.84rem; font-weight: 600; line-height: 1.25;
  padding: 0.42rem 0.8rem; border-radius: 999px; cursor: pointer;
  border: 1px solid rgba(47, 123, 255, 0.35);
  background: rgba(47, 123, 255, 0.06); color: var(--blue-btn);
  transition: background .15s ease;
}
.agent-chip:hover { background: rgba(47, 123, 255, 0.14); }

.agent-handoff {
  border: 1px solid rgba(47,123,255,.3); border-radius: var(--radius);
  background: rgba(47,123,255,.06); padding: 0.9rem;
}
.agent-handoff h4 { margin: 0 0 .3rem; font-size: .98rem; letter-spacing: -.01em; }
.agent-handoff p { margin: 0 0 .75rem; font-size: .89rem; line-height: 1.5; color: var(--steel-500); }
.agent-handoff .btn-row { gap: .5rem; }
.agent-handoff .btn { padding: .55rem 1rem; font-size: .86rem; }

.agent-panel__foot { flex: none; border-top: 1px solid var(--line-dark); padding: 0.75rem 0.85rem 0.85rem; background: var(--paper); }
.agent-form { display: flex; align-items: flex-end; gap: 0.5rem; }
.agent-form textarea {
  flex: 1; resize: none; font-family: var(--font); font-size: 0.92rem; line-height: 1.45;
  padding: 0.6rem 0.75rem; border: 1px solid var(--line-dark); border-radius: 12px;
  background: var(--paper); color: var(--ink); max-height: 120px; min-height: 42px;
}
.agent-form textarea::placeholder { color: var(--steel-300); }
.agent-send {
  flex: none; width: 42px; height: 42px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--blue-btn); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.agent-send:hover { background: var(--blue); }
.agent-send:disabled { opacity: .45; cursor: not-allowed; }
.agent-send svg { width: 18px; height: 18px; }
.agent-disclaimer {
  margin: .6rem 0 0; font-size: .72rem; line-height: 1.45; color: var(--steel-500);
  text-align: center; text-wrap: balance;
}
.agent-disclaimer a { color: var(--blue); font-weight: 600; }

.agent-sr {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- Welcome subtitle (Beacon leads with his role) ---- */
.agent-welcome__sub {
  margin: -0.1rem 0 0.5rem !important;
  font-size: 0.82rem; font-weight: 700; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--agent-accent, var(--blue));
}

/* ---- Insight cards ----
   Structured findings a connected endpoint can return. The knowledge layer
   never produces these — it has no verified data to put in them. */
.agent-insights { display: flex; flex-direction: column; gap: 0.6rem; }
.agent-insight {
  border: 1px solid var(--line-dark); border-left: 3px solid var(--agent-accent, var(--blue));
  border-radius: 12px; padding: 0.7rem 0.85rem; background: var(--paper-2);
}
.agent-insight h4 { margin: 0 0 .2rem; font-size: .95rem; }
.agent-insight p { margin: 0; font-size: .9rem; color: var(--steel-500); }
.agent-insight__v { font-size: 1.15rem !important; font-weight: 800; color: var(--ink) !important; letter-spacing: -.01em; }
.agent-insight__src { font-size: .76rem !important; font-style: italic; margin-top: .35rem !important; }

/* ---- Per-agent accent ----
   Finn keeps the site's electric blue. Beacon carries a warm lantern tone —
   his whole identity is a light in the dark. */
.agent-launcher, .agent-panel, .agent-cta { --agent-accent: var(--blue-btn); }
[data-agent="beacon"] { --agent-accent: #c8892c; }

[data-agent="beacon"].agent-launcher { box-shadow: 0 16px 40px -14px rgba(10, 17, 36, .6), 0 0 0 1px rgba(224, 168, 74, .18); }
[data-agent="beacon"].agent-launcher .agent-launcher__dot { background: #e0a84a; }
[data-agent="beacon"] .agent-chip {
  border-color: rgba(200, 137, 44, .38); background: rgba(200, 137, 44, .07); color: #8a5c12;
}
[data-agent="beacon"] .agent-chip:hover { background: rgba(200, 137, 44, .15); }
[data-agent="beacon"] .agent-handoff { border-color: rgba(200, 137, 44, .32); background: rgba(200, 137, 44, .07); }
[data-agent="beacon"] .agent-msg__cite { color: #8a5c12; border-color: rgba(200, 137, 44, .34); }
[data-agent="beacon"] .agent-msg__cite:hover { background: rgba(200, 137, 44, .09); }
[data-agent="beacon"] .agent-send { background: var(--navy-800); }
[data-agent="beacon"] .agent-send:hover { background: var(--navy-700); }
[data-agent="beacon"] .agent-disclaimer a { color: #8a5c12; }
