/* Shared set tree: native disclosures, native selection and navigation links. */
.set_select {
  display: none;
  box-sizing: border-box;
  max-width: 100%;
  max-height: min(480px, 55dvh);
  margin-block-start: var(--ui-space-2);
  padding: var(--ui-space-2);
  overflow: auto;
  background: var(--color-input-background);
  border: 1px solid var(--color-input-border);
  border-radius: var(--ui-radius-control);
  /* At either end, continue scrolling the containing settings panel. */
  overscroll-behavior: auto;
}

/* A tree shows once the script has built it, or at once when the server drew
   it built (SetPickerHelper#set_navigation_tree). */
.set_select:is(.tree-select-initialized, .tree-select) { display: block; }

/* A saved-open inspector tree changes the height of every panel below it.
   Restore that structure before revealing the column, with the shared
   fail-open deadline if enhancement cannot start. */
#panels:has(.panel:not(.hidden) .set_select:not(.tree-select-initialized)) > .panel {
  visibility: hidden;
  animation: tree-select-reveal 0s linear var(--ui-delay-enhancement) forwards;
}

@keyframes tree-select-reveal {
  to { visibility: visible; }
}

/* Only a little taller than the box: grow to fit instead of scrolling a few
   pixels (libraries/tree_select#fitHeight); a long tree keeps the cap. */
.set_select[data-fits] {
  max-height: none;
}

/* A navigation tree (the website overview's sets) is a list to read and
   open, not a field to fill in. It has no field box and no scrolling of its
   own (the surface around it grows). */
.set_select.expanded {
  max-height: none;
  padding: 0;
  overflow: visible;
  background: transparent;
  border: 0;
}

.tree-select-node,
.tree-select-children {
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* The tree's row: 24px with a mouse, as the set tree always had, and the
   44px touch target on touch. Each level steps in by one row. */
.tree-select {
  --tree-select-row: var(--ui-space-6);
}

@media (any-pointer: coarse) {
  .tree-select {
    --tree-select-row: var(--ui-control-height-inline);
  }
}

.tree-select-node {
  display: grid;
  grid-template-columns: var(--tree-select-row) minmax(0, 1fr);
  align-items: start;
}

/* A tick box sits at the right end of its row, inside the row's highlight,
   so the set's coloured folder always shows. */
.tree-select-node.has-choice > .tree-select-anchor,
.tree-select-node.has-choice > .tree-select-choice {
  grid-row: 1;
  grid-column: 2;
}

.tree-select-multiple .tree-select-node > .tree-select-anchor {
  padding-inline-end: calc(var(--tree-select-row) + var(--ui-space-1));
}

.tree-select-node.has-choice > .tree-select-choice {
  z-index: 1;
  align-self: center;
  justify-self: end;
}

/* Each level steps in by exactly one disclosure column. A set's own arrow
   then sits under its parent's folder and every level lines up, as in the
   Sets view and Finder. */
.tree-select-node > .tree-select-children {
  grid-column: 1 / -1;
  margin-inline-start: var(--tree-select-row);
}

/* Guide lines join each set to its parent. A line drops from the middle of
   the parent's arrow and a short branch meets each child's row. The line
   stops at the last child (└), so it never runs on past its family. A child
   without an arrow gets a longer branch, up to its folder. */
.tree-select-node > .tree-select-children > .tree-select-node {
  --tree-select-guide-x: calc(var(--tree-select-row) / -2);
  --tree-select-row-middle: calc(var(--tree-select-row) / 2);

  position: relative;
}

.tree-select-node > .tree-select-children > .tree-select-node::before,
.tree-select-node > .tree-select-children > .tree-select-node::after {
  position: absolute;
  inset-inline-start: var(--tree-select-guide-x);
  pointer-events: none;
  content: '';
}

.tree-select-node > .tree-select-children > .tree-select-node::before {
  inset-block: 0;
  border-inline-start: 1px solid var(--color-border-subtle);
}

/* The first child's line reaches up to its parent's arrow. */
.tree-select-node > .tree-select-children > .tree-select-node:first-child::before {
  inset-block-start: calc(var(--ui-space-1) * -1);
}

.tree-select-node > .tree-select-children > .tree-select-node.tree-select-last::before {
  inset-block-end: auto;
  height: var(--tree-select-row-middle);
}

.tree-select-node > .tree-select-children > .tree-select-node.tree-select-last:first-child::before {
  height: calc(var(--tree-select-row-middle) + var(--ui-space-1));
}

.tree-select-node > .tree-select-children > .tree-select-node::after {
  inset-block-start: var(--tree-select-row-middle);
  width: calc(var(--tree-select-row) / 2 + var(--ui-space-1));
  border-block-start: 1px solid var(--color-border-subtle);
}

/* A leaf has no arrow, so its branch runs on to just short of its folder. */
.tree-select-node > .tree-select-children > .tree-select-node.tree-select-leaf::after {
  width: calc(var(--tree-select-row) * 1.5);
}

.tree-select-closed > .tree-select-children,
.tree-select-leaf > .tree-select-children,
.tree-select-hidden,
.tree-select-node[hidden] { display: none; }

.tree-select-anchor,
.tree-select-ocl {
  box-sizing: border-box;
  min-width: 0;
  min-height: var(--tree-select-row);
  margin: 0;
  padding: 0 var(--ui-space-1);
  color: var(--color-text);
  font: inherit;
  text-align: start;
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: var(--ui-radius-control);
  touch-action: manipulation;
}

/* Set names read as one tree in the text colour, not as a column of
   separate blue links. The row's hover shows each is a way in. The top set
   is a step heavier. */
.tree-select-anchor,
#main .tree-select-anchor,
#main .tree-select-anchor:visited {
  color: var(--color-text);
}

