/*
 * M1 resource libraries (D-09, D-11, D-12, D-17) and resource detail (D-10, M-08).
 *   .lib-toolbar   subcategory pills, "Filter by title", Type select (components/filter-pills)
 *   .lib-group     one subcategory: heading + count over a .list.lib-list of .lib-row capsules
 *                  (below 1024px a row folds into title + .lib-row__compact meta, like phones)
 *   .lib-detail    detail grid: preview (PDF frame / file card / video / link card) + About & Related;
 *                  a document that requires acknowledgment adds the D-07 panel (.policy-ack, from
 *                  portal-policies.css) on top of the aside (.lib-detail--pending while it waits)
 */
@layer pages {
  /* Library list ------------------------------------------------------------------------------- */
  .lib-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .lib-group__head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 4px 4px;
  }

  .lib-group__title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
  }

  .lib-group__count {
    color: var(--color-neutral-700);
    font-size: 13px;
  }

  .lib-list {
    --list-cols: 52px minmax(0, 2.4fr) 90px 92px 140px 160px 120px;
    --list-cols-mobile: 42px minmax(0, 1fr) auto;
  }

  .lib-row:focus-within { box-shadow: var(--ring); }
  /* A library category an Admin added has the neutral tone: its icon disc sits on the page color. */
  .lib-row .icon-circle--neutral { background: var(--color-bg); }

  .lib-row__title {
    color: var(--color-text);
    text-decoration: none;
  }
  .lib-row__title:hover { color: var(--color-text); text-decoration: underline; }
  .lib-row__title:focus-visible { outline: none; }

  .lib-row__meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .lib-row__type {
    color: var(--color-neutral-700);
    font: 700 11.5px var(--font-mono);
  }

  .lib-row__updated { white-space: nowrap; }
  /* "Action required · due Oct 15" under the title of a document the Director must sign. */
  .lib-row__ack { align-self: flex-start; margin-top: 4px; }
  .lib-row__compact { display: none; }

  /* 24px between the pills and "Filter by title" without indenting the field when the row wraps. */
  .lib-toolbar .pill-filters { margin-right: 16px; }

  .lib-row__round {
    width: 44px;
    height: 44px;
    flex: none;
    display: grid;
    place-items: center;
    border: 1.5px solid var(--color-input-border);
    border-radius: 50%;
    color: var(--color-text);
    font-size: 18px;
  }
  .lib-row__round:hover { background: var(--color-btn-hover); color: var(--color-text); }

  /* Resource detail ---------------------------------------------------------------------------- */
  .lib-detail__summary { display: none; }

  .lib-detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 24px;
    align-items: start;
  }

  .lib-detail__main {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
  }

  .lib-detail__description { display: none; }

  .lib-detail__aside {
    display: flex;
    flex-direction: column;
    gap: 16px;
  }

  .lib-about .card__body { font-size: 14px; }

  .lib-related .rows__item { padding: 11px 0; gap: 10px; }
  .lib-related .rows__title { font-size: 14px; }
  .lib-related__chev {
    font-size: 16px;
    color: var(--color-neutral-700);
  }
  .lib-related .rows__item:hover .rows__title { text-decoration: underline; }

  .lib-video__player {
    display: block;
    width: 100%;
    height: auto;
    max-height: 600px;
    aspect-ratio: 16 / 9; /* holds its shape before (or without) the video's metadata */
    object-fit: contain;
    border-radius: var(--radius-row);
    background: var(--color-text);
  }

  .lib-detail__sheet {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .lib-detail__sheet .lib-detail__open { height: 48px; }

  @media (max-width: 1199px) {
    .lib-list { --list-cols: 48px minmax(0, 2.4fr) 70px 80px 136px 150px 112px; }
    .lib-detail { grid-template-columns: minmax(0, 1fr) 320px; }
  }

  /* Tablet: the phone row pattern (title over "v2.4 · PDF · Updated Jun 14, 2026") with the View button. */
  @media (max-width: 1023px) {
    .lib-list { --list-cols: 48px minmax(0, 1fr) auto; }
    .lib-row > .lib-row__type,
    .lib-row > .lib-row__version,
    .lib-row > .lib-row__updated,
    .lib-row > .lib-row__scope,
    .lib-row__meta { display: none; }
    .lib-row__compact { display: block; }
    .lib-detail { grid-template-columns: minmax(0, 1fr); }
  }

  /* Phones (M-08; libraries follow the same compact pattern) */
  @media (max-width: 767px) {
    .lib-toolbar .pill-filters {
      flex-wrap: wrap;
      overflow: visible;
      margin-right: 0;
    }
    .lib-toolbar .filter-field { flex: 1; width: auto; height: 38px; }

    .lib-row .icon-circle { width: 38px; height: 38px; font-size: 17px; }

    .lib-detail__head .page-head--detail .page-head__text { gap: 8px; }
    .lib-detail__head .page-head__meta .meta-pill,
    .lib-detail__head .page-head__actions { display: none; }
    .lib-detail__summary {
      display: block;
      color: var(--color-neutral-800);
      font-size: 13px;
    }

    .lib-detail .pdf-preview__well { height: 300px; }
    .lib-detail__description {
      display: block;
      color: var(--color-neutral-800);
      font-size: 14px;
      line-height: 1.55;
    }
    .lib-detail__aside { display: none; }
    /* A signed document keeps its D-08 · done panel on phones; About and Related stay hidden. */
    .lib-detail__aside--signed { display: flex; }
    .lib-detail__aside--signed > :not(.policy-ack) { display: none; }
    .lib-video__player { max-height: 300px; }

    /* M-08: 14px between the blocks (the shared .main uses 16px). */
    .main:has(> .lib-detail) { gap: 14px; }

    /* M-08: the actions sit on the page background at the bottom of the screen, 18px above its
       edge (the content column's padding), not the 30px the M-02/M-05 surface sheet keeps. A
       document waiting for the Director's signature keeps the M-02 sheet. */
    .app:has(.lib-detail:not(.lib-detail--pending)) > .sheet {
      padding-top: 10px;
      padding-bottom: max(18px, env(safe-area-inset-bottom));
      background: var(--color-bg);
      box-shadow: none;
    }
  }
}
