/* Stage Path widget.
   Light card. Horizontal 7-node path with a roving indicator that
   lands on each stage for an equal beat, while a role-detail panel
   below crossfades in sync. CSS-only (no JS), reduced-motion parks
   the indicator at stage 04 with its detail frame visible. */

.widget-stage-path {
  --wsp-teal: var(--brand-teal);
  --wsp-blue: var(--brand-blue);
  --wsp-surface: var(--color-card, #fff);
  --wsp-fg: var(--color-foreground);
  --wsp-muted: var(--color-muted-foreground);
  --wsp-line: var(--color-border);
  /* Shared nested-panel tint so the path panel, detail panel, and
     node halos all read as the same layer against the white card. */
  --wsp-panel: color-mix(in oklch, var(--wsp-fg) 3%, var(--wsp-surface));
  --wsp-cycle: 21s; /* overridden per-instance inline */

  min-width: 0;
  width: 100%;
}

.widget-stage-path__card {
  display: grid;
  grid-template-rows: auto auto auto auto;
  gap: 0.875rem;
  padding: 0.875rem 0.875rem 0.75rem;
  background: var(--wsp-surface);
  border: 1px solid var(--wsp-line);
  border-radius: var(--radius-lg);
  /* Layered soft shadow instead of the old dark-card drop. Gives the
     widget lift without the pitch-black halo. */
  box-shadow:
    0 1px 2px rgb(16 17 20 / 4%),
    0 10px 28px -14px rgb(16 17 20 / 14%),
    0 22px 48px -24px rgb(16 17 20 / 10%);
  color: var(--wsp-fg);
  --color-foreground: var(--wsp-fg);
  --color-muted-foreground: var(--wsp-muted);
  --color-border: var(--wsp-line);
}

/* --- Head row ------------------------------------------------------- */

.widget-stage-path__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.125rem 0.25rem;
}

.widget-stage-path__tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--wsp-fg);
}

.widget-stage-path__tag-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--wsp-teal);
  /* Denser halo + deeper glow so teal reads on a white card. */
  box-shadow:
    0 0 0 3px color-mix(in oklch, var(--wsp-teal) 35%, var(--wsp-surface)),
    0 0 10px color-mix(in oklch, var(--wsp-teal) 45%, transparent);
  animation: wsp-tag-breathe 2.6s ease-in-out infinite;
}

.widget-stage-path__status {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--wsp-muted);
}

/* --- Path: rail, 7 stage nodes, roving indicator ------------------- */

.widget-stage-path__path {
  position: relative;
  padding: 1.25rem 0.5rem 0.375rem;
  background: var(--wsp-panel);
  border: 1px solid color-mix(in oklch, var(--wsp-fg) 9%, transparent);
  border-radius: var(--radius-md);
}

.widget-stage-path__rail {
  position: absolute;
  top: 1.8rem;
  left: 1.5rem;
  right: 1.5rem;
  height: 2px;
  background: color-mix(in oklch, var(--wsp-fg) 14%, transparent);
  border-radius: 999px;
  overflow: hidden;
}
.widget-stage-path__rail-fill {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    var(--wsp-teal) 0%,
    var(--wsp-blue) 100%);
  opacity: 0.55;
}

.widget-stage-path__stages {
  position: relative;
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 0;
  z-index: 1;
}

.widget-stage-path__stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
}

.widget-stage-path__node {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  background: var(--wsp-surface);
  border: 1px solid color-mix(in oklch, var(--wsp-fg) 20%, transparent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* Halo matches the path panel tint so each node cleanly clears the
     rail beneath without looking like a bright white bead on a tinted
     field. */
  box-shadow: 0 0 0 4px var(--wsp-panel);
}

.widget-stage-path__node-num {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.04em;
  color: var(--wsp-muted);
}

.widget-stage-path__stage-label {
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--wsp-muted);
  white-space: nowrap;
}

/* --- Roving indicator: slides across the 7 stages evenly ----------
   The indicator lives inside `.widget-stage-path__stages` (a 7-column
   1fr grid) so percentage-based `left` values map directly to the
   grid's track centers without any parent-padding offset math. The
   wrapper is 1px wide; the visible glow is drawn by ::after and
   centered on that 1px line via `translate(-50%, -50%)`, which is
   what keeps it aligned with the node circles above. */

.widget-stage-path__indicator {
  position: absolute;
  /* Wrapper's bounding box matches the node: top of stages grid down
     to node height. ::after is centered inside with translate(-50%,
     -50%), which puts the dot's center at the node's geometric
     center (x = column center via left %, y = 0.875rem = half of
     1.75rem node height). Earlier bug: top was 0.875rem so the dot
     landed on the node's bottom edge. */
  top: 0;
  left: 0;
  width: 1px;          /* reference point only */
  height: 1.75rem;     /* match node height */
  pointer-events: none;
  z-index: 2;
  grid-column: 1 / -1; /* take no grid slot; positioned absolute */
}
.widget-stage-path__indicator::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.25rem;
  height: 1.25rem;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: var(--wsp-teal);
  /* Halo uses an opaque teal mix (not transparent over white, which
     washes out). Soft outer glow sells the "active" read on light. */
  box-shadow:
    0 0 0 4px color-mix(in oklch, var(--wsp-teal) 28%, var(--wsp-surface)),
    0 0 18px color-mix(in oklch, var(--wsp-teal) 55%, transparent);
}

/* The indicator lands on each of 7 columns evenly. We keyframe
   `left` as a percentage that hits the center of each column
   (100% / 7 = 14.2857%; column centers are at 7.14%, 21.43%, ...
   100%). Each stage gets an equal dwell (100/7 ≈ 14.28% of the
   cycle). The slide between stages takes a fraction of that dwell
   for a settled "you are here" read. */
