/* ───────────────────────────────────────────────────────────────────────────
 *  pulse.css — the unified hub "Pulse" panel
 *  ----------------------------------------------------------------------
 *  One gridded summary panel between every hub's hero and its tools. Folds
 *  the old KPI cockpit strips + alert cards + INSIGHTS panels + sidecar
 *  banner into a single component (src/ui/pulse.js → GUIDE_Pulse).
 *
 *  Token-compliant per styles/CONVENTIONS.md: all colors/spacing/radius/
 *  shadow/motion from --guide-* with literal fallbacks. No z-index ≥100, no
 *  new !important. Dark theme inherits via the token layer.
 * ─────────────────────────────────────────────────────────────────── */

.guide-pulse {
  /* Not the hub accent: pulse.js writes the hub's first KPI hex here inline
     (usually red), so everything below reads the interaction hue instead and
     this property survives only for third-party consumers. */
  --pulse-accent: var(--guide-color-action);
  position: relative;
  margin: var(--guide-sp-4, 16px) 0 var(--guide-sp-5, 20px);
  padding: var(--guide-sp-5, 20px);
  /* The Infinimaker sheet — raised, a 1px rule, a quiet contact shadow. It
     was cream glass with a cinematic float and a glossy accent rail, the same
     chrome as every other panel, so nothing about it said "this is the part
     that is current". */
  background: var(--guide-color-raised);
  border: 1px solid var(--guide-color-line);
  border-radius: var(--guide-radius-2xl);
  box-shadow: var(--guide-shadow-rest);
  overflow: hidden;
}

/* The accent rail is retired; the element stays because pulse.js emits it. */
.guide-pulse__rail { display: none; }

