/* ============================================================
   Smart Post Lister for Elementor — Frontend CSS
   ============================================================ */

/* ---------- CSS Variables ---------- */
.spl-wrapper {
    --spl-cols: 3;
    --spl-cols-tablet: 2;
    --spl-cols-mobile: 1;
    --spl-gap: 24px;
    --spl-radius: 12px;
    --spl-card-bg: #ffffff;
    --spl-accent: #3b6ef4;
    --spl-text: #1a1a2e;
    --spl-muted: #6b7280;
    --spl-border: #e5e7eb;
    --spl-shadow: 0 2px 12px rgba(0,0,0,.08);
    --spl-shadow-hover: 0 8px 32px rgba(0,0,0,.14);
    --spl-transition: 0.25s ease;
    font-family: inherit;
    position: relative;
}

/* ---------- Grid ---------- */
.spl-grid {
    display: grid;
    grid-template-columns: repeat(var(--spl-cols), 1fr);
    gap: var(--spl-gap);
}

@media (max-width: 1024px) {
    .spl-grid { grid-template-columns: repeat(var(--spl-cols-tablet), 1fr); }
}
@media (max-width: 600px) {
    .spl-grid { grid-template-columns: repeat(var(--spl-cols-mobile), 1fr); }
}

/* Masonry */
.spl-grid--masonry {
    align-items: start;
}
.spl-grid--masonry .spl-item {
    break-inside: avoid;
}

/* List */
.spl-grid--list {
    grid-template-columns: 1fr;
}
.spl-grid--list .spl-item {
    display: flex;
    flex-direction: row;
    align-items: stretch;
}
.spl-grid--list .spl-item__thumbnail {
    width: 220px;
    flex-shrink: 0;
}
.spl-grid--list .spl-item__thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.spl-grid--list .spl-item__body {
    flex: 1;
}

@media (max-width: 600px) {
    .spl-grid--list .spl-item { flex-direction: column; }
    .spl-grid--list .spl-item__thumbnail { width: 100%; height: 220px; }
}

/* ============================================================
   CARD BASE STYLES
   ============================================================ */
.spl-item {
    background: var(--spl-card-bg);
    border-radius: var(--spl-radius);
    box-shadow: var(--spl-shadow);
    overflow: hidden;
    transition: transform var(--spl-transition), box-shadow var(--spl-transition);
    display: flex;
    flex-direction: column;
}
.spl-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--spl-shadow-hover);
}

/* Thumbnail */
.spl-item__thumbnail {
    overflow: hidden;
    aspect-ratio: 16/9;
}
.spl-item__img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}
.spl-item:hover .spl-item__img {
    transform: scale(1.04);
}

/* Body */
.spl-item__body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 10px;
}

/* Terms / Badges */
.spl-item__terms,
.spl-item__category,
.spl-item__tags,
.spl-item__post-category {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.spl-term-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(59,110,244,.1);
    color: var(--spl-accent);
    text-decoration: none;
    transition: background var(--spl-transition), color var(--spl-transition);
}
.spl-term-badge:hover {
    background: var(--spl-accent);
    color: #fff;
}

/* Title */
.spl-item__title {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.35;
    font-weight: 700;
}
.spl-item__title a {
    color: var(--spl-text);
    text-decoration: none;
    transition: color var(--spl-transition);
}
.spl-item__title a:hover {
    color: var(--spl-accent);
}

