/* ==========================================================================
   AddiPress Listings — Search (instant + faceted + AI)
   Uses the theme's --apl-* design tokens with safe fallbacks.
   ========================================================================== */
.apl-search {
    --s-primary: var(--apl-primary, #4f46e5);
    --s-line: var(--apl-line, #e2e8f0);
    --s-muted: var(--apl-muted, #64748b);
    --s-radius: var(--apl-radius, 14px);
    --s-card: var(--apl-card, #ffffff);
    width: 100%;
}

/* ---------- Search bar ---------- */
.apl-search__row {
    display: flex;
    gap: 8px;
    background: var(--s-card);
    border: 1px solid var(--s-line);
    border-radius: var(--s-radius);
    padding: 8px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .06);
}
.apl-search--hero .apl-search__row { padding: 10px; }
.apl-search__field { display: flex; align-items: center; }
.apl-search__field--q { position: relative; flex: 1 1 auto; min-width: 0; }
.apl-search__icon { position: absolute; left: 14px; color: var(--s-muted); display: inline-flex; pointer-events: none; }
.apl-search__input {
    width: 100%;
    border: 0;
    background: transparent;
    padding: 14px 14px 14px 44px;
    font-size: 16px;
    color: inherit;
    outline: none;
}
.apl-search__field--sel select {
    border: 0;
    background: transparent;
    padding: 14px 12px;
    font-size: 15px;
    color: inherit;
    max-width: 190px;
    border-left: 1px solid var(--s-line);
    outline: none;
    cursor: pointer;
}
.apl-search__btn {
    flex: 0 0 auto;
    border: 0;
    background: var(--s-primary);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    padding: 0 26px;
    border-radius: calc(var(--s-radius) - 4px);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    min-width: 120px;
    transition: filter .15s, transform .05s;
}
.apl-search__btn:hover { filter: brightness(1.07); }
.apl-search__btn:active { transform: translateY(1px); }
.apl-search__btn[disabled] { opacity: .8; cursor: progress; }

.apl-search__spin {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
    display: inline-block; animation: apl-spin .7s linear infinite;
}
@keyframes apl-spin { to { transform: rotate(360deg); } }

/* AI toggle + popular */
.apl-search__ai { display: flex; align-items: center; gap: 8px; margin: 10px 2px 0; font-size: 14px; color: var(--s-muted); flex-wrap: wrap; cursor: pointer; }
.apl-search__ai input { accent-color: var(--s-primary); }
.apl-search__ai-hint { font-style: normal; opacity: .8; }
.apl-search__popular { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; color: var(--s-muted); }
.apl-search__popular a { background: rgba(79, 70, 229, .08); color: var(--s-primary); padding: 4px 12px; border-radius: 999px; text-decoration: none; font-weight: 600; }
.apl-search__popular a:hover { background: rgba(79, 70, 229, .16); }

/* Compact variant (results page) */
.apl-search--compact .apl-search__row { box-shadow: none; }
.apl-search--compact { margin-bottom: 18px; }

/* ---------- Instant suggestions ---------- */
.apl-suggest {
    position: absolute; z-index: 60; top: calc(100% + 10px); left: 0; right: 0;
    background: var(--s-card, #fff);
    border: 1px solid var(--s-line, #e2e8f0);
    border-radius: 14px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, .16);
    overflow: hidden;
    max-height: 70vh; overflow-y: auto;
}
.apl-suggest__item { display: flex; align-items: center; gap: 12px; padding: 10px 14px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--s-line, #eef2f7); }
.apl-suggest__item:last-of-type { border-bottom: 0; }
.apl-suggest__item:hover, .apl-suggest__item.is-active { background: rgba(79, 70, 229, .07); }
.apl-suggest__item img, .apl-suggest__ph { width: 46px; height: 46px; border-radius: 9px; object-fit: cover; flex: 0 0 auto; background: #eef2f7; }
.apl-suggest__txt { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.apl-suggest__txt strong { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.apl-suggest__txt small { color: var(--s-muted, #64748b); font-size: 12px; }
.apl-suggest__price { font-weight: 800; font-size: 14px; color: var(--s-primary, #4f46e5); white-space: nowrap; }
.apl-suggest__all { display: block; text-align: center; padding: 12px; font-weight: 700; color: var(--s-primary, #4f46e5); text-decoration: none; background: rgba(79, 70, 229, .05); }
.apl-suggest__all.is-active, .apl-suggest__all:hover { background: rgba(79, 70, 229, .12); }
.apl-suggest__empty { padding: 16px; text-align: center; color: var(--s-muted, #64748b); font-size: 14px; }

/* ==========================================================================
   Results page
   ========================================================================== */
.apl-results { --s-line: var(--apl-line, #e2e8f0); --s-muted: var(--apl-muted, #64748b); --s-primary: var(--apl-primary, #4f46e5); }
.apl-results__bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 6px 0 14px; }
.apl-results__count { font-size: 15px; font-weight: 700; }
.apl-results__sort { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--s-muted); }
.apl-results__sort select { border: 1px solid var(--s-line); border-radius: 10px; padding: 8px 12px; font: inherit; background: #fff; cursor: pointer; }

.apl-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.apl-chip { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--s-line); border-radius: 999px; padding: 5px 12px; font-size: 13px; color: inherit; text-decoration: none; }
.apl-chip:hover { border-color: var(--s-primary); color: var(--s-primary); }
.apl-chip--clear { background: rgba(239, 68, 68, .08); border-color: transparent; color: #dc2626; font-weight: 600; }

.apl-results__layout { display: grid; grid-template-columns: 260px 1fr; gap: 26px; align-items: start; }
.apl-results__side { position: sticky; top: 20px; }

/* Facets */
.apl-facets { background: #fff; border: 1px solid var(--s-line); border-radius: 16px; padding: 18px; display: grid; gap: 16px; }
.apl-facet h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--s-muted); }
.apl-facet select, .apl-facet input[type="number"] { width: 100%; border: 1px solid var(--s-line); border-radius: 10px; padding: 10px 12px; font: inherit; background: #fff; }
.apl-facet__range { display: flex; align-items: center; gap: 8px; }
.apl-facet__range span { color: var(--s-muted); }
.apl-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.apl-check input { accent-color: var(--s-primary); }

/* Grid + cards */
.apl-results__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 20px; }
.apl-scard { background: #fff; border: 1px solid var(--s-line); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s, border-color .12s; }
.apl-scard:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(15, 23, 42, .12); border-color: transparent; }
.apl-scard.is-featured { border-color: rgba(245, 158, 11, .5); box-shadow: 0 0 0 1px rgba(245, 158, 11, .25); }
.apl-scard__media { position: relative; display: block; aspect-ratio: 4 / 3; background: #eef2f7; }
.apl-scard__media img { width: 100%; height: 100%; object-fit: cover; }
.apl-scard__noimg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #cbd5e1; }
.apl-scard__badge { position: absolute; top: 10px; left: 10px; background: #f59e0b; color: #fff; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.apl-scard__body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; }
.apl-scard__price { font-size: 17px; font-weight: 800; color: var(--s-primary); }
.apl-scard__title { margin: 0; font-size: 15px; font-weight: 600; line-height: 1.3; }
.apl-scard__title a { color: inherit; text-decoration: none; }
.apl-scard__title a:hover { color: var(--s-primary); }
.apl-scard__meta { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12.5px; color: var(--s-muted); padding-top: 6px; }
.apl-scard__loc { display: inline-flex; align-items: center; gap: 4px; }

/* Empty state */
.apl-results__empty { text-align: center; padding: 60px 20px; background: #fff; border: 1px dashed var(--s-line); border-radius: 16px; }
.apl-results__empty h3 { margin: 0 0 8px; font-size: 20px; }
.apl-results__empty p { color: var(--s-muted); margin: 0 0 18px; }

/* Pagination */
.apl-pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 30px; }
.apl-pager .page-numbers { display: inline-flex; align-items: center; justify-content: center; min-width: 40px; height: 40px; padding: 0 10px; border: 1px solid var(--s-line); border-radius: 10px; text-decoration: none; color: inherit; font-weight: 600; background: #fff; }
.apl-pager .page-numbers.current { background: var(--s-primary); color: #fff; border-color: transparent; }
.apl-pager .page-numbers:hover:not(.current) { border-color: var(--s-primary); color: var(--s-primary); }
.apl-pager .dots { border: 0; background: transparent; }

/* Shared button (in case theme doesn't define it) */
.apl-results .apl-btn, .apl-facets .apl-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 12px; padding: 12px 18px; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; }
.apl-btn--primary { background: var(--s-primary, #4f46e5); color: #fff; }
.apl-btn--primary:hover { filter: brightness(1.07); }
.apl-btn--block { width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .apl-results__layout { grid-template-columns: 1fr; }
    .apl-results__side { position: static; }
}
@media (max-width: 640px) {
    .apl-search__row { flex-wrap: wrap; }
    .apl-search__field--q { flex: 1 0 100%; }
    .apl-search__field--sel select { border-left: 0; max-width: none; width: 100%; }
    .apl-search__field--sel { flex: 1 1 45%; }
    .apl-search__btn { flex: 1 0 100%; }
}
