/* ---------------------------------------------------------------------------
   Candid's pulse: the top bar's mark and its panel
   ---------------------------------------------------------------------------
   The mark sits left of the bell as a quiet control the bell's height: Pip
   (css/pip.css) at 28px, his state saying what Candid is doing, and one word
   beside him for it. Stuck adds amber words and the warning glyph. The panel hangs under it
   like the bell's, at the top layer: its sections, each its own
   stylesheet and each opening on a hairline and a heading with Pip beside it. On a phone the
   word goes (the bar has no room) and the panel spans the screen under the
   bar, as the bell's does. App: app/candid-pulse.js.
   --------------------------------------------------------------------------- */

.pulse { position: relative; flex: 0 0 auto; margin-right: -12px }

.pulsebtn {
  display: inline-flex; align-items: center; gap: 8px;
  height: var(--control-h); box-sizing: border-box; padding: 0 12px 0 6px;
  border-radius: var(--r-btn); cursor: pointer;
  background-color: var(--card); border: 1px solid transparent;
  color: var(--text); font: inherit; font-size: 13px; font-weight: 500; white-space: nowrap;
  transition: background-color .16s ease, color .16s ease, transform .14s var(--ease-out);
}
.pulsebtn > .ms { font-size: 18px }
.pulsebtn:hover, .pulsebtn[aria-expanded="true"] { background-color: color-mix(in srgb, var(--text) 6%, var(--card)) }
.pulsebtn:active { transform: scale(.97) }
.pulsebtn:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px }
.pulsebtn[data-tone="idle"], .pulsebtn[data-tone="next"] { color: var(--muted) }
.pulsebtn[data-tone="stuck"] { color: #8A5A00 }

/* Pip sits on the bar with no shadow under him; his own loops say the state. */
.pulsebtn__pip { margin: -2px 0 }

/* What he says: the verb quiet, the thing he is on (or how many he did) in ink. */
.pulsebtn__word { display: inline-flex; align-items: baseline; gap: 5px; min-width: 0 }
.pulsebtn[data-tone="run"] .pulsebtn__word, .pulsebtn[data-tone="done"] .pulsebtn__word { color: var(--muted) }
.pulsebtn__word b {
  font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums;
  max-width: 16ch; overflow: hidden; text-overflow: ellipsis;
}

/* ---- the panel --------------------------------------------------------- */
.pulsepanel {
  position: absolute; top: calc(100% + 12px); right: 0; z-index: 25;
  width: 420px; max-height: calc(var(--vh) * .75); overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: var(--shadow-top);
  animation: cdRise .16s ease both;
}
.pulsepanel[hidden] { display: none }
.pulsepanel__body { padding: 20px; display: flex; flex-direction: column; gap: 20px }
/* Each section under the first opens on a hairline, so the parts read as separate blocks. */
.pulsepanel__body > * + * { border-top: 1px solid var(--hair); padding-top: 20px }

/* Section headings (app/pulse-parts.js): Pip's reaction, then the title, as Problems' heading. */
.pulsesec__head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px }
.pulsesec__pip { flex: 0 0 32px }
.pulsesec__title { flex: 1; min-width: 0; margin: 0; font-size: 15px; font-weight: 600; color: var(--text) }

/* With nothing running: what Pip's state is, under the section heading. */
.pulsehead { display: flex; align-items: center; gap: 14px }
.pulsehead__text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px }
.pulsehead__title { margin: 0; font-size: 15px; font-weight: 500; color: var(--text) }
.pulsehead__sub {
  font-size: 12.5px; font-weight: 500; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.pulsepanel__none {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 0 8px; font-size: 13px; color: var(--muted);
}
.pulsepanel__none .ms { font-size: 28px; opacity: .6 }

/* On a phone the bar is ink: the mark takes the bell's wash, shows its disc
   alone, and the panel spans the screen under the bar. */
@media (max-width: 900px) {
  .pulse { margin-right: 0 }
  .pulsebtn, .pulsebtn:hover, .pulsebtn[aria-expanded="true"] {
    width: 40px; height: 40px; padding: 0; justify-content: center;
    background: color-mix(in srgb, var(--on-ink) 12%, transparent);
    border-color: color-mix(in srgb, var(--on-ink) 18%, transparent);
    color: var(--on-ink);
  }
  .pulsebtn > .ms, .pulsebtn__word { display: none }
  /* On the ink bar Pip turns to the bar's light ink, his eyes to its dark,
     so his shape still reads at 28px. */
  .pulsebtn .pulsebtn__pip { --pip-body: var(--on-ink); --pip-eye: var(--ink) }
  .pulsebtn[data-tone="stuck"] .pulsebtn__pip { --pip-body: var(--amber) }
  .pulsepanel {
    position: fixed; left: 12px; right: 12px; width: auto;
    top: calc(var(--topbar-h) + env(safe-area-inset-top) + 8px);
    max-height: calc(100dvh - var(--topbar-h) - 120px);
  }
  .topbar .search[data-open="1"] ~ .pulse { display: none }
}

@media (prefers-reduced-motion: reduce) {
  .pulsepanel { animation: none }
  .pulsebtn { transition: none }
}
