/* Redwood forms — form layout, field label, help and messages, and the text
 * field visuals shared by input, select and textarea.
 *
 * Values were read out of the JET 21.0.0 Redwood theme (oj-redwood-min.css:
 * --oj-form-layout-*, --oj-label-*, --oj-text-field-*, --oj-user-assistance-*;
 * identical at 19.0.0) and the core-pack theme beside it (oraclejet-preact
 * Theme-redwood/theme.css: FormLayout, Label, TextField, UserAssistance,
 * ComponentMessage), and mapped onto the --rw-* names. Where they disagree the
 * core pack wins. The one raw length is the field's 1px border.
 *
 * Load after redwood-tokens.css (and redwood-dark.css if you use it).
 *
 *   <form class="rw-form">
 *     <div class="rw-field">
 *       <label class="rw-label" for="c">Customer<span class="rw-required" aria-hidden="true">*</span></label>
 *       <select class="rw-input" id="c" required>…</select>
 *       <p class="rw-help">The customer this invoice bills.</p>
 *     </div>
 *     <div class="rw-field">
 *       <label class="rw-label" for="a">Amount</label>
 *       <input class="rw-input" id="a" aria-invalid="true" aria-describedby="a-m">
 *       <p class="rw-field-message rw-field-message-danger" id="a-m">
 *         <svg/>Enter an amount greater than zero.</p>
 *     </div>
 *     <div class="rw-form-wide">…</div>
 *   </form>
 *
 * Readings, and where each is rounded onto a token:
 *
 *   Layout     columns 18rem to 28rem wide, 1.5rem between them (6x); they
 *              fill the width and wrap, so one form works from one column to
 *              three. The theme puts .875rem under each field — three and a
 *              half steps — which is rounded here to 4x, the larger neighbour,
 *              so a reserved help line does not crowd the next label.
 *   Label      above the field, .5rem from it; body-sm at 600 in
 *              text-primary. Not text-secondary, not uppercase.
 *   Help       body-xs in text-secondary, under the field.
 *   Required   the legacy theme marks the label with a brand-110 indicator.
 *              The core pack's own marker was not verified; this uses the
 *              legacy color on an asterisk and relies on the `required`
 *              attribute for assistive technology.
 *   Field      2.75rem high (11x); 1px border-enabled; radius md; body-md;
 *              1rem from text to edge (the core pack; the legacy theme says
 *              12px); placeholder text-secondary; ground --rw-bg-content.
 *   Focus      the field is §8's exception: a brand-110 border plus a 1px
 *              inset shadow of the same color, instead of the outline ring.
 *   Invalid    a danger-120 border (--rw-text-danger, so it lifts in dark).
 *   Disabled   Oracle fills a disabled field with neutral-190 at .04 and draws
 *              its border at .20. Neither alpha has a token; the fill is
 *              rounded to --rw-bg-muted (what .04 composites to on white) and
 *              the border to --rw-divider (.12, the nearest line token).
 *
 * What people get wrong:
 *
 *   An error message is not red text. Redwood colors the icon and the field
 *   border; the message itself is body-xs in text-secondary, next to a 1rem
 *   status icon. Red paragraphs of text read as alarm, not guidance.
 *
 *   One assistance text at a time. Redwood shows a single line under a field,
 *   by precedence: the message if there is one, otherwise the instruction,
 *   the validator hint, the definition. A field wearing help, a hint and an
 *   error at once is off-system.
 *
 *   A validation message is about the user's own input and names the fix
 *   ("Enter an amount greater than zero"). A failure from the server is not a
 *   field message; it is a banner in plain language with a reference code
 *   (STYLE-GUIDE §9a).
 *
 *   Labels go above the field and say what the value is, in sentence case.
 *   A placeholder is not a label; it disappears when the user types.
 *
 *   Anything that could already exist — a customer, an account, an item — is
 *   a select or a search picker, not a free text box (STYLE-GUIDE §9a). This
 *   file draws the closed field; the popup list is not specified here.
 *
 * (c) Oracle. Internal brand asset — see NOTICE. */

