/*
 * Shared form controls
 *
 * This is deliberately loaded after module styles.  It gives every form one
 * accessible checkbox/switch language, a Select2 surface and a small-screen
 * layout without each module having to reimplement the same controls.
 */
:root{
  --form-control-height:44px;
  --form-control-radius:12px;
  --switch-width:46px;
  --switch-height:26px;
}

/* Keep the native select usable while Select2 is loading or unavailable. */
:where(.content-card,.guest-shell,dialog) select{
  min-height:var(--form-control-height);
}

/* A consistent, keyboard-accessible switch for every checkbox in the app. */
:where(.content-card,.guest-shell,dialog) input[type="checkbox"]{
  -webkit-appearance:none;
  appearance:none;
  position:relative;
  flex:none!important;
  box-sizing:border-box!important;
  max-inline-size:var(--switch-width)!important;
  max-block-size:var(--switch-height)!important;
  inline-size:var(--switch-width)!important;
  min-inline-size:var(--switch-width)!important;
  block-size:var(--switch-height)!important;
  min-block-size:var(--switch-height)!important;
  margin:0!important;
  padding:0!important;
  border:1px solid #aebfba!important;
  border-radius:999px!important;
  background:#c8d4d0!important;
  box-shadow:inset 0 1px 2px rgba(20,42,53,.13);
  cursor:pointer;
  transition:background-color .18s ease,border-color .18s ease,box-shadow .18s ease;
  vertical-align:middle;
}

:where(.content-card,.guest-shell,dialog) input[type="checkbox"]::before{
  content:"";
  position:absolute;
  inset-block-start:3px;
  inset-inline-start:3px;
  inline-size:18px;
  block-size:18px;
  border-radius:50%;
  background:#fff;
  box-shadow:0 2px 5px rgba(20,42,53,.25);
  transform:translateX(0);
  transition:transform .18s ease;
}

