/* ═══════════════════════════════════════════════════════════
   MARKET BREADTH — watchlist-summary card (graphs module).
   A donut (advancing / unchanged / declining) + legend. All
   classes are brd- prefixed; cc-section* are global + styled
   elsewhere. Colors are token vars only (auto light/dark). Every
   direction cue is paired with a sign or arrow (colorblind-safe).
   ═══════════════════════════════════════════════════════════ */

.brd-body { display: block; }

/* Body card recipe — mirrors the Sectors donut card: a large donut on the
   LEFT, legend filling the RIGHT (shared house style). align-items:stretch so
   the legend can take the donut's height and scroll a long member list. */
.brd-card {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: 1.5rem;
  padding: 0.875rem 1.25rem 1.125rem;
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--bg-tertiary) 90%, transparent);
  box-shadow: inset 0 0 0 1px var(--border-default), var(--shadow-pop);
  overflow: hidden;
}

/* ── Donut ─────────────────────────────────────────────────── */
.brd-donut {
  flex: none;
  align-self: center;
  width: clamp(11rem, 66%, 22rem);
  height: auto;
}
/* One transition per slice — the dash animation (redraw) PLUS the focus grow
   (stroke-width) and dim (opacity). Keep them in a single rule so the focus
   declarations don't clobber the dash animation. */
.brd-donut circle[data-brd] {
  cursor: pointer;
  --ring-c: 314.159;   /* 2·π·50 — the full ring circumference (r is always 50) */
  transition: stroke-dasharray 480ms var(--ease-out, ease),
              stroke-dashoffset 480ms var(--ease-out, ease),
              opacity .15s ease,
              stroke-width .2s var(--ease-out);
}
/* Page-load ring construction (the clockwise pen-stroke) is now JS-driven — a
   frame-capped requestAnimationFrame loop in graphs/breadth.js (_brdSweepTick)
   writes each slice's stroke-dasharray per frame, temporarily suppressing the
   dash transition above while it runs. CSS dash animations were wall-clock based
   and jumped ahead under cold-load main-thread jank; the JS driver caps each
   frame's advance so the sweep pauses and continues instead. */
/* Legend fades in softly under the ring draw — OPACITY ONLY, backwards fill so
   it settles at the stylesheet opacity and never pins the per-row focus dimming. */
@keyframes brd-leg-fade { from { opacity: 0; } }
.brd-legend.brd-leg-enter { animation: brd-leg-fade 300ms var(--ease-out) backwards; }
/* Selected slice grows IN PLACE — the stroke thickens around its own
   centreline (r stays 50, dash lengths untouched), no outward displacement.
   Outer edge 50 + 17/2 = 58.5 < 65, safely inside the viewBox. */
.brd-card.has-sel .brd-donut circle[data-brd] { opacity: 0.22; }
.brd-card.has-sel .brd-donut circle[data-brd].sel { opacity: 1; stroke-width: 17; }
.brd-ring-n {
  fill: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.brd-ring-lbl {
  fill: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 6px;
  letter-spacing: 1.4px;
}

/* ── Legend ────────────────────────────────────────────────── */
/* Stretches to the donut's height and scrolls rather than growing the card;
   gap is 0 (row padding does the spacing) so collapsed rows leave no gutter. */
.brd-legend {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}
.brd-legend::-webkit-scrollbar { width: 0.375rem; }
.brd-legend::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 0.25rem; }
.brd-legend:hover::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent) 28%, transparent); }
/* Flexible spacers keep the focused block vertically CENTRED in both states;
   zero flex-basis means they vanish when the content overflows, so a tall
   member list still top-aligns and scrolls. */
.brd-sp { flex: 1 1 0; min-height: 0; }

/* Each group = a collapsible grid block (header row + hidden member list). */
.brd-item {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows .22s var(--ease-out), opacity .16s ease;
}
.brd-item > .brd-item-inner { overflow: hidden; min-height: 0; }
.brd-legend.focused .brd-item { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }
.brd-legend.focused .brd-item.focus { grid-template-rows: 1fr; opacity: 1; pointer-events: auto; }

.brd-leg-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.375rem 0.5rem;
  border-radius: 0.375rem;
  transition: opacity .15s ease, background .15s ease;
}
.brd-leg-row:hover { background: color-mix(in srgb, var(--text-primary) 6%, transparent); }
/* Click-to-focus: the chosen row gets an accent wash across the whole
   rectangle, the rest dim (no left accent bar — the owner rejected it). */
