/*
 * Catalogue page surface — shared stylesheet.
 *
 * Extracted verbatim from the inline <style> of app/Views/frontend/catalog.php
 * so any public listing can wear the same shell: coloured hero
 * (.catalog-header), sticky facet sidebar (.filters-panel), results header,
 * cover grid (.books-grid / .book-card), empty state and pagination.
 *
 * Opt in from a view with `$catalogPageStyles = true;` before the frontend
 * layout renders; the layout links this file AFTER its own inline <style>, so
 * these rules win over the layout's base ones exactly as the old inline block
 * did, while the theme's "CSS personalizzato" still wins over them.
 *
 * Users: /catalogo, /emeroteca/articoli (storage/plugins/emeroteca).
 */

/*
 * No :root token block on purpose. The inline original opened with one, but it
 * was emitted inside the layout's own <style> after a literal "<style>" token,
 * so browsers discarded it as an invalid rule: the catalogue has always rendered
 * with the tokens defined by the layout and main.css (--border-color,
 * --text-muted, --radius-*, ...). Reinstating it here would silently restyle
 * /catalogo; tokens are documented in the frontend design guide instead.
 */

.catalog-header {
    background: var(--primary-color);
    color: white;
    padding: 4rem 0 3rem;
    position: relative;
    overflow: hidden;
}

.catalog-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.05);
}

.catalog-header-content {
    position: relative;
    z-index: 2;
}

.catalog-title {
    font-family: var(--serif);
    font-size: 3.5rem;
    font-weight: 420;
    letter-spacing: -0.03em;
    margin-bottom: 0.5rem;
    color: #fff;
}

.catalog-subtitle {
    font-size: 1.25rem;
    opacity: 0.9;
    font-weight: 300;
    margin-bottom: 1rem;
}

/* Enhanced Filters */
.filters-panel {
    background: none;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-color);
    box-shadow: none;
    position: sticky;
    top: 6.5rem;
    max-height: calc(100vh - 8rem);
    display: flex;
    flex-direction: column;
    padding: 0;
}

@media (max-width: 991.98px) {
    .filters-panel {
        padding-right: 0;
    }
}

.filters-header {
    background: none;
    padding: 1.25rem 1.125rem 1rem;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.filters-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filters-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 0.625rem 0.625rem;
}

.filter-section {
    padding: 1.5rem 0.625rem;
    border-bottom: 1px solid var(--border-light);
}

.filter-section:last-child {
    border-bottom: none;
}

.filter-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-box input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
    transition: var(--transition);
    background: var(--bg-primary);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: none;
}

