@layer components {
  /* ---------- Page header ---------- */
  .page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
  }

  .page-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
  }

  /* ---------- Summary strip (big numbers) ---------- */
  .summary-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin: 0 0 var(--space-8);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-lg);
    overflow: hidden;
  }

  .summary-strip__item {
    margin: 0;
    padding: var(--space-6);
    /* Hairlines between items, whether they sit side by side or wrap. */
    box-shadow: -1px 0 0 var(--color-hairline), 0 -1px 0 var(--color-hairline);
  }

  .summary-strip__label {
    color: var(--color-muted);
    font-size: var(--text-sm);
  }

  .summary-strip__value {
    margin: var(--space-1) 0 0;
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
  }

  /* ---------- Toolbar: pills on the left, search on the right ---------- */
  .toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-6);
  }

  /* ---------- Pill filter ---------- */
  .pills {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .pill {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    height: 36px;
    padding: 0 var(--space-4);
    border: 1px solid var(--color-hairline);
    border-radius: 999px;
    background: var(--color-ground);
    color: var(--color-ink);
    font-size: var(--text-md);
    text-decoration: none;
    white-space: nowrap;
  }

  /* Extends the hit area to 44px without changing the drawn size. */
  .pill::after,
  .btn--sm::after {
    content: "";
    position: absolute;
    inset: -4px;
  }

  .pill:hover {
    border-color: var(--color-ink);
  }

  .pill[aria-current="true"] {
    border-color: var(--color-ink);
    background: var(--color-ink);
    color: var(--color-on-ink);
  }

  /* ---------- Buttons ---------- */
  .btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--touch-target);
    padding: 0 var(--space-5);
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-size: var(--text-md);
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
  }

  .btn:disabled,
  .btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
  }

  .btn--dark {
    background: var(--color-ink);
    color: var(--color-on-ink);
  }

  .btn--dark:hover {
    background: var(--color-ink-raised);
  }

  .btn--accent {
    background: var(--color-accent);
    color: var(--color-on-accent);
  }

  .btn--accent:hover {
    filter: brightness(0.95);
  }

  .btn--outline {
    border-color: var(--color-hairline);
    background: var(--color-ground);
    color: var(--color-ink);
  }

  .btn--outline:hover {
    border-color: var(--color-ink);
  }

  .btn--sm {
    min-height: 36px;
    padding: 0 var(--space-3);
  }

  /* button_to wraps buttons in a form; keep it from breaking layout. */
  form.button_to {
    display: inline;
  }

  /* ---------- Cards (settings sections, panels) ---------- */
  .card {
    margin-bottom: var(--space-6);
    padding: var(--space-6);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-lg);
    background: var(--color-ground);
  }

  .card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
  }

  /* ---------- Form fields ---------- */
  .field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--space-4);
  }

  /* Fixed column counts that collapse to one column on narrow screens. */
  .field-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  @media (max-width: 720px) {
    .field-grid--2,
    .field-grid--3 { grid-template-columns: minmax(0, 1fr); }
  }

  .field__input--file {
    padding: var(--space-2) var(--space-3);
  }

  .card__note {
    margin-top: var(--space-4);
    color: var(--color-muted);
    font-size: var(--text-sm);
  }

  .card__actions {
    display: flex;
    gap: var(--space-3);
    justify-content: flex-end;
    margin-top: var(--space-5);
  }

  .logo-preview {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .logo-preview__image {
    max-width: 160px;
    max-height: 48px;
    object-fit: contain;
  }

  .logo-preview__remove {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
  }

  /* ---------- Member list (settings) ---------- */
  .member-list {
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .member-list__item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) 0;
  }

  .member-list__item + .member-list__item {
    border-top: 1px solid var(--color-hairline);
  }

  .member-list__avatar {
    display: grid;
    flex: none;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--color-ink);
    color: var(--color-ground);
    font-size: var(--text-sm);
    font-weight: 600;
  }

  .member-list__avatar--pending {
    border: 1px solid var(--color-hairline);
    background: var(--color-panel);
    color: var(--color-ink);
  }

  .member-list__who {
    display: flex;
    flex: 1 1 200px;
    flex-direction: column;
    min-width: 0;
  }

  .member-list__name {
    overflow-wrap: anywhere;
    font-weight: 500;
  }

  .member-list__meta {
    color: var(--color-muted);
    font-size: var(--text-sm);
  }

  .member-list__actions,
  .member-list__role {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
  }

  .member-list__role .field__input {
    width: auto;
  }

  /* A single-column form: fields stacked with even spacing. */
  .form-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    max-width: 480px;
  }

  .field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
  }

  .field__label {
    font-size: var(--text-xs);
    font-weight: 500;
  }

  .field__input {
    width: 100%;
    min-height: var(--touch-target);
    padding: 0 var(--space-3);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-md);
    background: var(--color-ground);
    font-size: var(--text-md);
  }

  textarea.field__input {
    padding: var(--space-3);
    min-height: 96px;
  }

  .field__input:hover {
    border-color: #c9c9c5;
  }

  .field__input:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 0;
    border-color: var(--color-ink);
  }

  .field__hint {
    color: var(--color-muted);
    font-size: var(--text-xs);
  }

  .field__error {
    color: var(--color-danger);
    font-size: var(--text-xs);
  }

  .field--invalid .field__input {
    border-color: var(--color-danger);
  }

  /* ---------- Table ---------- */
  /* Wide tables scroll inside their box instead of widening the page. */
  .table-wrap {
    position: relative; /* contains visually hidden labels so they scroll too */
    overflow-x: auto;
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-lg);
  }

  .table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-md);
  }

  .table th {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-hairline);
    color: var(--color-muted);
    font-size: var(--text-xs);
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
  }

  .table td {
    height: 64px;
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--color-hairline);
    vertical-align: middle;
  }

  .table tbody tr:last-child td {
    border-bottom: 0;
  }

  .table tbody tr:has(input[type="checkbox"]:checked) {
    background: var(--color-panel);
  }

  .table .col-check {
    width: 52px;
  }

  .table .col-num {
    text-align: right;
    white-space: nowrap;
  }

  .table__primary {
    display: block;
    white-space: nowrap;
    font-weight: 500;
  }

  .table__muted {
    color: var(--color-muted);
    white-space: nowrap;
  }

  .table__secondary {
    display: block;
    white-space: nowrap;
    color: var(--color-muted);
    font-size: var(--text-xs);
  }

  .table input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--color-ink);
  }

  /* Pad the checkbox's label to a 44px target. */
  .check-target {
    display: inline-grid;
    place-items: center;
    width: var(--touch-target);
    height: var(--touch-target);
    margin: -12px;
    cursor: pointer;
  }

  .empty-state {
    padding: var(--space-10) var(--space-6);
    color: var(--color-muted);
    text-align: center;
  }

  /* ---------- Tag and confidence meter ---------- */
  .tag {
    display: inline-flex;
    align-items: center;
    height: 30px;
    padding: 0 var(--space-3);
    border: 1px solid var(--color-hairline);
    border-radius: var(--radius-sm);
    font-size: var(--text-md);
    white-space: nowrap;
  }

  .meter {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    color: var(--color-muted);
    font-size: var(--text-xs);
  }

  .meter__bars {
    display: inline-flex;
    gap: 2px;
  }

  .meter__bar {
    width: 6px;
    height: 14px;
    border-radius: 2px;
    background: var(--color-hairline);
  }

  .meter__bar--on {
    background: var(--color-ink);
  }

  /* ---------- Search ---------- */
  .search {
    flex: 0 1 286px;
    min-width: 200px;
  }

  /* ---------- Bulk action bar ---------- */
  .bulk-bar {
    position: fixed;
    left: 50%;
    bottom: var(--space-8);
    z-index: 50;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    width: max-content;
    max-width: calc(100vw - var(--space-8));
    padding: var(--space-2) var(--space-2) var(--space-2) var(--space-5);
    border-radius: var(--radius-lg);
    background: var(--color-ink);
    color: var(--color-on-ink);
    transform: translateX(-50%);
    box-shadow: 0 8px 24px rgb(11 11 11 / 0.18);
  }

  /* On wide screens, centre the bar over the content column, not the window. */
  @media (min-width: 761px) {
    .app .bulk-bar {
      left: calc(50% + var(--sidebar-width) / 2);
      max-width: calc(100vw - var(--sidebar-width) - var(--space-8));
    }
  }

  .bulk-bar[hidden] {
    display: none;
  }

  .bulk-bar__summary {
    margin-right: var(--space-2);
    font-variant-numeric: tabular-nums;
  }

  .bulk-bar .btn--outline {
    border-color: var(--color-ink-raised);
    background: transparent;
    color: var(--color-on-ink);
  }

  .bulk-bar .btn--outline:hover {
    border-color: var(--color-on-ink);
  }

  .bulk-bar :focus-visible {
    outline-color: var(--color-accent);
  }

  @media (max-width: 760px) {
    .bulk-bar {
      left: var(--space-4);
      right: var(--space-4);
      bottom: var(--space-4);
      width: auto;
      max-width: none;
      padding: var(--space-2);
      transform: none;
    }

    .bulk-bar__summary {
      width: 100%;
      margin: 0;
      text-align: center;
    }
  }
}
