/* ==========================================================================
   Charts — monochrome data visualisation
   viz-1 carries the signal; lower steps are context. Shapes and fills
   (solid / hatched / ring) replace hue for categorical meaning.
   ========================================================================== */

.chart {
  position: relative;
  width: 100%;
  min-width: 0;
}

/* Labels near the edge of a force layout must not widen the page. */
.chart-network {
  overflow: hidden;
}

.chart > svg {
  display: block;
  overflow: visible;
}

.ax-label {
  font-family: var(--font-mono);
  font-size: 10px;
  fill: var(--fg-3);
  letter-spacing: 0.02em;
}

.ax-grid {
  stroke: var(--viz-grid);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.ax-base {
  stroke: var(--viz-axis);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.s-line {
  fill: none;
  stroke-width: 1.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.s-line.dashed {
  stroke-dasharray: 3 3;
}

.s-dot {
  stroke: var(--surface-1);
  stroke-width: 2;
}

.xhair {
  stroke: var(--line-3);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.hover-band {
  fill: var(--glow);
}

.chart-annot {
  font-family: var(--font-mono);
  font-size: 10.5px;
  fill: var(--fg-1);
}

.chart-annot.dim {
  fill: var(--fg-3);
}

/* Draw-in animation, applied only on first mount of a page */
.chart.anim .s-line {
  stroke-dasharray: var(--len) var(--len);
  stroke-dashoffset: var(--len);
  animation: chart-draw 1100ms var(--ease) forwards;
}

.chart.anim .s-line.dashed {
  animation: none;
  stroke-dasharray: 3 3;
  stroke-dashoffset: 0;
  opacity: 0;
  animation: fade-in 600ms 500ms var(--ease) forwards;
}

.chart.anim .s-area {
  opacity: 0;
  animation: fade-in 900ms 250ms var(--ease) forwards;
}

.chart.anim .s-bar {
  transform-box: fill-box;
  transform-origin: 50% 100%;
  animation: bar-grow 700ms var(--ease) both;
}

@keyframes chart-draw {
  to {
    stroke-dashoffset: 0;
  }
}

@keyframes bar-grow {
  from {
    transform: scaleY(0);
  }
  to {
    transform: scaleY(1);
  }
}

/* Tooltip */
.chart-tip {
  position: absolute;
  z-index: 5;
  min-width: 150px;
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: var(--surface-3);
  box-shadow: var(--shadow-pop);
  pointer-events: none;
  font-size: 12px;
  color: var(--fg-2);
  opacity: 0;
  transition: opacity var(--dur-1) var(--ease);
  white-space: nowrap;
}

.chart-tip.on {
  opacity: 1;
}

.chart-tip-title {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin-bottom: 6px;
}

.chart-tip-row {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.7;
}

.chart-tip-row b {
  margin-left: auto;
  padding-left: 14px;
  color: var(--fg-1);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 11.5px;
}

/* --- Sparkline ----------------------------------------------------------- */

.spark {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.spark .sp-line {
  fill: none;
  stroke: var(--viz-1);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  stroke-linejoin: round;
}

.spark.dim .sp-line {
  stroke: var(--viz-3);
}

/* --- Horizontal bars ----------------------------------------------------- */

.hbars {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hbar-row {
  display: grid;
  grid-template-columns: minmax(0, var(--hbar-label, 34%)) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  margin: 0 -8px;
  border-radius: var(--r-sm);
  font-size: 12.5px;
  transition: background var(--dur-1) var(--ease);
}

.hbar-row.clickable {
  cursor: pointer;
}

.hbar-row.clickable:hover {
  background: var(--surface-2);
}

.hbar-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--fg-1);
}

.hbar-label .truncate {
  flex: 1 1 auto;
}

.hbar-track {
  position: relative;
  height: 8px;
  border-radius: 2px;
  background: var(--viz-6);
  overflow: hidden;
}

.hbar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 2px;
  background: var(--viz-1);
  transform-origin: left;
  animation: bar-x 800ms var(--ease) both;
}

.hbar-fill.t2 { background: var(--viz-2); }
.hbar-fill.t3 { background: var(--viz-3); }
.hbar-fill.t4 { background: var(--viz-4); }

.hbar-fill.hatch {
  background: repeating-linear-gradient(135deg, var(--viz-2) 0 2px, transparent 2px 5px);
  box-shadow: inset 0 0 0 1px var(--viz-3);
}

.hbar-fill.ring {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--viz-3);
}

.hbar-value {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--fg-2);
  font-variant-numeric: tabular-nums;
  min-width: 42px;
  text-align: right;
}

.hbar-row.static .hbar-fill {
  animation: none;
}

@keyframes bar-x {
  from {
    transform: scaleX(0);
  }
  to {
    transform: scaleX(1);
  }
}

/* --- 100% stacked bar ---------------------------------------------------- */

.stackbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stackbar-track {
  display: flex;
  gap: 2px;
  height: 10px;
  border-radius: 2px;
  overflow: hidden;
}

.stackbar-track.tall {
  height: 28px;
  border-radius: var(--r-sm);
}

.stackbar-seg {
  height: 100%;
  min-width: 2px;
  background: var(--viz-1);
  transform-origin: left;
  animation: bar-x 900ms var(--ease) both;
}

.stackbar-seg.t2 { background: var(--viz-2); }
.stackbar-seg.t3 { background: var(--viz-3); }
.stackbar-seg.t4 { background: var(--viz-4); }
.stackbar-seg.t5 { background: var(--viz-5); }

.stackbar-seg.hatch {
  background: repeating-linear-gradient(135deg, var(--viz-2) 0 2px, transparent 2px 5px);
  box-shadow: inset 0 0 0 1px var(--viz-3);
}

.stackbar-seg.ring {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--viz-3);
}

