/* ==========================================================================
   Custom select
   --------------------------------------------------------------------------
   Paired with static/js/select.js. The native popup is drawn by the operating
   system and cannot be styled, so the list below reproduces it using the same
   vocabulary as the application's other menus: square corners, warm paper,
   a single hairline border and the 0 18px 40px shadow.
   ========================================================================== */

.sel {
  position: relative;
  display: block;
}

/* The native control keeps holding the value and submitting with the form, so
   it is hidden without being removed from the document. */
.sel-native {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

/* Trigger ---------------------------------------------------------------- */
/* Inherits whatever classes the original select carried, so it keeps the
   surrounding form's sizing and borders; only layout is added here. */

.sel-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--color-slate-950, #111411);
}

.sel-trigger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.sel-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sel-chevron {
  display: inline-flex;
  flex: 0 0 auto;
  color: var(--color-slate-500, #6d736b);
  transition: transform 150ms ease;
}
.sel-chevron svg { width: 0.95rem; height: 0.95rem; }

.sel-trigger[aria-expanded="true"] .sel-chevron { transform: rotate(180deg); }

/* List ------------------------------------------------------------------- */

.sel-list {
  position: absolute;
  z-index: 80;
  top: calc(100% + 2px);
  left: 0;
  /* Sized to its content so option text does not wrap in a narrow filter,
     but never wider than the viewport can show. */
  width: max-content;
  min-width: 100%;
  max-width: min(24rem, calc(100vw - 2rem));
  max-height: 16rem;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  overflow-y: auto;
  background: var(--color-white, #fbfaf4);
  border: 1px solid #c6c4ba;
  box-shadow: 0 18px 40px #11141124;
}

/* Opened upwards when there is no room below. */
.sel--up .sel-list {
  top: auto;
  bottom: calc(100% + 2px);
}

.sel-option {
  padding: 0.5rem 0.6rem;
  white-space: nowrap;
  font-size: 0.85rem;
  line-height: 1.35;
  color: var(--color-slate-700, #383e38);
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Keyboard and pointer share one highlight, so arrowing and hovering look the
   same and there is never a second, competing indicator. */
.sel-option.is-active {
  background: var(--color-slate-100, #eae8de);
  color: var(--color-slate-950, #111411);
}

.sel-option[aria-selected="true"] {
  font-weight: 600;
  color: var(--color-slate-950, #111411);
}

/* The tick marks the current value; the space is always reserved so options do
   not shift sideways as the selection moves. */
.sel-option::before {
  content: "";
  flex: 0 0 0.9rem;
  height: 0.9rem;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0.85rem;
}

.sel-option[aria-selected="true"]::before {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23111411' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 13 4 4L19 7'/%3E%3C/svg%3E");
}

.sel-option[aria-disabled="true"] {
  color: var(--color-slate-400, #8d9289);
  cursor: not-allowed;
}

/* On the console's dark chrome the list keeps the same shape but inverts. */
.pf-bar .sel-list {
  background: #1b201b;
  border-color: #4b5248;
}
.pf-bar .sel-option { color: #b6bcb2; }
.pf-bar .sel-option.is-active { background: #2e342d; color: #fbfaf4; }

@media (prefers-reduced-motion: reduce) {
  .sel-chevron { transition: none; }
}
