/* ==========================================================================
   Page · K10 Data Visualization
   Charts are plain HTML/CSS bars plus inline SVG for lines and flows.
   Data values sit in the markup as custom properties (--h, --x, --f …).
   ========================================================================== */

/* ---- Page frame --------------------------------------------------------- */

/* chart sections sit tighter than regular kit sections */
.viz-section {
  padding-top: 48px;
  padding-bottom: 48px;
}

/* two charts side by side, stacking below ~1000px */
.viz-pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr));
  gap: 40px;
}

.viz-figure {
  margin: 0;
}

/* ---- Figure texts ------------------------------------------------------- */

.fig-label {
  margin-bottom: 6px;
  font: 500 12px/1 var(--f-mono);
  color: var(--muted);
}

.fig-label--lg {
  margin-bottom: 16px;
}

.fig-title {
  margin: 0 0 20px;
  font: 700 26px/1 var(--f-display);
  text-transform: uppercase;
}

.fig-caption {
  margin-top: 8px;
  font: 400 12px/1.5 var(--f-mono);
  color: var(--muted);
}

.fig-caption--gap {
  margin-top: 12px;
}

/* SVG layer stretched over an HTML plot area (0…100 viewBox units) */
.viz-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* time / category ticks under a chart */
.viz-axis {
  display: flex;
  justify-content: space-between;
  font: 400 11px var(--f-mono);
  color: var(--muted);
}

/* bars grow once on load: k10-data-viz.js adds .is-collapsed to every
   [data-grow] chart, then removes it (after 300 ms, at once with reduced motion) */
.grow-bar {
  transform-origin: bottom;
}

.is-collapsed .grow-bar {
  transform: scaleY(0);
  transition: none;
}

/* ---- V.01 · KPI tiles --------------------------------------------------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 1px;
  background: var(--line-strong);
  border: 1px solid var(--line-strong);
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 18px;
  background: var(--canvas);
}

.kpi__head {
  display: flex;
  justify-content: space-between;
  font: 500 11px/1 var(--f-mono);
  letter-spacing: .06em;
  color: var(--ink-2);
}

.kpi__value {
  font: 800 48px/1 var(--f-display);
}

.kpi__unit {
  margin-left: 4px;
  font: 500 16px var(--f-mono);
  color: var(--ink-2);
}

.kpi__spark {
  display: block;
  width: 100%;
  height: 28px;
}

.kpi__spark polyline {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.kpi__source {
  font: 400 11px var(--f-mono);
  color: var(--muted);
}

/* ---- V.02 · OEE waterfall ----------------------------------------------- */

.waterfall {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  align-items: end;
  height: 240px;
  margin-top: 28px;
  border-bottom: 1.5px solid var(--ink);
}

.waterfall__col {
  position: relative;
  height: 100%;
}

.waterfall__bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--bottom);
  height: var(--h);
  transition: transform 600ms var(--ease-servo) var(--delay);
}

/* losses carry a pattern as well as a color */
.waterfall__bar--planned      { background: var(--ink-2); }
.waterfall__bar--availability { background: var(--sig-red); background-image: repeating-linear-gradient(0deg, rgba(0, 0, 0, .35) 0 2px, transparent 2px 4px); }
.waterfall__bar--performance  { background: var(--sig-yellow); background-image: repeating-linear-gradient(45deg, rgba(0, 0, 0, .3) 0 2px, transparent 2px 5px); }
.waterfall__bar--quality      { background: var(--dv-2); }
.waterfall__bar--oee          { background: var(--sig-green); }

.waterfall__value {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--top) + 4px);
  text-align: center;
  font: 500 13px var(--f-mono);
}

.waterfall__labels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 8px;
  font: 400 11px/1.3 var(--f-mono);
  color: var(--ink-2);
}

.waterfall__labels-total {
  color: var(--ink);
  font-weight: 500;
}

/* text alternative disclosure under a chart */
.text-alt {
  margin-top: 8px;
  font-size: 14px;
  color: var(--ink-2);
}

.text-alt__toggle {
  cursor: pointer;
  font: 500 12px var(--f-mono);
}

/* ---- V.03 · Torque–speed characteristic -------------------------------- */

.torque-chart {
  position: relative;
  height: 240px;
  border-left: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 25% 25%;
}

.torque-chart__rated,
.torque-chart__max {
  fill: none;
  vector-effect: non-scaling-stroke;
}

.torque-chart__rated {
  stroke: var(--dv-1);
  stroke-width: 2.5;
}

.torque-chart__max {
  stroke: var(--dv-2);
  stroke-width: 2;
  stroke-dasharray: 4 3;
}

