/* ─────────────────────────────────────────────────────────────
   Starboard · Fields family
   Field / Fieldset (focal-glow choreography), Input, Textarea,
   InputGroup, NativeSelect, InputOTP, Combobox.
   Pairs with Fields.jsx. Tokens come from colors_and_type.css.

   Static preview note: every :focus-within state also has an
   .is-focus alias so HTML specimen cards can pin the state.
   ───────────────────────────────────────────────────────────── */
@import url('../../colors_and_type.css');

/* ─── Field — label + control + help/error ─── */
.ad-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ad-field .ad-label { transition: opacity var(--motion-focus-primary); }

.ad-field__help { font-size: 13px; color: var(--fg-muted); line-height: 1.5; }
.ad-field__error {
  display: inline-flex; align-items: flex-start; gap: var(--space-3xs);
  font-size: 13px; color: var(--error-700); line-height: 1.5;
}
.ad-field__error svg { flex: 0 0 auto; margin-top: 2px; }

/* ─── Fieldset — focal-glow choreography ─────────────────────────
   When any control inside the fieldset holds focus, the focal
   field's label keeps full color while sibling labels dim. Scope is
   one logical group — never dim other sections on the page. */
.ad-fieldset { display: grid; gap: var(--space-sm); }
.ad-fieldset--2col { grid-template-columns: 1fr 1fr; }
.ad-fieldset:focus-within .ad-field:not(:focus-within) .ad-label {
  opacity: var(--opacity-dimmed-sibling);
}
/* Static preview alias */
.ad-field.is-dimmed .ad-label { opacity: var(--opacity-dimmed-sibling); }

/* ─── Input — 42px control, 10px radius ─── */
.ad-input {
  position: relative;
  display: flex; align-items: center; gap: var(--space-2xs);
  height: 42px; padding: 0 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-md);
  transition:
    border-color var(--motion-focus-primary),
    box-shadow var(--motion-focus-primary),
    background-color var(--duration-4) var(--ease-out);
}
.ad-input--sm { height: 36px; border-radius: var(--radius-sm); }

.ad-input__control {
  flex: 1; min-width: 0; width: 100%;
  border: 0; outline: 0; background: transparent; padding: 0;
  font-family: var(--font-body); font-size: 14px; line-height: 1.5;
  color: var(--fg-strong);
}
.ad-input__control::placeholder { color: var(--neutral-500); }
.ad-input--sm .ad-input__control { font-size: 13px; }

.ad-input__icon { display: inline-flex; flex: 0 0 auto; color: var(--neutral-500); transition: color var(--motion-focus-primary); }
.ad-input__icon svg { display: block; }

/* States */
.ad-input:hover { border-color: var(--neutral-400); }
.ad-input:focus-within,
.ad-input.is-focus {
  border-color: var(--primary-500);
  box-shadow: var(--shadow-focus-soft);
}
.ad-input:focus-within .ad-input__icon,
.ad-input.is-focus .ad-input__icon { color: var(--primary-700); }

.ad-input.is-error { border-color: var(--error-500); }
.ad-input.is-error:focus-within,
.ad-input.is-error.is-focus {
  border-color: var(--error-500);
  box-shadow: 0 0 0 1px rgba(240,68,56,0.08), 0 0 16px rgba(240,68,56,0.12);
}
.ad-input.is-error .ad-input__icon { color: var(--error-500); }

.ad-input.is-success { border-color: var(--success-500); }
.ad-input.is-success:focus-within,
.ad-input.is-success.is-focus { box-shadow: 0 0 0 3px rgba(18,183,106,0.10); }
.ad-input.is-success .ad-input__icon { color: var(--success-700); }

/* Disabled — dashed border, per the checkbox-disabled convention */
.ad-input.is-disabled {
  background: var(--neutral-50);
  border-color: var(--neutral-300); border-style: dashed;
  cursor: not-allowed;
}
.ad-input.is-disabled .ad-input__control { color: var(--neutral-500); cursor: not-allowed; }
.ad-input.is-disabled .ad-input__icon { color: var(--neutral-400); }
.ad-input.is-disabled:hover { border-color: var(--neutral-300); }

.ad-input.is-readonly { background: var(--neutral-50); }
.ad-input.is-readonly:focus-within { border-color: var(--neutral-400); box-shadow: none; }