.brd-card.has-sel .brd-leg-row { opacity: 0.4; }
.brd-card.has-sel .brd-leg-row.sel {
  opacity: 1;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
}

/* Member list — collapsed by default, expands only under the focused group.
   The inner wrapper carries a small upward offset that settles to 0 as the
   list opens, so the stocks glide in with the row instead of popping. */
.brd-members {
  display: grid;
  grid-template-rows: 0fr;
  opacity: 0;
  transition: grid-template-rows .22s var(--ease-out), opacity .18s ease;
}
.brd-members > .brd-members-inner {
  overflow: hidden;
  min-height: 0;
  padding-left: 1rem;
  transform: translateY(-0.375rem);
  transition: transform .22s var(--ease-out);
}
.brd-legend.focused .brd-item.focus .brd-members { grid-template-rows: 1fr; opacity: 1; }
.brd-legend.focused .brd-item.focus .brd-members > .brd-members-inner { transform: translateY(0); }

/* Member row — logo + ticker + signed change% + name (biggest movers first). */
.brd-mem {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 0.3125rem;
  transition: background .15s ease;
}
.brd-mem:hover { background: color-mix(in srgb, var(--text-primary) 6%, transparent); }
/* Compact company logo plate — /api/logo webp with a ticker-initial fallback. */
.brd-row-logo {
  width: 1.25rem;
  height: 1.25rem;
  flex: 0 0 auto;
  border-radius: 0.3125rem;
  overflow: hidden;
  background: var(--logo-plate);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--text-primary) 14%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: max(0.5625rem, var(--fs-floor));
  font-weight: 700;
  color: var(--text-secondary);
}
.brd-row-logo img { width: 100%; height: 100%; object-fit: contain; display: block; }
.brd-mem .bm-sym {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-primary);
  flex: 0 0 auto;
}
.brd-mem .bm-chg {
  font-family: var(--font-mono);
  font-size: max(0.6875rem, var(--fs-floor));
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}
.brd-mem .bm-chg.brd-up   { color: var(--green); }
.brd-mem .bm-chg.brd-down { color: var(--red); }
.brd-mem .bm-chg.brd-flat { color: var(--text-muted); }
.brd-mem .bm-name {
  font-size: max(0.6875rem, var(--fs-floor));
  color: var(--text-muted);
  min-width: 0;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* A focused group with no members today. */
.brd-mem-none {
  padding: 0.25rem 0.5rem;
  font-size: max(0.6875rem, var(--fs-floor));
  color: var(--text-muted);
}
.brd-leg-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--bg-primary) 22%, transparent);
}
.brd-leg-arw {
  font-size: max(0.6875rem, var(--fs-floor));
  width: 0.75rem;
  text-align: center;
  flex: 0 0 auto;
}
.brd-leg-row.brd-up   .brd-leg-arw { color: var(--green); }
.brd-leg-row.brd-down .brd-leg-arw { color: var(--red); }
.brd-leg-row.brd-flat .brd-leg-arw { color: var(--text-muted); }
.brd-leg-k {
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brd-leg-v {
  font-family: var(--font-mono);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

/* Average-change row under the legend — wrapped so it collapses away with the
   other rows when a group is focused, and returns when nothing is focused. */
.brd-avg {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows .22s var(--ease-out), opacity .16s ease;
}
.brd-avg > .brd-avg-inner { overflow: hidden; min-height: 0; }
.brd-legend.focused .brd-avg { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }
.brd-leg-avg {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.25rem;
  padding-top: 0.4375rem;
  border-top: 1px solid var(--border-subtle);
}
.brd-leg-avg-k {
  font-family: var(--font-sans);
  font-size: max(0.625rem, var(--fs-floor));
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.brd-leg-avg-v {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.brd-leg-avg-v.brd-up   { color: var(--green); }
.brd-leg-avg-v.brd-down { color: var(--red); }

/* Suppress the open/close animation for one reflow while a pinned group is
   re-applied in its end-state after the board's 30s redraw — including the
   donut circles, or the selected slice would replay its grow every cycle. */
.brd-card.brd-no-anim .brd-item,
.brd-card.brd-no-anim .brd-members,
.brd-card.brd-no-anim .brd-members > .brd-members-inner,
.brd-card.brd-no-anim .brd-avg,
.brd-card.brd-no-anim .brd-sp,
.brd-card.brd-no-anim .brd-donut circle[data-brd] { transition: none; }
