/* PB Usage & Engagement (CLO-260) — module-scoped styles.
 * Categorical palette validated (dataviz six-checks) on BOTH surfaces:
 *   dark #08101F and light #ffffff. Fixed hue order; color follows the
 *   module entity. Light-mode contrast WARN on s3/s4/s5 is relieved by
 *   direct value labels + data-table toggles (never color-alone).
 * Uses kit tokens (--fg, --fg-mute, --card-ink, --line-2, --accent). */

:root {
  --pb-s1: #3987e5;  /* Sherlock */
  --pb-s2: #008300;  /* Policy Search */
  --pb-s3: #d55181;  /* Field Translate */
  --pb-s4: #c98500;  /* Field Notes */
  --pb-s5: #199e70;  /* Training */
  --pb-s6: #d95926;  /* RCR */
  --pb-ctx: #94a3b8; /* global context — muted, never a categorical slot */
  --pb-good: #4ade80;
  --pb-warn: #facc15;
  --pb-bad:  #f87171;
}
html[data-theme="light"] {
  --pb-s1: #2a78d6; --pb-s2: #008300; --pb-s3: #e87ba4;
  --pb-s4: #eda100; --pb-s5: #1baf7a; --pb-s6: #eb6834;
  --pb-ctx: #64748b; --pb-good: #16a34a; --pb-warn: #b45309; --pb-bad: #dc2626;
}

/* ── shell ── */
.pb-wrap { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.pb-hdr { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end;
  justify-content: space-between; margin-bottom: .75rem; }
.pb-title { font-size: 1.45rem; margin: 0; color: var(--fg); }
.pb-sub { color: var(--fg-mute); font-size: .85rem; }
.pb-tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line-2);
  margin-bottom: 1rem; overflow-x: auto; }
.pb-tab { padding: .5rem .8rem; color: var(--fg-mute); text-decoration: none;
  border-bottom: 2px solid transparent; font-size: .9rem; white-space: nowrap; }
.pb-tab.active { color: var(--fg); border-bottom-color: var(--accent); }
.pb-tab:hover { color: var(--fg); }
.pb-filters { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.pb-filters .pb-on { border-color: var(--accent); color: var(--accent); }
.pb-scope { max-width: 240px; min-height: 32px; padding: .35rem 1.8rem .35rem .6rem;
  border: 1px solid var(--line-2); border-radius: 7px;
  background: var(--card-ink); color: var(--fg); font: inherit; font-size: .82rem; }
.pb-scope:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pb-body { display: flex; flex-direction: column; gap: 1rem; }

/* ── panels / KPI tiles ── */
.pb-panel { background: var(--card-ink); border: 1px solid var(--line-2);
  border-radius: 10px; padding: 1.1rem 1.25rem; }
.pb-panel-h { display: flex; justify-content: space-between; align-items: baseline;
  gap: .75rem; flex-wrap: wrap; margin: 0 0 .8rem; font-size: 1.02rem; color: var(--fg); }
.pb-panel-h h2 { margin: 0; font-size: 1.02rem; }
.pb-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: .6rem; }
.pb-kpi { background: var(--card-ink); border: 1px solid var(--line-2);
  border-radius: 10px; padding: .8rem .9rem; min-height: 74px; }
.pb-kpi-label { color: var(--fg-mute); font-size: .74rem; text-transform: uppercase;
  letter-spacing: .04em; margin-bottom: .3rem; }
.pb-kpi-value { color: var(--fg); font-size: 1.35rem; font-weight: 650;
  font-variant-numeric: tabular-nums; }
.pb-delta { font-size: .78rem; font-variant-numeric: tabular-nums; }
.pb-delta.up { color: var(--pb-good); } .pb-delta.down { color: var(--pb-bad); }
.pb-delta.flat { color: var(--fg-dim); }

/* ── data states (visually distinct; never just zero) ── */
.pb-state { display: inline-block; font-size: .72rem; padding: .12rem .5rem;
  border-radius: 999px; border: 1px solid; white-space: nowrap; }
.pb-st-zero  { color: var(--fg-mute); border-color: var(--line-2); }
.pb-st-ni    { color: var(--pb-warn); border-color: var(--pb-warn); border-style: dashed; }
.pb-st-nya   { color: var(--fg-mute); border-color: var(--fg-dim); border-style: dashed; }
.pb-st-ic, .pb-st-sup { color: var(--pb-ctx); border-color: var(--pb-ctx); font-style: italic; }
.pb-st-stale { color: var(--pb-warn); border-color: var(--pb-warn); }
.pb-st-unav  { color: var(--pb-bad); border-color: var(--pb-bad); }
.pb-st-unv   { color: var(--pb-ctx); border-color: var(--pb-ctx); border-style: dotted; }
.pb-fresh    { color: var(--pb-good); border-color: var(--pb-good); }

