/* Base card styles — shared by all three layouts, overridden per-layout below */

.news-agent-match {
    border: 1px solid #e2e2e2;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    position: relative;
}

.news-agent-match__hide {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    width: 22px;
    height: 22px;
    line-height: 20px;
    text-align: center;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 1rem;
    cursor: pointer;
    z-index: 2;
}

.news-agent-match__hide:hover {
    background: rgba(179, 45, 46, 0.9); /* matches the admin error red used elsewhere in the plugin */
}

.news-agent-match__image {
    width: 100%;
    aspect-ratio: var(--na-image-ratio, 16/9);
    object-fit: cover;
    display: block;
}

/* display:contents makes the wrapping <a> invisible to layout — the <img>
   inside it still participates directly in whatever flex/grid context
   it's in (list's flex row, cards' grid, etc.) exactly as if there were
   no wrapper at all, while still being clickable. */
.news-agent-match__image-link {
    display: contents;
}

/* image_ratio="auto" — natural proportions, no cropping */
.news-agent-matches--image-auto .news-agent-match__image {
    aspect-ratio: auto;
    height: auto;
    object-fit: initial;
}

.news-agent-match__body {
    padding: 0.75rem 0.9rem 0.9rem;
}

.news-agent-match__category {
    margin: 0 0 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.news-agent-match__category a {
    text-decoration: none;
    color: #2271b1;
}

.news-agent-match__title {
    font-size: 1.1rem;
    margin: 0 0 0.25rem;
}

.news-agent-match__title a {
    text-decoration: none;
}

.news-agent-match__date {
    margin: 0;
    font-size: 0.75rem;
    color: #888;
}

.news-agent-match__phrase {
    margin: 0.4rem 0 0;
    font-size: 0.8rem;
    color: #666;
}

.news-agent-match__summary {
    margin: 0.5rem 0 0;
    font-size: 0.9rem;
    line-height: 1.4;
}

.news-agent-match__tags {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin: 0.6rem 0 0;
    padding: 0;
}

.news-agent-match__tags li {
    background: #f1f1f1;
    border-radius: 999px;
    padding: 0.15rem 0.6rem;
    font-size: 0.75rem;
    color: #444;
}

.news-agent-match__tags li a {
    color: inherit;
    text-decoration: none;
}

.news-agent-match__tags li a:hover {
    text-decoration: underline;
}

/* --- Layout: cards (default) — even grid, uniform card heights --- */

.news-agent-matches--cards {
    display: grid;
    gap: 1.5rem;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

/* --- Layout: masonry — CSS-columns based, natural (uneven) heights.
   A true JS masonry (packed grid) isn't worth the dependency here;
   CSS columns give the same "brick wall" visual with zero JS. --- */

.news-agent-matches--masonry {
    columns: 280px 3; /* responsive column count, ~280px minimum width */
    column-gap: 1.5rem;
}

.news-agent-matches--masonry .news-agent-match {
    break-inside: avoid; /* keeps a single card from splitting across columns */
    margin-bottom: 1.5rem;
    display: inline-block;
    width: 100%;
}

/* --- Layout: list — compact single column, small thumbnail beside text --- */

.news-agent-matches--list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.news-agent-matches--list .news-agent-match {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    height: var(--na-list-item-height, auto);
    overflow: hidden; /* only matters when a fixed height is set — clips content that would otherwise overflow a too-short row */
}

.news-agent-matches--list .news-agent-match__image {
    width: var(--na-image-width, 140px);
    height: auto;
    min-height: 100%;
    flex-shrink: 0;
}

.news-agent-matches--list .news-agent-match__body {
    flex: 1;
    min-width: 0; /* allows text truncation/wrapping instead of overflowing the flex row */
}

.news-agent-matches--list .news-agent-match__summary {
    /* Lists are meant to be scannable — trim long summaries rather than
       stretching every row to the tallest one's height. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@media (max-width: 480px) {
    .news-agent-matches--list .news-agent-match {
        flex-direction: column;
    }
    .news-agent-matches--list .news-agent-match__image {
        width: 100%;
        height: auto;
        aspect-ratio: var(--na-image-ratio, 16/9);
    }
    .news-agent-matches--image-auto.news-agent-matches--list .news-agent-match__image {
        aspect-ratio: auto;
    }
}

/* --- Filter panel (show_filters="yes") --- */

.news-agent-filter-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 1.5rem 2rem;
    padding: 0.9rem 1.1rem;
    margin-bottom: 1.5rem;
    background: #f8f8f8;
    border: 1px solid #e2e2e2;
    border-radius: 8px;
}

.news-agent-filter-panel__group {
    border: none;
    margin: 0;
    padding: 0;
    min-width: 140px;
}

.news-agent-filter-panel__group legend {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.4rem;
    padding: 0;
}

.news-agent-filter-panel__group label {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 0.3rem;
    cursor: pointer;
}

.news-agent-filter-panel__count {
    color: #888;
    font-size: 0.8rem;
}

.news-agent-filter-panel__actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    align-self: flex-end;
}

.news-agent-filter-panel__submit {
    background: #2271b1;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    cursor: pointer;
}

.news-agent-filter-panel__submit:hover {
    background: #135e96;
}

.news-agent-filter-panel__reset {
    font-size: 0.85rem;
    color: #b32d2e;
    text-decoration: none;
}

.news-agent-filter-panel__reset:hover {
    text-decoration: underline;
}

/* --- Filter panel: accordion mode (filter_accordion="yes") --- */

.news-agent-filter-panel-accordion {
    margin-bottom: 1.5rem;
}

.news-agent-filter-panel-accordion > summary {
    cursor: pointer;
    font-weight: 600;
    padding: 0.6rem 1rem;
    background: #f0f0f1;
    border: 1px solid #e2e2e2;
    border-radius: 8px;
    list-style: none; /* hides the default disclosure triangle in most browsers — the native affordance is enough without it, and it renders inconsistently across browsers anyway */
}

.news-agent-filter-panel-accordion > summary::-webkit-details-marker {
    display: none; /* Safari/Chrome-specific equivalent of the list-style:none above */
}

.news-agent-filter-panel-accordion .news-agent-filter-panel {
    margin-top: 0.5rem;
    margin-bottom: 0; /* the accordion wrapper itself already has bottom margin */
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

/* --- Filter panel: sidebar layout (filter_position="left"/"right") --- */

.news-agent-layout {
    display: flex;
    gap: 2rem;
    align-items: flex-start;
}

.news-agent-layout--sidebar-right {
    flex-direction: row-reverse; /* markup order stays filter-panel-first (see PHP comment) — this just flips which side it visually renders on */
}

.news-agent-layout .news-agent-filter-panel,
.news-agent-layout .news-agent-filter-panel-accordion {
    flex: 0 0 220px;
    flex-direction: column; /* stack Category/Tag groups vertically in a sidebar, instead of the side-by-side row layout used in the default top position */
    position: sticky;
    top: 1rem; /* stays in view while scrolling a long results column */
    margin-bottom: 0;
}

.news-agent-layout__content {
    flex: 1;
    min-width: 0; /* without this, a long unbroken word/URL in a card can force the flex item wider than its share, pushing the sidebar out */
}

@media (max-width: 960px) {
    /* Sidebars stop looking good well before "phone-narrow" — even on a
       tablet, a fixed-width sidebar column reserved just for a collapsed
       accordion button looks disproportionate and wastes horizontal
       space that the results could use. Collapse to top-stacked at a
       generous threshold rather than only at phone widths. */
    .news-agent-layout {
        flex-direction: column;
    }
    .news-agent-layout .news-agent-filter-panel,
    .news-agent-layout .news-agent-filter-panel-accordion {
        position: static;
        /* Resets the desktop rule's "flex: 0 0 220px" — flex-basis
           applies to whichever axis is currently the *main* axis. In the
           desktop row layout that's width (fine, that's the intent), but
           once flex-direction switches to column above, the main axis is
           now vertical — so that same 220px would silently become a
           forced HEIGHT instead, leaving a large empty box around a
           collapsed accordion regardless of its actual content height.
           flex: 1 1 auto lets it size naturally in either axis. */
        flex: 1 1 auto;
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
    }
}

/* --- Filter notice (shown when a category/tag filter is active from the URL) --- */

.news-agent-active-filter {
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.news-agent-active-filter a {
    margin-left: 0.5rem;
}

/* --- Pagination (WordPress's own paginate_links() output) --- */

.news-agent-pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1.5rem;
    font-size: 0.9rem;
}

.news-agent-pagination .page-numbers {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.5rem;
    border-radius: 4px;
    text-decoration: none;
    color: inherit;
}

.news-agent-pagination a.page-numbers:hover {
    background: #f0f0f1;
}

.news-agent-pagination .page-numbers.current {
    background: #2271b1;
    color: #fff;
    font-weight: 600;
}

.news-agent-pagination .page-numbers.dots {
    color: #888;
}