/* Meta */
.spl-item__meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13px;
    color: var(--spl-muted);
}
.spl-item__date,
.spl-item__author {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Excerpt */
.spl-item__excerpt {
    font-size: 14px;
    line-height: 1.65;
    color: var(--spl-muted);
    flex: 1;
}
.spl-item__excerpt p { margin: 0; }

/* Footer */
.spl-item__footer {
    margin-top: auto;
    padding-top: 8px;
}
.spl-btn-read-more {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .02em;
    padding: 8px 18px;
    border-radius: 6px;
    background: var(--spl-accent);
    color: #fff;
    text-decoration: none;
    transition: background var(--spl-transition), opacity var(--spl-transition);
    border: none;
    cursor: pointer;
}
.spl-btn-read-more:hover { opacity: .85; }
.spl-btn-read-more svg { transition: transform var(--spl-transition); }
.spl-btn-read-more:hover svg { transform: translateX(3px); }

/* ============================================================
   TEMPLATE: OVERLAY
   ============================================================ */
.spl-template-overlay {
    position: relative;
    overflow: hidden;
}
.spl-template-overlay .spl-item__thumbnail {
    aspect-ratio: auto;
    position: absolute;
    inset: 0;
    z-index: 0;
}
.spl-template-overlay .spl-item__thumbnail::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(0deg, rgba(0,0,0,.8) 0%, rgba(0,0,0,.2) 60%, transparent 100%);
}
.spl-template-overlay .spl-item__body {
    position: relative;
    z-index: 2;
    min-height: 340px;
    justify-content: flex-end;
    padding: 24px;
    background: transparent;
}
.spl-template-overlay .spl-item__title a,
.spl-template-overlay .spl-item__meta,
.spl-template-overlay .spl-item__excerpt { color: #fff; }
.spl-template-overlay .spl-term-badge {
    background: rgba(255,255,255,.2);
    color: #fff;
    backdrop-filter: blur(4px);
}

/* ============================================================
   TEMPLATE: HORIZONTAL
   ============================================================ */
.spl-template-horizontal {
    flex-direction: row !important;
}
.spl-template-horizontal .spl-item__thumbnail {
    width: 200px;
    flex-shrink: 0;
    aspect-ratio: auto;
}
.spl-template-horizontal .spl-item__body { padding: 20px; }

@media (max-width: 600px) {
    .spl-template-horizontal { flex-direction: column !important; }
    .spl-template-horizontal .spl-item__thumbnail { width: 100%; height: 200px; }
}

/* ============================================================
   TEMPLATE: MINIMAL
   ============================================================ */
.spl-template-minimal {
    box-shadow: none !important;
    background: transparent !important;
    border-radius: 0;
    border-bottom: 1px solid var(--spl-border);
}
.spl-template-minimal:hover { transform: none; box-shadow: none !important; }
.spl-template-minimal .spl-item__body { padding: 16px 0; }

/* ============================================================
   TEMPLATE: MAGAZINE
   ============================================================ */
.spl-grid--grid .spl-item:first-child.spl-template-magazine {
    grid-column: span 2;
}
.spl-template-magazine .spl-item__title { font-size: 1.35rem; }

/* ============================================================
   SEARCH BAR
   ============================================================ */
.spl-search-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    padding: 16px 20px;
    background: #f8f9fc;
    border-radius: 10px;
    margin-bottom: 28px;
    border: 1px solid var(--spl-border);
}

.spl-search-field {
    position: relative;
    flex: 1;
    min-width: 200px;
}
.spl-search-field svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--spl-muted);
    pointer-events: none;
}

.spl-input {
    width: 100%;
    padding: 9px 12px 9px 38px;
    font-size: 14px;
    border: 1px solid var(--spl-border);
    border-radius: 7px;
    background: #fff;
    color: var(--spl-text);
    outline: none;
    transition: border-color var(--spl-transition), box-shadow var(--spl-transition);
    font-family: inherit;
    box-sizing: border-box;
}
.spl-filter-field .spl-input { padding-left: 12px; }
.spl-input:focus {
    border-color: var(--spl-accent);
    box-shadow: 0 0 0 3px rgba(59,110,244,.12);
}
select.spl-input { cursor: pointer; }

.spl-filter-field { min-width: 160px; }
.spl-date-range {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 280px;
}
.spl-date-range .spl-input { min-width: 120px; flex: 1; }
.spl-date-range span { color: var(--spl-muted); flex-shrink: 0; }

.spl-filter-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.spl-btn-apply-filter,
.spl-btn-reset-filter {
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 7px;
    border: none;
    cursor: pointer;
    transition: opacity var(--spl-transition), background var(--spl-transition);
    font-family: inherit;
}
.spl-btn-apply-filter {
    background: var(--spl-accent);
    color: #fff;
}
.spl-btn-apply-filter:hover { opacity: .85; }
.spl-btn-reset-filter {
    background: transparent;
    color: var(--spl-muted);
    border: 1px solid var(--spl-border);
}
.spl-btn-reset-filter:hover { background: #f1f1f1; }

@media (max-width: 600px) {
    .spl-search-bar { flex-direction: column; }
    .spl-search-field,
    .spl-filter-field { width: 100%; min-width: 0; }
    .spl-date-range { flex-wrap: wrap; min-width: 0; }
}

/* ============================================================
   LOADING
   ============================================================ */
.spl-loading-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,.7);
    backdrop-filter: blur(2px);
    z-index: 10;
    align-items: center;
    justify-content: center;
    border-radius: var(--spl-radius);
}
.spl-wrapper.is-loading .spl-loading-overlay {
    display: flex;
}
.spl-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--spl-border);
    border-top-color: var(--spl-accent);
    border-radius: 50%;
    animation: spl-spin 0.7s linear infinite;
}
@keyframes spl-spin { to { transform: rotate(360deg); } }

