/*
 * The reader's notebook in a company's header (notebook/shared/_entry_button,
 * _entry_slip), for a reader with the notebook:
 *
 *   .notebook-entry-button    beside Follow and Alert: "+ Add a note", the
 *                             outlined small button; --filled once there are
 *                             notes, in the accent's tint, with __count
 *   .notebook-entry-slot      the slip's frame: at the header's top right
 *                             (pages/company.css places it), above the
 *                             standfirst on a phone; nothing while empty
 *   .notebook-entry           the slip: a heavy rule on top and the field's
 *                             ground; when the page was changed and, with
 *                             more than one, ‹ 1 of 3 › (__head, __pager);
 *                             its first clip (__clip) beside five lines of
 *                             what it says (__text); the way in (__open)
 *
 * The button's frame takes no box (.notebook-entry-frame), so the button
 * sits in the row of buttons as if the frame were not there.
 */
@layer components {
  .notebook-entry-frame {
    display: contents;
  }

  .notebook-entry-button {
    white-space: nowrap;
  }

  .notebook-entry-button--filled {
    border-color: var(--color-accent);
    background-color: var(--color-accent-tint);
    color: var(--color-accent);
  }

  .notebook-entry-button__count {
    min-inline-size: 1.25rem;
    padding: 0 var(--space-2xs);
    border-radius: var(--radius-pill);
    background-color: var(--color-accent);
    color: var(--color-ink-inverse);
    font-size: var(--text-meta);
    letter-spacing: 0;
    text-align: center;
  }

  /* Free to be narrower than its slip, so on a phone the header's one
     column is the screen's width and the slip, capped at it, fits. */
  .notebook-entry-slot {
    display: flex;
    min-inline-size: 0;

    &:not(:has(*)) {
      display: none;
    }
  }

  .notebook-entry {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    /* A width of its own, not one taken from its text: the first line of a
       long page would otherwise set the header's right column to its whole
       length. It grows with the window, and its clip with it. */
    --notebook-entry-clip: clamp(9.5rem, 9vw, 14rem);

    inline-size: clamp(29rem, 30vw, 44rem);
    max-inline-size: 100%;
    min-inline-size: 0;
    padding: var(--space-xs) var(--space-sm) var(--space-sm);
    border-block-start: var(--rule-heavy);
    background-color: var(--color-field);
  }

  .notebook-entry__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    min-block-size: 1.75rem;
    color: var(--color-ink-muted);
    font-size: var(--text-meta-xs);
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

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

  .notebook-entry__turn-form {
    display: contents;
  }

  .notebook-entry__turn {
    inline-size: 1.75rem;
    block-size: 1.75rem;
    padding: 0;
    border: var(--rule-hairline);
    background: none;
    color: var(--color-ink);
    font: inherit;
    font-size: var(--text-ui);
    cursor: pointer;

    &:hover {
      background-color: var(--color-row-hover);
    }

    @media (pointer: coarse) {
      inline-size: var(--target-min);
      block-size: var(--target-min);
    }
  }

  .notebook-entry__position {
    min-inline-size: 3rem;
    letter-spacing: 0;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }

  /* The first clip beside the text, cropped to its top left, where a clip
     of a table or a chart starts. */
  .notebook-entry__body {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    /* Five lines or a clip's height, whichever is the more, whatever the
       page holds, so turning pages does not change the slip's height. */
    min-block-size: max(
      calc(var(--text-ui) * var(--leading-prose-sm) * 5),
      calc(var(--notebook-entry-clip) * 2 / 3)
    );
  }

  .notebook-entry__clip {
    flex: none;
    inline-size: var(--notebook-entry-clip);
    aspect-ratio: 3 / 2;
    border: var(--rule-hairline);
    background-color: var(--color-surface);
    object-fit: cover;
    object-position: top left;
  }

  .notebook-entry__text {
    display: -webkit-box;
    margin: 0;
    overflow: hidden;
    font-family: var(--font-prose);
    font-size: var(--text-ui);
    line-height: var(--leading-prose-sm);
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 5;
  }

  .notebook-entry__open {
    align-self: flex-start;
    color: var(--color-link);
    font-size: var(--text-ui-sm);
    font-weight: var(--weight-semibold);
    text-decoration: none;

    &:hover {
      text-decoration: underline;
    }
  }
}
