/* Agent pulse: the header badge (olive dot + number) and its glow card. Markup: app/templates/_agent_pulse.html,
   behaviour: site/agent-pulse.js. A site overrides tokens only: --apulse-c (dot, hairline, link), --apulse-fill,
   --apulse-txt, --apulse-mut, --apulse-line. Without them the template tokens (--surface, --ink, --ink-soft, --border)
   apply, then the house values. glow.css (design pack) will carry the card recipe; this file then drops its copy. */

.apulse {
  --apulse-olive: #5F6E1F; /* house olive for light surfaces: 6.4:1 on white */
  --ap-c: var(--apulse-c, var(--olive, var(--apulse-olive)));
  --ap-fill: var(--apulse-fill, var(--surface, #0E131B));
  --ap-txt: var(--apulse-txt, var(--ink, var(--text-1, #E6EAF0)));
  --ap-mut: var(--apulse-mut, var(--ink-soft, var(--text-2, #8A94A3)));
  --ap-line: var(--apulse-line, var(--border, #1C2430));
  --ap-edge: color-mix(in srgb, var(--ap-txt) 50%, var(--ap-fill)); /* control outline, at least 3:1 */
  --ap-ease: var(--m-out, cubic-bezier(0.23, 1, 0.32, 1));
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  margin-inline: 0.35rem;
}
[data-theme="dark"] .apulse { --apulse-olive: #9DAE51; }
@media screen and (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .apulse { --apulse-olive: #9DAE51; }
}

@media (scripting: none) { .apulse { display: none; } } /* a number needs the script: no script, no badge */

.apulse__btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--ap-edge);
  border-radius: 999px;
  background: color-mix(in srgb, var(--ap-c) 8%, var(--ap-fill));
  color: var(--ap-txt);
  font: 600 12px/1 var(--apulse-mono, "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.apulse__btn::after { content: ""; position: absolute; inset: -7px -3px; } /* 44 px target around the 32 px pill (padding box 30 px + 14) */
.apulse__btn:focus-visible {
  outline: 2px solid var(--ap-c);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px color-mix(in oklab, var(--ap-c) 24%, transparent);
}
@media (hover: hover) and (pointer: fine) {
  .apulse__btn:hover { border-color: color-mix(in srgb, var(--ap-c) 60%, var(--ap-edge)); }
}

/* The text box has the width of its widest state ("0 · resting"), so no state change moves a neighbour. */
.apulse__txt { display: inline-block; min-width: 11ch; text-align: start; }
.apulse__vh {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
@media (max-width: 520px) {
  .apulse { margin-inline: 0.1rem; }
  .apulse__btn { padding: 0 10px; gap: 6px; }
  .apulse__txt { min-width: 3ch; }
  .apulse__w { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
}

/* The dot. loading: muted disc. live: olive disc with a ring and a soft glow (8 px status dot, the one place a
   small shadow glow is allowed). resting: hollow muted ring. The words carry the state, never the colour alone. */
.apulse__dot {
  position: relative;
  flex: none;
  box-sizing: border-box;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ap-mut);
}
.apulse[data-state="live"] .apulse__dot {
  background: var(--ap-c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ap-c) 22%, transparent), 0 0 12px color-mix(in srgb, var(--ap-c) 55%, transparent);
}
.apulse[data-state="resting"] .apulse__dot { background: transparent; border: 2px solid var(--ap-mut); }
.apulse__dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--ap-c);
  opacity: 0;
}
@media (prefers-reduced-motion: no-preference) {
  .apulse[data-state="live"] .apulse__dot::after { animation: apulse-ring 2.4s var(--ap-ease) infinite; }
  @keyframes apulse-ring {
    from { transform: scale(1); opacity: 0.55; }
    to { transform: scale(2.2); opacity: 0; }
  }
}

/* The card (a native popover in the top layer): the glow recipe, 1 px line, olive tint, top hairline. */
.apulse__card {
  box-sizing: border-box;
  position: fixed;
  inset: auto;
  top: var(--apulse-top, 84px);
  right: var(--apulse-right, 16px);
  margin: 0;
  width: min(260px, calc(100vw - 32px));
  padding: 16px;
  overflow: visible;
  border: 1px solid var(--ap-line);
  border-radius: 12px;
  background: linear-gradient(180deg, color-mix(in oklab, var(--ap-c) 10%, var(--ap-fill)), var(--ap-fill) 60%);
  color: var(--ap-txt);
}
.apulse__card::before {
  content: "";
  position: absolute;
  top: -1px;
  left: 16px;
  right: 16px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--ap-c), transparent);
}
.apulse__line { margin: 0 0 8px; font: 500 15px/1.4 var(--font-body, var(--font-sans, Inter, system-ui, sans-serif)); color: var(--ap-txt); }
.apulse__more {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  font: 600 12px/1 var(--apulse-mono, "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  color: var(--ap-c);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.apulse__more:focus-visible { outline: 2px solid var(--ap-c); outline-offset: 2px; border-radius: 4px; }
@media (max-width: 520px) {
  .apulse__card { left: 16px; right: 16px; width: auto; }
}
@media (prefers-reduced-motion: no-preference) {
  .apulse__card { transition: opacity 150ms var(--ap-ease), transform 150ms var(--ap-ease); }
  @starting-style { .apulse__card:popover-open { opacity: 0; transform: scale(0.97); } }
}
@media (prefers-reduced-motion: reduce) {
  .apulse__dot::after { animation: none; }
  .apulse__card { transition: none; }
}
