/* Unified select controls are loaded after page-specific styles on purpose. */
select {
  color-scheme: light;
}

select:not([multiple]) {
  min-height: var(--control-height, 44px);
  padding: 10px 45px 10px 13px;
  border: 1px solid var(--ui-border,#aeb9c9);
  border-radius: var(--control-radius, 8px);
  -webkit-appearance: none;
  appearance: none;
  background-color: var(--ui-surface,#fff);
  background-image:
    var(--ui-select-arrow, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='10' viewBox='0 0 16 10' fill='none'%3E%3Cpath d='M2 2L8 8L14 2' stroke='%23244A7C' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")),
    linear-gradient(to left, var(--ui-info-soft,#edf2f8) 0, var(--ui-info-soft,#edf2f8) 42px, transparent 42px);
  background-repeat: no-repeat, no-repeat;
  background-position: right 13px center, 0 0;
  background-size: 16px 10px, 100% 100%;
  box-shadow: 0 1px 2px rgba(24, 34, 56, .04);
  color: var(--ink);
  cursor: pointer;
  line-height: 1.35;
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}

select:not([multiple]):hover:not(:disabled) {
  border-color: var(--ui-border,#8798b0);
  background-image:
    var(--ui-select-arrow, url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='10' viewBox='0 0 16 10' fill='none'%3E%3Cpath d='M2 2L8 8L14 2' stroke='%23183B63' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")),
    linear-gradient(to left, var(--ui-info-soft,#e3eaf4) 0, var(--ui-info-soft,#e3eaf4) 42px, transparent 42px);
}

select:not([multiple]):focus,
select:not([multiple]):focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 74, 124, .12);
  outline: 0;
}

select:not([multiple]):disabled {
  border-color: var(--ui-border,#d5dbe4);
  background-color: var(--ui-info-soft,#f3f5f8);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='10' viewBox='0 0 16 10' fill='none'%3E%3Cpath d='M2 2L8 8L14 2' stroke='%23808A9A' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(to left, var(--ui-info-soft,#e8ebf0) 0, var(--ui-info-soft,#e8ebf0) 42px, transparent 42px);
  color: var(--ui-muted,#707989);
  cursor: not-allowed;
}

select:not([multiple])[aria-invalid="true"] {
  border-color: var(--danger, #963247);
  box-shadow: 0 0 0 3px rgba(150, 50, 71, .1);
}

select:not([multiple]) option,
select:not([multiple]) optgroup {
  background: var(--ui-surface,#fff);
  color: var(--ink);
  font: inherit;
}

select[multiple] {
  min-height: 150px;
  padding: 6px;
  border: 1px solid var(--ui-border,#aeb9c9);
  border-radius: var(--control-radius, 8px);
  background: var(--ui-surface,#fff);
  box-shadow: inset 0 1px 2px rgba(24, 34, 56, .035);
  color: var(--ink);
}

select[multiple]:hover:not(:disabled) {
  border-color: var(--ui-border,#8798b0);
}

select[multiple]:focus,
select[multiple]:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(36, 74, 124, .12);
  outline: 0;
}

select[multiple] option {
  margin: 2px 0;
  padding: 9px 10px;
  border-radius: 6px;
}

select[multiple] option:checked {
  background: linear-gradient(var(--accent-soft), var(--accent-soft));
  color: var(--accent);
  font-weight: 700;
}

@supports selector(select:has(option[value=""]:checked)) {
  select:not([multiple]):has(option[value=""]:checked) {
    color: var(--muted);
  }
}

@media (max-width: 600px) {
  select:not([multiple]) {
    min-height: 48px;
    padding-top: 11px;
    padding-bottom: 11px;
    font-size: 16px;
  }
}

/* Enhanced dropdown. The native select stays in the form and owns its value. */
.custom-select {
  position: relative;
  display: inline-grid;
  max-width: 100%;
  min-width: 0;
  vertical-align: middle;
}

/* A wrapped select must still fill the same column as a text input. */
:is(.auth-form, .lesson-form-control, .analytics-filter, .teacher-filter-bar,
    .draft-sidebar, .draft-settings, .library-filter, .se-filters, .field-group) .custom-select {
  display: grid;
  width: 100%;
}

.custom-select__native,
.custom-select__trigger {
  grid-area: 1 / 1;
}

.custom-select__native {
  opacity: 0;
  pointer-events: none;
}

.custom-select__trigger,
button.custom-select__trigger {
  position: relative;
  z-index: 1;
  display: flex;
  width: 100%;
  min-width: 0;
  min-height: var(--control-height, 44px);
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 0 0 13px;
  overflow: hidden;
  border: 1px solid var(--ui-border,#aeb9c9);
  border-radius: var(--control-radius, 8px);
  background: var(--ui-surface,#fff);
  box-shadow: 0 1px 2px rgba(24, 34, 56, .04);
  color: var(--ink);
  font: inherit;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
}

.custom-select__trigger:hover:not(:disabled) {
  border-color: var(--ui-border,#8798b0);
  background: var(--ui-surface,#fff);
}

.custom-select__trigger:focus,
.custom-select__trigger:focus-visible,
.custom-select.is-open .custom-select__trigger {
  border-color: var(--accent);
  background: var(--ui-surface,#fff);
  box-shadow: 0 0 0 3px rgba(36, 74, 124, .12);
  outline: 0;
}

.custom-select__trigger:disabled {
  border-color: var(--ui-border,#d5dbe4);
  background: var(--ui-info-soft,#f3f5f8);
  color: var(--ui-muted,#707989);
  cursor: not-allowed;
  opacity: 1;
}

.custom-select.is-invalid .custom-select__trigger {
  border-color: var(--danger, #963247);
  box-shadow: 0 0 0 3px rgba(150, 50, 71, .1);
}

.custom-select__value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.custom-select__trigger.is-placeholder .custom-select__value {
  color: var(--muted);
}

.custom-select__chevron {
  position: relative;
  display: grid;
  width: 42px;
  min-width: 42px;
  min-height: calc(var(--control-height, 44px) - 2px);
  align-self: stretch;
  place-items: center;
  background: var(--ui-info-soft,#edf2f8);
}

.custom-select__chevron::before {
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  content: "";
  transform: translateY(-2px) rotate(45deg);
  transition: transform .16s;
}

.custom-select.is-open .custom-select__chevron {
  background: var(--accent-soft);
}

.custom-select.is-open .custom-select__chevron::before {
  transform: translateY(2px) rotate(225deg);
}

.custom-select__trigger:disabled .custom-select__chevron {
  background: var(--ui-info-soft,#e8ebf0);
}

.custom-select__trigger:disabled .custom-select__chevron::before {
  border-color: var(--ui-border,#808a9a);
}

.custom-select__menu {
  position: absolute;
  z-index: 1000;
  top: calc(100% + 7px);
  left: 0;
  width: max(100%, min(320px, calc(100vw - 32px)));
  max-width: min(720px, calc(100vw - 32px));
  padding: 7px;
  border: 1px solid var(--ui-border,#b7c2d1);
  border-radius: 11px;
  background: var(--ui-surface,#fff);
  box-shadow: 0 18px 45px rgba(24, 34, 56, .18), 0 4px 12px rgba(24, 34, 56, .08);
}

.custom-select.align-right .custom-select__menu {
  right: 0;
  left: auto;
}

.custom-select__menu[hidden] {
  display: none;
}

.custom-select.is-open {
  z-index: 200;
}

.custom-select__search {
  display: block;
  padding: 2px 2px 7px;
}

.custom-select__search input {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px 8px 36px;
  border-color: var(--ui-border,#c3ccd9);
  border-radius: 7px;
  background-color: var(--ui-info-soft,#f8fafd);
  background-image:
    linear-gradient(45deg, transparent 48%, var(--muted) 49%, var(--muted) 54%, transparent 55%),
    radial-gradient(circle, transparent 44%, var(--muted) 46%, var(--muted) 55%, transparent 57%);
  background-position: 19px 20px, 13px 13px;
  background-repeat: no-repeat;
  background-size: 8px 8px, 12px 12px;
}

.custom-select__list {
  display: grid;
  max-height: min(310px, 48vh);
  gap: 3px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #b6c1d0 transparent;
  scrollbar-width: thin;
}

.custom-select__list.is-empty::after {
  padding: 17px 12px;
  color: var(--muted);
  content: "Ничего не найдено";
  font-size: 13px;
  text-align: center;
}

.custom-select__option,
button.custom-select__option {
  display: flex;
  width: 100%;
  min-height: 39px;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  padding: 9px 36px 9px 11px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  white-space: normal;
  cursor: pointer;
}

.custom-select__option:hover:not(:disabled),
.custom-select__option:focus-visible {
  background: var(--ui-info-soft,#f0f4f9);
  color: var(--accent);
  outline: 0;
}

.custom-select__option.is-selected {
  position: relative;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 750;
}

.custom-select__option.is-selected::after {
  position: absolute;
  right: 13px;
  color: var(--accent);
  content: "✓";
  font-size: 15px;
  font-weight: 800;
}

.custom-select__option.is-placeholder {
  color: var(--muted);
}

.custom-select__option:disabled {
  color: var(--ui-muted,#929aa7);
  cursor: not-allowed;
  opacity: .68;
}

@media (max-width: 600px) {
  .custom-select__trigger,
  button.custom-select__trigger {
    min-height: 48px;
    font-size: 16px;
  }

  .custom-select__chevron {
    min-height: 46px;
  }

  .custom-select__menu {
    width: max(100%, min(300px, calc(100vw - 24px)));
    max-width: calc(100vw - 24px);
  }

  .custom-select__option,
  button.custom-select__option {
    min-height: 44px;
    font-size: 15px;
  }
}