:root {
  --rw-form-column-min: 18rem;
  --rw-form-column-max: 28rem;
}

/* ── Form layout ──────────────────────────────────────────────────────────── */

.rw-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--rw-form-column-min), 100%), var(--rw-form-column-max)));
  column-gap: var(--rw-space-6x);
  row-gap: var(--rw-space-4x);
  align-items: start;
}

.rw-form > .rw-form-wide,
.rw-form > fieldset,
.rw-form > footer {
  grid-column: 1 / -1;
}

/* A single column of fields, for a drawer or a narrow dialog. */
.rw-form-stacked { grid-template-columns: minmax(0, var(--rw-form-column-max)); }

/* ── Field ────────────────────────────────────────────────────────────────── */

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

.rw-label {
  color: var(--rw-text-primary);
  font-size: var(--rw-body-sm-size);
  line-height: var(--rw-body-sm-lh);
  font-weight: 600;
}

.rw-field:has(:disabled) .rw-label { color: var(--rw-text-disabled); }

.rw-required {
  margin-inline-start: var(--rw-space-1x);
  color: var(--rw-text-brand);
}

.rw-help,
.rw-field-message {
  margin: 0;
  color: var(--rw-text-secondary);
  font-size: var(--rw-body-xs-size);
  line-height: var(--rw-body-xs-lh);
}

.rw-field-message {
  display: flex;
  align-items: flex-start;
  gap: var(--rw-space-1x);
}

.rw-field-message > svg,
.rw-field-message > .rw-ico {
  flex-shrink: 0;
  width: var(--rw-space-4x);
  height: var(--rw-space-4x);
  font-size: var(--rw-space-4x);
  color: var(--rw-text-brand);
}

.rw-field-message-danger > :is(svg, .rw-ico)  { color: var(--rw-text-danger); }
.rw-field-message-warning > :is(svg, .rw-ico) { color: var(--rw-text-warning); }
.rw-field-message-success > :is(svg, .rw-ico) { color: var(--rw-text-success); }

/* ── Text field: input, select, textarea ──────────────────────────────────── */

.rw-input {
  box-sizing: border-box;
  width: 100%;
  min-height: var(--rw-space-11x);
  margin: 0;
  padding: 0 var(--rw-space-4x);
  border: 1px solid var(--rw-border-enabled);
  border-radius: var(--rw-radius-md);
  background-color: var(--rw-bg-content);
  color: var(--rw-text-primary);
  font: inherit;
  font-size: var(--rw-body-md-size);
  line-height: var(--rw-body-md-lh);
}

textarea.rw-input {
  min-height: calc(var(--rw-space-11x) * 2);
  padding-block: var(--rw-space-3x);
  resize: vertical;
}

.rw-input::placeholder { color: var(--rw-text-secondary); opacity: 1; }

.rw-input:focus,
.rw-input:focus-visible {
  outline: none;
  border-color: var(--rw-field-border-focus);
  box-shadow: inset 0 0 0 1px var(--rw-field-border-focus);
}

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

/* Keeps focus visible on an invalid field without losing the error color. */
.rw-input[aria-invalid="true"]:focus {
  border-color: var(--rw-text-danger);
  box-shadow: inset 0 0 0 1px var(--rw-text-danger);
}

.rw-input:disabled {
  border-color: var(--rw-divider);
  background-color: var(--rw-bg-muted);
  color: var(--rw-text-disabled);
  cursor: default;
}

/* Read only: the value as text, aligned where the field's text would be. */
.rw-input[readonly] {
  border-color: transparent;
  background-color: transparent;
  box-shadow: none;
}

/* ── Windows high contrast ────────────────────────────────────────────────── */

@media (forced-colors: active) {
  .rw-input { border-color: FieldText; }
  .rw-input:focus { outline: 2px solid Highlight; outline-offset: -2px; }
  .rw-input[aria-invalid="true"] { border-width: 3px; }
  .rw-input:disabled { border-color: GrayText; }
  .rw-field-message > :is(svg, .rw-ico) { color: CanvasText; }
}
