/* DECODE — components
   Buttons, selects, inputs, sliders, toggles, readouts, verdicts, tooltips, swatches.
   Color is reserved for data. Controls are ink on graphite with hairlines. */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: 0 var(--space-4);
  font-size: var(--step-0);
  font-weight: 500;
  line-height: 1;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-input);
  text-decoration: none;
  white-space: nowrap;
  transition:
    color var(--dur-micro) var(--ease-out),
    background-color var(--dur-micro) var(--ease-out),
    border-color var(--dur-micro) var(--ease-out);
}

.btn:hover {
  color: var(--ink);
  border-color: var(--hairline-strong);
}

.btn:active {
  background: var(--panel-2);
}

.btn--primary {
  color: var(--ink);
  background: var(--panel-2);
  border-color: var(--hairline-strong);
}

.btn--primary:hover {
  background: var(--panel-3);
}

.btn--small {
  min-height: 28px;
  padding: 0 var(--space-3);
  font-size: var(--step--1);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  color: var(--ink-3);
  border-color: var(--hairline);
  background: transparent;
  cursor: not-allowed;
}

.btn__icon {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: square;
}

/* ---------- Fields ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.field__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--ink-2);
}

.field__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--step--1);
  color: var(--ink);
}

.field__hint {
  font-size: var(--step--1);
  color: var(--ink-3);
}

/* Hints filled in by script keep one line of height from the start, so the
   controls do not shift when the data arrives. */
.field__hint[data-machine-hint],
.field__hint[data-model-hint],
.field__hint[data-quant-hint],
.field__hint[data-ctx-hint] {
  min-height: calc(var(--step--1) * 1.55);
}

.field__row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: var(--space-3);
}

/* ---------- Select ---------- */
.select {
  position: relative;
  display: block;
}

.select__input {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-7) 0 var(--space-3);
  appearance: none;
  -webkit-appearance: none;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-input);
  font-size: var(--step-0);
  line-height: 1.2;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: border-color var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out);
}

.select__input:hover {
  background: var(--panel-3);
}

.select__input:disabled {
  color: var(--ink-3);
  cursor: not-allowed;
}

.select::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--ink-2);
  border-bottom: 1.5px solid var(--ink-2);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.select__input optgroup {
  color: var(--ink-2);
  background: var(--panel-1);
}

.select__input option {
  color: var(--ink);
  background: var(--panel-1);
}

/* ---------- Text / number input ---------- */
.input {
  width: 100%;
  min-height: 40px;
  padding: 0 var(--space-3);
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-input);
  font-size: var(--step-0);
  transition: border-color var(--dur-micro) var(--ease-out);
}

.input--num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.input::placeholder {
  color: var(--ink-3);
}

.input[aria-invalid="true"] {
  border-color: var(--fail);
}

.input:hover {
  border-color: var(--ink-3);
}

.input:disabled {
  color: var(--ink-3);
  cursor: not-allowed;
}

/* Remove number spinners; a printed value is the readout, not the spinner. */
.input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.input[type="number"]::-webkit-outer-spin-button,
.input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-unit {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 0;
}

.input-unit .input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
}

.input-unit__unit {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  padding: 0 var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-2);
  background: var(--panel-1);
  border: 1px solid var(--hairline-strong);
  border-top-right-radius: var(--radius-input);
  border-bottom-right-radius: var(--radius-input);
}

/* ---------- Slider with detents and printed value ---------- */
.slider {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-2);
}

.slider__input {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

.slider__input::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--hairline-strong);
}

.slider__input::-moz-range-track {
  height: 2px;
  background: var(--hairline-strong);
}

.slider__input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 10px;
  height: 20px;
  margin-top: -9px;
  background: var(--ink);
  border: 0;
  border-radius: 2px;
  box-shadow: 0 0 0 3px var(--panel-0);
  transition: transform var(--dur-micro) var(--ease-out);
}

.slider__input::-moz-range-thumb {
  width: 10px;
  height: 20px;
  background: var(--ink);
  border: 0;
  border-radius: 2px;
  box-shadow: 0 0 0 3px var(--panel-0);
}

.slider__input:active::-webkit-slider-thumb {
  transform: scaleX(1.3);
}

.slider__input:focus-visible {
  outline: none;
}

.slider__input:focus-visible::-webkit-slider-thumb {
  outline: var(--focus-ring);
  outline-offset: 3px;
}

.slider__input:focus-visible::-moz-range-thumb {
  outline: var(--focus-ring);
  outline-offset: 3px;
}

/* Detent marks: a printed scale under the track */
.slider__scale {
  display: flex;
  justify-content: space-between;
  padding: 0 4px;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--step--1);
  color: var(--ink-3);
  line-height: 1;
  user-select: none;
}

.slider__tick {
  position: relative;
  padding-top: 8px;
}

.slider__tick::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 1px;
  height: 5px;
  background: var(--hairline-strong);
}

.slider__tick:first-child { text-align: left; }
.slider__tick:last-child { text-align: right; }

/* ---------- Segmented toggle with detents ---------- */
.seg {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  width: 100%;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-input);
  background: var(--panel-1);
  overflow: hidden;
}

.seg__option {
  position: relative;
  min-width: 0;
}

.seg__option + .seg__option {
  border-left: 1px solid var(--hairline);
}

.seg__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.seg__label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  min-height: 38px;
  padding: 0 var(--space-3);
  font-size: var(--step-0);
  font-weight: 500;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: color var(--dur-micro) var(--ease-out), background-color var(--dur-micro) var(--ease-out);
}