/* ─── Textarea ─── */
.ad-textarea { height: auto; align-items: stretch; padding: 10px 12px; }
.ad-textarea__control {
  resize: vertical; min-height: 56px; line-height: 1.55;
}
.ad-textarea.is-autogrow .ad-textarea__control { resize: none; overflow: hidden; }
.ad-textarea--counted { padding-bottom: 26px; }
.ad-textarea__count {
  position: absolute; inset-inline-end: 10px; bottom: 6px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  color: var(--neutral-500);
  transition: color var(--motion-status-change);
  pointer-events: none;
}
.ad-textarea__count.is-warn { color: var(--warning-700); }

/* ─── InputGroup — compound adornments, whole group glows ─── */
.ad-igrp {
  display: flex; align-items: stretch; width: 100%;
  height: 42px;
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition:
    border-color var(--motion-focus-primary),
    box-shadow var(--motion-focus-primary);
}
.ad-igrp--sm { height: 36px; border-radius: var(--radius-sm); }
.ad-igrp:hover { border-color: var(--neutral-400); }
.ad-igrp:focus-within,
.ad-igrp.is-focus {
  border-color: var(--primary-500);
  box-shadow: var(--shadow-focus-soft);
}
.ad-igrp.is-error { border-color: var(--error-500); }
.ad-igrp.is-disabled {
  background: var(--neutral-50);
  border-style: dashed; cursor: not-allowed;
}

.ad-igrp__addon {
  display: flex; align-items: center; flex: 0 0 auto;
  padding: 0 12px;
  background: var(--neutral-100);
  color: var(--fg-muted);
  font-size: 13px; white-space: nowrap;
  border-inline-end: 1px solid var(--neutral-200);
}
.ad-igrp__addon:last-child { border-inline-end: 0; border-inline-start: 1px solid var(--neutral-200); }
.ad-igrp__addon code, .ad-igrp__addon.ad-igrp__addon--mono { font-family: var(--font-mono); font-size: 12px; }

.ad-igrp > input,
.ad-igrp__input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  padding: 0 12px;
  font-family: var(--font-body); font-size: 14px;
  color: var(--fg-strong);
}
.ad-igrp > input::placeholder, .ad-igrp__input::placeholder { color: var(--neutral-500); }

/* Select addon — a flat native select fused to the group's end */
.ad-igrp > select, .ad-igrp__select {
  appearance: none; -webkit-appearance: none;
  flex: 0 0 auto;
  border: 0; outline: 0; cursor: pointer;
  background: var(--neutral-100);
  border-inline-start: 1px solid var(--neutral-200);
  padding-block: 0; padding-inline: 12px 28px;
  font-family: var(--font-body); font-size: 13px;
  color: var(--fg-default);
}
/* Inline button fused to the group's end */
.ad-igrp > .ad-btn {
  height: auto; border: 0; border-radius: 0;
  border-inline-start: 1px solid var(--neutral-200);
  box-shadow: none;
}
.ad-igrp > .ad-btn:active:not(:disabled) { transform: none; }
.ad-igrp > .ad-btn--primary { border-inline-start: 0; }

/* ─── NativeSelect — styled native <select> ─── */
.ad-nsel { position: relative; display: block; min-width: 0; }
.ad-nsel__control {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 42px;
  padding: 0 36px 0 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-md);
  font-family: var(--font-body); font-size: 14px;
  color: var(--fg-strong);
  cursor: pointer;
  transition:
    border-color var(--motion-focus-primary),
    box-shadow var(--motion-focus-primary),
    background-color var(--duration-4) var(--ease-out);
}
.ad-nsel--sm .ad-nsel__control { height: 36px; border-radius: var(--radius-sm); font-size: 13px; }
.ad-nsel__control:hover { border-color: var(--neutral-400); }
.ad-nsel__control:focus,
.ad-nsel.is-focus .ad-nsel__control {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: var(--shadow-focus-soft);
}
.ad-nsel.is-error .ad-nsel__control { border-color: var(--error-500); }
.ad-nsel.is-success .ad-nsel__control { border-color: var(--success-500); }
.ad-nsel.is-disabled .ad-nsel__control,
.ad-nsel__control:disabled {
  background: var(--neutral-50);
  border-color: var(--neutral-300); border-style: dashed;
  color: var(--neutral-500); cursor: not-allowed;
}
/* Chevron is an absolutely-positioned inline SVG using currentColor */
.ad-nsel__chev {
  position: absolute; inset-inline-end: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--neutral-500);
  pointer-events: none;
  display: flex;
}
.ad-nsel.is-disabled .ad-nsel__chev { color: var(--neutral-400); }

