/*
 * M8 · Compliance (A-14 Training completion, A-15 completion record, A-16 Acknowledgments and
 * the acknowledgment record) plus the list patterns shared with the audit log and "View as":
 *   .m8-row-link     stretched link: the whole row (position: relative) opens the record while the
 *                    row keeps its table semantics
 *   .m8-filters      filter toolbar (select pills, range pill, count / chips at the end)
 *   .m8-range        date-range pill + popover (admin/compliance/_range_filter, m8-popover)
 *   .m8-split        list + 380px record panel (A-15, A-18); .m8-split--open when a record is shown.
 *                    Side by side from 1440px (the design width); narrower, the panel stacks above the
 *                    list (the list columns need the room) and m8-panel scrolls it into view
 *   .m8-panel        the record panel (card) · .cmp-person · .cmp-signature · .cmp-trail
 *   .cmp-tabs        Acknowledgments | Training completion
 *   .cmp-list--*     column templates for the A-14 / A-16 rows; next to the panel and on laptops and
 *                    tablets the all-trainings list drops Site and Version, A-16 Site and Required by,
 *                    and on tablets one training's list drops Version
 */
@layer pages {
  /* Stretched row link ------------------------------------------------------------------------ */
  .m8-row-link {
    color: inherit;
    text-decoration: none;
  }
  .m8-row-link::after {
    content: "";
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
  }
  .m8-row-link:hover { color: inherit; }
  .m8-row-link:focus-visible { outline: none; }
  .list-row:has(.m8-row-link:hover) { box-shadow: 0 0 0 2px var(--color-divider); }
  .list-row:has(.m8-row-link:focus-visible),
  .list-row.is-selected:has(.m8-row-link) { box-shadow: var(--ring); }

  /* Filter toolbar ---------------------------------------------------------------------------- */
  .m8-filters { row-gap: 8px; }
  /* A-14: a long training title shortens in its pill, so the six filters and the three summary
     chips stay on one row at 1440 (1100px), also with the select pills at 13.5px. */
  .m8-filters .select-pill[for="filter_training"] .select-pill__value {
    max-width: 92px;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .m8-filters__end {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--color-neutral-700);
    font-size: 13.5px;
  }

  /* Range pill + popover ---------------------------------------------------------------------- */
  .m8-range {
    position: relative;
    display: inline-flex;
  }
  .m8-range__button {
    background: transparent;
    color: var(--color-text);
    line-height: 1.55;
  }
  .m8-range__button[aria-expanded="true"] { background: var(--color-btn-hover); }

  .m8-range__panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 30;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 14px;
    border-radius: var(--radius-row);
    background: var(--color-bg);
    box-shadow: var(--shadow-lg);
  }

  .m8-range__presets {
    display: flex;
    flex-direction: column;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-hairline);
  }
  .m8-range__preset {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 40px;
    padding: 0 12px;
    border-radius: 14px;
    color: var(--color-text);
    font-size: 14px;
    font-weight: 600;
  }
  .m8-range__preset:hover,
  .m8-range__preset:focus-visible { background: var(--color-surface); color: var(--color-text); outline: none; }
  .m8-range__preset.is-active { font-weight: 700; }
  .m8-range__preset .icon { font-size: 16px; color: var(--color-blue); }

  .m8-range__fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .m8-range__field { display: flex; flex-direction: column; gap: 4px; }
  .m8-range__field-label { font-size: 12.5px; font-weight: 700; }
  .m8-range__input.input {
    min-height: 40px;
    height: 40px;
    padding: 0 12px;
    font-size: 14px;
  }

  .m8-range__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
  }

  /* Tabs (A-16) ------------------------------------------------------------------------------- */
  .cmp-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1.5px solid var(--color-divider);
  }
  .cmp-tabs__tab {
    margin-bottom: -1.5px;
    padding: 10px 16px;
    border-bottom: 3px solid transparent;
    color: var(--color-neutral-700);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.55;
  }
  .cmp-tabs__tab:hover { color: var(--color-text); }
  .cmp-tabs__tab.is-active {
    border-bottom-color: var(--color-blue);
    color: var(--color-blue);
  }

  /* List + record panel ----------------------------------------------------------------------- */
  .m8-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 24px;
    align-items: start;
  }
  .m8-split--open { grid-template-columns: minmax(0, 1fr) 380px; }
  .m8-split__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
  }

  /* Sticky next to the list; a panel taller than the viewport scrolls inside itself. */
  .m8-panel {
    position: sticky;
    top: 16px;
    min-width: 0;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-margin-top: 12px;
  }
  .m8-panel > * { flex-shrink: 0; }
  .m8-panel .kv { margin-top: 0; }

  /* A-15 actions on an open assignment (Change Due Date, Cancel Assignment) and the certificates the
     person uploaded (review fixes 10 and 13). */
  .cmp-panel__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
  }
  .cmp-certificates {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .cmp-certificates__list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .cmp-certificates__file { background: var(--color-surface); }
  .cmp-certificates__file .tcms-file__icon { background: var(--petal-policy-bg); color: var(--petal-policy-fg); }
  .cmp-certificates__empty {
    margin: 0;
    color: var(--color-neutral-700);
    font-size: 13.5px;
  }

  /* "Include former staff" (A-14, A-16) beside Export CSV, and the "Disabled" mark of a former staff
     member's row. */
  .cmp-former-form { display: inline-flex; }
  .cmp-former {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    color: var(--color-text);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
  }
  .cmp-former__switch { transform: scale(0.85); }
  .cmp-former-chip {
    align-self: flex-start;
    padding: 2px 8px;
    font-size: 11.5px;
  }

  .cmp-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }
  /* Panel overlines are 12px in the design; the 11px .overline utility (a later layer) is not used here. */
  .cmp-panel__overline {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    line-height: 1.55;
    color: var(--color-neutral-700);
  }
  .cmp-panel__close {
    width: 36px;
    height: 36px;
    margin: -9px -9px -9px 0;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: var(--color-text);
    font-size: 18px;
  }
  .cmp-panel__close:hover { background: color-mix(in srgb, var(--color-text) 8%, transparent); color: var(--color-text); }

  .cmp-person {
    display: flex;
    align-items: center;
    gap: 12px;
  }
  .cmp-person .avatar { width: 44px; height: 44px; font-size: 14px; }
  .cmp-person__text { display: flex; flex-direction: column; min-width: 0; }
  .cmp-person__name { font-size: 17px; font-weight: 700; line-height: 1.55; }
  .cmp-person__meta { font-size: 13px; line-height: 1.55; color: var(--color-neutral-700); }

  .cmp-signature {
    height: 80px;
    margin: 0;
    display: grid;
    place-items: center;
    padding: 6px 16px;
    border-radius: var(--radius-row);
    background: var(--color-neutral-100);
  }
  .cmp-signature__image {
    max-width: 100%;
    max-height: 68px;
    object-fit: contain;
  }
  .cmp-signature--empty {
    background: repeating-linear-gradient(135deg, var(--color-neutral-100) 0 12px, var(--color-neutral-200) 12px 24px);
  }
  .cmp-signature__note {
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    background: var(--color-bg);
    color: var(--color-neutral-700);
    font-size: 12.5px;
    font-weight: 600;
  }

  .m8-panel .statement { background: var(--color-bg); }
  .m8-panel .statement__text { font-size: 13.5px; }

  /* Audit trail ------------------------------------------------------------------------------- */
  .cmp-trail { display: flex; flex-direction: column; gap: 8px; }
  .cmp-trail__list {
    margin: 0;
    padding: 0;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .cmp-trail__item { display: flex; gap: 12px; }
  .cmp-trail__rail {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: none;
  }
  .cmp-trail__rail::after {
    content: "";
    flex: 1;
    width: 2px;
    background: var(--color-neutral-300);
  }
  .cmp-trail__item:last-child .cmp-trail__rail::after { display: none; }
  .cmp-trail__dot {
    width: 10px;
    height: 10px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--color-blue);
  }
  .cmp-trail__item--err .cmp-trail__dot { background: var(--color-err); }
  .cmp-trail__item--neutral .cmp-trail__dot { background: var(--color-neutral-600); }
  .cmp-trail__text {
    display: flex;
    flex-direction: column;
    padding-bottom: 14px;
  }
  .cmp-trail__title { font-size: 13.5px; font-weight: 700; line-height: 1.55; }
  .cmp-trail__time { font-size: 12.5px; line-height: 1.55; color: var(--color-neutral-700); }

  /* A-14 / A-16 rows -------------------------------------------------------------------------- */
  .cmp-list .list-row { min-height: 58px; }
  .cmp-list__person {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    font-weight: 700;
  }
  .cmp-list__person .list-row__meta { font-weight: 400; }
  .cmp-list__title { min-width: 0; }
  .cmp-list .scope-badge--inline {
    flex-shrink: 1;
    min-width: 0;
    white-space: normal;
    line-height: 1.55;
  }

  .cmp-list--training { --list-cols: minmax(0, 1.3fr) minmax(0, 1.2fr) 70px 112px 120px minmax(0, 1.3fr); }
  .cmp-list--training.cmp-list--all { --list-cols: minmax(0, 1.2fr) minmax(0, 1.1fr) minmax(0, 1.6fr) 60px 112px 110px minmax(0, 1.2fr); }
  .cmp-list--acks { --list-cols: minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(0, 1.6fr) 70px 120px 140px minmax(0, 1.3fr); }

  /* Two columns fewer where the full set does not fit: next to the panel, and below 1280 (A-16) or
     1200 (all trainings). */
  @media (min-width: 1440px) {
    .m8-split--open .cmp-list--training.cmp-list--all {
      --list-cols: minmax(0, 1.1fr) minmax(0, 1.4fr) 104px 100px minmax(0, 1.1fr);
    }
    .m8-split--open .cmp-list--all > :is(.list-header, .list-row) > :is(:nth-child(2), :nth-child(4)) { display: none; }

    .m8-split--open .cmp-list--acks { --list-cols: minmax(0, 1.1fr) minmax(0, 1.5fr) 56px 140px minmax(0, 1.2fr); }
    .m8-split--open .cmp-list--acks > :is(.list-header, .list-row) > :is(:nth-child(2), :nth-child(5)) { display: none; }
  }

  @media (max-width: 1279px) {
    .cmp-list--acks { --list-cols: minmax(0, 1.1fr) minmax(0, 1.5fr) 56px 140px minmax(0, 1.2fr); }
    .cmp-list--acks > :is(.list-header, .list-row) > :is(:nth-child(2), :nth-child(5)) { display: none; }
  }

  @media (max-width: 1199px) {
    .cmp-list--training.cmp-list--all { --list-cols: minmax(0, 1.1fr) minmax(0, 1.4fr) 104px 100px minmax(0, 1.1fr); }
    .cmp-list--all > :is(.list-header, .list-row) > :is(:nth-child(2), :nth-child(4)) { display: none; }
  }

  /* Below the design width the list beside a 380px panel is too narrow for its columns: stack the
     panel above it. */
  @media (max-width: 1439px) {
    .m8-split--open { grid-template-columns: minmax(0, 1fr); }
    .m8-split--open > .m8-panel {
      position: static;
      order: -1;
      max-height: none;
      overflow: visible;
    }
  }

  @media (max-width: 1023px) {
    .m8-filters__end { margin-left: 0; flex-basis: 100%; }
    .cmp-list--training:not(.cmp-list--all) { --list-cols: minmax(0, 1.3fr) minmax(0, 1.2fr) 112px 120px minmax(0, 1.3fr); }
    .cmp-list--training:not(.cmp-list--all) > :is(.list-header, .list-row) > :nth-child(3) { display: none; }
  }

  @media (max-width: 767px) {
    .cmp-panel__close { width: 44px; height: 44px; margin: -13px -13px -13px 0; }
    .cmp-list { --list-cols-mobile: minmax(0, 1fr) auto; }
    .cmp-list .list-row > [role="cell"]:not(.cmp-list__person, .cmp-list__status) { display: none; }
    .cmp-list .list-row { align-items: center; }
    .cmp-tabs { overflow-x: auto; scrollbar-width: none; }
    .cmp-tabs__tab { white-space: nowrap; }
    .m8-range__panel { width: min(320px, calc(100vw - 36px)); }
  }
}
