/*
 * The research notebook's drawer (shared/_notebook_drawer,
 * frames/notebooks/drawer) and the editor in it (notebook/pages/_editor),
 * and the clip overlay the `notebook-drawer` controller lays over the page.
 *
 *   .notebook-drawer          the element Turbo keeps between pages
 *   .notebook-drawer__tab     the tab at the bottom right that opens it
 *   .notebook-drawer__panel   the drawer, the full width of the window and
 *                             --notebook-drawer-height tall, up from the
 *                             bottom ([hidden] when closed); the page makes
 *                             room for it underneath
 *   .notebook-drawer__handle  the drawer's top edge, dragged to resize it
 *   .notebook-drawer__bar     its top row: what the notes are about, the
 *                             pages as tabs and a +, Clip from page, Open,
 *                             close
 *   .notebook-editor          a page's title and its Lexxy body
 *   .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, as every
 * section does. Lexxy brings its own look for the editor's insides.
 *
 * In the drawer the editor takes all the room below the bar, and only the
 * text scrolls, not the drawer. Lexxy's stylesheet is unlayered, so every
 * rule of its wins over these whatever the selector: the editor keeps
 * Lexxy's `display: block`, and its content is sized with properties Lexxy
 * does not set — the editor's height less Lexxy's own toolbar height.
 */
@layer components {
  .notebook-drawer__tab {
    position: fixed;
    inset-block-end: 0;
    inset-inline-end: var(--space-xl);
    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-inline: 0;
    inset-block-end: 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);
  }

  :root:has(.notebook-drawer__panel:not([hidden])) .app {
    padding-block-end: var(--notebook-drawer-height);
  }

  .notebook-drawer__handle {
    position: absolute;
    inset-block-start: calc(-1 * var(--space-xs));
    inset-inline: 0;
    z-index: 1;
    block-size: var(--space-md);
    cursor: ns-resize;
    touch-action: none;

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

    &: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-drawer__body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: var(--space-sm);
    min-block-size: 0;
    padding: var(--space-sm) var(--gutter);
  }

  .notebook-drawer__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs) var(--space-md);
  }

  .notebook-drawer__subject {
    margin: 0;
  }

  .notebook-drawer__tabs {
    display: flex;
    flex: 1;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2xs);
    min-inline-size: 0;
  }

  .notebook-drawer__tab-link {
    padding: var(--space-2xs) var(--space-sm);
    border: var(--rule-hairline);
    color: var(--color-ink-muted);
    font-size: var(--text-ui-sm);
    text-decoration: none;

    &[aria-current="page"] {
      border-color: var(--color-rule-strong);
      background-color: var(--color-surface);
      color: var(--color-ink);
      font-weight: var(--weight-semibold);
    }
  }

  .notebook-drawer__add {
    inline-size: var(--control-height-sm);
    block-size: var(--control-height-sm);
    border: var(--rule-hairline);
    background-color: transparent;
    color: var(--color-accent);
    font-size: var(--text-ui);
    font-weight: var(--weight-semibold);
    cursor: pointer;
  }

  .notebook-drawer__tools {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
  }

  .notebook-editor {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
  }

  .notebook-editor__head {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
  }

  .notebook-editor__title {
    flex: 1;
    min-inline-size: 0;
    padding: var(--space-2xs) 0;
    border: 0;
    border-block-end: var(--rule-hairline);
    background-color: transparent;
    color: var(--color-ink);
    font-family: var(--font-prose);
    font-size: var(--text-h3);
    font-weight: var(--weight-semibold);
  }

  .notebook-editor__status {
    color: var(--color-ink-subtle);
    font-size: var(--text-meta);
  }

  .notebook-editor__body {
    min-block-size: 10rem;
    background-color: var(--color-field);
  }

  .notebook-drawer .notebook-editor {
    flex: 1;
    min-block-size: 0;
  }

  .notebook-drawer .notebook-editor__body {
    flex: 1;
    min-block-size: 0;

    & .lexxy-editor__content {
      box-sizing: border-box;
      block-size: calc(100% - var(--lexxy-toolbar-height));
      overflow-y: auto;
      overscroll-behavior: contain;
    }
  }

  .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-block-start: var(--space-md);
    inset-inline: 0;
    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;
  }
}
