/*
 * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 *
 * The waveform explorer of the operations guide (waveform-explorer.js). Colors
 * follow the theme's light and dark modes; Q is dashed as well as colored.
 * Muted text is at least 7:1 against the page in both modes (WCAG AA is 4.5:1).
 */

.pulse-waveform-explorer {
  --pwe-i: #5b8c00;
  --pwe-q: #3d6fa3;
  --pwe-muted: #4f565d;
  --pwe-env: #5f666d;
  border: 1px solid var(--pst-color-border, #c8c8c8);
  border-radius: 0.25rem;
  padding: 0.75rem 1rem;
  margin: 1rem 0 1.5rem;
}

.pulse-waveform-explorer:empty {
  display: none;
}

html[data-theme="dark"] .pulse-waveform-explorer {
  --pwe-i: #76b900;
  --pwe-q: #8fb8e8;
  --pwe-muted: #c4c9d0;
  --pwe-env: #d2d6dc;
}

.pulse-waveform-explorer [hidden] {
  display: none !important;
}

/* Every control is a cell of one grid, which fills two even columns where
   two cells fit side by side and one otherwise; a cell is its label, the
   control, and its value. */
.pulse-waveform-explorer .pwe-controls {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 27rem), 1fr));
  gap: 0.35rem 1.5rem;
  align-items: center;
}

.pulse-waveform-explorer .pwe-group {
  display: contents;
}

/* The value column is 12.5rem where the row has room. In a shorter row, as
   beside both sidebars at a larger text size, it gives way before anything
   is cut, and a unit wraps under its number field. */
.pulse-waveform-explorer .pwe-field {
  display: grid;
  grid-template-columns: 7rem minmax(6rem, 1fr) minmax(0, 12.5rem);
  align-items: center;
  gap: 0.5rem;
  min-height: 2rem;
}

/* A label wider than its column, as with wider letter spacing, breaks
   inside a word and stays clear of the control. */
.pulse-waveform-explorer .pwe-field > :first-child {
  margin: 0;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.pulse-waveform-explorer input[type="range"],
.pulse-waveform-explorer select,
.pulse-waveform-explorer .pwe-field .pwe-button {
  width: 100%;
  min-width: 0;
  margin: 0;
  box-sizing: border-box;
}

/* Sliders and number fields are targets at least 24px high. */
.pulse-waveform-explorer input[type="range"] {
  accent-color: var(--pwe-i);
  min-height: 1.5rem;
}

/* A slider's value: the number field to type it into, then its unit, which
   wraps under the field where the line is short. */
.pulse-waveform-explorer .pwe-entry {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.1rem 0.35rem;
}

/* At 1rem like the selects: phone browsers zoom the page in on a field with
   smaller text when it takes the focus. */
.pulse-waveform-explorer input[type="number"] {
  width: 4.5rem;
  min-height: 1.5rem;
  margin: 0;
  box-sizing: border-box;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.pulse-waveform-explorer input[type="checkbox"] {
  justify-self: start;
  margin: 0;
}

.pulse-waveform-explorer .pwe-entry,
.pulse-waveform-explorer .pwe-value {
  font-size: 0.9em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.pulse-waveform-explorer .pwe-value {
  color: var(--pwe-muted);
}

.pulse-waveform-explorer select,
.pulse-waveform-explorer input[type="number"],
.pulse-waveform-explorer .pwe-button {
  color: var(--pst-color-text-base, inherit);
  background: var(--pst-color-surface, transparent);
  border: 1px solid var(--pst-color-border, #c8c8c8);
  border-radius: 0.25rem;
  padding: 0.1rem 0.4rem;
}

/* A text field is found by its edge: the muted color, at least 7:1 against
   the page in both modes. */
.pulse-waveform-explorer input[type="number"] {
  border-color: var(--pwe-muted);
}

.pulse-waveform-explorer .pwe-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.pulse-waveform-explorer svg {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 0.75rem;
  color: var(--pst-color-text-base, currentColor);
}

/* The script draws the plot in CSS pixels at the width of its box, so this
   is the size on screen at any width. */
.pulse-waveform-explorer svg text {
  fill: currentColor;
  font-size: 12px;
}

.pulse-waveform-explorer .pwe-axes line {
  stroke: currentColor;
  stroke-opacity: 0.6;
}

.pulse-waveform-explorer .pwe-axes .pwe-zero {
  stroke-opacity: 0.35;
}

.pulse-waveform-explorer .pwe-axes .pwe-gridline {
  stroke-opacity: 0.12;
}

.pulse-waveform-explorer polyline {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
}

.pulse-waveform-explorer polyline.pwe-i {
  stroke: var(--pwe-i);
}

.pulse-waveform-explorer polyline.pwe-q {
  stroke: var(--pwe-q);
  stroke-dasharray: 6 4;
}

.pulse-waveform-explorer polyline.pwe-env {
  stroke: var(--pwe-env);
  stroke-width: 1.5;
  stroke-dasharray: 3 3;
}

.pulse-waveform-explorer .pwe-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
}

.pulse-waveform-explorer .pwe-key::before {
  content: "";
  display: inline-block;
  width: 1.75rem;
  margin-right: 0.4rem;
  vertical-align: middle;
  border-top: 2px solid var(--pwe-i);
}

.pulse-waveform-explorer .pwe-key-q::before {
  border-top: 2px dashed var(--pwe-q);
}

.pulse-waveform-explorer .pwe-key-env::before {
  border-top: 2px dotted var(--pwe-env);
}

.pulse-waveform-explorer .pwe-code {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.pulse-waveform-explorer .pwe-code pre {
  flex: 1 1 20rem;
  margin: 0;
  white-space: pre-wrap;
}

.pulse-waveform-explorer .pwe-note {
  color: var(--pwe-muted);
  font-size: 0.9em;
  margin: 0.25rem 0 0;
}

/* The note under a control runs the width of the grid. */
.pulse-waveform-explorer .pwe-controls .pwe-note {
  grid-column: 1 / -1;
  margin: 0;
}

/* Narrow screens: a cell is lines, not columns, so nothing is cut at a 320px
   screen: its label and value on the first line and the control at full
   width on the second. The label takes at most half the line and wraps; the
   value takes the rest, at the right, and wraps too. */
@media (max-width: 34rem) {
  .pulse-waveform-explorer .pwe-field {
    grid-template-columns: fit-content(50%) minmax(0, 1fr);
    row-gap: 0.2rem;
  }

  .pulse-waveform-explorer .pwe-field > :nth-child(2) {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .pulse-waveform-explorer .pwe-field > :nth-child(3) {
    justify-content: flex-end;
    text-align: end;
  }

  /* A slider's cell is three lines. Its number field is the next Tab stop
     after the slider, so it goes under the slider with its unit, not beside
     the label above: the keyboard then moves down the screen. */
  .pulse-waveform-explorer .pwe-field > .pwe-entry {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-content: flex-start;
  }

  /* The label of a slider has its line to itself. */
  .pulse-waveform-explorer .pwe-field:has(> .pwe-entry) > :first-child {
    grid-column: 1 / -1;
  }
}