/* ── Header ────────────────────────────────────────────────────────── */
.guide-pulse__header {
  display: flex;
  align-items: center;
  gap: var(--guide-sp-3, 12px);
  flex-wrap: wrap;
  margin-bottom: var(--guide-sp-4, 16px);
}
.guide-pulse__title {
  display: inline-flex;
  align-items: center;
  gap: var(--guide-sp-2, 8px);
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--guide-fs-13, 13px);
  font-weight: var(--guide-fw-bold, 700);
  text-transform: var(--guide-label-case, uppercase);
  letter-spacing: var(--guide-letter-eyebrow, 0.08em);
  color: var(--guide-color-ink-soft);
}
.guide-pulse__title-icon { width: 16px; height: 16px; color: var(--guide-color-action); }
.guide-pulse__title-spark { width: 13px; height: 13px; color: var(--guide-color-mt-warm, #92710A); opacity: 0.85; }
.guide-pulse__title--action {
  cursor: pointer;
  border-radius: var(--guide-radius-pill, 999px);
  padding: var(--guide-sp-1, 4px) var(--guide-sp-2, 8px);
  margin: calc(var(--guide-sp-1, 4px) * -1) calc(var(--guide-sp-2, 8px) * -1);
  transition: background var(--guide-dur-fast, 140ms) var(--guide-ease-out, ease-out),
    color var(--guide-dur-fast, 140ms) var(--guide-ease-out, ease-out);
}
.guide-pulse__title--action:hover {
  background: var(--guide-color-paper-2);
  color: var(--guide-color-ink);
}
.guide-pulse__title--action:focus-visible {
  outline: 2px solid var(--guide-color-action);
  outline-offset: 2px;
}

.guide-pulse__header-right {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--guide-sp-2, 8px);
}

/* Status chip — replaces the full-width "Sidecar unreachable" banner. */
.guide-pulse__status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px var(--guide-sp-2, 8px);
  font-size: var(--guide-fs-11, 11px);
  font-weight: var(--guide-fw-semi, 600);
  border-radius: var(--guide-radius-pill, 999px);
  border: 1px solid transparent;
  white-space: nowrap;
}
.guide-pulse__status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.guide-pulse__status--ok {
  color: var(--guide-color-status-ok, #157347);
  background: var(--guide-color-status-ok-bg, rgba(21, 115, 71, 0.08));
  border-color: var(--guide-color-status-ok-border, rgba(21, 115, 71, 0.20));
}
.guide-pulse__status--degraded {
  color: var(--guide-color-status-warn, #B45309);
  background: var(--guide-color-status-warn-bg, rgba(180, 83, 9, 0.08));
  border-color: var(--guide-color-status-warn-border, rgba(180, 83, 9, 0.20));
}
.guide-pulse__status--offline {
  color: var(--guide-color-status-crit, #C0392F);
  background: var(--guide-color-mt-red-soft, rgba(178, 34, 52, 0.10));
  border-color: var(--guide-color-mt-red-soft, rgba(178, 34, 52, 0.10));
}

/* ── Metrics grid ──────────────────────────────────────────────────── */
/* metrics + alerts share one grid definition (auto-FILL keeps equal-width
   tracks) so every metric tile and every alert card is the SAME size and
   aligns to the same columns, regardless of how many of each there are. */
.guide-pulse__metrics {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: var(--guide-sp-3, 12px);
}
/* Alerts are not tiles: a sentence is a line, so they stack at full width. They
   shared the metrics' 180px grid and a 92px minimum, which squeezed a sentence into
   one narrow column and wrapped it to five lines under the tiles. */
.guide-pulse__alerts {
  display: flex;
  flex-direction: column;
  gap: var(--guide-sp-2, 8px);
}
/* The metric tiles themselves are .guide-kpi (styles/modules/guide-primitives.css).
   No hover lift: most tiles are not buttons, and a tile that moves under the
   pointer promises a click that does nothing. Clickable tiles get their own
   hover from .guide-kpi--clickable. Shared min-height keeps tiles + alert
   cards a consistent size. */
.guide-pulse__metrics .guide-kpi {
  min-height: 92px;
  justify-content: center;
}

/* ── Alert chips ───────────────────────────────────────────────────── */
.guide-pulse__alerts {
  /* Grid definition shared with .guide-pulse__metrics above. */
  margin-top: var(--guide-sp-3, 12px);
}
/* A flat note: one rule, no glass, no coloured edge. The status is the icon's colour. */
.guide-pulse__alert {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: var(--guide-sp-2, 8px) var(--guide-sp-3, 12px);
  font-size: var(--guide-fs-13, 13px);
  font-weight: var(--guide-fw-semi, 600);
  color: var(--guide-color-ink);
  background: var(--guide-color-raised);
  border: 1px solid var(--guide-color-line);
  border-radius: var(--guide-radius-md, 8px);
  text-align: left;
}
.guide-pulse__alert [data-lucide] { width: 15px; height: 15px; flex-shrink: 0; }
.guide-pulse__alert--clickable {
  cursor: pointer;
  font: inherit;
  font-size: var(--guide-fs-12, 12px);
  font-weight: var(--guide-fw-semi, 600);
}
.guide-pulse__alert--clickable:hover { border-color: var(--guide-color-action); }
.guide-pulse__alert--ok   [data-lucide] { color: var(--guide-color-status-ok, #157347); }
.guide-pulse__alert--info [data-lucide] { color: var(--guide-color-status-info, #2A6F97); }
.guide-pulse__alert--watch [data-lucide] { color: var(--guide-color-status-watch, #92710A); }
.guide-pulse__alert--warn [data-lucide] { color: var(--guide-color-status-warn, #B45309); }
.guide-pulse__alert--crit [data-lucide] { color: var(--guide-color-status-crit, #C0392F); }

/* ── Insight cards ─────────────────────────────────────────────────── */
.guide-pulse__insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--guide-sp-3, 12px);
  margin-top: var(--guide-sp-4, 16px);
}
.guide-pulse__insight {
  display: flex;
  gap: var(--guide-sp-3, 12px);
  padding: var(--guide-sp-3, 12px) var(--guide-sp-4, 16px);
  background: var(--guide-color-raised);
  border: 1px solid var(--guide-color-line);
  border-radius: var(--guide-radius-md, 8px);
}
.guide-pulse__insight-icon {
  flex-shrink: 0;
  width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--guide-radius-md, 8px);
  background: var(--guide-color-paper-2);
  border: 1px solid var(--guide-color-line);
  color: var(--guide-color-ink-soft);
}
.guide-pulse__insight--crit .guide-pulse__insight-icon { color: var(--guide-color-status-crit, #C0392F); }
.guide-pulse__insight--warn .guide-pulse__insight-icon { color: var(--guide-color-status-warn, #B45309); }
.guide-pulse__insight-icon [data-lucide] { width: 16px; height: 16px; }
.guide-pulse__insight-body { min-width: 0; flex: 1 1 auto; }

/* Title row — title on the left, severity badge pinned right. */
.guide-pulse__insight-head {
  display: flex;
  align-items: baseline;
  gap: var(--guide-sp-2, 8px);
  margin-bottom: 3px;
}
.guide-pulse__insight-title {
  font-size: var(--guide-fs-13, 13px);
  font-weight: var(--guide-fw-bold, 700);
  color: var(--guide-color-text-primary, #1A1A1F);
  line-height: 1.3;
}
.guide-pulse__insight-sev {
  margin-left: auto;
  flex-shrink: 0;
  align-self: flex-start;
  font-size: var(--guide-fs-2xs);
  font-weight: var(--guide-fw-bold, 700);
  text-transform: var(--guide-label-case, uppercase);
  letter-spacing: var(--guide-letter-eyebrow, 0.06em);
  padding: 2px var(--guide-sp-2, 8px);
  border-radius: var(--guide-radius-pill, 999px);
  color: var(--guide-color-status-info, #2A6F97);
  background: color-mix(in srgb, currentColor 12%, transparent);
}
@supports not (background: color-mix(in srgb, red, blue)) {
  .guide-pulse__insight-sev { background: var(--guide-color-bg-3, #F7F5F0); }
}
.guide-pulse__insight-sev--ok    { color: var(--guide-color-status-ok, #157347); }
.guide-pulse__insight-sev--info  { color: var(--guide-color-status-info, #2A6F97); }
.guide-pulse__insight-sev--watch { color: var(--guide-color-status-watch, #92710A); }
.guide-pulse__insight-sev--warn  { color: var(--guide-color-status-warn, #B45309); }
.guide-pulse__insight-sev--crit  { color: var(--guide-color-status-crit, #C0392F); }

/* Meta row — trend chip · source/freshness · sparkline. */
.guide-pulse__insight-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--guide-sp-2, 8px) var(--guide-sp-3, 12px);
  margin-bottom: var(--guide-sp-2, 8px);
  font-size: var(--guide-fs-11, 11px);
  color: var(--guide-color-text-tertiary, #6B6B76);
}
.guide-pulse__insight-trend { font-weight: var(--guide-fw-semi, 600); }
.guide-pulse__insight-trend--worsening { color: var(--guide-color-status-warn, #B45309); }
.guide-pulse__insight-trend--improving { color: var(--guide-color-status-ok, #157347); }
.guide-pulse__insight-trend--stable    { color: var(--guide-color-text-tertiary, #6B6B76); }
.guide-pulse__insight-source {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.guide-pulse__insight-source [data-lucide] {
  width: 12px; height: 12px;
  flex-shrink: 0;
  opacity: 0.7;
}
.guide-pulse__insight-source > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Sparkline — inherits the card's severity color via currentColor. */
.guide-pulse__spark {
  width: 60px; height: 18px;
  margin-left: auto;
  color: var(--guide-color-action);
  flex-shrink: 0;
}
.guide-pulse__insight--ok    .guide-pulse__spark { color: var(--guide-color-status-ok, #157347); }
.guide-pulse__insight--watch .guide-pulse__spark { color: var(--guide-color-status-watch, #92710A); }
.guide-pulse__insight--warn  .guide-pulse__spark { color: var(--guide-color-status-warn, #B45309); }
.guide-pulse__insight--crit  .guide-pulse__spark { color: var(--guide-color-status-crit, #C0392F); }
.guide-pulse__spark-line {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
}
.guide-pulse__spark-fill {
  fill: currentColor;
  opacity: 0.12;
  stroke: none;
}

/* Body — legacy single blob, or structured finding → so-what → action. */
.guide-pulse__insight-desc {
  font-size: var(--guide-fs-12, 12px);
  line-height: 1.45;
  color: var(--guide-color-text-secondary, #4A4A52);
}
.guide-pulse__insight-finding {
  margin: 0 0 4px;
  font-size: var(--guide-fs-12, 12px);
  line-height: 1.45;
  color: var(--guide-color-text-primary, #1A1A1F);
}
.guide-pulse__insight-line {
  margin: 0 0 3px;
  font-size: var(--guide-fs-12, 12px);
  line-height: 1.4;
  color: var(--guide-color-text-secondary, #4A4A52);
}
.guide-pulse__insight-line:last-child { margin-bottom: 0; }
.guide-pulse__insight-tag {
  display: inline-block;
  margin-right: 6px;
  font-size: var(--guide-fs-2xs);
  font-weight: var(--guide-fw-bold, 700);
  text-transform: var(--guide-label-case, uppercase);
  letter-spacing: var(--guide-letter-eyebrow, 0.06em);
  color: var(--guide-color-text-tertiary, #6B6B76);
  vertical-align: 1px;
}
.guide-pulse__insight-line--action .guide-pulse__insight-tag {
  color: var(--guide-color-action);
}

/* Optional per-insight action buttons (dashboard cross-system cards). */
.guide-pulse__insight-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--guide-sp-2, 8px);
  margin-top: var(--guide-sp-3, 12px);
}
.guide-pulse__insight-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px var(--guide-sp-2, 8px);
  font: inherit;
  font-size: var(--guide-fs-11, 11px);
  font-weight: var(--guide-fw-semi, 600);
  color: var(--guide-color-text-secondary, #4A4A52);
  background: var(--guide-color-bg-3, #F7F5F0);
  border: 1px solid var(--guide-color-border-subtle, rgba(0, 0, 0, 0.06));
  border-radius: var(--guide-radius-pill, 999px);
  cursor: pointer;
  transition: background var(--guide-dur-fast, 140ms) var(--guide-ease-out, ease-out),
    color var(--guide-dur-fast, 140ms) var(--guide-ease-out, ease-out),
    border-color var(--guide-dur-fast, 140ms) var(--guide-ease-out, ease-out);
}
.guide-pulse__insight-action [data-lucide] { width: 12px; height: 12px; }
.guide-pulse__insight-action:hover {
  color: var(--guide-color-text-primary, #1A1A1F);
  border-color: color-mix(in srgb, var(--guide-color-action) 40%, transparent);
  background: color-mix(in srgb, var(--guide-color-action) 8%, var(--guide-color-bg-3, #F7F5F0));
}
.guide-pulse__insight-action:focus-visible {
  outline: 2px solid var(--guide-color-action);
  outline-offset: 2px;
}
/* The accent is per-hub DATA and stays on the border, which is where it already
   was. Using it as the label's ink put "Ask AI" at 1.90:1 on the dark surface —
   the fourth time in this overhaul that a data-driven accent was serving as
   text (.hh-tool-card__tag, the planning headers and .dhome-card-type are the
   others). No flip can fix a colour that arrives as data. */
.guide-pulse__insight-action--ai {
  color: var(--guide-color-link);
  border-color: color-mix(in srgb, var(--guide-color-action) 30%, transparent);
}

/* ── Responsive ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .guide-pulse { padding: var(--guide-sp-4, 16px); }
  .guide-pulse__metrics { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--guide-sp-2, 8px); }
  .guide-pulse__insights { grid-template-columns: 1fr; }
}
@media (max-width: 480px) {
  .guide-pulse__metrics { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .guide-pulse__alert--clickable:hover { transform: none; }
}