.torque-chart__axis {
  position: absolute;
  font: 400 11px var(--f-mono);
  color: var(--ink-2);
}

.torque-chart__axis--y {
  left: 8px;
  top: 6px;
}

.torque-chart__axis--x {
  right: 6px;
  bottom: 6px;
}

.torque-chart__tick {
  position: absolute;
  font: 400 11px var(--f-mono);
}

.torque-chart__tick--y-max {
  left: -36px;
  top: -6px;
}

.torque-chart__tick--y-min {
  left: -36px;
  bottom: -6px;
}

.torque-chart__tick--x-max {
  right: 0;
  bottom: -20px;
}

/* legend for line charts: solid = typical, dashed = maximum */
.line-legend {
  display: flex;
  gap: 20px;
  margin-top: 28px;
  font: 500 12px var(--f-mono);
}

.line-legend > span {
  display: flex;
  gap: 6px;
  align-items: center;
}

.line-legend__key {
  width: 20px;
}

.line-legend__key--rated {
  height: 3px;
  background: var(--dv-1);
}

.line-legend__key--max {
  height: 0;
  border-top: 2px dashed var(--dv-2);
}

/* ---- V.04 · Machine-state timeline ------------------------------------- */

.machine-timelines {
  display: grid;
  gap: 8px;
}

.machine-timeline {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 12px;
  align-items: center;
}

.machine-timeline--axis {
  align-items: stretch;
}

.machine-timeline__name {
  font: 500 12px var(--f-mono);
}

/* tracks and legend: .machine-state-track / .machine-state-legend */
.machine-timelines__legend {
  --key-size: 14px;
  margin-top: 14px;
}

/* ---- V.05 · SPC control chart ------------------------------------------ */

.spc-chart {
  position: relative;
  height: 220px;
  border-left: 1.5px solid var(--ink);
  border-bottom: 1.5px solid var(--ink);
}

.spc-chart__limit {
  position: absolute;
  left: 0;
  right: 0;
}

.spc-chart__limit--ucl {
  top: 12%;
  border-top: 1.5px dashed var(--sig-red);
}

.spc-chart__limit--mean {
  top: 50%;
  border-top: 1px solid var(--line-strong);
}

.spc-chart__limit--lcl {
  top: 88%;
  border-top: 1.5px dashed var(--sig-red);
}

.spc-chart__limit-label {
  position: absolute;
  right: 0;
  font: 500 11px var(--f-mono);
  color: var(--sig-red);
}

.spc-chart__limit-label--ucl {
  top: calc(12% - 16px);
}

.spc-chart__limit-label--mean {
  top: calc(50% - 16px);
  color: var(--ink-2);
}

.spc-chart__limit-label--lcl {
  top: calc(88% - 16px);
}

.spc-chart__line {
  fill: none;
  stroke: var(--ink-2);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}

.spc-chart__point {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  background: var(--ink);
  clip-path: circle(50%);
}