.search-box input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.search-box svg {
    width: 1rem;
    height: 1rem;
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-box i {
    position: absolute;
    left: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 0.875rem;
    width: 18px;
}

.filter-options {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    /* Long facet lists (authors, genres, publishers) scroll inside the
       section instead of stretching the whole sidebar. */
    max-height: 24rem;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
    /* Open list — no boxed frame. Lighter, taller, editorial.
       Small right inset so the scrollbar never overlaps the counts. */
    border: none;
    border-radius: 0;
    /* …but it does need an end. Without one the authors list stops
       mid-alphabet with ninety-two names still inside it and reads as a
       finished list, so the facet below looks like the empty one. The rule
       closes the box without putting a frame back around it. */
    border-bottom: 1px solid var(--border-color);
    padding: 0 0.375rem 0.25rem 0;
}
/* And this is what says scroll: the last line fades out, but only while
   something is actually below it. The class is set from JS because CSS
   cannot ask whether a box overflows, and it is cleared again once the
   list is scrolled to the bottom — a cue that never goes away stops being
   read as a cue. A mask is used rather than a gradient over the content
   because the panel is transparent: the four layouts and the colour theme
   paint different things behind it, and a fade hard-coded to white would
   be a white smear on three of them.
   The last pixel row is deliberately opaque again. A mask is clipped to
   the border box, so a fade that reaches zero at 100 per cent takes the
   closing rule with it — and it does so exactly when the list is long,
   which is when the rule is carrying the most weight. Measured: the row
   holding the border goes from 29 to 0 ink the moment the cue turns on. */
.filter-options.facet-has-more {
    -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 2rem), transparent calc(100% - 1px), #000 calc(100% - 1px));
    mask-image: linear-gradient(to bottom, #000 calc(100% - 2rem), transparent calc(100% - 1px), #000 calc(100% - 1px));
}
@media (prefers-reduced-motion: reduce) {
    .filter-options.facet-has-more { transition: none; }
}
.filter-options::-webkit-scrollbar { width: 6px; }
.filter-options::-webkit-scrollbar-track { background: transparent; }
.filter-options::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 999px;
}
.filter-options::-webkit-scrollbar-thumb:hover { background: var(--text-muted, #94a3b8); }
/* A collapsed facet (single pill) must never show a scrollbar, a box or a
   closing rule: there is nothing to scroll and nothing to delimit. */
.filter-options.facet-is-collapsed {
    max-height: none;
    overflow: visible;
    border: none;
    border-bottom: none;
    padding: 0;
    -webkit-mask-image: none;
    mask-image: none;
}

.filter-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 0.7rem 0.75rem;
    border-radius: 2px;
    color: var(--text-color, var(--text-primary));
    text-decoration: none;
    font-size: 0.925rem;
    transition: var(--transition);
    cursor: pointer;
    gap: 0.5rem;
    word-break: break-word;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.filter-option:hover {
    background: color-mix(in srgb, var(--primary-color) 7%, transparent);
    color: var(--primary-color);
    transform: translateX(2px);
}

.filter-option.active {
    background: var(--primary-color);
    color: white;
    font-weight: 600;
}

.filter-option.subgenre {
    margin-left: 1rem;
    font-size: 0.8125rem;
}

.filter-option .count-badge {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
}

.filter-option.active .count-badge {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Year Range Slider */
.year-range {
    position: relative;
    margin: 1rem 0;
}

.year-range-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.year-slider-container {
    position: relative;
    height: 6px;
    background: #000000;
    border-radius: 3px;
    margin: 1rem 0;
}

.year-slider-track {
    position: absolute;
    height: 100%;
    background: var(--primary-color);
    border-radius: 3px;
}

.year-slider {
    position: absolute;
    width: 100%;
    height: 6px;
    background: transparent;
    outline: none;
    pointer-events: none;
    -webkit-appearance: none;
}

.year-slider::-webkit-slider-thumb {
    appearance: none;
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    pointer-events: all;
    border: 3px solid white;
    box-shadow: none;
    transition: var(--transition);
}

.year-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: none;
}

.year-slider::-moz-range-thumb {
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background: var(--primary-color);
    cursor: pointer;
    pointer-events: all;
    border: 3px solid white;
    box-shadow: none;
}

.year-values {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.75rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.year-value {
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.75rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    min-width: 60px;
    text-align: center;
}

.year-reset {
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

.year-reset:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Enhanced Availability Filter */
.availability-options {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.5rem;
}

.availability-option {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.availability-option:hover {
    border-color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: none;
}

.availability-option.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
    box-shadow: none;
}

.availability-option.active::before {
    display: none;
}

.availability-icon {
    font-size: 1.25rem;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

.availability-option .availability-icon {
    background: var(--bg-secondary);
    color: var(--primary-color);
    transition: var(--transition);
}

.availability-option.active .availability-icon,
.availability-option.active .availability-icon svg {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    fill: white;
}

.availability-text {
    flex: 1;
}

.availability-title {
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.2;
    margin-bottom: 0.125rem;
}

.availability-desc {
    font-size: 0.75rem;
    opacity: 0.8;
    line-height: 1.3;
}

.availability-option.active .availability-desc {
    opacity: 1;
}

.availability-count {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.availability-option.active .availability-count {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Pages Range Filter */
.pages-filter {
    position: relative;
    margin: 1rem 0;
}

.pages-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.pages-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.75rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.75rem;
}

.pages-option:hover {
    border-color: var(--primary-color);
    background: var(--bg-secondary);
}

.pages-option.active {
    border-color: var(--primary-color);
    background: var(--primary-color);
    color: white;
}

.pages-option-icon {
    font-size: 1rem;
    opacity: 0.7;
}

.pages-option.active .pages-option-icon {
    opacity: 1;
}

.pages-option-text {
    font-weight: 600;
    text-align: center;
    line-height: 1.2;
}

.custom-range-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: var(--transition);
    margin-bottom: 0.5rem;
}

.custom-range-toggle:hover,
.custom-range-toggle.active {
    border-color: var(--primary-color);
    color: var(--primary-color);
    background: var(--bg-primary);
}

.custom-pages-inputs {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0.5rem;
    align-items: center;
    margin-top: 0.5rem;
}

.custom-pages-inputs.hidden {
    display: none;
}

.pages-input {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    text-align: center;
}

.pages-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: none;
}

.pages-input:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.pages-separator {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.clear-all-btn {
    width: 100%;
    padding: 0.75rem;
    background: #0f172a;
    color: #fff;
    border: 1px solid #0f172a;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    box-shadow: none;
}

.clear-all-btn:hover {
    background: #000000;
    border-color: #000000;
    transform: translateY(-1px);
}

.clear-all-btn i {
    font-size: 0.875rem;
}

/* Results Header */
.results-header {
    background: none;
    padding: 0 0 1.25rem;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border-color);
    box-shadow: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    /* Clear the fixed site header (~82px desktop / ~77px mobile) when this
       becomes the scroll anchor on pagination — see goToPage(). */
    scroll-margin-top: 6.5rem;
    margin-bottom: 1.5rem;
}

.results-info {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.results-info strong {
    color: var(--primary-color);
    font-weight: 700;
}

.sort-select {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: var(--transition);
}

.sort-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: none;
}

.sort-select:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.clear-filters-top-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #1f2937;
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.clear-filters-top-btn:hover {
    background: #111827;
    transform: translateY(-1px);
}

.clear-filters-top-btn i {
    font-size: 1rem;
}

/* Active Filters */
.active-filters {
    background: none;
    padding: 0 0 1rem;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.active-filters-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    margin-bottom: 0.5rem;
}

.filter-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    background: #1f2937;
    color: white;
    border-radius: var(--radius-md);
    font-size: 0.75rem;
    font-weight: 600;
    transition: var(--transition);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.filter-tag:hover {
    background: #111827;
    transform: translateY(-1px);
    box-shadow: none;
}

.filter-tag-remove {
    cursor: pointer;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
    transition: var(--transition);
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.1);
    border-radius: 50%;
    width: 1.25rem;
    height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 0.25rem;
}

.filter-tag-remove:hover {
    background: rgba(0, 0, 0, 0.2);
    color: white;
    transform: scale(1.1);
}

/* Enhanced Book Cards */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
    gap: 1.5rem;
}

.book-card {
    background: none;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    border: none;
    transition: var(--transition);
    position: relative;
}

.book-card:hover {
    transform: none;
    box-shadow: none;
}

/* The cover is the visual hero: the only element allowed elevation, and it
   lifts subtly on hover instead of the whole card. */
.book-image-container {
    position: relative;
    aspect-ratio: 2/3;
    overflow: hidden;
    background: var(--bg-tertiary);
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    transition: var(--transition);
}

.book-card:hover .book-image-container {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.book-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    transition: var(--transition);
}

.book-card:hover .book-image {
    transform: scale(1.012);
}

.book-status-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    padding: 0.375rem 0.75rem;
    border-radius: 2px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    backdrop-filter: none;
}

.status-available {
    background: var(--success-color); /* fallback for browsers without color-mix() */
    background: color-mix(in srgb, var(--success-color) 90%, transparent);
    color: white;
}

.status-borrowed {
    background: var(--danger-color); /* fallback for browsers without color-mix() */
    background: color-mix(in srgb, var(--danger-color) 90%, transparent);
    color: white;
}

.status-reserved {
    background: rgba(139, 92, 246, 0.9);
    color: white;
}

.book-content {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.book-title {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.book-title a {
    color: inherit;
    text-decoration: none;
    transition: var(--transition);
}

.book-title a:hover {
    color: var(--dark-color);
}

.book-author {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    min-height: 1.2em;
}

.book-author a {
    color: inherit;
    text-decoration: none;
}

.book-author a:hover {
    color: var(--primary-color);
}

.book-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: auto;
    min-height: 1.5em;
}

.book-actions {
    margin-top: auto;
    display: flex;
    gap: 0.5rem;
    padding-top: 1rem;
}

.book-actions .btn-cta {
    width: 100%;
    justify-content: center;
}

.btn-secondary {
    padding: 0.5rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Loading States */
.loading-skeleton {
    background: var(--bg-tertiary);
    animation: pulse 1.2s ease-in-out infinite alternate;
}

@keyframes pulse {
    from { opacity: 0.6; }
    to { opacity: 1; }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    width: 100%;
    background: none;
    border-radius: 0;
    border: none;
    border-top: 1px solid var(--border-color);
    grid-column: 1 / -1;
}

#books-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state-text {
    font-size: 1rem;
    margin-bottom: 1.5rem;
}

.btn-cta {
    display: inline-flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--button-color);
    color: var(--button-text-color);
    border: 1px solid var(--button-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-cta:hover {
    background: var(--button-hover);
    border-color: var(--button-hover);
    transform: translateY(-1px);
}

.btn-cta-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Responsive Design */
@media (max-width: 991.98px) {
    .catalog-title {
        font-size: 2.5rem;
    }

    .filters-panel {
        position: static;
        max-height: none;
        margin-bottom: 2rem;
    }
}

@media (max-width: 768px) {
    .catalog-header {
        padding: 2rem 0 1.5rem;
    }

    .catalog-title {
        font-size: 2rem;
    }

    .books-grid {
        grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr));
        gap: 1rem;
    }

    .results-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .filter-section {
        padding: 1.25rem 0.75rem;
    }

    .clear-filters-text {
        display: none;
    }

    .clear-filters-top-btn {
        padding: 0.5rem 0.75rem;
    }
}

@media (max-width: 480px) {
    .catalog-title {
        font-size: 1.75rem;
    }



    .book-actions {
        flex-direction: column;
    }
}

/* Smooth Transitions */
.fade-in {
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Pagination - keep in sync with global dark accent */
/* Horizontal row of page links. The .pagination/.page-item classes carry no
   framework CSS anymore (Bootstrap was removed), so the list is laid out
   here: a centered, wrapping flex row instead of stacked <li> blocks. */
.pagination {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 0.4rem;
    list-style: none;
    padding: 0;
    margin: 0;
}

.pagination .page-item {
    margin: 0;
}

.pagination .page-link {
    /* 44px touch target, number centred. */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    color: #111827;
    border-color: #111827;
    font-weight: 600;
    border-radius: var(--radius-md);
    padding: 0.5rem 0.9rem;
    transition: var(--transition);
}

.pagination .page-link:hover,
.pagination .page-link:focus {
    color: #ffffff;
    background-color: #111827;
    border-color: #111827;
    box-shadow: none;
    text-decoration: none;
}

.pagination .page-item.active .page-link {
    color: #ffffff;
    background-color: #000000;
    border-color: #000000;
}

.page-item:first-child .page-link {
    border-top-left-radius: var(--radius-md);
    border-bottom-left-radius: var(--radius-md);
}

.pagination .page-item.disabled .page-link {
    color: var(--text-muted);
    border-color: #d1d5db;
    background-color: transparent;
    box-shadow: none;
}

/* Genre filter back button container */
.filter-back-container {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

/* Genre filter back button */
.filter-back-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 0.875rem;
    transition: var(--transition);
    cursor: pointer;
    text-decoration: none;
    width: fit-content;
}

.filter-back-btn:hover {
    background: var(--primary-color);
    color: white;
}

.filter-back-btn i {
    font-size: 0.75rem;
}

.filter-back-btn span {
    font-weight: 500;
}

/* Faceted search: collapsed facet pill (collapse-on-select) */
.facet-collapsed {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    align-self: flex-start;
    max-width: 100%;
    padding: 0.45rem 0.5rem 0.45rem 0.75rem;
    background: var(--primary-color);
    color: white;
    border: 1px solid var(--primary-color);
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 600;
    transition: var(--transition);
}

.facet-collapsed .facet-collapsed-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.facet-collapsed-remove {
    cursor: pointer;
    border: none;
    padding: 0;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    width: 1.25rem;
    height: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 700;
    line-height: 1;
    flex-shrink: 0;
    transition: var(--transition);
}

.facet-collapsed-remove:hover {
    background: rgba(255, 255, 255, 0.35);
    transform: scale(1.1);
}

.facet-change-link {
    display: inline-block;
    margin-top: 0.5rem;
    align-self: flex-start;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--primary-color);
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
}

.facet-change-link:hover {
    text-decoration: underline;
    color: var(--primary-hover, var(--primary-color));
}

.facet-fade-in {
    animation: facetFade 0.2s ease-out;
}

@keyframes facetFade {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Catalogue card details ───────────────────────────────────────────────
 * Moved from the <style> block of app/Views/frontend/catalog-grid.php, which
 * only /catalogo included: every other page listing the same cards (home,
 * author/publisher, emeroteca, events) rendered a full-width filled "Dettagli"
 * and unclamped titles. Placed after the catalogue rules above and before the
 * additions below, the order the inline block had on /catalogo. */
/* Enhanced book card styling */
.book-card {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: none;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
    border: none;
    transition: var(--transition);
}

.book-card:hover {
    transform: none;
    box-shadow: none;
}

/* The cover is the visual hero: the only element carrying elevation, lifting
   subtly on hover instead of the whole card. */
.book-image-container {
    position: relative;
    aspect-ratio: 2/3;
    overflow: hidden;
    background: var(--bg-tertiary);
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    transition: var(--transition);
}

.book-card:hover .book-image-container {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.book-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), filter 0.3s ease;
    will-change: transform;
}

.book-card:hover .book-image {
    transform: scale(1.012) translateZ(0);
    filter: brightness(1.05);
}

.book-image-container::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(0,0,0,0.1) 100%);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.book-card:hover .book-image-container::after {
    opacity: 1;
}

