@layer cinder.tokens, cinder.foundation, cinder.components, cinder.utilities;
@layer cinder.components {
  /* ========================================
 * PAGINATION
 * ======================================== */

  .cinder-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--cinder-space-4);
    flex-wrap: wrap;
    container-type: inline-size;
    container-name: cinder-pagination;
  }

  /* ----------------------------------------
 * Result count
 * ---------------------------------------- */

  .cinder-pagination__count {
    margin: 0;
    font-size: var(--cinder-text-sm);
    color: var(--cinder-text-muted);
    white-space: nowrap;
  }

  /* ----------------------------------------
 * Controls row (prev + pages + next)
 * ---------------------------------------- */

  .cinder-pagination__controls {
    display: flex;
    align-items: center;
    gap: var(--cinder-space-1);
  }

  /* ----------------------------------------
 * Pages list
 * ---------------------------------------- */

  .cinder-pagination__pages {
    display: flex;
    align-items: center;
    gap: var(--cinder-space-1);
  }

  /* ----------------------------------------
 * Shared button styles (step + page)
 * ---------------------------------------- */

  .cinder-pagination__step,
  .cinder-pagination__page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.25rem;
    min-height: 2.25rem;
    padding: var(--cinder-space-1) var(--cinder-space-2);

    border: 1px solid transparent;
    border-radius: var(--cinder-radius-md);
    background: transparent;
    color: var(--cinder-text-default);
    font-size: var(--cinder-text-sm);
    font-weight: var(--cinder-font-medium);
    line-height: 1;
    cursor: pointer;

    transition:
      background-color var(--cinder-duration-fast) var(--cinder-ease-standard),
      border-color var(--cinder-duration-fast) var(--cinder-ease-standard),
      color var(--cinder-duration-fast) var(--cinder-ease-standard),
      box-shadow var(--cinder-duration-fast) var(--cinder-ease-standard);
  }

  /* ----------------------------------------
 * Hover — non-current, non-disabled
 * ---------------------------------------- */

  @media (hover: hover) {
    .cinder-pagination__step:hover:not(:disabled),
    .cinder-pagination__page:hover:not([data-cinder-current]) {
      background: color-mix(in oklch, var(--cinder-text-default) 8%, transparent);
      border-color: var(--cinder-border-muted);
    }
  }

  /* ----------------------------------------
 * Focus ring
 * ---------------------------------------- */

  .cinder-pagination__step:focus-visible,
  .cinder-pagination__page:focus-visible {
    outline: var(--cinder-ring-width) solid transparent;
    /* Ring replaces the border while focused rather than stacking on it — the two
       together read as one heavier shape than either was designed to be. */
    border-color: transparent;
    box-shadow: var(--_cinder-focus-ring-shadow);
  }

  @media (forced-colors: active) {
    .cinder-pagination__step:focus-visible,
    .cinder-pagination__page:focus-visible {
      outline: var(--cinder-ring-width) solid ButtonText;
      outline-offset: 3px;
    }
  }

  /* ----------------------------------------
 * Current page
 * ---------------------------------------- */

  .cinder-pagination__page[data-cinder-current] {
    background: var(--cinder-accent-solid);
    border-color: var(--cinder-accent-solid);
    color: var(--cinder-accent-contrast);
    cursor: default;
  }

  /* ----------------------------------------
 * Disabled step buttons (prev / next at boundary)
 * ---------------------------------------- */

  .cinder-pagination__step:disabled {
    color: var(--cinder-text-disabled, var(--cinder-text-muted));
    cursor: not-allowed;
    pointer-events: none;
  }

  /* opacity is ignored under forced colors, so signal the disabled boundary with
   the GrayText system color instead. */
  @media (forced-colors: active) {
    .cinder-pagination__step:disabled {
      color: GrayText;
      opacity: 1;
    }
  }

  /* ----------------------------------------
 * Ellipsis
 * ---------------------------------------- */

  .cinder-pagination__ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 var(--cinder-space-1);
    color: var(--cinder-text-muted);
    font-size: var(--cinder-text-sm);
    user-select: none;
  }

  /* ----------------------------------------
 * Responsive: hide page list on very small screens
 * to avoid overflow; prev/next remain accessible
 * ---------------------------------------- */

  @container cinder-pagination (max-width: 30rem) {
    .cinder-pagination__pages {
      display: none;
    }

    .cinder-pagination {
      justify-content: center;
    }
  }

  /* ----------------------------------------
 * Reduced motion
 * ---------------------------------------- */

  @media (prefers-reduced-motion: reduce) {
    :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
      .cinder-pagination__step,
    :root:not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off'])
      .cinder-pagination__page {
      transition: none;
    }
  }
}