/* ─── InputOTP ─── */
.ad-otp { display: inline-flex; align-items: center; gap: var(--space-2xs); }
.ad-otp__cell {
  width: 44px; height: 52px;
  text-align: center;
  font-family: var(--font-mono); font-size: 20px; font-weight: 500;
  color: var(--fg-strong);
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-300);
  border-radius: var(--radius-md);
  caret-color: var(--primary-500);
  transition:
    border-color var(--motion-focus-primary),
    box-shadow var(--motion-focus-primary),
    background-color var(--duration-4) var(--ease-out);
}
.ad-otp__cell::placeholder { color: var(--neutral-400); }
.ad-otp__cell:hover { border-color: var(--neutral-400); }
.ad-otp__cell:focus,
.ad-otp__cell.is-focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: var(--shadow-focus-soft);
}
.ad-otp__cell.is-filled { border-color: var(--neutral-400); }
.ad-otp.is-error .ad-otp__cell { border-color: var(--error-500); }
.ad-otp.is-error .ad-otp__cell:focus { box-shadow: 0 0 0 3px rgba(240,68,56,0.10); }
.ad-otp.is-disabled .ad-otp__cell {
  background: var(--neutral-50);
  border-style: dashed; color: var(--neutral-500); cursor: not-allowed;
}
/* Separator dot between digit groups */
.ad-otp__dot {
  width: 6px; height: 6px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--neutral-300);
  margin: 0 2px;
}

/* ─── Combobox ─── */
.ad-cbx { position: relative; min-width: 0; }
.ad-cbx__anchor { cursor: text; }
.ad-cbx__anchor--chips {
  height: auto; min-height: 42px;
  flex-wrap: wrap;
  padding: 5px 12px; gap: var(--space-3xs) var(--space-2xs);
}
.ad-cbx__anchor--chips .ad-input__control { min-width: 80px; flex: 1; }
.ad-cbx__chev { transition: transform var(--motion-focus-primary); }
.ad-cbx.is-open .ad-cbx__chev { transform: rotate(180deg); }

/* Removable chip — pill with × button */
.ad-chip {
  display: inline-flex; align-items: center; gap: var(--space-3xs);
  padding: 3px 4px 3px 10px;
  background: var(--primary-50);
  color: var(--primary-700);
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 500; line-height: 1.4;
  white-space: nowrap;
}
.ad-chip__x {
  display: grid; place-items: center;
  width: 16px; height: 16px; padding: 0;
  border: 0; border-radius: 50%;
  background: transparent; color: inherit;
  cursor: pointer;
  transition: background-color var(--duration-3) var(--ease-out);
}
.ad-chip__x:hover { background: var(--primary-100); }
.ad-chip__x:focus-visible { outline: none; box-shadow: var(--shadow-focus-ring); }

/* Popup listbox */
.ad-cbx__pop {
  background: var(--bg-elevated);
  border: 1px solid var(--neutral-200);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 240px;
  overflow: hidden;
  transform-origin: top left;
  animation: ad-scale-in var(--motion-overlay-enter);
}
.ad-cbx__list { list-style: none; margin: 0; padding: 4px; }
.ad-cbx__opt {
  display: flex; align-items: center; gap: var(--space-2xs);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px; color: var(--fg-default);
  cursor: pointer;
  transition: background-color var(--duration-3) var(--ease-out), color var(--duration-3) var(--ease-out);
}
.ad-cbx__opt.is-active { background: var(--primary-50); color: var(--primary-700); }
.ad-cbx__opt-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-cbx__opt-meta { flex: 0 0 auto; font-family: var(--font-mono); font-size: 11px; color: var(--neutral-500); }
.ad-cbx__check { display: inline-flex; flex: 0 0 auto; color: var(--primary-600); }
/* Highlighted match substring */
.ad-cbx__hl { background: transparent; color: var(--primary-700); font-weight: 600; }
/* Empty state */
.ad-cbx__empty { padding: 12px 10px; font-size: 13px; color: var(--fg-muted); }
