/**
 * Form-field primitive (r-39 step c2a).
 *
 * One box model for every text input, select and textarea
 * (ui-design-system.md §13 "Fields"):
 *   .input     single-line text/number/date input
 *   .select    native <select>, with the chevron redrawn (appearance:none
 *              strips the native one, and the native chrome ignores author
 *              padding/font-size — the header selects' "all different sizes",
 *              Peter 2026-09-20)
 *   .textarea  multi-line text, vertical resize only
 * Size modifier: .field-sm (compact fields inside a filter drop-down).
 * Molecules (r-39 c2b): .input-icon-left (search boxes), .field-suffix
 * (a unit inside the field), .field-group + .field-group-input (a field
 * with buttons inside its border: the PISTA chat composers).
 *
 * min-width: 0 lets a field shrink inside a flex row; without it a long
 * <option> kept the item picker's select wide and the row overflowed (b-70).
 * Width, flex and margins stay with the organism; this file only owns how a
 * field looks.
 *
 * @see docs/architecture/ui-design-system.md §13
 * @see docs/architecture/module-map/fields.css.md
 */

.input,
.select,
.textarea {
  min-width: 0;
  /* Inset: darker than the white card in light mode (r-152); the page colour in dark mode. */
  background: var(--color-bg-field);
  /* §9: the same box as .btn, so both come to --control-height. */
  border: var(--control-border-width) solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2) var(--space-3);
  color: var(--color-text-primary);
  font-family: var(--font-family-body);
  font-size: var(--font-size-sm);
  line-height: var(--control-line-height);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--color-text-secondary);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--color-accent);
}

.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-tint-3);
}

.input:disabled,
.select:disabled,
.textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* A static data-URI SVG can't read a custom property, hence one arrow per
   theme (the only colour literals the colour guard allows, via url()). */
.select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%2364748B' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 0.65rem;
  cursor: pointer;
}

.dark .select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' fill='none' stroke='%2394A3B8' stroke-width='1.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* A locked field (a repair price under Warranty, 2026-10-12): read-only plus
   aria-disabled. It reads as a value nobody can type over: a dashed border,
   the surface colour, secondary text at full opacity (the 0.5 fade left
   "0 Ft" at 2.8:1 in light mode), and, in a money field, a lock icon before
   the value with its reason on hover or focus (.field-locked below): the
   border alone went unnoticed (Peter, 2026-10-13). */
.input[aria-disabled="true"] {
  background: var(--color-bg-surface);
  border-style: dashed;
  color: var(--color-text-secondary);
  cursor: not-allowed;
}
.field-suffix:has(> .input[aria-disabled="true"]) { cursor: not-allowed; }
.field-suffix:has(> .input[aria-disabled="true"]) .field-suffix-text { color: var(--color-text-secondary); }
.input[aria-disabled="true"]:hover { border-color: var(--color-border); }

.textarea {
  resize: vertical;
  min-height: 4rem;
}

/* The native date pop-up and its in-field icon follow the app theme, not the
   browser's assumed light scheme (b-47). */
.input[type="date"] { color-scheme: light; }
.dark .input[type="date"] { color-scheme: dark; }

/* ── Size modifier ───────────────────────────────────────────────────── */
.field-sm {
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-md);
}

.select.field-sm {
  padding-right: var(--space-6);
  background-position: right var(--space-2) center;
}

/* A date past the field's `max` (create-order/create-case's "no future date"
   rule) shows at once, without a submit round-trip (i-41). */
.input[type="date"]:out-of-range,
.input[type="date"]:out-of-range:focus-visible {
  border-color: var(--color-invalid-border);
  box-shadow: 0 0 0 1px var(--color-invalid-border), 0 0 0 4px var(--color-invalid-ring),
    inset 0 0 0 999px var(--color-invalid-bg);
}

