/* A grid's filter menu, beside Select (media_items/_filter_menu), and what it narrows the grid down to */
.filter-menu {
  /* Its button stands out while any filter is on, or the order isn't the default */
  &:has(.filter-panel.filtering) > summary {
    --button-bg: color-mix(in srgb, var(--button-color) 35%, var(--bg-color));
    border-color: var(--button-color);
  }

  &[open] > summary {
    --tooltip-display: none;
  }
}

.filter-panel {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  z-index: 20;

  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 22rem;
  max-width: calc(100vw - 2 * var(--space-4));
  max-height: calc(100svh - 6rem);
  overflow-y: auto;
  padding: var(--space-3) var(--space-4) var(--space-4);

  background-color: var(--card-bg-color);
  border-radius: var(--radius-s);
  box-shadow: 0 4px 12px var(--drop-shadow-color);

  /* Clearing only shows while there's something to clear */
  &:not(.filtering) .filter-clear {
    visibility: hidden;
  }
}

.filter-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);

  h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
  }

  .actions {
    flex-wrap: nowrap;
  }

  /* As tall as the chips */
  :is(.filter-clear, .filter-apply) {
    padding: var(--space-1) var(--space-3);
    font-size: var(--fs-small);
  }
}

.filter-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: none;

  /* With any choices about the whole filter at the end, such as whether items need any or all of the people */
  legend {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    width: 100%;
    margin-bottom: var(--space-2);
    padding: 0;
    color: var(--meta-text-color);
    font-size: var(--fs-small);
    font-weight: 600;
  }
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* A choice that's on or off */
.filter-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin: 0;
  padding: var(--space-1) var(--space-3);

  border: 1px solid var(--border-color);
  border-radius: var(--radius-m);
  background-color: var(--bg-color);
  font-size: var(--fs-small);
  font-weight: 600;
  line-height: 1.5;
  cursor: pointer;
  user-select: none;

  @media (hover: hover) {
    &:hover {
      background-color: var(--card-bg-hover-color);
    }
  }

  &:has(:checked) {
    border-color: var(--button-color);
    background-color: color-mix(in srgb, var(--button-color) 35%, var(--bg-color));
  }

  &:has(:focus-visible) {
    box-shadow: 0 0 var(--focus-glow-size) var(--focus-shadow-color);
  }
}

/* The checkboxes and radio buttons of chips and toggles can't be seen, but can still be reached with the keyboard */
:is(.filter-chip, .filter-match label) input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* Whether items need any or all of the chosen people: two small halves, the chosen one filled */
.filter-match {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-m);
  background-color: var(--bg-color);

  label {
    position: relative;
    margin: 0;
    padding: 0 var(--space-2);
    font-size: 0.75rem;
    cursor: pointer;
    user-select: none;

    &:has(:checked) {
      background-color: color-mix(in srgb, var(--button-color) 35%, var(--bg-color));
      color: var(--text-color);
    }

    &:has(:focus-visible) {
      box-shadow: inset 0 0 var(--focus-glow-size) var(--focus-shadow-color);
    }
  }
}

/* What the grid is put in order by, and which way round in the words for what it's picked
   (FiltersHelper#order_direction_choices). The albums page's order menus have name and count too */
.filter-order {
  select {
    width: 100%;
    font-size: var(--fs-small);
  }

  [data-direction-of] {
    display: none;
  }

  &:has(option[value=taken]:checked, option[value=added]:checked) [data-direction-of=date],
  &:has(option[value=rating]:checked) [data-direction-of=rating],
  &:has(option[value=size]:checked) [data-direction-of=size],
  &:has(option[value=name]:checked) [data-direction-of=name],
  &:has(option[value=count]:checked) [data-direction-of=count] {
    display: inline;
  }
}

/* A rating's star with its number */
.filter-stars {
  display: inline-flex;
  align-items: center;
  gap: 2px;

  .icon svg {
    width: 1rem;
    height: 1rem;
    fill: var(--star-color);
  }
}

.filter-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);

  label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
    margin: 0;
    color: var(--meta-text-color);
    font-size: var(--fs-small);
  }

  input {
    min-width: 0;
    color: var(--text-color);
  }
}