.stackbar-track.tall .stackbar-seg {
  display: flex;
  align-items: center;
  padding: 0 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--canvas);
  white-space: nowrap;
  overflow: hidden;
}

.stackbar-track.tall .stackbar-seg.t3,
.stackbar-track.tall .stackbar-seg.t4,
.stackbar-track.tall .stackbar-seg.t5,
.stackbar-track.tall .stackbar-seg.hatch,
.stackbar-track.tall .stackbar-seg.ring {
  color: var(--fg-1);
}

/* --- Range / dumbbell plot (price erosion) ------------------------------ */

.range-plot {
  display: flex;
  flex-direction: column;
}

.range-axis {
  display: grid;
  grid-template-columns: minmax(0, var(--range-label, 30%)) minmax(0, 1fr) 64px;
  gap: 14px;
  padding: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-3);
}

.range-axis-scale {
  position: relative;
  height: 12px;
}

.range-axis-scale span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}

.range-row {
  display: grid;
  grid-template-columns: minmax(0, var(--range-label, 30%)) minmax(0, 1fr) 64px;
  align-items: center;
  gap: 14px;
  padding: 7px 0;
  border-top: 1px solid var(--line-1);
  font-size: 12.5px;
}

.range-row.clickable {
  cursor: pointer;
}

.range-row.clickable:hover .range-name {
  text-decoration: underline;
  text-decoration-color: var(--line-3);
  text-underline-offset: 3px;
}

.range-name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--fg-1);
}

.range-track {
  position: relative;
  height: 18px;
}

.range-track::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--viz-grid);
}

.range-span {
  position: absolute;
  top: 50%;
  height: 2px;
  margin-top: -1px;
  background: linear-gradient(90deg, var(--viz-1), var(--viz-4));
  transform-origin: right;
  animation: bar-x 800ms var(--ease) both;
}

.range-dot {
  position: absolute;
  top: 50%;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border-radius: 50%;
}

.range-dot.grey {
  background: var(--viz-1);
  box-shadow: 0 0 0 3px var(--surface-1);
}

.range-dot.msrp {
  border: 1.5px solid var(--viz-3);
  background: var(--surface-1);
}

.range-dot.auth {
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 1px;
  background: var(--viz-3);
  transform: rotate(45deg);
}

.range-value {
  text-align: right;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-1);
  font-variant-numeric: tabular-nums;
}

/* --- Gauge & donut ------------------------------------------------------- */

.gauge {
  position: relative;
  display: grid;
  place-items: center;
}

.gauge svg {
  display: block;
}

.gauge-track {
  fill: none;
  stroke: var(--viz-6);
}

.gauge-tick {
  stroke: var(--viz-4);
  stroke-width: 1;
}

.gauge-tick.major {
  stroke: var(--viz-3);
}

.gauge-value {
  fill: none;
  stroke: var(--viz-1);
  stroke-linecap: butt;
  stroke-dasharray: var(--len) var(--len);
  stroke-dashoffset: var(--off);
  animation: gauge-fill 1400ms var(--ease) both;
}

@keyframes gauge-fill {
  from {
    stroke-dashoffset: var(--len);
  }
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.gauge-num {
  font-size: 40px;
  font-weight: 500;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.gauge-num small {
  font-size: 18px;
  color: var(--fg-3);
  margin-left: 1px;
  letter-spacing: 0;
}

.gauge-cap {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-3);
}

.donut-seg {
  fill: none;
  animation: fade-in 900ms var(--ease) both;
}

/* --- Vertical histogram -------------------------------------------------- */

.histo {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
}

.histo-col {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  height: 100%;
  min-width: 0;
}

.histo-bar {
  width: 100%;
  border-radius: 2px 2px 0 0;
  background: var(--viz-1);
  min-height: 2px;
  transform-origin: bottom;
  animation: bar-grow 700ms var(--ease) both;
}

.histo-bar.t2 { background: var(--viz-2); }
.histo-bar.t3 { background: var(--viz-3); }
.histo-bar.t4 { background: var(--viz-4); }

.histo-val {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-2);
}

