/* Money input
 *
 * An amount and its currency, as one control. STORY-020 calls this the
 * highest-risk field in the product, and the risk is not the styling.
 *
 *   <div class="amount">
 *     <input class="field__control" id="tx-amount" type="text" inputmode="decimal"
 *            autocomplete="off" aria-describedby="tx-amount-err">
 *     <select class="amount__cur" id="tx-currency" aria-label="Currency"></select>
 *   </div>
 *   <p class="field__error" id="tx-amount-err" role="alert" hidden></p>
 *
 * ── the amount and the currency are one value ────────────────────────────────
 * ADR-0005: money is an integer in the minor unit plus an ISO 4217 code, never
 * a float and never a bare number. The two inputs are joined visually because
 * neither means anything alone — a "12000" with no currency is not a smaller
 * amount, it is not an amount.
 *
 * ── why the digit count cannot be a constant ─────────────────────────────────
 * The minor-unit digits come from the currency: JPY has 0, KWD has 3, most have
 * 2. So the SAME keystrokes are three different amounts depending on the select
 * beside them, and changing the currency must re-validate the field rather than
 * only relabel it.
 *
 * ── and neither can the separators ───────────────────────────────────────────
 * `1.234,50` is one thousand in Turkish and malformed in English. The parser's
 * separators come from the locale, so the same input is two different numbers
 * in the two languages the product ships — found in this prototype, ADR-0014.
 * A component that hardcodes `.` as the decimal point is wrong for half the
 * users on day one.
 *
 * ── behaviour this file cannot express, and that is not optional ─────────────
 *   · `inputmode="decimal"`, not `type="number"`. A number input's spinners are
 *     meaningless for money, its scroll-wheel changes values by accident, and
 *     browsers disagree about what it does with a comma.
 *   · Digits are tabular and end-aligned, so a column of amounts compares by eye.
 *   · Parse on submit, not per keystroke. A field that rejects "12," while the
 *     reader is halfway through typing "12,50" is fighting them.
 *   · An invalid amount keeps what was typed. Clearing the field to "fix" it
 *     loses the only copy of what they meant.
 */

.amount {
  display: flex;
  align-items: stretch;
}

/* Joined, so the pair reads as one control: the input loses its trailing
   corners and the select loses its leading border. */
.amount .field__control {
  border-start-end-radius: 0;
  border-end-end-radius: 0;
  font-variant-numeric: tabular-nums;
  text-align: end;
}

/* A real <select>. design.md prefers the OS control wherever the behaviour
 * allows, and a currency list of one to five enabled values is exactly that —
 * keyboard-operable, screen-reader correct, and right on mobile for free.
 *
 * The full ISO 4217 set is NEVER offered here. An Organisation enables a handful
 * and this offers those; searching all ~180 happens in one place, Settings.
 * i18n.md owns that rule. */
.amount__cur {
  flex: none;
  min-block-size: var(--target-min);
  padding-inline: var(--space-3);

  font: inherit;
  font-size: var(--text-sm);
  color: var(--color-text);
  background: var(--color-surface-sunken);

  border: 1px solid var(--color-border-strong);
  border-inline-start: 0;
  border-start-end-radius: var(--radius-md);
  border-end-end-radius: var(--radius-md);
  cursor: pointer;
}

/* Raised while focused so the ring is not clipped by the input it abuts. */
.amount__cur:focus-visible {
  outline: var(--focus-ring-width) solid var(--color-focus-ring);
  outline-offset: var(--focus-ring-offset);
  position: relative;
  z-index: 1;
}

/* Read-only, for an amount derived from somewhere else — an Inventory item's
 * cost read from the Transaction that bought it. Disabled rather than hidden:
 * the reader came to check this number, and hiding it would leave them unable
 * to see what the link decided. */
.amount .field__control:disabled,
.amount__cur:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}
