/* ==========================================================================
   DEVEXA — Chart & data-visualization layer
   Shared presentational rules for Observable Plot / D3 output, plus the
   editorial framing (insight headline, key stats, big numbers) around any
   chart — including the static SVG exports this case study actually uses.
   Loaded only on pages that render charts (analyses/*) — the homepage
   never needs this file. Depends on tokens defined in css/devexa.css
   (--font-*, --space-*, --content-*, --paper/--ink/--muted, --editorial-red),
   which must load first.
   Rules follow docs/devexa_visualization_system.md — read that before
   changing anything here.
   ========================================================================== */

:root {
  /* chart-specific neutrals (design system §6) */
  --chart-ink: #1B1B19;
  --chart-dark-gray: #3D3C38;
  --chart-mid-gray: #77746D;
  --chart-light-gray: #B8B4AB;
  --chart-grid: #D7D4CD;
  --chart-highlight: var(--editorial-red);

  /* semantic colors — use only when the analysis truly needs pos/neg
     meaning, never as decoration (design system §8). Independent of
     --chart-highlight: red here means "look here", not "negative". */
  --chart-positive: #638B66;
  --chart-negative: #B5655D;
  --chart-warning: #C4934D;
  --chart-information: #607D91;

  --chart-grid-opacity: 0.65;
}

/* Chart sits directly on the page surface — never a card, never a shadow.
   Wide content column (design system §22 / brief §15-16): charts run
   wider than the 660px reading column on purpose. */
.chart-block {
  width: 100%;
  max-width: var(--content-wide);
  margin-inline: auto;
  margin-top: var(--space-6); /* text → chart: ~64px (brief §18) */
}

.chart-block + .chart-block {
  margin-top: var(--space-8); /* finding → next finding: ~128px (brief §18) */
}

.chart-block--full { max-width: none; }

.chart-figure {
  margin: 0;
}

.chart-figure svg,
.chart-figure img {
  display: block;
  width: 100%;
  height: auto;
  font-family: var(--font-sans);
}

/* Observable Plot / D3 draw text as SVG <text>; apply these classes via
   Plot's className option or D3's .attr("class", ...) so chart code never
   hardcodes a color. */
.chart-figure .chart-axis text {
  font-family: var(--font-sans);
  font-size: 12px;
  fill: var(--muted);
}

.chart-figure .chart-axis path,
.chart-figure .chart-axis line,
.chart-figure line.chart-gridline {
  stroke: var(--chart-grid);
  stroke-opacity: var(--chart-grid-opacity);
  shape-rendering: crispEdges;
}

/* Vertical gridlines are off by default (design system §9). */
.chart-figure line.chart-gridline--vertical { display: none; }

.chart-figure .chart-series-main {
  stroke: var(--chart-ink);
  stroke-width: 2.5;
  fill: none;
}

.chart-figure .chart-series-context {
  stroke: var(--chart-light-gray);
  stroke-width: 1.25;
  fill: none;
}

.chart-figure .chart-series-highlight {
  stroke: var(--chart-highlight);
  stroke-width: 2.75;
  fill: none;
}

.chart-figure .chart-point-highlight { fill: var(--chart-highlight); }

.chart-figure .chart-bar { fill: var(--chart-dark-gray); }
.chart-figure .chart-bar--context { fill: var(--chart-light-gray); }
.chart-figure .chart-bar--highlight { fill: var(--chart-highlight); }
.chart-figure .chart-bar--positive { fill: var(--chart-positive); }
.chart-figure .chart-bar--negative { fill: var(--chart-negative); }

/* Direct labeling is preferred over a legend (design system §11). */
.chart-figure .chart-direct-label {
  font-family: var(--font-sans);
  font-size: 13px;
  fill: var(--chart-ink);
}

/* Insight headline states the finding, not a technical description:
   "Import elektroniki wzrósł 3,4× w ciągu dekady.", never
   "Import wg kategorii 2015–2025." (design system §5). Same display
   tracking logic as headings — tight at this size. */
.chart-insight {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--fs-h3);
  line-height: var(--lh-h3);
  letter-spacing: var(--ls-h3);
  max-width: 28ch;
  margin-bottom: var(--space-2);
}

.chart-context {
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--muted);
  max-width: var(--measure);
  margin-bottom: var(--space-4);
}

/* Key-figure callout between the insight headline and the chart itself,
   e.g. "0,41 → 0,78 EUR/kg" with a small caption underneath. Deliberately
   modest in size — the insight headline carries the weight of the finding,
   this is a supporting reference figure, not a standalone hero statistic
   (see .chart-big-number below for that case). The accent dot marks it as
   a "look here" figure without coloring the number itself — text-color
   red doesn't clear 4.5:1 against the paper background at this size.
   Wrap 2+ related stats (e.g. a before/after pair) in .chart-stat-group to
   lay them side by side instead of stacking. */
.chart-stat {
  position: relative;
  padding-left: 16px;
  margin-bottom: var(--space-3);
}

.chart-stat::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--chart-highlight);
}

.chart-stat__value {
  display: block;
  font-family: var(--font-mono);
  font-size: clamp(1rem, 0.94rem + 0.3vw, 1.1875rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--chart-ink);
}

.chart-stat__label {
  display: block;
  font-family: var(--font-sans);
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.chart-stat-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-8);
  margin-bottom: var(--space-3);
}

.chart-stat-group .chart-stat { margin-bottom: 0; }

/* SOURCE / PERIOD / UNIT / NOTE metadata block under a chart (design
   system §26), rendered by js/devexa-charts.js renderMetaBlock(). Sits
   close to the chart it describes — chart → source: ~24px (brief §18). */