.histo-lab {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-3);
  white-space: nowrap;
}

/* --- Heat matrix --------------------------------------------------------- */

.heat {
  display: grid;
  gap: 3px;
  align-items: center;
}

.heat-label {
  font-size: 12px;
  color: var(--fg-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.heat-cell {
  height: 16px;
  border-radius: 2px;
  background: var(--viz-6);
}

.heat-cell[data-v="1"] { background: var(--viz-5); }
.heat-cell[data-v="2"] { background: var(--viz-4); }
.heat-cell[data-v="3"] { background: var(--viz-3); }
.heat-cell[data-v="4"] { background: var(--viz-2); }
.heat-cell[data-v="5"] { background: var(--viz-1); }

.heat-col-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--fg-3);
  text-align: center;
  white-space: nowrap;
}

/* --- Tile map ------------------------------------------------------------ */

.tilemap {
  display: grid;
  grid-template-columns: repeat(var(--tm-cols, 12), minmax(0, 1fr));
  gap: 4px;
}

.tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--r-xs);
  border: 1px solid var(--line-1);
  background: transparent;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-4);
  transition: transform var(--dur-1) var(--ease);
}

.tile[data-v] {
  color: var(--fg-1);
  border-color: var(--line-2);
}

.tile[data-v="1"] { background: var(--viz-6); }
.tile[data-v="2"] { background: var(--viz-5); }
.tile[data-v="3"] { background: var(--viz-4); }
.tile[data-v="4"] {
  background: var(--viz-2);
  color: var(--canvas);
}
.tile[data-v="5"] {
  background: var(--viz-1);
  color: var(--canvas);
  border-color: var(--viz-1);
}

.tile.home {
  box-shadow: inset 0 0 0 1px var(--fg-2);
}

.tile.home::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: currentColor;
}

.tile:hover {
  transform: scale(1.06);
  z-index: 1;
}

/* --- Network graph ------------------------------------------------------- */

.network {
  position: relative;
  width: 100%;
  cursor: grab;
}

.network.dragging {
  cursor: grabbing;
}

.net-link {
  stroke: var(--viz-4);
  stroke-width: 1;
  transition: opacity var(--dur-2) var(--ease), stroke var(--dur-2) var(--ease);
}

.net-node {
  cursor: pointer;
  transition: opacity var(--dur-2) var(--ease);
}

.net-node .n-core {
  stroke: var(--surface-1);
  stroke-width: 2;
}

.net-node.seller.s-crit .n-core {
  fill: var(--viz-1);
}

.net-node.seller.s-warn .n-core {
  fill: url(#net-hatch);
  stroke: var(--viz-2);
  stroke-width: 1.25;
}

.net-node.seller.s-ok .n-core {
  fill: var(--surface-1);
  stroke: var(--viz-3);
  stroke-width: 1.5;
}

.net-node.product .n-core {
  fill: var(--viz-3);
  stroke-width: 1.5;
}

.net-node.brand .n-core {
  fill: var(--inv-bg);
  stroke: var(--surface-1);
  stroke-width: 3;
}

.net-node .n-halo {
  fill: none;
  stroke: var(--viz-4);
  stroke-dasharray: 2 3;
}

.net-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  fill: var(--fg-2);
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--surface-1);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.net-label.brand {
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  fill: var(--fg-1);
}

.net-label.product {
  font-size: 9.5px;
  fill: var(--fg-3);
  opacity: 0;
  transition: opacity var(--dur-2) var(--ease);
}

.network.focus .net-link {
  opacity: 0.12;
}

.network.focus .net-link.hl {
  opacity: 1;
  stroke: var(--viz-1);
}

.network.focus .net-node {
  opacity: 0.18;
}

.network.focus .net-node.hl {
  opacity: 1;
}

.network.focus .net-node.hl + .net-label.product,
.network .net-label.product.show {
  opacity: 1;
}

.network.focus .net-label {
  opacity: 0.2;
}

.network.focus .net-label.hl {
  opacity: 1;
}

.net-legend {
  position: absolute;
  left: 12px;
  bottom: 10px;
  pointer-events: none;
}

/* --- Sankey & scatter -------------------------------------------------------- */

.sk-link {
  fill: none;
  stroke: var(--viz-3);
  stroke-opacity: 0.28;
  transition: stroke-opacity var(--dur-1) var(--ease);
}

.sk-link:hover {
  stroke-opacity: 0.6;
}

.sk-node {
  cursor: default;
}

.sk-node[data-open-seller],
.sk-node[data-nav] {
  cursor: pointer;
}

.sk-label {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--fg-1);
  paint-order: stroke;
  stroke: var(--surface-1);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

.sk-val {
  fill: var(--fg-3);
}

.sc-dot {
  transition: r var(--dur-1) var(--ease);
}

.sc-dot:hover {
  r: 6.5;
}
