/* Shared native form controls. Contract and verification: docs/form-controls.md. */
:root {
  --form-control-focus: #1a3a5c;
  --form-control-error: #b22d35;
}
:root[data-color-mode="dark"] {
  --form-control-focus: #9abce0;
  --form-control-error: #ff9fa7;
}
/* Authentication keeps its own light surface even when the surrounding site is dark. */
.login-surface { --form-control-focus: #527697; --form-control-error: #b22d35; }

/* New fields reuse this base; existing feature layouts retain their dimensions. */
.form-control {
  box-sizing: border-box;
  min-width: 0;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--color-border, #dbe2e9);
  border-radius: 6px;
  background: var(--color-surface, #fff);
  color: var(--color-text, #243549);
  font: inherit;
}
:root[data-color-mode="dark"] .form-control {
  background: var(--color-surface, #20262d);
  color: var(--color-text, #e4eaf1);
  border-color: var(--color-border, #3d4855);
}
.form-control:disabled { cursor: not-allowed; opacity: .65; }

/* Only these four focus properties are authoritative across legacy/lazy CSS.
   Insetting the 2px outline over the existing border draws one continuous frame
   without changing dimensions. Buttons, checkboxes and other native widgets
   retain their own focus treatment. Keep !important here, not in feature CSS. */
:root :is(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"], [type="button"], [type="submit"], [type="reset"], [type="image"]), select, textarea):focus {
  border-color: var(--form-control-focus) !important;
  outline: 2px solid var(--form-control-focus) !important;
  outline-offset: -2px !important;
  box-shadow: none !important;
}
:where(input, select, textarea)[aria-invalid="true"] {
  --form-control-focus: var(--form-control-error);
  border-color: var(--form-control-error) !important;
}

/* Existing borderless inner fields are adapters to the same group contract.
   New composite fields use data-form-control-group instead of another adapter. */
:is([data-form-control-group], .login-surface .phone-auth-number, .login-surface .phone-auth-row, .main-directory-search .search, .main-directory-search .folder-search, .plaza-gallery .pg-search, .search-box, .search-exclusive-input-wrap, .qa-panel-input, .points-section .aus-compact .aus-input-row):has(:where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]), select, textarea):focus) {
  border-color: var(--form-control-focus) !important;
  outline: 2px solid var(--form-control-focus) !important;
  outline-offset: -2px !important;
  box-shadow: none !important;
}
:is([data-form-control-group], .login-surface .phone-auth-number, .login-surface .phone-auth-row, .main-directory-search .search, .main-directory-search .folder-search, .plaza-gallery .pg-search, .search-box, .search-exclusive-input-wrap, .qa-panel-input, .points-section .aus-compact .aus-input-row) :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"]), select, textarea):focus {
  outline: none !important;
  box-shadow: none !important;
}
:is([data-form-control-group], .login-surface .phone-auth-number, .login-surface .phone-auth-row, .main-directory-search .search, .main-directory-search .folder-search, .plaza-gallery .pg-search, .search-box, .search-exclusive-input-wrap, .qa-panel-input, .points-section .aus-compact .aus-input-row):has([aria-invalid="true"]) {
  --form-control-focus: var(--form-control-error);
}

/* System high-contrast colors remain visible without relying on shadows. */
@media (forced-colors: active) {
  :root, .login-surface { --form-control-focus: Highlight; --form-control-error: LinkText; }
}