.chart-meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px var(--space-4);
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--rule);
}

.chart-meta dt {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.chart-meta dd {
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--muted);
  margin: 0;
}

/* Big number finding, shown without a conventional chart or a dashboard
   card (design system §19, brief §14/29). */
.chart-big-number {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: var(--fs-metric);
  line-height: var(--lh-metric);
  letter-spacing: var(--ls-metric);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.chart-big-number__context {
  font-family: var(--font-sans);
  color: var(--muted);
  margin-top: var(--space-3);
  max-width: var(--measure);
}

/* Waiting-for-data state. Every case study ships with this until its real
   dataset lands in analyses/<slug>/data/ — never fill it with invented
   numbers in the meantime. */
.chart-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  border: 1px dashed var(--rule);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 13px;
  text-align: center;
  padding: var(--space-4);
}

/* Tooltip (design system §25) */
.chart-tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--paper-light);
  border: 1px solid var(--rule);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 13px;
  line-height: 1.4;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}

.chart-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.chart-tooltip dt {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

@media (max-width: 767px) {
  .chart-meta { grid-template-columns: 1fr; gap: 2px var(--space-4); }
}

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

/* ==========================================================================
   Semantic figure + reading notes + HTML bar lists (analyses/lalka-filmweb).
   Bar lists are used where labels are too long for a vertical DataFigure bar
   chart (25 aspects, aspect pairs). Numbers stay in the text; the bar is
   decoration (aria-hidden).
   ========================================================================== */

figure.chart-block { margin-inline: auto; margin-bottom: 0; }

.chart-reading {
  max-width: var(--content-narrow);
  margin-top: var(--space-4);
  font-size: var(--fs-small);
  line-height: 1.6;
  color: var(--ink-soft);
}
.chart-reading__label {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: var(--space-1);
}

.bar-track {
  position: relative;
  height: 6px;
  background: var(--rule);
  margin-top: 6px;
}
.bar-track__fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--ink);
}
.bar-track__mark {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 1px;
  background: var(--editorial-red);
}

.aspect-map {
  list-style: none;
  padding: 0;
  margin: var(--space-4) 0 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 var(--space-5);
}
.aspect-map__item {
  padding-block: var(--space-2) var(--space-3);
  border-top: 1px solid var(--rule);
}
.aspect-map__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
}
.aspect-map__name {
  font-family: var(--font-sans);
  font-size: 1.0625rem;
  font-weight: 550;
  line-height: 1.3;
  color: var(--ink);
}
.aspect-map__rank {
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-right: 4px;
}
.aspect-map__value {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.aspect-map__value span { color: var(--ink); font-weight: 600; }
.aspect-map__question {
  margin-top: var(--space-1);
  font-size: var(--fs-small);
  line-height: 1.5;
  color: var(--ink-soft);
}
.aspect-map__quote,
.aspect-map__note {
  margin-top: 6px;
  font-size: var(--fs-small);
  line-height: 1.5;
}
.aspect-map__quote {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 1.0625rem;
  color: var(--ink);
}
.aspect-map__note { color: var(--muted); }

.pair-list {
  list-style: none;
  padding: 0;
  margin: var(--space-4) 0 0;
  max-width: var(--content-reading);
}
.pair-list__item {
  padding-block: var(--space-2);
  border-top: 1px solid var(--rule);
}
.pair-list__head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  font-size: var(--fs-small);
}
.pair-list__name { color: var(--ink); font-weight: 500; }
.pair-list__value {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--ink);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.pair-list__item--baseline .bar-track__fill { background: var(--tertiary); }
.pair-list__meta {
  margin-top: 6px;
  font-family: var(--font-mono);
  font-size: var(--fs-mono);
  letter-spacing: 0.06em;
  color: var(--muted);
}
.pair-list__meta.is-empty { color: var(--tertiary); }
.pair-list__legend {
  margin-top: var(--space-2);
  font-size: 0.8125rem;
  color: var(--muted);
}

@media (max-width: 720px) {
  .aspect-map { grid-template-columns: 1fr; }
}

.term-list {
  margin-block: var(--space-3);
  font-family: var(--font-display);
  font-style: italic;
  font-size: var(--fs-lead);
  line-height: 1.5;
  color: var(--ink);
  max-width: var(--content-reading);
}

/* Prose that resumes after a figure inside the intro. */
.chart-block + .case-intro__body,
.chart-block + .case-section__body { margin-top: var(--space-6); }

/* ==========================================================================
   ImageOverlay (js/charts/image-overlay.js): interaction layer over a
   static chart image. Hit areas are invisible; focus shows an ink outline
   on the mark and dims nothing, so the delivered graphic stays intact.
   ========================================================================== */

.image-overlay__frame { position: relative; }
.image-overlay__frame img { display: block; width: 100%; height: auto; }

.image-overlay__layer {
  position: absolute;
  inset: 0;
}

.image-overlay__hit {
  position: absolute;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.image-overlay__hit:focus { outline: none; }

.image-overlay__mark {
  position: absolute;
  pointer-events: none;
  outline: 2px solid transparent;
  outline-offset: 2px;
  transition: outline-color 120ms ease;
}
.image-overlay__hit.is-active .image-overlay__mark { outline-color: var(--ink); }
.image-overlay__hit.is-pinned .image-overlay__mark { outline-color: var(--editorial-red); }
.image-overlay__hit:focus-visible .image-overlay__mark { outline-color: var(--editorial-red); }

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