/* Field — PR27 Library "Field" (Figma 1193:32612: Label stack, then the
   Field Box 1193:565 + Note) on PR27 tokens. Replaces the old library's
   "Input" (4aRpVkr9Ldy9hbRR0ICVoJ 188:3668). One field box for every type:
     text · text area · select (a text field with a chevron — the "dropdown
     launcher" is just this; its window is the Dropdown Menu).

   Sizes follow the Button so the two line up side by side:
               height  pad-x  text      icon
     L (def)   42      10     Title S   16
     M         32      10     Title S   16
     S         24      6      Title XS  12
   Shape: Regular (radius 6, the Button's; 2026-11-14) · .field-box--rounded (pill).

   States
     empty     n0 fill, 1px edge + Shadow 2: raised, ready to fill
     filled    n0 fill, the 0.5px edge + Shadow 0
     focus     1.5px n80 edge (Figma's neutral-40 ≈ n35 would read lighter
               than the resting shadow — one clear step stronger instead)
     error     1.5px red100 edge + red120 helper with warning icon
     disabled  neutralTint25 fill, no shadow, n80 text
   Text n150, placeholder n90, label Title S n110, helpers Body S n110. */

@layer components {
  .field { display: flex; flex-direction: column; gap: var(--space-8); min-width: 0; }
  .field-label { font: var(--title-s); letter-spacing: var(--title-s-ls); color: var(--n110); }
  .field-helper, .field-note { display: flex; align-items: flex-start; gap: var(--space-4); font: var(--body-s); letter-spacing: var(--body-s-ls); color: var(--n110); margin: 0; }
  .field-note .icon { margin-top: var(--space-2); }
  .field-note--error { color: var(--red120); }
  .field-stack { display: flex; flex-direction: column; gap: var(--space-6); }

  .field-box {
    /* No fixed height (Corey, 2026-10-06): one line as tall as the icon
       (--fb-lh) plus padding (--fb-py) lands on 42 / 32 / 24, matching the
       Button. --fb-h is only that sum, for the stepper's spacing. */
    --fb-lh: 16px; --fb-py: 13px; --fb-h: calc(var(--fb-lh) + 2 * var(--fb-py));
    --fb-px: 10px; --fb-gap: 8px;
    --fb-text: var(--title-s); --fb-text-ls: var(--title-s-ls);
    position: relative;
    display: flex; align-items: center; gap: var(--fb-gap);
    padding: var(--fb-py) var(--fb-px);
    border-radius: var(--radius-6);
    background: var(--n0);
    box-shadow: inset 0 0 0 var(--control-edge-width) var(--control-edge-ink), var(--shadow-0); /* edge: tokens.css */
    color: var(--n150);
    font: var(--fb-text); letter-spacing: var(--fb-text-ls); line-height: var(--fb-lh);
    cursor: text;
    transition: box-shadow var(--dur-120) var(--ease-fade);
  }
  .field-box--m { --fb-py: var(--space-8); }
  .field-box--s { --fb-lh: 12px; --fb-py: var(--space-6); --fb-px: 6px; --fb-gap: 6px; --fb-text: var(--title-xs); --fb-text-ls: var(--title-xs-ls); }
  .field-box--rounded { border-radius: 999px; --fb-px: 14px; }
  .field-box--s.field-box--rounded { --fb-px: 10px; }

  /* The real control fills the box and inherits its type. */
  .field-box > input, .field-box > textarea {
    flex: 1; min-width: 0; height: var(--fb-lh);
    margin: 0; padding: 0; border: none; outline: none; background: none;
    font: inherit; letter-spacing: inherit; color: inherit;
  }
  /* Number stepper: down / up buttons on the right, 2px apart, rounded on
     their outer sides only (Figma 2710:4394). They sit as far from the
     right edge as from the top and bottom, and use a light neutral tint —
     one step lighter than a secondary button (neutralTint25). */
  .field-box--number { --fb-step: 22px; padding-right: calc((var(--fb-h) - var(--fb-step)) / 2); }
  .field-box--number.field-box--m { --fb-step: 20px; }
  .field-box--number.field-box--s { --fb-step: 16px; }
  .field-box--number > input { font-variant-numeric: tabular-nums; }
  .field-suffix { color: var(--n90); }
  .field-steps { display: flex; gap: var(--space-2); flex: none; margin-block: calc((var(--fb-lh) - var(--fb-step)) / 2); } /* taller than the line: let it overhang into the padding instead of growing the box */
  .field-steps button {
    display: grid; place-items: center; width: var(--fb-step); height: var(--fb-step);
    padding: 0; border: none; background: var(--neutralTint10); color: var(--n130); cursor: pointer;
    transition: background-color var(--dur-120) var(--ease-fade);
  }
  .field-steps button:first-child { border-radius: var(--radius-6) 0 0 var(--radius-6); }
  .field-steps button:last-child { border-radius: 0 var(--radius-6) var(--radius-6) 0; }
  @media (hover: hover) { .field-steps button:hover:not(:disabled) { background: var(--neutralTint25); } }
  .field-steps button:active:not(:disabled) { background: var(--n35); }
  .field-steps button:disabled { color: var(--n35); cursor: default; }

  .field-box ::placeholder { color: var(--n90); opacity: 1; } /* n90: 5.78:1 on white (DSN-43) */
  .field-box > .icon-wrap, .field-box > .icon { color: var(--n110); }

  /* Text area: grows downward; padding scales with size. */
  .field-box--area { height: auto; min-height: calc(var(--fb-h) + 16px); align-items: flex-start; padding: var(--space-16); }
  .field-box--area.field-box--m { padding: var(--space-8); }
  .field-box--area.field-box--s { padding: var(--space-8); }
  .field-box--area > textarea { height: auto; min-height: 3.3em; resize: vertical; line-height: 1.5; }

  /* Select: the whole box is the button that opens a Dropdown Menu. */
  .field-box--select { cursor: pointer; text-align: left; border: none; width: 100%; }
  .field-box--select .field-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; padding-block: 0.25em; margin-block: -0.25em; /* room for descenders (g, y): overflow clips at the line box (2026-10-09) */ white-space: nowrap; }
  .field-box--select .field-value[data-placeholder] { color: var(--n90); }
  .field-box--select .icon[data-icon="chevron-down"] { color: var(--n110); transition: rotate var(--dur-160) var(--ease-fade); }
  .field-box--select[data-state="open"] .icon[data-icon="chevron-down"] { rotate: 180deg; }

  /* States */
  /* Empty (DSN-43, 2026-11-14): white, a 1px edge and Shadow 2, so it looks
     raised and ready to fill. Filled settles to the thin edge + Shadow 0. */
  .field-box:not([data-disabled], [data-invalid], [data-state="open"], .is-focus, :focus-within, :focus-visible):is(:has(> :is(input, textarea):placeholder-shown), :has(.field-value[data-placeholder])) {
    box-shadow: inset 0 0 0 max(1px, var(--control-edge-width)) var(--control-edge-ink), var(--shadow-2);
  }
  .field-box:focus-within, .field-box--select:focus-visible, .field-box--select[data-state="open"], .field-box.is-focus {
    outline: none; box-shadow: inset 0 0 0 1.5px var(--n80), var(--shadow-0); /* the edge, darker and 1.5px (first, so it animates from the edge) */
  }
  .field-box[data-invalid] { box-shadow: inset 0 0 0 1.5px var(--red100); }
  /* Invalid + focus (WCAG 2.4.7): the red edge stays and the kit's blue100
     focus ring goes around it, so focus still shows (after the red rule, so it wins). */
  .field-box[data-invalid]:is(:focus-within, .field-box--select:focus-visible, [data-state="open"], .is-focus) {
    outline: none; box-shadow: inset 0 0 0 1.5px var(--red100), 0 0 0 2px var(--n0), 0 0 0 4px var(--blue100);
  }
  /* Clear (Input / TagInput clearable, 2026-10-07): an icon-only × at the
     end, only while there's a value; n90 → n150 on hover. */
  .field-clear { display: inline-flex; flex: none; margin: calc(-1 * var(--space-2)) calc(-1 * var(--space-2)) calc(-1 * var(--space-2)) 0; /* the 2 padding stays outside the line, so the box keeps its height */ padding: var(--space-2); border: 0; border-radius: var(--radius-2); background: none; color: var(--n90); cursor: pointer; transition: color var(--dur-120) var(--ease-fade), background-color var(--dur-120) var(--ease-fade); }
  @media (hover: hover) { .field-clear:hover { color: var(--n150); background: rgb(from var(--n150) r g b / 8%); } }
  .field-clear:focus-visible { outline: 2px solid var(--blue100); outline-offset: 1px; }
  /* End padding rule (Spacing rules, 2026-10-18): with the × at the end, the
     end padding = the top/bottom padding (L 13, M 8, S 6; was 10 / 10 / 6),
     so the × sits as far from the right edge as from the top. */
  .field-box { --fb-end: calc(var(--fb-py) + (var(--fb-lh) - var(--fb-glyph, 16px)) / 2); } /* the clear ×'s distance from the top (its glyph centred on the first line) */
  .field-box--s { --fb-glyph: 12px; }
  .field-box:has(> .field-clear:last-child) { padding-right: var(--fb-end); }
  /* TagInput: the clear-all × always sits top right (Santiago, 2026-10-18), on
     the first line, as far from the end as from the top; tags never run under it. */
  .field-box--tags:has(> .field-clear:last-child) { padding-right: calc(var(--fb-end) + var(--fb-glyph, 16px) + var(--space-2) + var(--fb-gap)); }
  .field-box--tags > .field-clear { position: absolute; top: calc(var(--fb-end) - var(--space-2)); right: calc(var(--fb-end) - var(--space-2)); margin: 0; }
  /* Tags (TagInput, 2026-10-07): removable Tag S chips and the input share
     the box and wrap onto more lines. Inside it a tag is 4 / 6 padded on an
     18 line = 26, so one row is 8 + 26 + 8 = 42 (L), like every other field. */
  .field-box--tags { flex-wrap: wrap; gap: var(--space-6); --fb-py: var(--space-8); --fb-lh: 26px; /* the line is as tall as a tag, so the box is 42 with or without tags */ padding-inline: var(--space-8); }
  .field-box--tags > .tag { padding: var(--space-4) var(--space-6); line-height: 18px; max-width: 100%; }
  .field-box--tags > .tag > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; padding-block: 0.25em; margin-block: -0.25em; /* room for descenders (g, y): overflow clips at the line box (2026-10-09) */ white-space: nowrap; }
  .field-box--tags > input { flex: 1 0 80px; padding-left: var(--space-2); }
  .field-box[data-disabled] { background: var(--neutralTint25); box-shadow: none; color: var(--n80); cursor: not-allowed; }
  .field-box[data-disabled] > .icon-wrap, .field-box[data-disabled] .icon { color: var(--n80); }

  @media (prefers-reduced-motion: reduce) {
    .field-box, .field-box--select .icon { transition: none; }
  }
}
