/* Number input — a numeric field with stepper buttons in a bordered cell.
   Markup: .govbb-number-input-wrapper holds the .govbb-number-input input and
   a .govbb-number-input__steppers column (two __step buttons around a
   __divider; the second carries --down). The steppers ship as styles only —
   consumers must wire their own JavaScript to make them change the value. */

.govbb-number-input-wrapper {
  display: grid;
  grid-template-columns: 1fr 2.9375rem;
  align-items: center;
  width: 100%;
  max-width: 11rem; /* 176px; shrinks with a narrower column */
  background: var(--govbb-color-surface);
  border: var(--govbb-border-width-form) solid var(--govbb-color-ink);
  border-radius: var(--govbb-radius);
  transition:
    box-shadow 0.2s,
    border-color 0.2s;
}

.govbb-number-input-wrapper:hover {
  box-shadow: var(--govbb-shadow-form-hover);
}

.govbb-number-input-wrapper:has([aria-invalid='true']) {
  border-color: var(--govbb-color-error);
}

.govbb-number-input-wrapper:has(
  .govbb-number-input:disabled,
  [aria-invalid='true']
) {
  box-shadow: none;
}

/* Keyboard focus ring: shared rule in focus.css. Because focus.css is
   imported after this file, it also restores the ring that the
   box-shadow:none above clears for invalid fields (WCAG 2.4.7). */

.govbb-number-input-wrapper:has(.govbb-number-input:disabled) {
  opacity: var(--govbb-opacity-disabled);
  cursor: not-allowed;
}

.govbb-number-input {
  grid-area: 1 / 1 / auto / -1;
  width: 100%;
  min-width: 0;
  padding: var(--govbb-space-s);
  padding-right: 2.9375rem;
  font: inherit;
  font-size: var(--govbb-font-size-body);
  font-variant-numeric: tabular-nums;
  line-height: var(--govbb-line-height-base);
  color: var(--govbb-color-ink);
  background: none;
  border: 0;
  border-radius: inherit;
  outline: 0;
  appearance: textfield;
}

/* Hide the native spinners — the styled steppers replace them. */
.govbb-number-input::-webkit-outer-spin-button,
.govbb-number-input::-webkit-inner-spin-button {
  margin: 0;
  appearance: none;
}

.govbb-number-input__steppers {
  display: flex;
  flex-direction: column;
  grid-area: 1 / 2;
  align-self: stretch;
  overflow: hidden;
  background: color-mix(
    in srgb,
    var(--govbb-color-neutral) 50%,
    var(--govbb-color-surface)
  );
  border-left: var(--govbb-border-width-form) solid var(--govbb-color-ink);
  border-start-end-radius: calc(
    var(--govbb-radius) - var(--govbb-border-width-form)
  );
  border-end-end-radius: calc(
    var(--govbb-radius) - var(--govbb-border-width-form)
  );
}

.govbb-number-input-wrapper:has([aria-invalid='true'])
  .govbb-number-input__steppers {
  border-left-color: var(--govbb-color-error);
}

.govbb-number-input__step {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--govbb-color-ink);
  background: none;
  border: 0;
  outline: 0;
  cursor: pointer;
  transition: background-color 0.15s;
}

/* The arrow: a border-drawn triangle, pointing up by default. */
.govbb-number-input__step::before {
  content: '';
  width: 0;
  height: 0;
  border-inline: 0.375rem solid transparent;
  border-bottom: 0.5rem solid;
}

.govbb-number-input__step:hover {
  background: color-mix(in srgb, var(--govbb-color-neutral) 70%, transparent);
}

.govbb-number-input__step:active {
  background: var(--govbb-color-neutral);
}

.govbb-number-input__step:disabled {
  color: color-mix(
    in srgb,
    var(--govbb-color-ink) 35%,
    var(--govbb-color-surface)
  );
  background: color-mix(in srgb, var(--govbb-color-neutral) 35%, transparent);
  cursor: not-allowed;
}

.govbb-number-input__step--down::before {
  transform: rotate(180deg);
}

.govbb-number-input__divider {
  flex-shrink: 0;
  width: 100%;
  height: var(--govbb-border-width-form);
  background: var(--govbb-color-ink);
}

.govbb-number-input-wrapper:has([aria-invalid='true'])
  .govbb-number-input__divider {
  background: var(--govbb-color-error);
}
