/* ============================================================================
   lap_animate htmlwidget styles
   ============================================================================
   Visual language: warm orange for workers (rows), cool blue for jobs (cols),
   green for the matching, red for the active augmenting path. Matches the
   palette used in the algorithms.Rmd vignette.
   ============================================================================ */

.couplr-lap-animate {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #3E3F3A;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}

.couplr-lap-animate * {
  box-sizing: border-box;
}

/* Top bar: algorithm name + step counter ----------------------------------- */
.couplr-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  border-bottom: 1px solid #E5E5E5;
  font-size: 13px;
}

/* Lock the two header rows to a single line so a long phase name or
   a growing "k / n matched" string never wraps and shifts header
   height between frames. */
.couplr-header > div {
  white-space: nowrap;
}

.couplr-header .algo-name {
  font-weight: 600;
  font-size: 14px;
}

.couplr-header .phase-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #F0F0F0;
  font-size: 11px;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Empty phase pill would still occupy padded space and shift the
   baseline of surrounding text; collapse it when there's no phase. */
.couplr-header .phase-badge:empty {
  display: none;
}

.couplr-header .step-counter {
  font-variant-numeric: tabular-nums;
  color: #777;
}

.couplr-header .match-counter {
  display: inline-block;
  margin-right: 8px;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(93, 214, 93, 0.18);
  color: #2E7D32;
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  font-weight: 600;
}

/* Main SVG canvas ---------------------------------------------------------- */
.couplr-canvas {
  flex: 1 1 auto;
  min-height: 200px;
  overflow: hidden;
  background: #FAFAFA;
}

.couplr-canvas svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Nodes -------------------------------------------------------------------
   Nodes sit at fixed slots; opacity is what changes per frame. Once a
   row/col is in the current matching it gets .matched and fades to a
   low opacity, so finished pairs recede while the algorithm's active
   work stays prominent. */
.couplr-node {
  stroke: #FFFFFF;
  stroke-width: 1.5;
  transition: opacity 280ms ease;
}

.couplr-node.row { fill: #E07B39; }
.couplr-node.col { fill: #3D8EAF; }

.couplr-node.matched { opacity: 0.25; }

.couplr-node-label {
  fill: #FFFFFF;
  font-weight: 600;
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  transition: opacity 280ms ease;
}

.couplr-node-label.matched { opacity: 0.25; }

.couplr-dual-label {
  fill: #3E3F3A;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* Edges -------------------------------------------------------------------
   The JS never creates a bare .couplr-edge — every edge is added with one
   of the modifier classes below. The base rule exists only so partial
   draw-in animations still show the right colour mid-transition. The
   x1/y1/x2/y2 transitions let edges follow their nodes when the slot
   permutation reshuffles after a new match. */
.couplr-edge {
  fill: none;
  stroke-linecap: round;
  transition: stroke 180ms ease, stroke-width 180ms ease, opacity 180ms ease;
}

/* Matched edges fade to a low-opacity green: they record the result but
   recede so the algorithm's active work (orange / red dashed) reads
   loud against them. Newly-matched edges get a brief inline opacity:1
   pulse from JS, then settle here. */
.couplr-edge.matched {
  stroke: #5DD65D;
  stroke-width: 2.4;
  opacity: 0.4;
}

.couplr-edge.active {
  stroke: #F39C12;
  stroke-width: 2.0;
  opacity: 1;
}

/* Path edges (red dashed) override the JS-set inline stroke-dasharray so
   the augmenting-path frames read as dashed rather than solid. !important
   beats the inline attribute that drives the draw-in animation. */
.couplr-edge.path {
  stroke: #E74C3C;
  stroke-width: 2.4;
  opacity: 1;
  stroke-dasharray: 4 2 !important;
}

.couplr-edge-cost {
  fill: #3E3F3A;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

/* Bottom panel: description + controls ------------------------------------ */
.couplr-footer {
  padding: 8px 12px;
  border-top: 1px solid #E5E5E5;
  font-size: 12px;
  background: #FFFFFF;
}

/* Fixed height so per-frame description length never reflows the footer.
   Without this, a 1-line -> 2-line -> 3-line transition between frames
   shrinks the canvas, the SVG (CSS 100% with fixed viewBox) rescales,
   and every node appears to jitter. Keep the content scrollable rather
   than letting the box grow. */
.couplr-description {
  height: 56px;
  margin-bottom: 8px;
  color: #3E3F3A;
  line-height: 1.4;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.couplr-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.couplr-controls button {
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  border: 1px solid #CCC;
  background: #FFFFFF;
  border-radius: 4px;
  cursor: pointer;
  color: #3E3F3A;
}

.couplr-controls button:hover {
  background: #F0F0F0;
}

.couplr-controls button:active {
  background: #E0E0E0;
}

.couplr-controls button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.couplr-controls .play-pause {
  min-width: 60px;
  font-weight: 600;
}

.couplr-controls .speed-control {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: #777;
}

.couplr-controls .speed-control input[type=range] {
  width: 100px;
}