.book-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
}

.book-title {
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1.4;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    /* #298: cap at two lines; the exact height is equalised per grid row by the
       script below, so a row of short titles stays compact while a row that
       needs two lines lines up. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-title a {
    color: inherit;
    text-decoration: none;
    transition: color 0.2s ease;
}

.book-subtitle {
    font-size: 0.9rem;
    font-style: italic;
    line-height: 1.35;
    margin-top: -0.25rem;
    margin-bottom: 0.5rem;
    color: var(--text-secondary, #6b7280);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    /* #298: the subtitle is rendered only when the book has one, so it takes
       space conditionally — no reserved gap on the (majority) of cards without
       a subtitle. */
}

.book-title a:hover {
    color: var(--dark-color);
}

.book-author {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    /* #298: fixed single-line box so a long author name can't push the row
       below out of alignment with adjacent cards. line-height matches the
       height so the single line isn't clipped by overflow:hidden. */
    height: 1.3em;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: auto;
    /* #298: fixed single-line box (see .book-author). */
    height: 1.5em;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-actions {
    margin-top: auto;
    display: flex;
    gap: 0.5rem;
    padding-top: 0.75rem;
}

/* Detail action = quiet text link, not a filled button (matches home). */
.book-actions .btn-cta {
    width: auto;
    justify-content: flex-start;
    background: none !important;
    color: var(--primary-color) !important;
    border: none !important;
    padding: 0 !important;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    box-shadow: none !important;
    gap: 0.4rem;
}
.book-actions .btn-cta:hover {
    background: none !important;
    color: var(--primary-color) !important;
    transform: none;
    gap: 0.6rem;
    transition: gap .3s cubic-bezier(.22,1,.36,1);
}

.book-status-badge {
    position: absolute;
    top: 0.6rem;
    right: 0.6rem;
    padding: 0.28rem 0.55rem;
    border-radius: 2px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    backdrop-filter: none;
    transition: transform 0.3s ease;
}

.book-card:hover .book-status-badge {
    transform: translateY(-2px);
}

.status-available {
    background: var(--success-color); /* fallback for browsers without color-mix() */
    background: color-mix(in srgb, var(--success-color) 90%, transparent);
    color: white;
}

.status-borrowed {
    background: var(--danger-color); /* fallback for browsers without color-mix() */
    background: color-mix(in srgb, var(--danger-color) 90%, transparent);
    color: white;
}

.status-reserved {
    background: var(--warning-color); /* fallback for browsers without color-mix() */
    background: color-mix(in srgb, var(--warning-color) 90%, transparent);
    color: white;
}

.status-unavailable {
    /* Neutral grey — theme-agnostic, signals "not circulating" without alarm */
    background: #6b7280;
    color: white;
}

.availability-pending {
    background: #6b7280;
    color: white;
}

/* Ensure consistent grid layout */
.books-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr));
    gap: 1.5rem;
    align-items: stretch;
}