/* out of control: red diamond */
.spc-chart__point--out {
  background: var(--sig-red);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

/* ---- V.06 · Pareto ------------------------------------------------------ */

.pareto {
  position: relative;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  align-items: end;
  height: 220px;
  border-bottom: 1.5px solid var(--ink);
}

.pareto__bar {
  position: relative;
  height: var(--h);
  background: var(--dv-1);
  transition: transform 600ms var(--ease-servo) var(--delay);
}

.pareto__value {
  position: absolute;
  top: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font: 500 11px var(--f-mono);
}

.pareto__cumulative {
  fill: none;
  stroke: var(--dv-2);
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}

.pareto__labels {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin-top: 8px;
  font: 400 11px/1.3 var(--f-mono);
  color: var(--ink-2);
}

/* ---- V.07 · Capacity heatmap ------------------------------------------- */

.heatmap {
  display: grid;
  grid-template-columns: 70px repeat(3, 1fr);
  gap: 3px;
  font: 500 12px var(--f-mono);
}

.heatmap__shift {
  text-align: center;
}

.heatmap__machine,
.heatmap__cell {
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0 8px;
}

.heatmap__machine {
  justify-content: flex-start;
  color: var(--ink);
}

.heatmap__cell {
  justify-content: center;
}

/* sequential blue scale; "off" = machine not scheduled */
.heatmap__cell--off  { background: var(--surface); color: var(--muted); }
.heatmap__cell--low  { background: #B6CCEA; color: #0B0C0D; }
.heatmap__cell--mid  { background: #7FA5D8; color: #0B0C0D; }
.heatmap__cell--high { background: #0F4C9A; color: #FFFFFF; }
.heatmap__cell--max  { background: #08305F; color: #FFFFFF; }

.heatmap__scale {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  font: 400 11px var(--f-mono);
  color: var(--ink-2);
}

.heatmap__ramp {
  flex: 1;
  max-width: 200px;
  height: 10px;
  background: linear-gradient(90deg, #E3ECF7, #7FA5D8, #0F4C9A, #08305F);
}

/* ---- V.08 · Energy load profile ---------------------------------------- */

.load-profile {
  display: flex;
  gap: 2px;
  align-items: end;
  height: 200px;
  padding-left: 2px;
  border-bottom: 1.5px solid var(--ink);
  border-left: 1.5px solid var(--ink);
}

.load-profile__bar {
  flex: 1;
  height: var(--h);
  background: var(--dv-1);
  transition: transform 300ms var(--ease-index) var(--delay);
}

.load-profile__bar--peak {
  background: var(--accent);
}

.viz-axis--load {
  margin-top: 6px;
}

/* ---- V.09 · Sankey ------------------------------------------------------ */

.sankey {
  position: relative;
  height: 220px;
}

.sankey__svg {
  display: block;
  width: 100%;
  height: 100%;
}

.sankey__label {
  position: absolute;
  font: 500 11px var(--f-mono);
}

.sankey__label--grid {
  left: 18px;
  top: 4px;
}

.sankey__label--spindles {
  left: 52%;
  top: 4px;
}

.sankey__label--hvac {
  left: 52%;
  top: 49%;
}

.sankey__label--air {
  left: 52%;
  top: 77%;
}

.sankey__label--recovery {
  right: 0;
  top: 40%;
  text-align: right;
}

/* ---- V.10 · Gantt ------------------------------------------------------- */

.gantt {
  display: grid;
  gap: 6px;
}

.gantt__row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  align-items: center;
}

.gantt__row--axis {
  align-items: stretch;
}

.gantt__task {
  font-size: 14px;
}

.gantt__track {
  position: relative;
  height: 22px;
  background: var(--surface);
}

.gantt__bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--start);
  width: var(--len);
  clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
}

.gantt__bar--supplier { background: var(--ink-2); }
.gantt__bar--customer { background: var(--action); }  /* action required by the customer */
.gantt__bar--site     { background: var(--ink); }
.gantt__bar--rampup   { background: var(--sig-green); }

/* ---- V.11 · Data table -------------------------------------------------- */

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
  margin: 12px 0 16px;
}

.table-toolbar__count {
  font: 500 13px var(--f-mono);
}

.table-toolbar__actions {
  display: flex;
  gap: 8px;
}

/* static specimens of the bulk actions */
.table-toolbar__action {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  font: 600 13px var(--f-text);
  text-transform: uppercase;
}

.table-toolbar__action--bulk {
  border: 0;
  background: var(--panel);
}

.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line-strong);
}

/* a real <table> laid out with CSS grid rows, so the columns can use
   fr units (44px 1.2fr 1fr 1fr 1fr) — table semantics are kept */
.data-table {
  display: block;
  min-width: 640px;
  font: 400 14px/1.3 var(--f-mono);
}

.data-table thead,
.data-table tbody {
  display: block;
}

.data-table tr {
  display: grid;
  grid-template-columns: 44px 1.2fr repeat(3, 1fr);
}

.data-table th {
  padding: 0;
  background: var(--ink);
  color: var(--canvas);
  font-weight: inherit;
  text-align: left;
}

.data-table td {
  padding: 10px 14px;
}

.data-table .num {
  text-align: right;
}

.data-table__sort {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: none;
  color: inherit;
  font: 500 13px var(--f-mono);
  text-align: inherit;
  cursor: pointer;
}

.data-table__row {
  border-top: 1px solid var(--line);
}

.data-table__row--selected {
  background: rgba(15, 76, 154, .08);
}

.data-table .data-table__check {
  padding: 0;
}

/* row selection checkbox (role="checkbox", state in aria-checked) */
.row-check {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border: 0;
  background: none;
  cursor: pointer;
}

.row-check__box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--ink);
  color: var(--action-ink);
  font-size: 12px;
}

.row-check[aria-checked="true"] .row-check__box {
  background: var(--action);
}

/* ---- Chart rules -------------------------------------------------------- */

.chart-rules__title {
  margin-bottom: 24px;
}

.chart-rules {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 1px;
  background: var(--line-strong);
  border: 1px solid var(--line-strong);
}

.chart-rule {
  padding: 18px;
  background: var(--canvas);
}

.chart-rule__title {
  font: 700 20px var(--f-display);
  text-transform: uppercase;
}

.chart-rule__text {
  margin: 6px 0 0;
  font-size: 14px;
  color: var(--ink-2);
}
