/* ════════════════════════════════════════════════════════════════════════════
 * LuckyWP Search Modal — fully isolated stylesheet.
 *
 * Loaded as its own file (build/search-modal.css) AFTER main.css so external
 * styles, plugin button rules, navigation typography, etc. cannot bleed into
 * the modal. Every descendant of `.lwpt-search-modal` is reset before being
 * styled. No Tailwind, no @layer — plain CSS so cascade order is predictable.
 *
 * Strategy:
 *   1. Define modal-local CSS variables (with fallbacks to theme tokens).
 *   2. Hard-reset typography / appearance on EVERY descendant element.
 *   3. Apply the actual design using high-specificity selectors so site CSS
 *      with similar specificity cannot win without `!important`.
 * ════════════════════════════════════════════════════════════════════════════ */

/* ── Modal-local design tokens ───────────────────────────────────────────── */

.lwpt-search-modal {
    /* Surfaces */
    --sm-bg:            var(--lwpt-color-bg,      #ffffff);
    --sm-bg-alt:        var(--lwpt-color-bg-alt,  #f8fafc);
    --sm-bg-soft:       #f1f5f9;
    --sm-bg-elev:       #ffffff;
    --sm-border:        var(--lwpt-color-border,  #e5e7eb);
    --sm-border-soft:   rgba(15, 23, 42, .06);

    /* Typography */
    --sm-text:          var(--lwpt-color-text,    #0f172a);
    --sm-heading:       var(--lwpt-color-heading, #0f172a);
    --sm-muted:         var(--lwpt-color-muted,   #64748b);

    /* Brand */
    --sm-primary:       var(--lwpt-color-primary, #4f46e5);
    --sm-primary-soft:  color-mix(in srgb, var(--sm-primary) 12%, transparent);
    --sm-primary-text:  #ffffff;

    /* Geometry */
    --sm-radius-panel:  16px;
    --sm-radius-pill:   999px;
    --sm-radius-md:     10px;
    --sm-radius-sm:     6px;

    /* Effects */
    --sm-shadow:        0 24px 60px -12px rgba(15, 23, 42, .35), 0 4px 12px -2px rgba(15, 23, 42, .08);
    --sm-ring:          0 0 0 3px color-mix(in srgb, var(--sm-primary) 22%, transparent);

    /* Font stack — fully self-contained */
    --sm-font:          ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
                        "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
    --sm-font-mono:     ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

/* ─────────────────────────────────────────────────────────────────────────
 * 1. POSITIONING SHELL
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;             /* sits above sticky headers, drawers, etc. */
    isolation: isolate;          /* new stacking context — keeps blur clean */
    pointer-events: auto;
}

.lwpt-search-modal[hidden] { display: none !important; }

/* CSS-only :target fallback for no-JS environments. */

.lwpt-search-modal:target { display: block !important; }

.lwpt-search-modal:target .lwpt-search-modal__panel,
.lwpt-search-modal:target .lwpt-search-modal__backdrop { opacity: 1; transform: none; }

/* ─────────────────────────────────────────────────────────────────────────
 * 2. HARD RESET — every descendant inherits clean, predictable styling.
 *    This is the wall that stops nav/button/plugin CSS from leaking in.
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal,
.lwpt-search-modal *,
.lwpt-search-modal *::before,
.lwpt-search-modal *::after {
    box-sizing: border-box;
}

.lwpt-search-modal,
.lwpt-search-modal :where(div, span, p, ul, ol, li, h1, h2, h3, h4, h5, h6,
                          form, button, input, a, kbd, mark, label, svg, img) {
    font-family: var(--sm-font);
    font-weight: 400;
    font-style: normal;
    font-variant: normal;
    line-height: 1.5;
    color: var(--sm-text);
    letter-spacing: normal;
    text-transform: none;
    text-decoration: none;
    text-align: left;
    text-shadow: none;
    -webkit-font-smoothing: antialiased;
}

.lwpt-search-modal :where(ul, ol) {
    list-style: none;
    margin: 0;
    padding: 0;
}

.lwpt-search-modal :where(p, h1, h2, h3, h4, h5, h6) {
    margin: 0;
}

.lwpt-search-modal :where(button) {
    -webkit-appearance: none;
       -moz-appearance: none;
            appearance: none;
    background: transparent;
    border: 0;
    padding: 0;
    margin: 0;
    cursor: pointer;
    color: inherit;
    font: inherit;
    line-height: inherit;
    text-transform: none;       /* explicit — beats plugin button rules */
    letter-spacing: normal;
}

.lwpt-search-modal :where(a) {
    color: inherit;
    background: transparent;
    border: 0;
    text-decoration: none;
}

.lwpt-search-modal :where(input) {
    -moz-appearance: none;
         appearance: none;
    -webkit-appearance: none;
    background: transparent;
    border: 0;
    outline: 0;
    margin: 0;
    padding: 0;
    color: inherit;
    font: inherit;
    text-transform: none;
    box-shadow: none;
}

.lwpt-search-modal :where(svg) {
    display: inline-block;
    flex-shrink: 0;
    vertical-align: middle;
}

.lwpt-search-modal :where(img) {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Suppress native search-input clear glyphs */

.lwpt-search-modal input[type="search"]::-webkit-search-cancel-button,
.lwpt-search-modal input[type="search"]::-webkit-search-decoration,
.lwpt-search-modal input[type="search"]::-webkit-search-results-button,
.lwpt-search-modal input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

.lwpt-search-modal input[type="search"]::-ms-clear,
.lwpt-search-modal input[type="search"]::-ms-reveal { display: none; width: 0; height: 0; }

/* ─────────────────────────────────────────────────────────────────────────
 * 3. BACKDROP
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal .lwpt-search-modal__backdrop {
    position: absolute;
    inset: 0;
    background: radial-gradient(120% 80% at 50% 0%,
                                rgba(15, 23, 42, .55) 0%,
                                rgba(15, 23, 42, .72) 60%);
    backdrop-filter: blur(8px) saturate(140%);
    -webkit-backdrop-filter: blur(8px) saturate(140%);
    opacity: 0;
    transition: opacity .25s cubic-bezier(.4, 0, .2, 1);
    cursor: zoom-out;
}

.lwpt-search-modal--bg-dimmed .lwpt-search-modal__backdrop {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.lwpt-search-modal--bg-none .lwpt-search-modal__backdrop {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

.lwpt-search-modal.is-open .lwpt-search-modal__backdrop { opacity: 1; }

/* ─────────────────────────────────────────────────────────────────────────
 * 4. PANEL
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal .lwpt-search-modal__panel {
    position: relative;
    z-index: 1;
    width: calc(100% - 32px);
    max-width: 640px;
    margin: 8vh auto 0;
    max-height: min(78vh, 720px);
    display: flex;
    flex-direction: column;
    background: var(--sm-bg);
    border: 1px solid var(--sm-border);
    border-radius: var(--sm-radius-panel);
    box-shadow: var(--sm-shadow);
    overflow: hidden;
    transform: translateY(-10px) scale(.98);
    opacity: 0;
    transition: transform .26s cubic-bezier(.34, 1.56, .64, 1),
                opacity .2s ease;
}

.lwpt-search-modal--w-narrow .lwpt-search-modal__panel { max-width: 480px; }

.lwpt-search-modal--w-medium .lwpt-search-modal__panel { max-width: 640px; }

.lwpt-search-modal--w-wide   .lwpt-search-modal__panel { max-width: 800px; }

/* Vertically-centered variant */

.lwpt-search-modal--p-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.lwpt-search-modal--p-center .lwpt-search-modal__panel { margin: 0; }

.lwpt-search-modal.is-open .lwpt-search-modal__panel {
    transform: translateY(0) scale(1);
    opacity: 1;
}

/* ─────────────────────────────────────────────────────────────────────────
 * 5. SEARCH FORM (top row)
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal .lwpt-search-modal__form {
    display: grid;
    grid-template-columns: auto 1fr auto auto;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--sm-border);
    background: var(--sm-bg);
}

.lwpt-search-modal .lwpt-search-modal__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    color: var(--sm-muted);
}

.lwpt-search-modal .lwpt-search-modal__icon svg {
    width: 20px;
    height: 20px;
}

.lwpt-search-modal .lwpt-search-modal__input {
    width: 100%;
    min-width: 0;
    font-size: 17px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--sm-heading);
    padding: 4px 0;
    caret-color: var(--sm-primary);
}

.lwpt-search-modal .lwpt-search-modal__input::-moz-placeholder {
    color: var(--sm-muted);
    font-weight: 400;
    opacity: 1;
}

.lwpt-search-modal .lwpt-search-modal__input::placeholder {
    color: var(--sm-muted);
    font-weight: 400;
    opacity: 1;
}

.lwpt-search-modal .lwpt-search-modal__clear {
    width: 26px;
    height: 26px;
    border-radius: var(--sm-radius-pill);
    background: var(--sm-bg-soft);
    color: var(--sm-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .14s ease, color .14s ease, transform .14s ease;
}

.lwpt-search-modal .lwpt-search-modal__clear:hover {
    background: color-mix(in srgb, var(--sm-text) 12%, transparent);
    color: var(--sm-text);
}

.lwpt-search-modal .lwpt-search-modal__clear:active { transform: scale(.92); }

.lwpt-search-modal .lwpt-search-modal__clear svg { width: 14px; height: 14px; }

.lwpt-search-modal .lwpt-search-modal__close {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 8px;
    border-radius: var(--sm-radius-sm);
    color: var(--sm-muted);
    font-size: 12px;
    font-weight: 500;
    transition: color .14s ease, background .14s ease;
}

.lwpt-search-modal .lwpt-search-modal__close:hover {
    color: var(--sm-text);
    background: var(--sm-bg-soft);
}

.lwpt-search-modal .lwpt-search-modal__kbd {
    font-family: var(--sm-font-mono);
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    padding: 4px 7px;
    border-radius: 5px;
    color: var(--sm-muted);
    background: var(--sm-bg-soft);
    border: 1px solid var(--sm-border);
    box-shadow: inset 0 -1px 0 rgba(15, 23, 42, .04);
}

/* ─────────────────────────────────────────────────────────────────────────
 * 6. CATEGORY CHIPS — horizontal filter strip
 *    Fully isolated; nav menu / button plugin styles cannot reach here.
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal .lwpt-search-modal__chips {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
    border-bottom: 1px solid var(--sm-border);
    background: var(--sm-bg);
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
}

.lwpt-search-modal .lwpt-search-modal__chips::-webkit-scrollbar { display: none; }

.lwpt-search-modal .lwpt-search-modal__chips[hidden] { display: none; }

.lwpt-search-modal .lwpt-search-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 28px;
    padding: 0 12px;
    border-radius: var(--sm-radius-pill);
    background: var(--sm-bg-soft);
    border: 1px solid transparent;
    color: var(--sm-text);
    font-size: 13px;
    font-weight: 500;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background .14s ease, color .14s ease, border-color .14s ease, transform .14s ease;
    scroll-snap-align: start;
}

.lwpt-search-modal .lwpt-search-chip:hover {
    background: color-mix(in srgb, var(--sm-text) 8%, transparent);
}

.lwpt-search-modal .lwpt-search-chip:active { transform: scale(.97); }

.lwpt-search-modal .lwpt-search-chip:focus-visible {
    outline: 0;
    box-shadow: var(--sm-ring);
}

.lwpt-search-modal .lwpt-search-chip.is-active {
    background: var(--sm-primary);
    color: var(--sm-primary-text);
    border-color: transparent;
    font-weight: 600;
}

.lwpt-search-modal .lwpt-search-chip.is-empty {
    opacity: .45;
}

.lwpt-search-modal .lwpt-search-chip.is-empty:hover { opacity: .7; }

.lwpt-search-modal .lwpt-search-chip.is-empty.is-active { opacity: 1; }

.lwpt-search-modal .lwpt-search-chip__name {
    font: inherit;
    color: inherit;
}

.lwpt-search-modal .lwpt-search-chip__count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    border-radius: var(--sm-radius-pill);
    background: rgba(15, 23, 42, .08);
    color: var(--sm-muted);
}

.lwpt-search-modal .lwpt-search-chip.is-active .lwpt-search-chip__count {
    background: rgba(255, 255, 255, .22);
    color: var(--sm-primary-text);
}

/* ─────────────────────────────────────────────────────────────────────────
 * 7. BODY / RESULT STATES
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal .lwpt-search-modal__body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px 0;
    background: var(--sm-bg);
    scrollbar-width: thin;
    scrollbar-color: var(--sm-border) transparent;
}

.lwpt-search-modal .lwpt-search-modal__body::-webkit-scrollbar { width: 8px; }

.lwpt-search-modal .lwpt-search-modal__body::-webkit-scrollbar-thumb {
    background: var(--sm-border);
    border-radius: 999px;
    border: 2px solid var(--sm-bg);
}

.lwpt-search-modal .lwpt-search-modal__state { padding: 14px 18px; }

.lwpt-search-modal .lwpt-search-modal__state[hidden] { display: none; }

.lwpt-search-modal .lwpt-search-modal__state--loading,
.lwpt-search-modal .lwpt-search-modal__state--none {
    padding: 48px 20px;
    text-align: center;
}

.lwpt-search-modal .lwpt-search-modal__hint {
    color: var(--sm-muted);
    font-size: 13.5px;
    line-height: 1.55;
}

.lwpt-search-modal .lwpt-search-modal__recent { margin-top: 18px; }

.lwpt-search-modal .lwpt-search-modal__recent h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--sm-muted);
    margin: 0 0 8px;
}

.lwpt-search-modal .lwpt-search-modal__recent ul {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.lwpt-search-modal .lwpt-search-modal__recent button {
    padding: 5px 12px;
    border-radius: var(--sm-radius-pill);
    background: var(--sm-bg-soft);
    color: var(--sm-text);
    font-size: 12.5px;
    font-weight: 500;
    border: 1px solid transparent;
    transition: background .14s ease, color .14s ease, border-color .14s ease;
}

.lwpt-search-modal .lwpt-search-modal__recent button:hover {
    background: var(--sm-primary-soft);
    color: var(--sm-primary);
}

.lwpt-search-modal .lwpt-search-modal__spinner {
    width: 30px;
    height: 30px;
    margin: 0 auto 14px;
    border-radius: 50%;
    border: 3px solid var(--sm-border);
    border-top-color: var(--sm-primary);
    animation: lwpt-sm-spin .8s linear infinite;
}

@keyframes lwpt-sm-spin { to { transform: rotate(360deg); } }

.lwpt-search-modal .lwpt-search-modal__state--loading p,
.lwpt-search-modal .lwpt-search-modal__state--none p {
    color: var(--sm-muted);
    font-size: 14px;
}

.lwpt-search-modal .lwpt-search-modal__count {
    font-size: 11px;
    font-weight: 600;
    color: var(--sm-muted);
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 12px 18px 6px;
}

/* ─── Result list ──────────────────────────────────────────────────────── */

.lwpt-search-modal .lwpt-search-modal__results { display: block; }

.lwpt-search-modal .lwpt-search-modal__results li { display: block; margin: 0; padding: 0; }

.lwpt-search-modal .lwpt-search-modal__results li a {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 10px 18px;
    color: var(--sm-text);
    border-left: 3px solid transparent;
    transition: background .14s ease, border-color .14s ease;
    cursor: pointer;
}

.lwpt-search-modal .lwpt-search-modal__results li a:hover,
.lwpt-search-modal .lwpt-search-modal__results li a.is-active,
.lwpt-search-modal .lwpt-search-modal__results li a:focus-visible {
    background: var(--sm-primary-soft);
    border-left-color: var(--sm-primary);
    outline: 0;
}

.lwpt-search-modal .lwpt-search-result__thumb {
    width: 48px;
    height: 48px;
    border-radius: var(--sm-radius-md);
    overflow: hidden;
    background: var(--sm-bg-soft);
    flex-shrink: 0;
    position: relative;
}

.lwpt-search-modal .lwpt-search-result__thumb img {
    width: 100%;
    height: 100%;
    -o-object-fit: cover;
       object-fit: cover;
}

.lwpt-search-modal .lwpt-search-result__body {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.lwpt-search-modal .lwpt-search-result__meta {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--sm-muted);
    text-transform: uppercase;
    letter-spacing: .07em;
}

.lwpt-search-modal .lwpt-search-result__type { color: var(--sm-primary); }

.lwpt-search-modal .lwpt-search-result__title {
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--sm-heading);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lwpt-search-modal .lwpt-search-result__excerpt {
    font-size: 12.5px;
    color: var(--sm-muted);
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}

.lwpt-search-modal .lwpt-search-result__arrow {
    color: var(--sm-muted);
    font-size: 18px;
    line-height: 1;
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity .15s ease, transform .15s ease, color .15s ease;
}

.lwpt-search-modal .lwpt-search-modal__results li a:hover .lwpt-search-result__arrow,
.lwpt-search-modal .lwpt-search-modal__results li a.is-active .lwpt-search-result__arrow {
    opacity: 1;
    transform: translateX(0);
    color: var(--sm-primary);
}

.lwpt-search-modal .lwpt-search-modal__results mark {
    background: color-mix(in srgb, var(--sm-primary) 18%, transparent);
    color: var(--sm-heading);
    padding: 0 2px;
    border-radius: 3px;
    font-weight: 600;
}

.lwpt-search-modal .lwpt-search-modal__all {
    display: block;
    padding: 12px 18px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--sm-primary);
    border-top: 1px solid var(--sm-border);
    transition: background .14s ease;
}

.lwpt-search-modal .lwpt-search-modal__all:hover { background: var(--sm-bg-alt); }

.lwpt-search-modal .lwpt-search-modal__all[hidden] { display: none; }

/* ─────────────────────────────────────────────────────────────────────────
 * 8. FOOTER LEGEND
 * ───────────────────────────────────────────────────────────────────────── */

.lwpt-search-modal .lwpt-search-modal__footer {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 10px 18px;
    background: var(--sm-bg-alt);
    border-top: 1px solid var(--sm-border);
    font-size: 11.5px;
    color: var(--sm-muted);
}

.lwpt-search-modal .lwpt-search-modal__legend {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.lwpt-search-modal .lwpt-search-modal__footer kbd {
    font-family: var(--sm-font-mono);
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1;
    padding: 3px 5px;
    border-radius: 4px;
    background: var(--sm-bg);
    color: var(--sm-text);
    border: 1px solid var(--sm-border);
    box-shadow: inset 0 -1px 0 rgba(15, 23, 42, .04);
}

/* ─────────────────────────────────────────────────────────────────────────
 * 9. BODY LOCK + RESPONSIVE
 * ───────────────────────────────────────────────────────────────────────── */

body.lwpt-has-search {
    overflow: hidden !important;
}

@media (max-width: 640px) {
    .lwpt-search-modal .lwpt-search-modal__panel {
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: 100%;
        margin: 0;
        border-radius: 0;
        border: 0;
    }
    .lwpt-search-modal--p-center { align-items: stretch; }
    .lwpt-search-modal .lwpt-search-modal__form { padding: 12px 14px; }
    .lwpt-search-modal .lwpt-search-modal__close { display: none; }
    .lwpt-search-modal .lwpt-search-modal__input { font-size: 16px; } /* avoids iOS zoom */
}

/* Honour reduced motion */

@media (prefers-reduced-motion: reduce) {
    .lwpt-search-modal .lwpt-search-modal__panel,
    .lwpt-search-modal .lwpt-search-modal__backdrop,
    .lwpt-search-modal .lwpt-search-chip,
    .lwpt-search-modal .lwpt-search-modal__results li a,
    .lwpt-search-modal .lwpt-search-result__arrow {
        transition: none !important;
        animation: none !important;
    }
}