/* Hide empty elements but maintain spacing */
.book-author[style*="visibility: hidden"],
.book-meta-empty {
    visibility: hidden !important;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .book-content {
    flex: 1;
        padding: 1rem;
    }

    .book-title {
        font-size: 1rem;
    }
}

.empty-state .btn-cta {
    justify-content: center;
}

.book-media-badge {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
    background: rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    padding: 0.375rem;
    box-shadow: none;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-media-badge i {
    color: var(--text-secondary, #6b7280);
    font-size: 0.75rem;
}

/* ── Article cards (partials/article-card.php) ───────────────────────────
 * Same card as a book; these cover the parts a book card does not have. */
.book-card .book-subtitle {
    margin: -0.25rem 0 0.5rem;
    font-size: 0.875rem;
    line-height: 1.4;
    color: var(--text-muted, #64748b);
}

.book-card .book-meta a {
    color: inherit;
    text-decoration: none;
}

.book-card .book-meta a:hover,
.book-card .book-meta a:focus-visible {
    color: var(--primary-color);
    text-decoration: underline;
}

/* "Articolo" in a mixed grid: a neutral ink label, not a status colour —
   it says what the record is, not whether it can be borrowed. */
.status-article {
    background: #1f2937;
    color: #fff;
}

/* ── Periodical cards (emeroteca) ────────────────────────────────────────
 * A masthead logo is a mark, not a cover: square box, contained. */
.book-card--square .book-image-container {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.book-card--square .book-image-container .book-image {
    padding: 12%;
}

.book-card .book-image-icon {
    font-size: 3rem;
    color: var(--text-muted, #64748b);
    opacity: 0.6;
}

/* ── Listing sections inside a page (e.g. a periodical's issues, then its
   articles): a plain heading with a rule, the catalogue's quiet hierarchy. */
.listing-section + .listing-section {
    margin-top: 3rem;
}

.listing-section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    font-family: var(--serif);
    font-size: 1.5rem;
    font-weight: 460;
    letter-spacing: -0.02em;
    color: var(--text-color);
    padding-bottom: 0.75rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.listing-section-title a {
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0;
    color: var(--primary-color);
    text-decoration: none;
}

.listing-section-title a:hover,
.listing-section-title a:focus-visible {
    text-decoration: underline;
}

/* ── Server-rendered listings ─────────────────────────────────────────────
 * /catalogo drives its "clear" controls from JS as <button>s; listings that
 * work without JS (the emeroteca) render the same controls as links. */
a.clear-all-btn,
a.clear-filters-top-btn,
a.filter-tag-remove {
    text-decoration: none;
}

a.clear-all-btn,
a.clear-all-btn:hover,
a.clear-filters-top-btn,
a.clear-filters-top-btn:hover,
a.filter-tag-remove {
    color: #fff;
}

/* /catalogo's sidebar heading is an <h5>; a page whose outline needs an <h2>
   keeps the catalogue's UI face instead of the layout's display serif. */
h2.filters-title {
    /* !important: the layout sets every h1–h4 in the display serif with
       !important; this one is a UI label, not a heading voice. */
    font-family: inherit !important;
    margin: 0;
}

/* An A–Z index in the sidebar: tiles, not 27 rows. Still 44px targets. */
.filter-options--grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
    gap: 0.25rem;
    max-height: none;
    border-bottom: none;
    padding: 0;
}

.filter-options--grid .filter-option {
    justify-content: center;
    padding: 0.5rem 0;
    font-weight: 600;
}

.filter-options--grid .filter-option:hover {
    transform: none;
}

/* book-detail.css owns a page-level `.book-meta` band (negative margin, rule,
   padding). A card's metadata line shares the name, so on pages that load
   both sheets (an issue or article page listing related articles) the card
   keeps its own, plain line. */
.book-card .book-meta {
    background: none;
    padding: 0;
    margin-top: 0;
    border: none;
    position: static;
    z-index: auto;
}

/* Status badges that catalog-grid.php also defines in its own <style>: a page
   that renders catalogue cards without that file (author and publisher
   archives) must not show a transparent, unreadable badge. */
.status-unavailable,
.availability-pending {
    background: #6b7280;
    color: #fff;
}

/* Two columns on a phone: one full-width cover per row made a page of twelve
   books nearly ten thousand pixels tall. Last in the sheet so it wins over
   every earlier .books-grid declaration. */
@media (max-width: 480px) {
    .books-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem 0.75rem;
    }

    .books-grid .book-content {
        padding: 0.75rem 0.25rem 0;
    }

    .books-grid .book-title {
        font-size: 1rem;
    }
}
