/* =====================================================================
   OSE · Input & textarea
   ---------------------------------------------------------------------
   The field box: text, tel and email inputs, and <textarea> with
   .input--textarea. It is also the box of the native select
   (.select__control) and of the dropdown trigger (.dropdown__trigger),
   see select.css, so every field in a form shares one look and one set
   of states. Use it inside a .field (label, help, error).

   Markup
     <input class="input" id="name" name="name" type="text"
            autocomplete="name" required>
     <input class="input" id="phone" name="phone" type="tel"
            inputmode="tel" autocomplete="tel" placeholder="0900 000 000">
     <textarea class="input input--textarea" id="message" name="message"
               rows="4"></textarea>

   States
     default · placeholder shown · filled
     hover        pointer devices only
     focus        :focus-visible → strong border + shared focus ring
     error        aria-invalid="true" (+ .field__error linked with
                  aria-describedby); keeps the error border while focused
     read-only    [readonly]: transparent, dashed border, still focusable
     disabled     :disabled or aria-disabled="true"
     autofill     browser autofill keeps the field colours
   Text stays at --input-font-size (≥ 16px) so iOS never zooms on focus.
   Tokens   --input-*, --textarea-* only.
   JS       none.
   ===================================================================== */

@layer components {
  .input {
    --_bg: var(--input-bg);
    --_text: var(--input-text);
    --_border: var(--input-border);
    display: block;
    inline-size: 100%;
    min-block-size: var(--input-height);
    margin: 0;
    padding-block: var(--input-padding-block);
    padding-inline: var(--input-padding-inline);
    border: var(--input-border-width) solid var(--_border);
    border-radius: var(--input-radius);
    background-color: var(--_bg);
    color: var(--_text);
    font: inherit;
    font-size: var(--input-font-size);
    line-height: var(--input-leading);
    appearance: none;
    transition:
      border-color var(--input-duration) var(--input-ease),
      background-color var(--input-duration) var(--input-ease),
      box-shadow var(--input-duration) var(--input-ease);
  }

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

  .input--textarea {
    min-block-size: var(--textarea-min-height);
    resize: vertical;
  }

  @media (hover: hover) {
    .input:hover {
      --_bg: var(--input-bg-hover);
      --_border: var(--input-border-hover);
    }
  }

  .input:focus-visible {
    --_bg: var(--input-bg-focus);
    --_border: var(--input-border-focus);
    box-shadow: var(--input-focus-ring);
  }

  /* Error after hover/focus so it wins; the explicit focus rule keeps the
     error border under the focus ring (and in the styleguide's frozen
     focus state). */
  .input[aria-invalid="true"],
  .input[aria-invalid="true"]:focus-visible {
    --_bg: var(--input-bg-error);
    --_border: var(--input-border-error);
  }

  .input[readonly] {
    --_bg: var(--input-bg-readonly);
    --_border: var(--input-border-readonly);
    border-style: dashed;
  }

  .input:disabled,
  .input[aria-disabled="true"] {
    --_bg: var(--input-bg-disabled);
    --_text: var(--input-text-disabled);
    --_border: var(--input-border-disabled);
    cursor: not-allowed;
    opacity: var(--input-opacity);
    -webkit-text-fill-color: var(--_text);
  }

  .input:disabled::placeholder,
  .input[aria-disabled="true"]::placeholder {
    color: var(--input-text-disabled);
  }

  /* Autofill: paint the field colour over the UA's autofill fill. */
  .input:-webkit-autofill {
    -webkit-text-fill-color: var(--_text);
    box-shadow: inset 0 0 0 var(--input-height) var(--_bg);
  }

  .input:-webkit-autofill:focus-visible {
    box-shadow: var(--input-focus-ring), inset 0 0 0 var(--input-height) var(--_bg);
  }
}
