/*
 * The research notebook's drawer (shared/_notebook_drawer): the tab at the
 * bottom right of every page, the drawer it opens from the bottom, and the
 * clip overlay the `notebook-drawer` controller lays over the page. What is
 * inside the drawer is components/notebook-panes.css, which /notebook draws
 * too.
 *
 *   .notebook-drawer          the element Turbo keeps between pages
 *   .notebook-drawer__tab     the tab that opens it, gone while it is open
 *   .notebook-drawer__panel   the drawer: the full width of the window and
 *                             --notebook-drawer-height tall. `data-open`
 *                             slides it in and out; `data-size` (peek, half,
 *                             full, custom) is the size it is at, and at peek
 *                             the panes show the note alone; `data-resizing`
 *                             while its edge is dragged, which stops the
 *                             height from easing behind the pointer
 *   .notebook-drawer__handle  its top edge, dragged to resize it
 *   .notebook-clip            the overlay a clip is dragged on, and __box,
 *                             the rectangle being dragged
 *
 * Raised paper with the overlay shadow, opening on a heavy rule. It comes in
 * fast (--duration-drawer-in, easing out) and goes faster
 * (--duration-fast, easing in); with reduced motion it simply appears
 * (base.css). The page makes room underneath while it is open.
 */
@layer components {
  .notebook-drawer__tab {
    position: fixed;
    inset: auto var(--space-xl) 0 auto;
    z-index: 40;
    min-block-size: var(--target-min);
    padding: var(--space-xs) var(--space-md);
    border: var(--rule-heavy);
    border-block-end: 0;
    background-color: var(--color-surface-raised);
    color: var(--color-ink);
    font-family: var(--font-ui);
    font-size: var(--text-caps);
    font-weight: var(--weight-semibold);
    letter-spacing: var(--tracking-caps);
    text-transform: uppercase;
    cursor: pointer;
    box-shadow: var(--shadow-overlay);

    &[aria-expanded="true"] {
      display: none;
    }
  }

  .notebook-drawer__panel {
    position: fixed;
    inset: auto 0 0;
    z-index: 40;
    display: flex;
    flex-direction: column;
    block-size: var(--notebook-drawer-height);
    border-block-start: var(--rule-heavy);
    background-color: var(--color-surface-raised);
    box-shadow: var(--shadow-overlay);
    transition:
      block-size var(--duration-drawer-in) var(--ease-out),
      translate var(--duration-drawer-in) var(--ease-out);

    &[data-open="false"] {
      visibility: hidden;
      translate: 0 100%;
      transition:
        translate var(--duration-fast) var(--ease-in),
        visibility 0s linear var(--duration-fast);
    }

    &[data-resizing] {
      transition: none;
    }
  }

  :root:has(.notebook-drawer__panel[data-open="true"]) .app {
    padding-block-end: var(--notebook-drawer-height);
  }

  .notebook-drawer__handle {
    position: absolute;
    inset: calc(-1 * var(--space-xs)) 0 auto;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    block-size: var(--space-md);
    cursor: ns-resize;
    touch-action: none;

    /* The grip: a short bar in the middle of the edge. */
    &::before {
      inline-size: var(--space-2xl);
      block-size: var(--space-2xs);
      background-color: var(--color-rule-strong);
      content: "";
    }

    &:hover::before,
    &:focus-visible::before {
      background-color: var(--color-accent);
    }
  }

  .notebook-drawer__frame {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-block-size: 0;
    overflow: hidden;
  }

  .notebook-clip {
    position: fixed;
    inset: 0;
    z-index: 50;
    background-color: color-mix(in srgb, var(--color-ink) 12%, transparent);
    cursor: crosshair;
    user-select: none;
    touch-action: none;
  }

  .notebook-clip__hint {
    position: fixed;
    inset: var(--space-md) 0 auto;
    inline-size: max-content;
    margin: 0 auto;
    padding: var(--space-xs) var(--space-md);
    background-color: var(--color-ink);
    color: var(--color-ink-inverse);
    font-family: var(--font-ui);
    font-size: var(--text-ui-sm);
    pointer-events: none;
  }

  .notebook-clip__box {
    position: fixed;
    border: 2px solid var(--color-accent);
    background-color: color-mix(in srgb, var(--color-accent) 10%, transparent);
    pointer-events: none;
  }
}
