/* Charts (Task 1.3 rework, design handoff "Chart component").
   Colours and fonts come from tokens.css (--ug-*). No inline styles are used by the chart
   markup: label positions are emitted in a per-chart nonce'd <style> block (see
   web/charts/overlay.py); everything else is here. */

/* ------------------------------------------------------------------ variants */
/* Both the desktop (1000x366) and phone (356x282) charts are in the page; the phone one is
   shown at viewport widths up to 480px, the desktop one above. */
.chart-phone { display: none; }
@media (max-width: 480px) {
  .chart-desktop { display: none; }
  .chart-phone { display: block; }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- series colours */
.s-sales { --series: var(--ug-series-sales); }
.s-labour { --series: var(--ug-series-labour); }
.s-wastage { --series: var(--ug-series-wastage); }
.s-food { --series: var(--ug-series-food); }
.s-spend { --series: var(--ug-series-spend, var(--ug-series-sales)); }
.s-share { --series: var(--ug-series-share, var(--ug-series-labour)); }
.s-mini { --series: var(--ug-series-sales); }

/* ---------------------------------------------------------------- history chart */
.chart { width: 100%; }
.chart-plot { position: relative; }
.chart-svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.chart-svg .gridline { stroke: var(--ug-line-divider); stroke-width: 1; }
.chart-svg .baseline { stroke: var(--ug-line-axis); stroke-width: 1; }
.chart-svg .bar { fill: var(--series); }
.chart-svg .bar.provisional {
  fill-opacity: 0.55;
  stroke: var(--series);
  stroke-width: 1;
  stroke-dasharray: 3 2;
}
.chart-svg .gap-marker {
  stroke: var(--ug-line-axis);
  stroke-width: 1.5;
  stroke-dasharray: 3 2;
}
.chart-svg .line {
  fill: none;
  stroke: var(--series);
  stroke-linejoin: round;
  stroke-linecap: round;
}
.chart-svg .point { fill: var(--ug-surface); stroke: var(--series); }
.chart-svg .point.provisional { stroke-dasharray: 2 1.5; }
.chart-desktop .line, .chart-desktop .point { stroke-width: 2.5; }
.chart-phone .line, .chart-phone .point { stroke-width: 2; }

/* HTML labels over the SVG. left/top come from the per-chart <style> block. */
.chart-labels { position: absolute; inset: 0; pointer-events: none; }
.cl {
  position: absolute;
  white-space: nowrap;
  pointer-events: none;
  font-family: var(--ug-font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  background: var(--ug-surface);
  padding: 0 3px;
  border-radius: 2px;
  color: var(--ug-ink-muted);
  font-size: 12px;
}
.cl-axis-title-l { transform: translate(0, -100%); font-size: 10.5px; }
.cl-axis-title-r { transform: translate(-100%, -100%); font-size: 10.5px; }
.cl-tick-l { transform: translate(-100%, -50%); }
.cl-tick-r { transform: translate(0, -50%); }
.cl-period { transform: translate(-50%, 0); }
.cl-bar-value { transform: translate(-50%, 0); color: var(--ug-ink-title); }
.cl-bar-value.gap { color: var(--ug-ink-muted); font-style: italic; }
.cl-line-value { transform: translate(-50%, 0); color: var(--series); }
.chart-phone .cl { font-size: 9.5px; }
.chart-phone .cl-axis-title-l, .chart-phone .cl-axis-title-r { font-size: 9px; }

/* Empty states: "No data" and the dashed "Turn a series on" box. */
.chart-empty-box {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  margin: 0;
  padding: 0 24px;
  height: 224px;
  border: 1px dashed var(--ug-line-chip-off);
  background: var(--ug-empty);
  font-size: 12px;
  line-height: 1.45;
  color: var(--ug-ink-muted);
}
.chart-desktop .chart-empty-box { height: 292px; font-size: 13px; }
.chart-mini .chart-empty-box, .chart-channel .chart-empty-box,
.chart-categories .chart-empty-box, .chart-sitemix .chart-empty-box { height: auto; padding: 14px 24px; }

/* First-to-last row under the chart. */
.chart-deltas {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--ug-line-row);
}
.chart-deltas .delta { display: flex; align-items: baseline; gap: 10px; }
.chart-deltas .swatch {
  width: 7px;
  height: 7px;
  border-radius: var(--ug-r-seg);
  background: var(--series);
  flex: none;
}
.chart-deltas .delta-name { flex: 1; font-size: 12px; color: var(--ug-ink-secondary); }
.chart-deltas .delta-values {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ug-ink-heading);
  font-variant-numeric: tabular-nums;
}
@media (min-width: 481px) {
  .chart-deltas { display: flex; flex-wrap: wrap; gap: 36px; margin-top: 16px; padding-top: 16px; }
  .chart-deltas .delta-name { flex: none; font-size: 12.5px; }
  .chart-deltas .delta-values { font-size: 13.5px; }
  .chart-deltas .swatch { width: 8px; height: 8px; }
}