.tree-select-container-ul > .tree-select-node > .tree-select-anchor {
  font-weight: var(--ui-weight-medium);
}

/* A click picks the set, so a double or shift click never selects its
   name's text as well. */
.tree-select-anchor {
  display: flex;
  align-items: center;
  gap: var(--ui-space-2);
  overflow-wrap: anywhere;
  cursor: pointer;
  border-radius: 0;
  -webkit-user-select: none;
  user-select: none;
}

.tree-select-anchor:not([aria-disabled='true'], :disabled):not(.tree-select-clicked):hover,
button.tree-select-ocl:hover { background-color: var(--color-surface-muted); }

.tree-select-label {
  min-width: 0;
}

.tree-select-count {
  flex: none;
  margin-inline-start: auto;
  padding: 0 var(--ui-space-2);
  color: var(--color-count-badge-text);
  font-size: var(--ui-font-size-small);
  font-weight: var(--ui-weight-medium);
  font-variant-numeric: tabular-nums;
  line-height: var(--ui-space-5);
  white-space: nowrap;
  background: var(--color-count-badge-bg);
  border-radius: var(--ui-radius-pill);
}

.tree-select-anchor.tree-select-clicked,
#main .tree-select-anchor.tree-select-clicked {
  color: var(--color-selection-text);
  background: var(--color-neutral-state-one);
}

/* The checkbox focus outline also sits on the selected row's fill. */
.tree-select-anchor.tree-select-clicked + .tree-select-choice {
  color: var(--color-selection-text);
}

.tree-select-anchor:focus-visible,
.tree-select-ocl:focus-visible,
.tree-select-choice:has(input:focus-visible) {
  outline: 2px solid currentColor;
  outline-offset: -2px;
}

.tree-select-ocl {
  display: grid;
  width: var(--tree-select-row);
  height: var(--tree-select-row);
  place-items: center;
}

button.tree-select-ocl { cursor: pointer; }

button.tree-select-ocl::before,
.tree-select-themeicon::before {
  display: block;
  font-family: var(--ui-icon-font-family);
  font-size: var(--ui-icon-size);
  font-weight: var(--ui-icon-weight);
  font-style: normal;
}

button.tree-select-ocl::before {
  content: var(--ui-icon-angle-right) var(--ui-icon-alt,);
  transition: transform var(--ui-duration-feedback) var(--ui-ease-feedback);
}

