/*
 * Focus: a group and its items draw their ring on an `::after` overlay rather than the element's own box-shadow,
 * because their children (cards, tiles) usually paint opaque backgrounds that would cover an inset shadow. The ring
 * takes Next's focus-ring variables; a group also shows it, or the error colour, while a member reports a
 * state (`data-focus-state`), and `border` keeps a separator edge visible at rest.
 */

@layer dx-components {
  .dx-focus-group,
  .dx-focus-item {
    position: relative;
    outline: none;
  }
  .dx-focus-group::after,
  .dx-focus-item::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
  }
  /* A Card shares the element and writes `data-border='false'` for no edge, which a presence match would read as one. */
  .dx-focus-group[data-border]:where(:not([data-border='false']))::after,
  .dx-focus-item[data-border]:where(:not([data-border='false']))::after {
    box-shadow: inset 0 0 0 1px var(--color-separator);
  }
  /*
   * The selected items of a collection (`aria-selected`): one edge, whatever the container. Before the focus rules, so on
   * an item both selected and focused the focus ring (the current item) is the one drawn.
   */
  .dx-focus-item[aria-selected='true']::after {
    box-shadow: inset 0 0 0 var(--dx-focus-ring-width) var(--dx-selected-color);
  }
  /* A tile in a list (`data-focus-click`) is where the arrow keys continue from, so it shows the ring after a click too. */
  .dx-focus-group:focus-visible::after,
  .dx-focus-item:focus-visible::after,
  .dx-focus-item[data-focus-click]:focus::after {
    box-shadow: inset 0 0 0 var(--dx-focus-ring-width) var(--dx-focus-ring-color);
  }
  /*
   * A tile in a collection (`data-focus-click`) reads as a list's rows do: the selection is the focus
   * colour and the cursor is neutral — the inverse of a lone focus item, where the ring marks focus
   * and the subtle edge marks selection.
   */
  .dx-focus-item[data-focus-click] {
    --dx-selected-color: var(--color-focus);
    --dx-focus-ring-color: var(--color-neutral-border);
  }
  /*
   * An item that is both the cursor and the selection shows both, as a list's rows do: the selected
   * edge stays inside the box and the cursor moves to an outline outside it. Without this the focus
   * ring above replaces the selected edge, so clicking a tile in a collection hides what it selected.
   */
  .dx-focus-item[aria-selected='true']:is(:focus-visible, [data-focus-click]:focus) {
    outline: var(--dx-focus-ring-width) solid var(--dx-focus-ring-color);
    outline-offset: 1px;
  }
  .dx-focus-item[aria-selected='true']:is(:focus-visible, [data-focus-click]:focus)::after {
    box-shadow: inset 0 0 0 var(--dx-focus-ring-width) var(--dx-selected-color);
  }
  /* A group a drag is over takes the focus ring's colour, so the drop target reads as the focus does. */
  .dx-focus-group[data-focus-state='active']::after {
    box-shadow: inset 0 0 0 var(--dx-focus-ring-width) var(--dx-focus-ring-color);
  }
  .dx-focus-group[data-focus-state='error']::after {
    box-shadow: inset 0 0 0 var(--dx-focus-ring-width) var(--color-error-bg);
  }
}
