/*
 * View toggles (DESIGN.md §5): a GET form of checkbox buttons that switch what
 * a page shows. Each .toggle-button is a <label> around a native checkbox that
 * looks like a quiet .btn--small; the checked checkbox is the pressed state,
 * so the state lives in the URL and works without JavaScript. The checkbox is
 * visually hidden but stays focusable; the label is the click target.
 * .planning-toolbar puts the toggles beside a page-level action link and
 * sticks under the banner, so the switches stay in reach anywhere on the page.
 * Its single-line height is the --planning-toolbar-height token, which the
 * sidebar (tree_page.css) sits below; the drag auto-scroll band starts under
 * its measured edge (objective_tree_controller.js).
 */
@layer components {
  .planning-toolbar {
    position: sticky;
    inset-block-start: var(--app-header-height);
    z-index: 6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    min-block-size: var(--planning-toolbar-height);
    margin: 0;
    padding-block: var(--space-2);
    border-block-end: var(--rule);
    background: var(--color-surface);

    & > * {
      margin: 0;
    }
  }

  /* The toolbar's rule is the first section's: stuck, it still separates the bar from what scrolls under it. */
  .planning-toolbar + .tree-page > .tree > .section:first-child {
    border-block-start: 0;
  }

  .view-toggles {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-4);
    margin: 0;
  }

  /* A fieldset is a row of buttons here, not a form section: drop forms.css's rule. */
  .view-toggles__group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    border: 0;

    & > * {
      margin: 0;
    }
  }

  .toggle-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-1) var(--space-3);
    border: var(--border);
    border-radius: var(--radius-s);
    background: var(--color-paper);
    color: var(--color-text);
    font: var(--text-small);
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;

    &:hover {
      background: var(--color-surface-2);
      border-color: var(--color-text);
      color: var(--color-ink);
    }

    /* Hidden, not removed: it keeps keyboard focus and the checked state. */
    & input[type="checkbox"] {
      position: absolute;
      inline-size: 1px;
      block-size: 1px;
      margin: 0;
      opacity: 0;
      pointer-events: none;
    }

    &:has(:checked) {
      background: var(--color-ink);
      border-color: var(--color-ink);
      color: var(--color-paper);

      &:hover {
        background: var(--color-graphite);
        border-color: var(--color-graphite);
        color: var(--color-paper);
      }
    }

    &:has(:focus-visible) {
      outline: 2px solid var(--color-focus);
      outline-offset: 2px;
    }
  }
}
