/*
 * docs/_shared/charts.css — palette + structure for shared chart primitives
 *
 * Loaded by docs/index.html, docs/insights.html, and the static portal
 * pages. Variables fall back to either the warm-paper public palette,
 * the Archive theme (`html[data-public-theme="archive"]` in
 * `public-theme.css`), or the dark console palette depending on which
 * page mounts the file.
 *
 * Every selector is namespaced under `.chart-` so it can co-exist with
 * existing portal styles without collision.
 */

:root {
  --chart-accent: var(--accent, #7a2f1b);
  --chart-accent-warm: var(--accent-warm, #a0421e);
  --chart-good: var(--good, #1f7a4d);
  --chart-axis: var(--line, rgba(31, 26, 23, 0.18));
  --chart-grid: rgba(31, 26, 23, 0.07);
  --chart-tick: var(--muted, #5f544b);
  --chart-spark: var(--accent, #7a2f1b);
  --chart-edge: rgba(31, 26, 23, 0.55);
  --chart-node-fill: rgba(255, 251, 245, 0.95);
  --chart-node-stroke: var(--accent, #7a2f1b);
}

/* The chart primitives also work on the dark console. Detect by sniffing
   the CSS variable that the portal already carries. We keep both palettes
   in this stylesheet so it stays a single asset to ship. */
:root[data-portal-theme="dark"],
.console-dark {
  --chart-axis: rgba(255, 255, 255, 0.16);
  --chart-grid: rgba(255, 255, 255, 0.06);
  --chart-tick: rgba(255, 255, 255, 0.6);
  --chart-edge: rgba(201, 107, 60, 0.45);
  --chart-node-fill: rgba(20, 14, 9, 0.85);
  --chart-node-stroke: var(--accent-bright, #c96b3c);
}

/* ── Horizontal bars ───────────────────────────────────── */
.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(60px, 2.4fr) auto;
  gap: 12px;
  align-items: center;
  font-size: 14px;
  margin-bottom: 8px;
}

.bar-label-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.bar-kicker {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--chart-tick);
  margin-bottom: 1px;
}

.bar-label {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar-sub {
  font-size: 12px;
  color: var(--chart-tick);
  margin-top: 1px;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--chart-grid);
  overflow: hidden;
  position: relative;
}

.bar-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--chart-accent), #d78a49);
  transition: width 720ms cubic-bezier(0.22, 1, 0.36, 1);
}

.bar-fill--accent {
  background: linear-gradient(90deg, #2c5d8c, var(--chart-accent));
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--chart-accent);
  font-size: 14px;
}

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}

/* ── Tempo line/area chart ─────────────────────────────── */
.chart-svg { width: 100%; height: auto; display: block; }

.chart-empty {
  padding: 32px 12px;
  text-align: center;
  color: var(--chart-tick);
  font-size: 13px;
}

.chart-grid {
  stroke: var(--chart-grid);
  stroke-width: 1;
  fill: none;
}

.chart-tick {
  fill: var(--chart-tick);
  font-size: 10px;
  font-family: "SFMono-Regular", Consolas, monospace;
}

.chart-tempo-area {
  fill: var(--chart-accent);
  fill-opacity: 0.10;
  stroke: none;
}

.chart-tempo-line {
  fill: none;
  stroke: var(--chart-accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-tempo-analyzed {
  fill: none;
  stroke: var(--chart-good);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

.chart-tempo-patterns {
  fill: none;
  stroke: #5b6f9b;
  stroke-width: 1.5;
  stroke-opacity: 0.8;
}

.chart-milestone circle {
  fill: var(--chart-accent-warm);
  stroke: var(--chart-node-fill);
  stroke-width: 2;
}

.chart-axis {
  stroke: var(--chart-axis);
  stroke-width: 1;
  fill: none;
}

.chart-axis-label {
  fill: var(--chart-tick);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ── Force graph ──────────────────────────────────────── */
.chart-force-edge {
  stroke: var(--chart-edge);
  fill: none;
  transition: stroke-opacity 160ms ease;
}

.chart-force-node circle {
  fill: var(--chart-node-fill);
  stroke: var(--chart-node-stroke);
  stroke-width: 1.6;
  transition: transform 200ms ease, stroke-width 160ms ease;
}

.chart-force-node:hover circle,
.chart-force-node:focus circle {
  stroke-width: 3;
  filter: drop-shadow(0 4px 14px rgba(122, 47, 27, 0.30));
}

.chart-force-node text {
  fill: var(--chart-tick);
  font-size: 10px;
  font-weight: 700;
  font-family: "SFMono-Regular", Consolas, monospace;
  pointer-events: none;
}

.chart-force-node {
  cursor: pointer;
  outline: none;
}

.chart-force-node:focus { outline: none; }

/* Per-category accents — keep these subtle. Class names follow the
   `chart-force-cat-{slug}` convention where slug is the lowercased,
   space-replaced category band returned by the catalog parser. */
.chart-force-cat-core-institutional circle      { fill: rgba(122, 47, 27, 0.18); stroke: #7a2f1b; }
.chart-force-cat-championship-patterns circle    { fill: rgba(31, 122, 77, 0.18); stroke: #1f7a4d; }
.chart-force-cat-cross-artifact circle            { fill: rgba(45, 95, 154, 0.18); stroke: #2d5f9a; }
.chart-force-cat-formation-patterns circle        { fill: rgba(155, 93, 25, 0.20); stroke: #9b5d19; }
.chart-force-cat-post-surge circle                { fill: rgba(120, 80, 130, 0.20); stroke: #785082; }
.chart-force-cat-corpus-compendium circle         { fill: rgba(196, 110, 79, 0.20); stroke: #c46e4f; }
.chart-force-cat-field-patterns circle            { fill: rgba(35, 80, 110, 0.20); stroke: #23506e; }
.chart-force-cat-uncategorized circle             { fill: rgba(95, 84, 75, 0.18); stroke: #5f544b; }

/* ── Scatter ──────────────────────────────────────────── */
.chart-scatter-dot circle {
  fill: var(--chart-node-fill);
  stroke: var(--chart-node-stroke);
  stroke-width: 1.4;
  cursor: pointer;
  transition: transform 200ms ease, stroke-width 160ms ease;
}

.chart-scatter-dot:hover circle,
.chart-scatter-dot:focus circle {
  stroke-width: 3;
}

.chart-scatter-dot { cursor: pointer; outline: none; }

/* ── Sparkline ────────────────────────────────────────── */
.chart-spark {
  width: 100%;
  height: 28px;
}

.chart-spark rect {
  fill: var(--chart-spark);
  fill-opacity: 0.55;
}

/* ── Category stack ───────────────────────────────────── */
.cat-stack {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 16px;
  align-items: end;
}

.cat-stack-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.cat-stack-bar {
  width: 38px;
  background: var(--chart-grid);
  border-radius: 8px 8px 4px 4px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  min-height: 24px;
}

.cat-stack-fill {
  width: 100%;
  background: linear-gradient(180deg, #d78a49, var(--chart-accent));
  transition: height 700ms cubic-bezier(0.22, 1, 0.36, 1);
}

.cat-stack-num {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-weight: 700;
  font-size: 14px;
  color: var(--chart-accent);
}

.cat-stack-num span {
  color: var(--chart-tick);
  font-weight: 500;
  font-size: 11px;
  margin-left: 2px;
}

.cat-stack-label {
  text-align: center;
  color: var(--chart-tick);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  max-width: 110px;
}

@media (prefers-reduced-motion: reduce) {
  .cat-stack-fill { transition: none; }
}
