/* Pagination — server-side numbered, CSS-only window/markers.
   See partials/pagination.hbs.

   The partial emits one <li data-n="N"> per page (1..pagination.pages).
   The rules below hide cells that aren't relevant on the current page:
     - page 1 (always)
     - last page (always)
     - multiples of 5 (:nth-child(5n))
     - current page (.current)
     - 3 cells after current (.current + li, …)
     - 3 cells before current (:has(+ .current), …)
*/

.pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 720px;
    margin: 4vmin auto 0;
    padding: 2vmin 0 0;
    font-size: 1.4rem;
    line-height: 1.4;
    color: var(--color-midgrey);
    gap: 16px;
}

.pagination a {
    color: var(--color-darkgrey);
    text-decoration: none;
    transition: border-color .15s ease, color .15s ease, background-color .15s ease;
}

/* Arrows */
.pagination .newer-posts,
.pagination .older-posts {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 100px;
    padding: 8px 16px;
    border: 1px solid var(--color-lightgrey);
    border-radius: 6px;
    font-weight: 500;
}

.pagination .newer-posts { order: 1; justify-content: flex-start; }
.pagination .page-list   { order: 2; }
.pagination .older-posts  { order: 3; justify-content: flex-end; }

.pagination .newer-posts:hover,
.pagination .older-posts:hover {
    border-color: var(--color-darkgrey);
}

/* Keep page-list centered when one arrow is missing */
.pagination > .page-list:first-child { margin-left: auto; }
.pagination > .page-list:last-child  { margin-right: auto; }

/* Numbered list — hide everything by default, then unhide selectively */
.page-list {
    display: flex;
    flex: 1;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.page-list li {
    display: none;
    margin: 0;
    padding: 0;
}

/* Always shown: edges, multiples of 5, current */
.page-list li:first-child,
.page-list li:last-child,
.page-list li:nth-child(5n),
.page-list li.current {
    display: inline-flex;
}

/* Window AFTER current (3 cells) — uses adjacent-sibling combinator */
.page-list li.current + li,
.page-list li.current + li + li,
.page-list li.current + li + li + li {
    display: inline-flex;
}

/* Window BEFORE current (3 cells) — uses :has() for "next-sibling is X" */
.page-list li:has(+ .current),
.page-list li:has(+ li + .current),
.page-list li:has(+ li + li + .current) {
    display: inline-flex;
}

/* Cell button styling */
.page-list li a,
.page-list li.current span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--color-lightgrey);
    border-radius: 6px;
    color: var(--color-darkgrey);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.page-list li a:hover {
    border-color: var(--color-darkgrey);
    background-color: var(--color-wash);
}

.page-list li.current span {
    background-color: var(--color-darkgrey);
    border-color: var(--color-darkgrey);
    color: #fff;
    cursor: default;
}

/* Ellipsis between page 1 and the rest of the visible cells.
   Page 2 is naturally visible only when current ∈ {1..5} (current itself,
   or .current + li, or :has(+ .current) chains). When current is further
   in (>5), page 2 is hidden → we show "…" right after page 1. */
.page-list li:first-child::after {
    content: '…';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 38px;
    margin-left: 6px;
    color: var(--color-midgrey);
    user-select: none;
}

.page-list:has(li:nth-child(-n+5).current) li:first-child::after {
    content: none;
}

/* Ellipsis between the rest of the visible cells and the last page.
   Hidden when current ∈ {last-4..last} (page (last-1) is in window), OR
   when page (last-1) is itself a multiple of 5 (shown via :nth-child(5n)). */
.page-list li:last-child::before {
    content: '…';
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 38px;
    margin-right: 6px;
    color: var(--color-midgrey);
    user-select: none;
}

.page-list:has(li:nth-last-child(-n+5).current) li:last-child::before,
.page-list:has(li:nth-last-child(2):nth-child(5n)) li:last-child::before {
    content: none;
}

/* Mobile: stack vertically, wrap numbers */
@media (max-width: 500px) {
    .pagination {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .pagination .newer-posts,
    .pagination .older-posts {
        justify-content: center;
        min-width: 0;
    }

    .page-list {
        justify-content: center;
        flex-wrap: wrap;
    }
}

/* Dark mode */
.dark-mode .pagination .newer-posts,
.dark-mode .pagination .older-posts,
.dark-mode .page-list li a {
    color: var(--color-lightgrey);
    border-color: rgba(197, 210, 217, 0.3);
}

.dark-mode .pagination .newer-posts:hover,
.dark-mode .pagination .older-posts:hover,
.dark-mode .page-list li a:hover {
    color: #fff;
    border-color: var(--color-lightgrey);
    background-color: transparent;
}

.dark-mode .page-list li.current span {
    background-color: var(--color-lightgrey);
    color: var(--color-darkgrey);
    border-color: var(--color-lightgrey);
}
