/* xSort controls use the template tokens, so admin styling and dark mode apply. */
.xsort-scope > .xsort-area {
  margin-bottom: 20px;
}

.xsort-area {
  position: relative;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: 500 13px/1.4 var(--font);
  isolation: isolate;
}

.xsort-area[aria-busy="true"] {
  opacity: 0.7;
  pointer-events: none;
}

.xsort-label {
  padding-right: 6px;
  color: var(--text-strong);
  font-weight: 700;
}

.xsort-div {
  position: relative;
  min-width: 0;
  max-width: 100%;
  height: 40px;
  border: 1px solid var(--border-btn);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-nav);
  transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease;
}

.xsort-div:hover,
.xsort-div.is-open {
  border-color: var(--green);
}

.xsort-div.xsort-active {
  border-color: var(--green);
  background: var(--hover-soft);
  color: var(--accent-text);
}

.xsort-div.is-open {
  z-index: 2;
}

.xsort-selected {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 32px 0 12px;
  overflow: hidden;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  outline: none;
}

.xsort-selected > span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.xsort-selected::after {
  content: "";
  position: absolute;
  top: 14px;
  right: 13px;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  opacity: 0.65;
  transform: rotate(45deg);
  transition: transform 0.16s ease;
}

.is-open > .xsort-selected::after {
  top: 17px;
  transform: rotate(225deg);
}

.xsort-div:has(.xsort-selected:focus-visible),
.xsort-div-clearall:focus-visible,
.xsort-empty__reset:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
}

.xsort-ul {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  width: max-content;
  min-width: 200px;
  max-width: min(280px, calc(100vw - 32px));
  max-height: min(340px, 50vh);
  margin: 0;
  padding: 6px;
  overflow: auto;
  overscroll-behavior: contain;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  color: var(--text);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.xsort-ul li {
  position: relative;
  padding: 9px 32px 9px 12px;
  border-radius: var(--radius-sm);
  line-height: 1.4;
  overflow-wrap: anywhere;
  cursor: pointer;
  outline: none;
}

.xsort-ul li + li {
  margin-top: 2px;
}

.xsort-ul li:hover,
.xsort-ul li:focus-visible {
  background: var(--control-hover);
}

.xsort-ul li.current {
  background: var(--hover-soft);
  color: var(--accent-text);
  font-weight: 600;
}

.xsort-ul li.current::after {
  content: "";
  position: absolute;
  top: 12px;
  right: 13px;
  width: 5px;
  height: 9px;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  transform: rotate(45deg);
}

.xsort-area .xasc::before {
  content: "↑";
  margin-right: 6px;
}

.xsort-area .xdesc::before {
  content: "↓";
  margin-right: 6px;
}

.xsort-div-clearall {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-shrink: 0;
  padding: 0 12px;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  cursor: pointer;
}

.xsort-div-clearall:hover {
  background: var(--surface);
  color: var(--text);
}

.xsort-area:not(:has(.xsort-active)) .xsort-div-clearall {
  display: none;
}

.xsort_empty {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px;
  grid-column: 1 / -1;
  margin: 0;
  padding: 28px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: 400 14px/1.6 var(--font);
  text-align: center;
}

.xsort-empty__reset {
  padding: 9px 14px;
  border: 1px solid var(--green);
  border-radius: var(--radius-sm);
  background: var(--hover-soft);
  color: var(--accent-text);
  font: 600 13px/1.4 var(--font);
  cursor: pointer;
}

.xsort-empty__reset:hover {
  background: color-mix(in srgb, var(--green) 20%, transparent);
}

@media (max-width: 600px) {
  .xsort-area {
    padding: 12px;
  }

  .xsort-label {
    flex-basis: 100%;
    padding: 0 0 2px;
  }

  .xsort-area > .xsort-div:not(button) {
    flex: 1 1 calc(50% - 4px);
  }

  .xsort-div {
    height: 44px;
  }

  .xsort-selected {
    min-height: 42px;
  }

  .xsort-selected::after {
    top: 16px;
  }

  .is-open > .xsort-selected::after {
    top: 19px;
  }
}

/* Home page: filter results replace the default feed while a filter is active. */
.home-page:not(.is-on) .home-xsort-results {
  display: none;
}

.home-page.is-on .home-feed-default {
  display: none;
}