:where(.content-card,.guest-shell,dialog) input[type="checkbox"]:checked{
  border-color:var(--primary,#4c246d)!important;
  background:var(--primary,#4c246d)!important;
}

:where(.content-card,.guest-shell,dialog) input[type="checkbox"]:checked::before{
  transform:translateX(20px);
}

:where(.content-card,.guest-shell,dialog) input[type="checkbox"]:focus-visible{
  outline:3px solid color-mix(in srgb,var(--primary,#4c246d) 30%,transparent);
  outline-offset:3px;
}

:where(.content-card,.guest-shell,dialog) input[type="checkbox"]:disabled{
  cursor:not-allowed;
  opacity:.55;
}

/* A label containing a switch remains a readable control row. */
@supports selector(label:has(> input[type="checkbox"])){
  :where(.content-card,.guest-shell,dialog) label:has(> input[type="checkbox"]){
    display:flex!important;
    flex-direction:row!important;
    align-items:center;
    justify-content:space-between;
    gap:.8rem;
    min-block-size:var(--form-control-height);
    padding:.45rem .65rem;
    border:1px solid color-mix(in srgb,var(--line,#d9e3df) 88%,transparent);
    border-radius:var(--form-control-radius);
    background:color-mix(in srgb,var(--surface,#fff) 88%,#eef5f2);
  }
  :where(.content-card,.guest-shell,dialog) label:has(> input[type="checkbox"]) > input[type="checkbox"]{
    order:2;
    margin-inline-start:auto!important;
  }
}

/* Select2 uses the native select as its source of truth; these styles only
 * replace the visible control. */
.select2-container{
  min-width:0!important;
  width:100%!important;
  max-width:100%;
  font:inherit;
}

.select2-container--default .select2-selection--single,
.select2-container--default .select2-selection--multiple{
  min-height:var(--form-control-height);
  border:1px solid #bfd0c8;
  border-radius:var(--form-control-radius);
  background:#fff;
  color:var(--ink,#13243d);
  transition:border-color .18s ease,box-shadow .18s ease;
}

.select2-container--default .select2-selection--single .select2-selection__rendered{
  padding-inline:12px 38px;
  color:var(--ink,#13243d);
  line-height:42px;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder{
  color:#62728a;
}

.select2-container--default .select2-selection--single .select2-selection__arrow{
  inset-inline-end:10px;
  block-size:42px;
}

.select2-container--default .select2-selection--multiple{
  padding:4px 34px 4px 8px;
}

.select2-container--default .select2-selection--multiple .select2-selection__rendered{
  display:block;
  padding:0;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice{
  margin:3px 4px 3px 0;
  padding:3px 7px;
  border:0;
  border-radius:999px;
  background:color-mix(in srgb,var(--primary,#4c246d) 12%,#fff);
  color:var(--ink,#13243d);
  font-size:.82em;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--focus .select2-selection--multiple,
.select2-container--default.select2-container--open .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--multiple{
  border-color:var(--primary,#4c246d);
  box-shadow:0 0 0 3px color-mix(in srgb,var(--primary,#4c246d) 16%,transparent);
}

.select2-dropdown{
  z-index:10050;
  overflow:hidden;
  border:1px solid #bfd0c8;
  border-radius:var(--form-control-radius);
  box-shadow:0 16px 32px rgba(17,37,53,.16);
}

.select2-search--dropdown{
  padding:8px;
  background:#f6faf8;
}

.select2-container--default .select2-search--dropdown .select2-search__field{
  min-height:38px;
  padding:8px 10px;
  border:1px solid #bfd0c8;
  border-radius:9px;
  font:inherit;
}

.select2-results__option{
  padding:9px 12px;
  font-size:.9rem;
  overflow-wrap:anywhere;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable{
  background:var(--primary,#4c246d);
}

/* Dropdowns may be attached to body or a dialog, so theme every Select2
 * surface from the root rather than relying on the surrounding form. */
html[data-theme="dark"] .select2-container--default :is(.select2-selection--single,.select2-selection--multiple),
html[data-theme="dark"] .select2-dropdown{
  background:#101d2b;
  border-color:#405269;
  color:#fff;
}
html[data-theme="dark"] .select2-container--default .select2-selection__rendered,
html[data-theme="dark"] .select2-container--default .select2-selection__clear{
  color:#fff;
}
html[data-theme="dark"] .select2-container--default .select2-selection__placeholder{
  color:#bac7d6;
}
html[data-theme="dark"] .select2-container--default .select2-selection__arrow b{
  border-color:#d6e1ec transparent transparent;
}
html[data-theme="dark"] .select2-container--default.select2-container--open .select2-selection__arrow b{
  border-color:transparent transparent #d6e1ec;
}
html[data-theme="dark"] .select2-search--dropdown{background:#162536}
html[data-theme="dark"] .select2-container--default .select2-search__field{
  background:#101d2b;
  color:#fff;
  caret-color:#fff;
  border-color:#405269;
}
html[data-theme="dark"] .select2-search__field::placeholder{color:#bac7d6;opacity:1}
html[data-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__choice,
html[data-theme="dark"] .select2-container--default .select2-results__option--selected{
  background:#2a4057;
  color:#fff;
}
html[data-theme="dark"] .select2-container--default .select2-selection__choice__remove{
  color:#d6e1ec;
  border-color:#526b82;
}
html[data-theme="dark"] .select2-container--default .select2-selection__choice__remove:is(:hover,:focus){
  background:#3c546d;
  color:#fff;
}
html[data-theme="dark"] .select2-container--default .select2-results__option--highlighted.select2-results__option--selectable{
  background:#17583f;
  color:#fff;
}
html[data-theme="dark"] .select2-container--default.select2-container--disabled :is(.select2-selection--single,.select2-selection--multiple){
  background:#202c3a;
  border-color:#354354;
}
html[data-theme="dark"] .select2-container--default .select2-results__option--disabled,
html[data-theme="dark"] .select2-container--disabled .select2-selection__rendered{color:#9baabc}
html[data-theme="dark"] .select2-container--default:is(.select2-container--focus,.select2-container--open) :is(.select2-selection--single,.select2-selection--multiple){
  border-color:var(--primary,#008b3c);
}

/* Dialogs need their menus above the dialog surface and not below its clip. */
dialog .select2-container{z-index:1}

.locale-form .select2-container{width:154px!important}
.locale-form .select2-container--default .select2-selection--single{min-height:38px}
.locale-form .select2-container--default .select2-selection--single .select2-selection__rendered{line-height:36px}
.locale-form .select2-container--default .select2-selection--single .select2-selection__arrow{block-size:36px}

@media(max-width:700px){
  :root{--form-control-height:46px}

  :where(.content-card,dialog,.guest-shell) :is(.patuh-form,.form-grid,.standard-form,.event-form-grid,.inspection-inline-support,.admin-role-fields){
    grid-template-columns:minmax(0,1fr)!important;
    gap:.8rem;
  }

  :where(.content-card,dialog,.guest-shell) :is(.span-2,.full){grid-column:auto!important}

  :where(.content-card,dialog,.guest-shell) :is(input:not([type="checkbox"]):not([type="radio"]),select,textarea){
    font-size:16px;
  }

  :where(.content-card,dialog,.guest-shell) :is(.form-actions,.detail-actions,.hero-actions,.actions){
    align-items:stretch;
  }

  :where(.content-card,dialog,.guest-shell) .form-actions .button{
    flex:1 1 170px;
    min-height:44px;
  }

  :where(.content-card,dialog,.guest-shell) :is(.inline-form,.upload-form){
    align-items:stretch;
  }

  :where(.content-card,dialog,.guest-shell) :is(.inline-form,.upload-form) :is(input,select,.select2-container,.button){
    width:100%;
    max-width:none;
  }

  .select2-dropdown{max-width:calc(100vw - 20px)}
  .locale-form .select2-container{width:140px!important}
}

/* Native radio semantics, fixed geometry even inside column/grid labels. */
:where(.content-card,.guest-shell,dialog) input[type="radio"]{appearance:auto!important;flex:none!important;box-sizing:border-box!important;width:20px!important;height:20px!important;min-width:20px!important;max-width:20px!important;min-height:20px!important;max-height:20px!important;padding:0!important;margin:0!important;accent-color:var(--primary,#008e75);vertical-align:middle}
:where(.content-card,.guest-shell,dialog) label:has(>input[type="radio"]){display:flex;flex-direction:row!important;align-items:center;gap:.65rem}
:where(.content-card,.guest-shell,dialog) input[type="radio"]:focus-visible{outline:3px solid var(--primary,#008e75);outline-offset:3px}
:where(.content-card,.guest-shell,dialog) input[type="radio"]:disabled{opacity:.55;cursor:not-allowed}
[data-theme=dark] :where(.content-card,.guest-shell,dialog) input[type="checkbox"]:not(:checked){background:#40556a!important;border-color:#698198!important}
:where(.content-card,.guest-shell,dialog) input[hidden]{display:none!important}
