/* Shared select controls: school forms, account details, and report filters. */
.custom-select {
  position: relative;
  display: inline-block;
  width: 100%;
  min-width: 0;
  vertical-align: middle;
}
.list-toolbar .custom-select { min-width: 160px; }
@media (max-width: 780px) { .list-toolbar .custom-select { min-width: 0; } }

/* Keep the original form control available for validation and value changes. */
select.custom-select-native {
  position: absolute !important;
  top: 0;
  left: 0;
  width: 1px !important;
  height: 1px !important;
  min-width: 0 !important;
  min-height: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  pointer-events: none;
}

.custom-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--control-radius);
  background: var(--surface);
  box-shadow: var(--control-shadow), inset 0 1px 0 #ffffff12;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
  transition: background-color .16s, border-color .16s, box-shadow .16s;
}

.custom-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.custom-select:not(.has-value) .custom-select-value { color: var(--muted); }
.custom-select-chevron {
  display: grid;
  place-items: center;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  transition: transform .18s, color .16s;
}
.custom-select-chevron svg { width: 18px; height: 18px; }
.custom-select-trigger:hover:not(:disabled) {
  background: var(--surface-soft);
  border-color: var(--blue);
}
.custom-select-trigger:focus-visible,
.custom-select.is-open .custom-select-trigger {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: var(--control-shadow);
}
.custom-select.is-open .custom-select-chevron { color: var(--blue); transform: rotate(180deg); }
.custom-select-trigger:disabled {
  background: var(--surface-soft);
  box-shadow: none;
  cursor: not-allowed;
  opacity: .65;
}
.custom-select.is-invalid .custom-select-trigger,
.custom-select-trigger[aria-invalid="true"] {
  border-color: #b43835;
  outline-color: #b43835;
}
.custom-select-error {
  display: block;
  padding-top: 7px;
  color: #a32d27;
  font-size: 12px;
  line-height: 1.5;
}

/* The popover sits in the top layer, independent of card overflow and dialogs. */
.custom-select-menu {
  position: fixed;
  inset: auto;
  display: none;
  margin: 0;
  padding: 6px;
  max-width: calc(100vw - 24px);
  max-height: min(320px, calc(100dvh - 24px));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 4px 12px #142c5010, 0 16px 40px #142c5026;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  text-align: left;
  transform-origin: top center;
}
.custom-select-menu:popover-open { display: block; }
.custom-select-menu[popover]:not(:popover-open) { display: none; }
.custom-select-menu.is-fallback.is-open { display: block; z-index: 1000; }
.custom-select-menu[hidden] { display: none !important; }
.custom-select-menu[data-placement="above"] { transform-origin: bottom center; }
.custom-select-menu::backdrop { background: transparent; }
.custom-select-menu::-webkit-scrollbar { width: 9px; }
.custom-select-menu::-webkit-scrollbar-track { background: transparent; }
.custom-select-menu::-webkit-scrollbar-thumb {
  border: 3px solid var(--surface);
  border-radius: 12px;
  background: var(--line-strong);
}
.custom-select-menu:focus { outline: none; }
.custom-select-group + .custom-select-group {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
}
.custom-select-group-label {
  padding: 8px 12px 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.5;
  text-transform: uppercase;
}
.custom-select-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin: 2px 0;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--ink);
  overflow-wrap: anywhere;
  cursor: pointer;
  user-select: none;
  transition: background-color .12s, color .12s;
}
.custom-select-option[aria-selected="true"] {
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 650;
}
.custom-select-option-label { flex: 1; min-width: 0; }
.custom-select-option:hover:not([aria-disabled="true"]),
.custom-select-option.is-active {
  background: var(--surface-hover);
  color: var(--ink);
}
.custom-select-option.is-active { border-color: var(--line-strong); }
.custom-select-option[aria-selected="true"].is-active { color: var(--blue); }
.custom-select-option[aria-disabled="true"] { color: var(--muted); cursor: not-allowed; opacity: .55; }
.custom-select-check {
  flex: 0 0 17px;
  width: 17px;
  height: 17px;
  color: var(--blue);
  opacity: 0;
}
.custom-select-option[aria-selected="true"] .custom-select-check { opacity: 1; }
.custom-select-empty { margin: 0; padding: 14px 12px; color: var(--muted); font-size: 12px; }

:root[data-theme="dark"] .custom-select-menu { box-shadow: 0 4px 12px #00000030, 0 16px 40px #00000050; }
:root[data-theme="dark"] .custom-select-error { color: #ffb6b0; }
:root[data-theme="dark"] .custom-select.is-invalid .custom-select-trigger,
:root[data-theme="dark"] .custom-select-trigger[aria-invalid="true"] { border-color: #ef9b94; outline-color: #ef9b94; }

@media (max-width: 520px) {
  .custom-select-trigger, .custom-select-menu { font-size: 16px; }
  .custom-select-trigger { padding-inline: 12px; }
  .custom-select-menu { max-height: min(280px, calc(100dvh - 24px)); }
  .custom-select-option { padding-inline: 10px; }
}
@media (prefers-reduced-motion: no-preference) {
  .custom-select-menu:popover-open { animation: select-menu-arrive .14s ease-out; }
  @keyframes select-menu-arrive {
    from { opacity: 0; transform: translateY(-3px) scale(.99); }
    to { opacity: 1; transform: translateY(0) scale(1); }
  }
}
@media (prefers-reduced-motion: reduce) {
  .custom-select-trigger, .custom-select-chevron, .custom-select-option { transition: none; }
}
@media (forced-colors: active) {
  .custom-select-trigger, .custom-select-menu { border-color: ButtonText; }
  .custom-select-option.is-active { border-color: Highlight; }
  .custom-select-option[aria-selected="true"] { outline: 1px solid Highlight; outline-offset: -2px; }
  .custom-select-check { color: Highlight; }
}
