/**
 * Plots Loop Grid — layout, Load More button, loading + empty states.
 *
 * Visual properties (colours, typography, padding, radius) are
 * overridable per-instance through the widget's Style tab; these
 * rules are only the layout primitives needed to guarantee the
 * grid renders before any user-set style kicks in.
 */

.plots-loop-grid {
    width: 100%;
    position: relative;
}

.plots-loop-grid__items {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    align-items: stretch;
}

/* Each card fills its cell so loop item templates with min-heights
   behave predictably inside the grid track. */
.plots-loop-grid__item {
    position: relative;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
}
.plots-loop-grid__item > * {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
}

/* Integration with existing Plot Filter widget — filter hides cards
   via this class; honour it on our custom item wrapper too. */
.plots-loop-grid__item.plot-card-hidden,
.plots-loop-grid .e-loop-item.plot-card-hidden {
    display: none !important;
}

/* Pagination row */
.plots-loop-grid__pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 32px;
    flex-wrap: wrap;
}

/* Load More button (style tab controls override). */
.plots-loop-grid__load-more {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 32px;
    background: #283634;
    color: #fff;
    border: none;
    border-radius: 999px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1;
    transition: opacity .2s ease, transform .1s ease;
    -webkit-appearance: none;
    appearance: none;
}
.plots-loop-grid__load-more:hover:not(:disabled) {
    opacity: .9;
}
.plots-loop-grid__load-more:disabled {
    opacity: .5;
    cursor: wait;
}

.plots-loop-grid__status {
    color: #666;
    font-size: 14px;
    min-height: 1em;
}

.plots-loop-grid__sentinel {
    height: 1px;
    width: 100%;
    flex-basis: 100%;
}

/* ---------------------------------------------------------------
   Loading state
   --------------------------------------------------------------- */

/* Loading overlay block — hidden until the grid enters .is-loading. */
.plots-loop-grid__loading {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 16px;
    color: #555;
    font-size: 15px;
    text-align: center;
}

.plots-loop-grid__loading-text {
    line-height: 1.2;
}

/* CSS spinner — plain ring that rotates. Colour overridable via
   the Style tab (widget writes inline --plg-spinner-color). */
.plots-loop-grid__spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2.5px solid rgba(0, 0, 0, 0.12);
    border-top-color: var(--plg-spinner-color, #283634);
    animation: plots-loop-grid-spin 0.8s linear infinite;
    flex: 0 0 auto;
}

@keyframes plots-loop-grid-spin {
    to { transform: rotate(360deg); }
}

/* When loading, display the overlay. If there are already items
   in the grid (load-more case) we dim them; otherwise the overlay
   takes the vertical space on its own. */
.plots-loop-grid.is-loading .plots-loop-grid__loading {
    display: flex;
}

.plots-loop-grid.is-loading .plots-loop-grid__items {
    opacity: 0.45;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

/* When a filter-triggered refetch begins with an empty grid, hide
   the stale items track entirely so the spinner sits where the
   results would. Keeps layout calm. */
.plots-loop-grid.is-loading.is-empty .plots-loop-grid__items {
    display: none;
}

/* During loading, the pagination row (Load More button) is not
   useful — the button is already disabled by JS, but hide the
   row to avoid double controls. */
.plots-loop-grid.is-loading .plots-loop-grid__pagination {
    opacity: 0.5;
    pointer-events: none;
}

/* ---------------------------------------------------------------
   Empty state
   --------------------------------------------------------------- */

.plots-loop-grid__empty {
    display: none;
    padding: 48px 16px;
    text-align: center;
    color: var(--plg-empty-color, #666);
    font-size: 16px;
    line-height: 1.45;
}

/* Only show the empty message once the server has confirmed zero
   results AND we are NOT currently refetching. */
.plots-loop-grid.is-empty:not(.is-loading) .plots-loop-grid__empty {
    display: block;
}

/* Hide the items + pagination row when confirmed empty. */
.plots-loop-grid.is-empty:not(.is-loading) .plots-loop-grid__items,
.plots-loop-grid.is-empty:not(.is-loading) .plots-loop-grid__pagination {
    display: none;
}

/* Responsive fallbacks — overridden per-breakpoint by the
   Columns responsive control. */
@media (max-width: 1024px) {
    .plots-loop-grid__items {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 640px) {
    .plots-loop-grid__items {
        grid-template-columns: 1fr;
    }
}