/* ============================================================
   NO RESULTS
   ============================================================ */
.spl-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 24px;
    color: var(--spl-muted);
    font-size: 15px;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.spl-pagination {
    margin-top: 36px;
    display: flex;
    justify-content: center;
}

.spl-pagination--numbers {
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}
.spl-pagination--numbers a,
.spl-pagination--numbers span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    padding: 0 8px;
    border-radius: 7px;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    border: 1px solid var(--spl-border);
    color: var(--spl-text);
    background: #fff;
    transition: all var(--spl-transition);
}
.spl-pagination--numbers a:hover,
.spl-pagination--numbers .current {
    background: var(--spl-accent);
    color: #fff;
    border-color: var(--spl-accent);
}

.spl-btn-load-more {
    padding: 12px 32px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: 2px solid var(--spl-accent);
    background: transparent;
    color: var(--spl-accent);
    cursor: pointer;
    transition: all var(--spl-transition);
    font-family: inherit;
}
.spl-btn-load-more:hover {
    background: var(--spl-accent);
    color: #fff;
}
.spl-btn-load-more.is-loading {
    opacity: .6;
    cursor: not-allowed;
}

/* ============================================================
   ANIMATION — card entrance
   ============================================================ */
.spl-item {
    animation: spl-fade-up 0.4s ease both;
}
@keyframes spl-fade-up {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   META FIELDS — Stili per i custom field visualizzati nelle card
   ============================================================ */

/* Gruppo container per una posizione */
.spl-meta__group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Singolo campo */
.spl-meta__field {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 13px;
    line-height: 1.5;
}

/* Etichetta */
.spl-meta__label {
    font-weight: 600;
    color: var(--spl-muted);
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.spl-meta__label i { font-size: 13px; }

/* Icona senza label */
.spl-meta__icon { color: var(--spl-muted); }
.spl-meta__icon i { font-size: 14px; }

/* Valore generico */
.spl-meta__value { color: var(--spl-text); }
.spl-meta__text  { color: inherit; }

/* Numero */
.spl-meta__number {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Data */
.spl-meta__date { font-size: 12px; color: var(--spl-muted); }

/* Link */
.spl-meta__link {
    color: var(--spl-accent);
    text-decoration: none;
    font-weight: 500;
    transition: opacity var(--spl-transition);
}
.spl-meta__link:hover { opacity: .75; }

/* Booleano */
.spl-meta__bool {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    letter-spacing: .04em;
}
.spl-meta__bool--yes {
    background: rgba(16,185,129,.1);
    color: #059669;
}
.spl-meta__bool--no {
    background: rgba(239,68,68,.1);
    color: #dc2626;
}

/* Colore Swatch */
.spl-meta__color-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,.15);
    vertical-align: middle;
    flex-shrink: 0;
}
.spl-meta__color-label { font-size: 12px; font-family: monospace; }

/* Rating Stelle */
.spl-meta__rating {
    display: inline-flex;
    gap: 2px;
    align-items: center;
}
.spl-meta__star { color: var(--spl-border); font-size: 16px; line-height: 1; }
.spl-meta__star--full { color: #f59e0b; }

/* Lista */
.spl-meta__list {
    margin: 4px 0 0 0;
    padding-left: 18px;
    font-size: 13px;
    color: var(--spl-text);
    line-height: 1.6;
}

/* Immagine meta */
.spl-meta__img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 6px;
    margin-top: 4px;
}

/* ── Filtro meta: range numerico ── */
.spl-range-filter {
    display: flex;
    align-items: center;
    gap: 6px;
}
.spl-range-filter .spl-input {
    min-width: 80px;
    flex: 1;
    padding-left: 10px;
}
.spl-range-filter span { color: var(--spl-muted); flex-shrink: 0; }

/* ── Posizione in_footer: affiancare al bottone ── */
.spl-item__footer {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}
.spl-item__footer .spl-meta__group { margin: 0; }