.widget-stage-path__indicator {
  animation: wsp-indicator-slide var(--wsp-cycle) steps(7, jump-none) infinite;
}

@keyframes wsp-indicator-slide {
  0%   { left: calc(100% / 14 * 1); }   /* ~7.14%, column 1 center */
  100% { left: calc(100% / 14 * 13); }  /* ~92.86%, column 7 center */
}

/* --- Detail panel: crossfades to match the indicator --------------- */

.widget-stage-path__detail {
  position: relative;
  padding: 0.625rem 0.875rem 0.875rem;
  background: var(--wsp-panel);
  border: 1px solid color-mix(in oklch, var(--wsp-fg) 9%, transparent);
  border-radius: var(--radius-md);
  min-height: 6.25rem;
  overflow: hidden;
}

.widget-stage-path__detail-eyebrow {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  font-weight: var(--font-weight-medium);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: color-mix(in oklch, var(--wsp-teal) 70%, var(--wsp-fg));
  margin-bottom: 0.5rem;
}

.widget-stage-path__detail-frame {
  position: absolute;
  left: 0.875rem;
  right: 0.875rem;
  top: 1.875rem;
  bottom: 0.75rem;
  opacity: 0;
  transform: translateY(4px);
  animation: wsp-detail-fade var(--wsp-cycle) ease-in-out infinite;
  /* Each frame lags the previous one by 1/7 of the cycle (3s at 21s
     total) so frame i is visible during the indicator's dwell on stage
     i+1. Positive delay — frame 0 starts immediately, frame 1 waits
     one dwell, and so on. The keyframe's visible window (3–12% of
     cycle) aligns with the center of each 3-second stage hold. */
  animation-delay: calc((var(--i) / 7) * var(--wsp-cycle));
}

@keyframes wsp-detail-fade {
  /* 14.28% of cycle per stage: 0-3% fade-in, 3-12% visible,
     12-14.28% fade-out, rest hidden. */
  0%    { opacity: 0; transform: translateY(4px); }
  3%    { opacity: 1; transform: translateY(0); }
  12%   { opacity: 1; transform: translateY(0); }
  14.28%{ opacity: 0; transform: translateY(-4px); }
  100%  { opacity: 0; transform: translateY(-4px); }
}

.widget-stage-path__detail-title {
  margin: 0 0 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  color: var(--wsp-fg);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.widget-stage-path__detail-n {
  color: color-mix(in oklch, var(--wsp-teal) 75%, var(--wsp-fg));
  font-weight: var(--font-weight-medium);
}

.widget-stage-path__detail-name {
  font-weight: var(--font-weight-medium);
}

.widget-stage-path__detail-roles {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  row-gap: 0.1875rem;
  column-gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.04em;
}

.widget-stage-path__detail-roles > div {
  display: contents;
}

.widget-stage-path__detail-roles dt {
  color: var(--wsp-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.widget-stage-path__detail-roles dd {
  margin: 0;
  color: var(--wsp-fg);
}

/* --- Meter strip --------------------------------------------------- */

.widget-stage-path__meters {
  display: grid;
  grid-template-columns: 0.85fr 1.1fr 1.1fr;
  gap: 0.5rem;
  padding: 0.5rem 0.375rem 0;
  border-top: 1px solid color-mix(in oklch, var(--wsp-fg) 9%, transparent);
}

.widget-stage-path__meter {
  display: flex;
  flex-direction: column;
  gap: 0.1875rem;
  padding: 0.25rem 0.375rem;
  min-width: 0;
}

.widget-stage-path__meter-label {
  font-family: var(--font-mono);
  font-size: 0.5625rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--wsp-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.widget-stage-path__meter-value {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: var(--font-weight-medium);
  color: var(--wsp-teal);
  letter-spacing: -0.005em;
  white-space: nowrap;
}

/* --- Head tag-dot breathe (shared with the other two widgets) ----- */

@keyframes wsp-tag-breathe {
  0%, 100% {
    box-shadow:
      0 0 0 3px color-mix(in oklch, var(--wsp-teal) 35%, var(--wsp-surface)),
      0 0 10px color-mix(in oklch, var(--wsp-teal) 45%, transparent);
  }
  50% {
    box-shadow:
      0 0 0 5px color-mix(in oklch, var(--wsp-teal) 22%, var(--wsp-surface)),
      0 0 16px color-mix(in oklch, var(--wsp-teal) 60%, transparent);
  }
}

/* --- Responsive: narrow viewports --------------------------------- */

@media (max-width: 560px) {
  .widget-stage-path__stage-label {
    font-size: 0.5625rem;
  }
  .widget-stage-path__detail-title {
    font-size: 0.6875rem;
  }
  .widget-stage-path__meters {
    grid-template-columns: 1fr;
  }
  .widget-stage-path__meter-label {
    font-size: 0.625rem;
  }
}

/* --- Reduced motion ----------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  .widget-stage-path__tag-dot,
  .widget-stage-path__indicator,
  .widget-stage-path__detail-frame {
    animation: none;
  }
  /* Park the indicator on stage 04 (visual center). */
  .widget-stage-path__indicator {
    left: 50%;
  }
  /* Hide every detail frame except stage 04's. */
  .widget-stage-path__detail-frame {
    opacity: 0;
    transform: none;
  }
  .widget-stage-path__detail-frame:nth-child(5) { /* header + 4 prior frames → stage 04 */
    opacity: 1;
  }
}