/* Shared "this field is invalid right now" state (b-55, i-41): applied and
   removed live by JS, not just after submit. b-111: a 1px dark-red border
   alone was barely visible on the dim light pages, and the focus ring
   replaced its ring once the field took focus (prompts.js focuses it). Now
   a solid ring, a soft outer ring and a danger wash, kept while focused.
   The wash is an inset shadow, so it lies over the field's own solid fill
   (what check-contrast measures) instead of replacing it, and keeps a
   select's chevron. !important on the border because the field kinds
   (.select, .field-group, …) set their own later in the cascade. */
.field-invalid,
.field-invalid:focus,
.field-invalid:focus-visible {
  border-color: var(--color-invalid-border) !important;
  box-shadow: 0 0 0 1px var(--color-invalid-border), 0 0 0 4px var(--color-invalid-ring),
    inset 0 0 0 999px var(--color-invalid-bg);
}

/* The native number spinner is hidden: it can't be themed, and quantities
   use the .qty-stepper buttons instead (b-60). Arrow keys still step. */
.input[type="number"]::-webkit-outer-spin-button,
.input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.input[type="number"] {
  -moz-appearance: textfield;
}

/* ── Molecules built on the field look (r-39 c2b) ────────────────────── */

/* Leading icon (table search boxes): room for an absolutely placed <i>. */
.input-icon-left {
  padding-left: var(--space-8);
}

/* Unit shown inside the right edge of a field (e.g. "Ft" after an amount). */
.field-suffix {
  position: relative;
}
.field-suffix > .input {
  width: 100%;
  padding-right: var(--space-10);
}
/* An amount with its unit (r-53/r-54): a line price or fee amount. Fills its
   table cell; in an add row it keeps a fixed width beside the growing text. */
.field-amount { width: 100%; }
.form-row .field-amount { flex: none; width: 9rem; }
.field-amount > .input { text-align: right; }
.field-suffix-text {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
}
/* A locked money field (moneyInput({ locked })): a lock before the value
   (the input carries .input-icon-left for its room), and the reason in a
   small pop-up above the field on hover, focus or tap (above, so it never covers
   the Warranty checkbox below, unless there is no room above), laid over the content
   so nothing moves (the panel look of .status-legend-panel). */
.field-lock-icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-secondary);
  font-size: var(--icon-sm);
  pointer-events: none;
}
.field-lock-reason {
  display: none;
  position: absolute;
  bottom: calc(100% + var(--space-1));
  left: 0;
  z-index: 20;
  pointer-events: none;
  width: max-content;
  max-width: 16rem;
  background: var(--color-bg-surface);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-2);
  padding: var(--space-2);
  color: var(--color-text-primary);
}
.field-locked:hover > .field-lock-reason,
.field-locked:focus-within > .field-lock-reason { display: block; }
/* Where the scrolled pop-up body would cut it off above, it opens below
   (case-line-fields.js moneyInput). */
.field-lock-reason.field-lock-reason-below {
  bottom: auto;
  top: calc(100% + var(--space-1));
}

/* A field with buttons inside its border (the PISTA chat composers). The
   wrapper carries the field look and shows the focus ring while its inner
   input is focused; the input itself is bare. */
.field-group {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 2.8rem;
  padding: 0 var(--space-2) 0 var(--space-4);
  background: var(--color-bg-field); /* the field look (r-152 review F2) */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.field-group:hover {
  border-color: var(--color-accent);
}
.field-group:focus-within {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-tint-3);
}
.field-group-input {
  flex: 1;
  min-width: 0;
  padding: var(--space-2) 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-text-primary);
  font-family: var(--font-family-body);
  font-size: var(--font-size-sm);
}
.field-group-input::placeholder {
  color: var(--color-text-secondary);
}

/* r-96 (§31): after Reload, a field both people changed keeps the person's
   value, outlined, and the list above the form names both values with
   "Use Frost's". */
.field-clash .input,
.field-clash .select,
.field-clash .textarea {
  border-color: var(--color-warning);
}
.clash-panel {
  margin-bottom: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-warning);
  border-radius: var(--radius-md);
  background: var(--color-warning-bg);
  font-size: var(--font-size-sm);
}
.clash-panel-title { margin: 0 0 var(--space-2); color: var(--color-warning-text); }
.clash-list { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--space-2); }
.clash-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