button.tree-select-ocl[aria-expanded='true']::before { transform: rotate(90deg); }
/* Sets show the same coloured folders as the Sets view. The account colours
   stylesheet (style_sheets/colours) paints each set in its own colour, with a
   lock when locked. Other nodes use DPG's default folder. The same artwork
   suits both themes. The artwork draws the folder in the middle half of a
   square. So the icon is cut to the folder's own 4:3 box, with no empty
   margin in the row. The artwork is drawn at twice the icon's width,
   centred. */
.tree-select-themeicon {
  flex: none;
  width: 16px;
  height: 12px;
  background-image: url("/assets/tree_select/tree_select-ed9193c6.svg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 200%;
}

.tree-select-themeicon::before { content: none; }

/* The same coloured folder outside the tree, with its name beside it
   (ImagesHelper#image_set_icon). It shows a set in a list, such as the image
   review's Sets panel. The account colours stylesheet paints it per colour. */
.set_icon {
  display: inline-block;
  flex: none;
  width: 24px;
  height: 24px;
  vertical-align: middle;
  background-image: url("/assets/tree_select/tree_select-ed9193c6.svg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: 24px 24px;
}

/* ImagesHelper#set_name_link: a larger folder beside the set's own name,
   with the sets it sits in on a quieter line under it. Each line keeps to
   one line and is cut short (the whole path is the link's title). */
.set_name {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: var(--ui-space-3);
  min-width: 0;
  text-decoration: none;
}

/* The folder spans both lines. The artwork draws it in the middle half of
   a square. The icon is cut to the folder's own 4:3 box, and the artwork is
   drawn at twice the icon's width, centred. */
.set_name > .set_icon {
  width: 32px;
  height: 24px;
  background-size: 200%;
}

.set_name_text {
  display: grid;
  min-width: 0;
}

.set_name_title,
.set_name_path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.set_name_title {
  color: var(--color-text);
  font-size: var(--ui-font-size-label);
  font-weight: var(--ui-weight-medium);
  line-height: var(--ui-line-height-control);
}

.set_name_path {
  color: var(--color-text-secondary);
  font-size: var(--ui-font-size-small);
  line-height: var(--ui-line-height-control);
}

.set_name:hover .set_name_title {
  text-decoration: underline;
}

.tree-select-choice {
  display: grid;
  box-sizing: border-box;
  width: var(--tree-select-row);
  height: var(--tree-select-row);
  margin: 0;
  padding: 0;
  place-items: center;
  border-radius: var(--ui-radius-control);
  cursor: pointer;
  touch-action: manipulation;
}

.tree-select-choice input[type='checkbox'] {
  position: static;
  min-width: 0;
  margin: 0;
}

/* With a mouse, a set is chosen by clicking its name (Cmd, Ctrl or Shift adds
   more), so the tree reads like the Sets view. Pointing at a row, reaching its
   box with the keyboard, or ticking it shows the box for choosing several.
   Touch screens always show it, since there is no modifier key there. */
@media (hover: hover) and (pointer: fine) {
  .tree-select-node.has-choice > .tree-select-choice {
    width: 24px;
    height: 24px;
    opacity: 0;
  }

  .tree-select-node.has-choice > .tree-select-anchor:hover + .tree-select-choice,
  .tree-select-node.has-choice > .tree-select-choice:hover,
  .tree-select-node.has-choice > .tree-select-choice:focus-within,
  .tree-select-node.has-choice > .tree-select-choice:has(input:checked) {
    opacity: 1;
  }

  .tree-select-multiple .tree-select-node > .tree-select-anchor {
    padding-inline-end: calc(24px + var(--ui-space-2));
  }
}

.tree-select-anchor:disabled,
.tree-select-anchor[aria-disabled='true'],
.tree-select-choice:has(:disabled) {
  cursor: not-allowed;
}

.tree-select-node[data-hidden='true'] > .tree-select-anchor:not(.tree-select-clicked) { opacity: 0.75; }
