/*
 * Floating action bar (DESIGN.md §5): the bar fixed to the bottom of the
 * viewport that offers actions on the objectives ticked on /planning. It is
 * plain CSS -- no JavaScript:
 *
 *  - Shown by :has(). Each tick is a checkbox form-associated with
 *    form#planning_selection; the bar shows while any of them is :checked.
 *  - The count is a CSS counter. .tree-page (tree_page.css) resets "selected",
 *    every checked box increments it, and the bar follows the tree in document
 *    order, so counter(selected) in the bar is the final tally.
 *  - An element with display: none does not increment a counter, so a hidden
 *    tree level collapses its header with visibility: hidden instead
 *    (tree.css): a tick on a hidden level stays counted.
 *
 * z-index sits under the banner and toasts (10) and the sticky filter bar
 * (6, view_toggles.css). A modal <dialog> opened from the bar is in the top
 * layer and always covers it, whatever the z-index.
 */
@layer components {
  .tree-page input[form="planning_selection"]:checked {
    counter-increment: selected;
  }

  /* Never let the bar cover the last row: its height, its offset, and a gap. */
  .tree-page:has(input[form="planning_selection"]:checked) {
    padding-block-end: calc(var(--control-height) + var(--space-3) * 2 + var(--space-4) * 2);
  }

  .bulk-toolbar {
    position: fixed;
    inset-inline: 0;
    inset-block-end: var(--space-4);
    z-index: 5;
    display: none;
    align-items: center;
    gap: var(--space-3);
    margin-inline: auto;
    inline-size: fit-content;
    max-inline-size: calc(100vw - var(--space-8));
    padding: var(--space-3) var(--space-4);
    border: var(--border);
    border-radius: var(--radius-m);
    background: var(--color-paper);
    box-shadow: var(--shadow-overlay);
    font: var(--text-small);

    & > * {
      margin: 0;
    }

    /* The archive confirmation (text and buttons) joins the bar's own row. */
    & turbo-frame {
      display: contents;
    }
  }

  .tree-page:has(input[form="planning_selection"]:checked) .bulk-toolbar {
    display: flex;
  }

  .bulk-toolbar__count {
    font: var(--text-body-strong);
    white-space: nowrap;

    &::before {
      content: counter(selected) " selected";
    }
  }

  /* The Link dialog's search row: the level toggles, the field, and Search. */
  .planning-selection {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    margin: 0;

    & input[type="search"] {
      flex: 1;
      min-inline-size: 12rem;
    }
  }
}