.seg__label .num {
  font-size: var(--step-0);
}

.seg__label:hover {
  color: var(--ink);
}

.seg__input:checked + .seg__label {
  color: var(--ink);
  background: var(--panel-2);
  box-shadow: inset 0 -2px 0 var(--ink);
}

.seg__input:focus-visible + .seg__label {
  outline: var(--focus-ring);
  outline-offset: -3px;
}

.seg__input:disabled + .seg__label {
  color: var(--ink-3);
  cursor: not-allowed;
}

/* ---------- Switch (boolean) with printed state ---------- */
.switch {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  user-select: none;
}

.switch__input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}

.switch__track {
  position: relative;
  width: 40px;
  height: 22px;
  background: var(--panel-2);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-input);
  transition: background-color var(--dur-ui) var(--ease-out);
}

.switch__track::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  background: var(--ink-3);
  border-radius: 2px;
  transition: transform var(--dur-ui) var(--ease-out), background-color var(--dur-ui) var(--ease-out);
}

.switch__input:checked + .switch__track::before {
  transform: translateX(18px);
  background: var(--ink);
}

.switch__input:focus-visible + .switch__track {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.switch__state {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-2);
  min-width: 2.5ch;
  white-space: nowrap;
}

.switch__input:checked ~ .switch__state {
  color: var(--ink);
}

.switch__text {
  font-size: var(--step-0);
  font-weight: 500;
  color: var(--ink-2);
}

/* ---------- Readout: label / value / unit ---------- */
.readout {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.readout__label {
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--ink-2);
}

.readout__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-weight: 400;
  font-size: var(--step-4);
  line-height: var(--leading-flat);
  color: var(--ink);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.readout__unit {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-2);
  margin-left: 0.4em;
  letter-spacing: 0;
}

.readout__note {
  font-size: var(--step--1);
  color: var(--ink-3);
}

.readout--sm .readout__value { font-size: var(--step-2); }
.readout--lg .readout__value { font-size: var(--step-6); letter-spacing: -0.02em; }
.readout--xl .readout__value { font-size: var(--step-7); letter-spacing: -0.03em; }

.readout--muted .readout__value {
  color: var(--ink-3);
}

.readout__range {
  color: var(--ink-3);
  font-size: 0.7em;
  margin-inline: 0.15em;
}

/* Data-tinted readouts: color only when it means the thing */
.readout--weights .readout__value { color: var(--weights); }
.readout--cache .readout__value { color: var(--cache); }
.readout--room .readout__value { color: var(--room); }
.readout--overhead .readout__value { color: var(--overhead); }

.readout-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-5);
}

/* ---------- Verdict badge ---------- */
.verdict {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--step-4);
  font-weight: 500;
  line-height: var(--leading-flat);
  letter-spacing: -0.01em;
  color: var(--ink);
}

.verdict__icon {
  width: 0.9em;
  height: 0.9em;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.verdict--fits { color: var(--room); }
.verdict--tight { color: var(--warn); }
.verdict--wont-fit { color: var(--fail); }
.verdict--unknown { color: var(--ink-3); }

.verdict--lg {
  font-size: var(--step-6);
}

.verdict__reason {
  font-size: var(--step-1);
  color: var(--ink-2);
  max-width: 52ch;
}

/* ---------- Tooltip (glossary) ---------- */
.tip {
  position: relative;
  display: inline;
}

.tip__term {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: help;
  text-decoration: underline dotted;
  text-decoration-color: var(--ink-3);
  text-underline-offset: 0.2em;
}

.tip__body {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 20;
  width: max-content;
  max-width: 32ch;
  padding: var(--space-3) var(--space-4);
  font-size: var(--step--1);
  line-height: 1.45;
  color: var(--ink);
  background: var(--panel-2);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--radius-panel);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity var(--dur-micro) var(--ease-out), transform var(--dur-micro) var(--ease-out), visibility 0s linear var(--dur-micro);
}

.tip:hover .tip__body,
.tip:focus-within .tip__body {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition-delay: 0s;
}

/* ---------- Swatches and legend ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-5);
  font-size: var(--step--1);
  color: var(--ink-2);
  list-style: none;
  padding: 0;
  margin: 0;
}

.legend__item {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.legend__value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  min-width: 6ch;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 1px;
  background: var(--ink-3);
  flex: 0 0 auto;
}

.swatch--weights { background: var(--weights); }
.swatch--cache { background: var(--cache); }
.swatch--overhead { background: var(--overhead); }
.swatch--room { background: var(--room); }
.swatch--fail { background: var(--fail); }

/* ---------- Notice (inline, quiet) ---------- */
.notice {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  font-size: var(--step-0);
  color: var(--ink-2);
}

.notice__key {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-3);
  padding-top: 0.15em;
}

/* ---------- Definition list ---------- */
.dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: var(--space-2) var(--space-5);
  font-size: var(--step-0);
}

.dl dt {
  color: var(--ink-2);
}

.dl dd {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

/* ---------- Table on mobile: rows become definition lists ---------- */
@media (max-width: 720px) {
  .table--stack thead {
    display: none;
  }

  .table--stack tr {
    display: block;
    padding-block: var(--space-3);
    border-bottom: 1px solid var(--hairline);
  }

  .table--stack td {
    display: grid;
    grid-template-columns: minmax(0, 9em) 1fr;
    gap: var(--space-3);
    padding: var(--space-1) 0;
    border: 0;
    text-align: left;
  }

  .table--stack td::before {
    content: attr(data-label);
    color: var(--ink-2);
    font-size: var(--step--1);
  }
}