/* ── charts ── */
.pb-chartwrap { width: 100%; }
.pb-svg svg { width: 100%; height: auto; display: block; }
.pb-chart .pb-grid { stroke: var(--line); stroke-width: 1; }
.pb-chart .pb-axis { fill: var(--fg-dim); font-size: 10px; font-family: var(--font-sans); }
.pb-chart .pb-vlabel { fill: var(--fg); font-size: 11px; font-weight: 600;
  font-family: var(--font-sans); }
.pb-chart .pb-flabel { fill: var(--fg-mute); font-size: 12px; font-family: var(--font-sans); }
.pb-line { stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.pb-line.pb-s1 { stroke: var(--pb-s1); } .pb-dot.pb-s1 { fill: var(--pb-s1); }
.pb-line.pb-s2 { stroke: var(--pb-s2); } .pb-dot.pb-s2 { fill: var(--pb-s2); }
.pb-line.pb-s3 { stroke: var(--pb-s3); } .pb-dot.pb-s3 { fill: var(--pb-s3); }
.pb-line.pb-s4 { stroke: var(--pb-s4); } .pb-dot.pb-s4 { fill: var(--pb-s4); }
.pb-line.pb-s5 { stroke: var(--pb-s5); } .pb-dot.pb-s5 { fill: var(--pb-s5); }
.pb-line.pb-s6 { stroke: var(--pb-s6); } .pb-dot.pb-s6 { fill: var(--pb-s6); }
.pb-line.pb-ctx { stroke: var(--pb-ctx); stroke-dasharray: 4 3; stroke-width: 1.5; }
.pb-dot { stroke: var(--ink-2); stroke-width: 2; } /* 2px surface ring on marks */
.pb-dot:focus { outline: none; stroke: var(--accent); stroke-width: 2.5; }
/* browsed-but-nothing-completed is a STATE, not an entity: encoded as a
   hollow ring in the semantic warn color so it never consumes a categorical
   hue slot and never reads as a sixth module. */
.pb-dot-browse { fill: none; stroke: var(--pb-warn); stroke-width: 2; cursor: help; }
.pb-dot-browse:focus { outline: none; stroke: var(--accent); stroke-width: 2.5; }
.pb-fill.pb-s1 { fill: var(--pb-s1); }
.pb-anno line { stroke: var(--fg-dim); stroke-dasharray: 2 3; stroke-width: 1; }
.pb-anno circle { fill: var(--gold, #c9a227); cursor: help; }
.pb-heat .pb-cell { fill: var(--pb-s1); }
.pb-heat .pb-cell[data-empty] { fill: var(--line); }
.pb-legend { display: inline-flex; align-items: center; gap: .35rem;
  color: var(--fg-mute); font-size: .78rem; flex-wrap: wrap; }
.pb-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  background: var(--pb-ctx); }
.pb-swatch.pb-s1 { background: var(--pb-s1); } .pb-swatch.pb-s2 { background: var(--pb-s2); }
.pb-swatch.pb-s3 { background: var(--pb-s3); } .pb-swatch.pb-s4 { background: var(--pb-s4); }
.pb-swatch.pb-s5 { background: var(--pb-s5); } .pb-swatch.pb-s6 { background: var(--pb-s6); }
.pb-swatch.pb-ctx { background: var(--pb-ctx); }
.pb-swatch.pb-browse { background: transparent; border: 2px solid var(--pb-warn);
  border-radius: 50%; }
.pb-module-names { display: flex; flex-wrap: wrap; gap: .3rem; min-width: 12rem; }
.pb-module-name { display: inline-flex; align-items: center; border: 1px solid var(--line-2);
  border-radius: 999px; padding: .15rem .48rem; color: var(--fg);
  background: var(--ink-3); font-size: .75rem; line-height: 1.25; white-space: nowrap; }
.pb-tablebtn { margin-top: .4rem; }
.pb-tablewrap { margin-top: .5rem; max-height: 260px; overflow: auto; }

/* ── website tab: side-by-side rank panels ── */
.pb-webgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: .7rem; }
.pb-webgrid .pb-panel { margin: 0; }

/* ── website tab: charts ── */
.pb-webchart svg { width: 100%; height: auto; aspect-ratio: 5 / 1; display: block; overflow: visible; }
.pb-cgrid { stroke: var(--line-2); stroke-width: 1; vector-effect: non-scaling-stroke; }
.pb-cax { fill: var(--fg-dim); font-size: 11px; }
.pb-cbar { fill: var(--accent); opacity: .7; }
.pb-cbar:hover { opacity: 1; }
.pb-cshade { fill: var(--fg-dim); opacity: .15; }
.pb-cmarker { stroke: var(--fg-dim); stroke-width: 1; stroke-dasharray: 4 3;
  vector-effect: non-scaling-stroke; }
.pb-cline { fill: none; stroke-width: 2; vector-effect: non-scaling-stroke;
  stroke-linejoin: round; stroke-linecap: round; }
.pb-cline.pb-c1 { stroke: #FEE780; } .pb-cdot.pb-c1 { fill: #FEE780; }
.pb-cline.pb-c2 { stroke: #5b9df9; } .pb-cdot.pb-c2 { fill: #5b9df9; }
.pb-cline.pb-c3 { stroke: #4bc0a4; } .pb-cdot.pb-c3 { fill: #4bc0a4; }
.pb-weblegend { display: flex; flex-wrap: wrap; gap: .35rem 1rem; margin-top: .5rem; font-size: .8rem;
  color: var(--fg-dim); }
.pb-lg { display: flex; align-items: center; gap: .35rem; }
.pb-sw { width: 12px; height: 3px; border-radius: 2px; display: inline-block; }
.pb-sw1 { background: #FEE780; } .pb-sw2 { background: #5b9df9; } .pb-sw3 { background: #4bc0a4; }

/* ── website tab: scroll-reach funnel ── */
td.pb-fnwrap { min-width: 220px; white-space: normal; }
.pb-fn { display: flex; align-items: center; gap: .45rem; margin: 2px 0; }
.pb-fnl { color: var(--fg-dim); font-size: 11px; width: 30px; text-align: right; }
.pb-fnbar { flex: 1; height: 8px; background: var(--line-2); border-radius: 4px;
  overflow: hidden; }
.pb-fnbar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.pb-fnv { font-size: 11px; width: 34px; font-variant-numeric: tabular-nums; }

/* ── module grid ── */
.pb-modgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: .7rem; }
.pb-modcard { display: block; background: var(--card-ink); border: 1px solid var(--line-2);
  border-radius: 10px; padding: .9rem 1rem; text-decoration: none; color: var(--fg);
  transition: border-color .15s ease; }
.pb-modcard:hover { border-color: var(--accent); }
.pb-modh { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; }
.pb-modn { color: var(--fg-mute); font-size: .82rem; margin-bottom: .35rem; }

/* ── heat rows / officers ── */
.pb-heatrow { display: grid; grid-template-columns: 170px 1fr 150px; gap: .6rem;
  align-items: center; padding: .3rem 0; border-bottom: 1px solid var(--line); }
.pb-heatrow:last-child { border-bottom: 0; }
.pb-heatname { color: var(--fg); font-size: .85rem; }
.pb-heatmeta { color: var(--fg-dim); font-size: .76rem; text-align: right; }
.pb-heatsvg svg { width: 100%; height: 18px; }
.pb-datatable { width: 100%; font-variant-numeric: tabular-nums; }
.pb-timeline { list-style: none; padding: 0; margin: 0; }
.pb-timeline li { padding: .35rem 0; border-bottom: 1px solid var(--line);
  color: var(--fg-mute); font-size: .86rem; }
.pb-timeline li strong { color: var(--fg); }

/* ── misc ── */
.pb-changes { list-style: none; padding: 0; margin: 0; }
.pb-changes li { padding: .3rem 0; color: var(--fg-mute); font-size: .88rem;
  display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.pb-note { color: var(--fg-dim); font-size: .78rem; margin: .6rem 0 0; }
.pb-skel { height: 92px; border-radius: 10px; border: 1px solid var(--line);
  background: linear-gradient(100deg, var(--card-ink) 40%, var(--ink-3) 50%, var(--card-ink) 60%);
  background-size: 200% 100%; animation: pb-shimmer 1.4s infinite linear; }
@keyframes pb-shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .pb-skel { animation: none; } }
.pb-boundary { margin: 2rem auto; max-width: 560px; }
.pb-annoform { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }
.pb-input { background: var(--input-bg); border: 1px solid var(--line-2);
  color: var(--fg); border-radius: 8px; padding: .45rem .6rem; font-size: .85rem; }
.pb-grow { flex: 1 1 220px; }
.pb-briefout { margin-top: 1rem; }
.pb-briefh { color: var(--fg); font-size: .92rem; margin: .9rem 0 .3rem; }
.pb-briefmeta { color: var(--fg-dim); font-size: .76rem; border-bottom: 1px solid var(--line);
  padding-bottom: .4rem; }
.pb-briefrow { padding: .2rem 0; }
.pb-exp { margin-left: .5rem; }
.pb-healthline { display: flex; gap: .4rem; align-items: baseline; }

/* ── responsive: 768px / 390px acceptance sizes ── */
@media (max-width: 768px) {
  .pb-heatrow { grid-template-columns: 120px 1fr; }
  .pb-heatmeta { grid-column: 1 / -1; text-align: left; }
  .pb-kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
@media (max-width: 480px) {
  .pb-wrap { padding: .75rem .6rem 2rem; }
  .pb-hdr { flex-direction: column; align-items: stretch; }
  .pb-heatrow { grid-template-columns: 1fr; }
  .pb-tablewrap { max-height: 200px; }
  .pb-kpi-value { font-size: 1.15rem; }
}

/* ── interactive layer: crosshair + floating tooltip ── */
.pb-tip { position: fixed; top: 0; left: 0; z-index: 300; pointer-events: none;
  background: var(--ink-3); border: 1px solid var(--line-2); border-radius: 8px;
  padding: .45rem .6rem; font-size: .78rem; color: var(--fg);
  box-shadow: 0 6px 24px rgba(0,0,0,.35); max-width: 240px; }
html[data-theme="light"] .pb-tip { box-shadow: 0 6px 24px rgba(15,23,42,.18); }
.pb-tip-day { color: var(--fg-mute); font-size: .72rem; margin-bottom: .2rem; }
.pb-tip-row { display: flex; align-items: center; gap: .35rem; }
.pb-tip-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.pb-cross { stroke: var(--fg-dim); stroke-width: 1; stroke-dasharray: 3 3; }
.pb-chart { touch-action: pan-y; }

/* ── KPI sparkline + count-up row ── */
.pb-kpi-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem;
  justify-content: space-between; }
.pb-kpi-spark { flex: 1 1 100px; min-width: 0; }
.pb-kspark { width: 100%; max-width: 120px; height: 28px; display: block; margin-left: auto; }
.pb-kspark-line { stroke-width: 1.5; }
.pb-kspark.pb-s1 .pb-kspark-line { stroke: var(--pb-s1); }
.pb-kspark.pb-s2 .pb-kspark-line { stroke: var(--pb-s2); }
.pb-kspark.pb-s5 .pb-kspark-line { stroke: var(--pb-s5); }
.pb-kspark-area { opacity: .14; }
.pb-kspark.pb-s1 .pb-kspark-area { fill: var(--pb-s1); }
.pb-kspark.pb-s2 .pb-kspark-area { fill: var(--pb-s2); }
.pb-kspark.pb-s5 .pb-kspark-area { fill: var(--pb-s5); }

/* ── insights strip ── */
.pb-insights { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: .6rem; }
.pb-insight { display: flex; gap: .5rem; align-items: flex-start;
  background: var(--card-ink); border: 1px solid var(--line-2); border-left-width: 3px;
  border-radius: 10px; padding: .65rem .8rem; font-size: .84rem; color: var(--fg-mute); }
.pb-insight.good { border-left-color: var(--pb-good); }
.pb-insight.warn { border-left-color: var(--pb-warn); }
.pb-insight.info { border-left-color: var(--pb-ctx); }
.pb-insight-ic { font-size: 1rem; line-height: 1.2; }

/* ── charter target meters ── */
.pb-meters { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: .8rem; }
.pb-meter-top { display: flex; justify-content: space-between; gap: .5rem;
  font-size: .82rem; color: var(--fg); margin-bottom: .3rem; }
.pb-meter-n { color: var(--fg-mute); font-variant-numeric: tabular-nums; }
.pb-meter-bar { position: relative; height: 8px; border-radius: 999px;
  background: var(--line); overflow: visible; }
.pb-meter-fill { height: 100%; border-radius: 999px; background: var(--pb-s1);
  transition: width .5s ease; }
.pb-meter.met .pb-meter-fill { background: var(--pb-good); }
.pb-meter-target { position: absolute; top: -3px; width: 2px; height: 14px;
  background: var(--fg-mute); }
.pb-meter-state { font-size: .72rem; color: var(--fg-dim); margin-top: .3rem; }
.pb-meter.met .pb-meter-state { color: var(--pb-good); }
@media (prefers-reduced-motion: reduce) { .pb-meter-fill { transition: none; } }

/* ── funnel drop labels + on-bar labels ── */
.pb-chart .pb-drop { fill: var(--pb-warn); font-size: 10px; font-style: italic;
  font-family: var(--font-sans); }
.pb-chart .pb-onbar { fill: #fff; }
.pb-fill.pb-s2 { fill: var(--pb-s2); } .pb-fill.pb-s3 { fill: var(--pb-s3); }
.pb-fill.pb-s4 { fill: var(--pb-s4); } .pb-fill.pb-s5 { fill: var(--pb-s5); }
.pb-fill.pb-s6 { fill: var(--pb-s6); }

/* ── weekly cohort grid ── */
.pb-cohort-cell { color: var(--fg-dim); }
.pb-cohort-cell.hit { color: var(--fg); background:
  color-mix(in srgb, var(--pb-s1) 18%, transparent); border-radius: 4px; }

/* hover lift on module cards / KPI tiles (no motion when reduced) */
.pb-kpi, .pb-modcard { transition: transform .12s ease, border-color .15s ease; }
.pb-kpi:hover, .pb-modcard:hover { transform: translateY(-1px); }
@media (prefers-reduced-motion: reduce) {
  .pb-kpi, .pb-modcard { transition: none; }
  .pb-kpi:hover, .pb-modcard:hover { transform: none; }
}
:where(.pb-wrap) a:focus-visible, :where(.pb-wrap) button:focus-visible,
.pb-dot:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* insight text tags (replaces emoji product icons — B12) */
.pb-insight-ic { font-size: .62rem; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; padding: .15rem .4rem; border-radius: 5px;
  border: 1px solid var(--line-2); color: var(--fg-mute); flex: 0 0 auto;
  line-height: 1.3; }
.pb-insight.good .pb-insight-ic { color: var(--pb-good); border-color: var(--pb-good); }
.pb-insight.warn .pb-insight-ic { color: var(--pb-warn); border-color: var(--pb-warn); }

/* v9: training stall highlight */
.pb-stallwarn { color: var(--pb-warn); font-weight: 700; }

/* alignment cleanup v2 (2026-07-21): numeric headers sit over their values.
   Charter meters are STACKED — with twelve targets the label/summary pair
   can be long ("108/109 successful · 99% …"), so each gets its own wrapping
   block line; bars follow at whatever height their text needs. Never
   overflow-wrap:anywhere (per-character breaks) and never nowrap on long
   summaries (neighbor overlap) — that combination broke the board. */
.pb-datatable th.num { text-align: right; }
.pb-meter { min-width: 0; }
.pb-meter-top { display: block; min-height: 0; }
.pb-meter-top > span:first-child { display: block; overflow-wrap: break-word;
  color: var(--fg); }
.pb-meter-n { display: block; white-space: normal; overflow-wrap: break-word;
  text-align: left; margin: .15rem 0 .35rem; }
.pb-meter-state { white-space: normal; }


/* ── responsive audit 2026-07-29 ─────────────────────────────────────────────
   Wide tables scroll inside their own host (page-level overflow is clipped by
   styles.css `main{overflow-x:clip}`, so unwrapped tables lose columns). */
.pb-tablehost { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Undefined until now: checkbox label in the Discovery Brief admin form. */
.pb-check { display: inline-flex; align-items: center; gap: .4rem;
  font-size: .85rem; color: var(--fg-mute); }

/* In-SVG text is sized in viewBox units; at phone widths the uniform scale
   (~0.27) makes 10-11px labels unreadable. Bump the units, not the layout. */
@media (max-width: 640px) {
  .pb-cax { font-size: 24px; }
}
@media (max-width: 560px) {
  .pb-chart .pb-axis { font-size: 20px; }
  .pb-chart .pb-vlabel { font-size: 22px; }
  .pb-chart .pb-flabel, .pb-chart .pb-drop { font-size: 20px; }
}

/* Heat strips: keep day cells legible and let the strip scroll instead of
   shrinking 90 days into a sliver. */
@media (max-width: 768px) {
  .pb-heatsvg { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pb-heatsvg svg { width: auto; min-width: 100%; height: 18px; }
}

/* Scroll-reach funnel cell: 220px ate most of a 375px-wide panel. */
@media (max-width: 480px) {
  td.pb-fnwrap { min-width: 150px; }
}