/* ----------------------------------------------------------------- mini series */
.chart-mini { max-width: 240px; }
.chart-mini .cl { font-size: 10px; }

/* ---------------------------------------------------------------- stacked bars */
.stack-bar { display: block; }
.stack-bar .segment { stroke: var(--ug-surface); stroke-width: 2; paint-order: stroke; }

.chart-channel .seg-0 { fill: var(--ug-ch-instore); background: var(--ug-ch-instore); }
.chart-channel .seg-1 { fill: var(--ug-ch-delivery); background: var(--ug-ch-delivery); }
.chart-channel .seg-2 { fill: var(--ug-ch-corporate); background: var(--ug-ch-corporate); }

.chart-categories .seg-0, .chart-sitemix .seg-0 { fill: var(--ug-prod-salads); background: var(--ug-prod-salads); }
.chart-categories .seg-1, .chart-sitemix .seg-1 { fill: var(--ug-prod-bowls); background: var(--ug-prod-bowls); }
.chart-categories .seg-2, .chart-sitemix .seg-2 { fill: var(--ug-prod-trays); background: var(--ug-prod-trays); }
.chart-categories .seg-3, .chart-sitemix .seg-3 { fill: var(--ug-prod-breakfast); background: var(--ug-prod-breakfast); }
.chart-categories .seg-4, .chart-sitemix .seg-4 { fill: var(--ug-prod-drinks); background: var(--ug-prod-drinks); }
/* Fallbacks beyond the handoff's palette. */
.chart-channel .seg-3, .chart-channel .seg-4, .chart-channel .seg-5, .chart-channel .seg-6,
.chart-channel .seg-7, .chart-categories .seg-5, .chart-categories .seg-6, .chart-categories .seg-7,
.chart-sitemix .seg-5, .chart-sitemix .seg-6, .chart-sitemix .seg-7 {
  fill: var(--ug-line-axis);
  background: var(--ug-line-axis);
}

.chart-channel .stack-bar, .chart-categories .stack-bar { width: 100%; }
.legend, .leader-list, .site-mix { list-style: none; margin: 0; padding: 0; }
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 12px;
  font-size: 12px;
  color: var(--ug-ink-secondary);
}
.legend li { display: flex; align-items: baseline; gap: 6px; }
.legend-value { font-weight: 600; color: var(--ug-ink-heading); font-variant-numeric: tabular-nums; }
.legend .swatch, .leader-list .swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--ug-r-seg);
  flex: none;
}

.leader-list { margin-top: 14px; }
.leader-list li { display: flex; align-items: baseline; gap: 8px; padding: 5px 0; font-size: 13px; }
.leader-name { color: var(--ug-ink-body); }
.leader-dots { flex: 1; border-bottom: 1px dotted var(--ug-line-leader); transform: translateY(-3px); }
.leader-value { color: var(--ug-ink-secondary); font-variant-numeric: tabular-nums; }
.leader-pct {
  min-width: 48px;
  text-align: right;
  font-weight: 600;
  color: var(--ug-ink-heading);
  font-variant-numeric: tabular-nums;
}

.site-mix { display: grid; gap: 12px; }
.site-mix li { display: grid; gap: 5px; }
.site-name { font-size: 13px; color: var(--ug-ink-body); }

/* By-site mix rows are links to the site page (v3 "tap for detail"): name left, bar right. */
.site-mix { gap: 4px; }
.site-mix li { display: block; }
.site-mix-link,
.site-mix li:not(:has(a)) {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 5px 0;
  color: inherit;
  text-decoration: none;
}
.site-mix-link:hover { background: var(--ug-panel); color: inherit; }
.site-name { font-size: 12px; }
