/* =========================================================
   MB Quick Search — belt typeahead dropdown with thumbnails
   Markup: includes/class-mb-quick-search.php
   Behavior: js/mb-quick-search.js
   Also styles the hover/tap image preview dialog (.mb-qs-preview).
   Replaces the #custom-dropdown / #typeahead-input / #dropdown-options
   rules in custom-styles.css (§2 and part of §11), which no longer match.
   ========================================================= */

.mb-qs {
    position: relative;
    width: 420px;
    max-width: 100%;
    margin: 0 auto;
    z-index: 300000;
    overflow: visible;
    font-family: "Nunito Sans", sans-serif;
    text-align: left;
}

.mb-qs__input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
}

/* ---------- List ---------- */

.mb-qs__list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 300px;
    overflow-y: auto;
    overscroll-behavior: contain;   /* don't scroll the page behind it */
    background: #fff;
    border: 1px solid #ccc;
    border-top: none;
    border-radius: 0 0 5px 5px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
    z-index: 330000;
}

.mb-qs__list[hidden],
.mb-qs__option[hidden],
.mb-qs__status[hidden] {
    display: none !important;
}

/* ---------- Rows ---------- */

.mb-qs__option {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 4px 8px;
    cursor: pointer;
    box-sizing: border-box;
}

.mb-qs__option:hover,
.mb-qs__option.is-active {
    background-color: #f0f0f0;
}

.mb-qs__part {
    flex: 0 0 auto;
    background-color: #e0e0e0;
    padding: 2px 5px;
    border-radius: 4px;
    white-space: nowrap;
    font-size: 13px;
}

.mb-qs__desc {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 13px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

/* ---------- Thumbnail (right side) ---------- */

.mb-qs__thumb {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 4px;
    overflow: hidden;
    background: #f1f1f1;   /* placeholder while loading — no layout shift */
}

.mb-qs__thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.mb-qs__thumb img.is-loaded {
    opacity: 1;
}

/* No featured image: neutral empty tile */
.mb-qs__thumb.is-empty {
    background: #f6f6f6;
    box-shadow: inset 0 0 0 1px #e6e6e6;
}

/* ---------- Status rows (loading / no results / error) ---------- */

.mb-qs__status {
    padding: 10px 12px;
    font-size: 13px;
    color: #666;
}

/* ---------- Responsive ---------- */

/* Tablet */
@media (min-width: 768px) and (max-width: 1024px) {
    .mb-qs {
        width: 360px;
    }
}

/* Mobile: narrow box, smaller thumb */
@media (max-width: 767px) {
    .mb-qs {
        width: 220px;
    }

    .mb-qs__input {
        padding: 8px 10px;
        font-size: 13px;
    }

    .mb-qs__option {
        gap: 6px;
        min-height: 36px;
        padding: 4px 6px;
    }

    .mb-qs__part,
    .mb-qs__desc {
        font-size: 12px;
    }

    .mb-qs__thumb {
        flex-basis: 28px;
        width: 28px;
        height: 28px;
    }
}

/* ---------- Thumbnail affordance for the preview ---------- */

@media (hover: hover) and (pointer: fine) {
    .mb-qs__thumb.has-preview {
        cursor: zoom-in;
        transition: box-shadow 0.15s ease;
    }
    .mb-qs__thumb.has-preview:hover {
        box-shadow: 0 0 0 2px #008345;
    }
}

/* =========================================================
   Image preview dialog (one per page, appended to <body>)
   Styled to match the belt loop card (Elementor template 196795):
   Poppins, centered 26px part number, bold labels on 14px lines,
   15px corners with a soft inset edge, green #008345 pill button.

   .is-hover  — mouse hover: hands-off, clicks pass through
   .is-pinned — touch tap: interactive, close + View Specification
   ========================================================= */

.mb-qs-preview {
    position: fixed;
    inset: 0;
    z-index: 600000;              /* above header (99990), dropdown (330000), modals (500001) */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.mb-qs-preview[hidden] {
    display: none !important;
}

.mb-qs-preview.is-visible {
    opacity: 1;
}

.mb-qs-preview.is-hover {
    pointer-events: none;         /* never steals the hover from the thumbnail */
}

.mb-qs-preview__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.25);
}

.mb-qs-preview.is-pinned .mb-qs-preview__backdrop {
    background: rgba(0, 0, 0, 0.55);
}

/* ---------- Card ---------- */

.mb-qs-preview__card {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-sizing: border-box;
    margin: 0;
    padding: 10px;
    /* 4:3 image + text must fit the viewport height */
    width: min(520px, 100%, calc((100vh - 300px) * 4 / 3 + 20px));
    min-width: min(300px, 100%);
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    background: #fff;
    border-radius: 15px;
    box-shadow:
        inset 0 0 3px 1px rgba(0, 0, 0, 0.2),   /* the card's own edge */
        0 20px 50px rgba(0, 0, 0, 0.35);         /* lift off the page */
    font-family: Poppins, sans-serif;
    color: #353535;
    text-align: left;
    transform: scale(0.97);
    transition: transform 0.15s ease;
}

.mb-qs-preview.is-visible .mb-qs-preview__card {
    transform: none;
}

/* Theme and Elementor kit styles target bare elements (h3, dl, dd,
   figcaption…). Reset inside the dialog so only the rules below apply. */
.mb-qs-preview .mb-qs-preview__card,
.mb-qs-preview .mb-qs-preview__card * {
    font-style: normal;
}

/* Part number — like the card's centered heading */
.mb-qs-preview .mb-qs-preview__title {
    margin: 0;
    padding: 0 36px;               /* room for the close button, stays centered */
    font-family: Poppins, sans-serif;
    font-size: 26px;
    font-weight: 700;
    line-height: 40px;
    color: #0d0e0e;
    text-align: center;
    text-transform: none;
    letter-spacing: normal;
}

/* ---------- Image (4:3 like the card, fixed so nothing jumps) ---------- */

.mb-qs-preview__frame {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    flex: 0 0 auto;
    overflow: hidden;
    background: #f4f4f4;
}

.mb-qs-preview__low,
.mb-qs-preview__img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.mb-qs-preview__low {
    filter: blur(8px);
    transform: scale(1.04);
    opacity: 0.6;
}

.mb-qs-preview__img {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.mb-qs-preview.is-loaded .mb-qs-preview__img {
    opacity: 1;
}

.mb-qs-preview.is-loaded .mb-qs-preview__low {
    opacity: 0;
}

/* Spinner while the large image loads */
.mb-qs-preview__spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 28px;
    height: 28px;
    margin: -14px 0 0 -14px;
    border: 3px solid rgba(0, 131, 69, 0.2);
    border-top-color: #008345;
    border-radius: 50%;
    animation: mb-qs-spin 0.8s linear infinite;
}

.mb-qs-preview.is-loaded .mb-qs-preview__spinner,
.mb-qs-preview.is-error .mb-qs-preview__spinner {
    display: none;
}

@keyframes mb-qs-spin {
    to { transform: rotate(360deg); }
}

/* ---------- Label / value lines ---------- */

.mb-qs-preview__caption {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 4px 0 6px;
}

.mb-qs-preview__specs {
    margin: 0;
    padding: 0;
}

.mb-qs-preview__specs[hidden] {
    display: none;
}

.mb-qs-preview .mb-qs-preview__spec {
    margin: 0;
    font-family: Poppins, sans-serif;
    font-size: 14px;
    line-height: 26px;
    color: #353535;
}

.mb-qs-preview__spec + .mb-qs-preview__spec {
    margin-top: 8px;
}

.mb-qs-preview .mb-qs-preview__spec dt,
.mb-qs-preview .mb-qs-preview__spec dd {
    display: inline;
    margin: 0;
    padding: 0;
    font: inherit;
    color: inherit;
}

.mb-qs-preview .mb-qs-preview__spec dt {
    font-weight: 700;
    margin-right: 6px;
}

/* ---------- View Specification (pinned / tap mode only) ---------- */

.mb-qs-preview__actions {
    display: none;
    justify-content: center;
    padding: 4px 0 6px;
}

.mb-qs-preview.is-pinned .mb-qs-preview__actions {
    display: flex;
}

.mb-qs-preview__button,
.mb-qs-preview__button:visited {
    display: inline-block;
    padding: 12px 24px;
    border-radius: 25px;
    background-color: #008345;
    color: #fff;
    font-family: "Nunito Sans", sans-serif;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.3px;
    line-height: 1;
    text-decoration: none;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.mb-qs-preview__button:hover,
.mb-qs-preview__button:focus-visible {
    color: #fff;
    background-color: #006b38;
    box-shadow: 0 4px 12px rgba(0, 131, 69, 0.4);
}

/* ---------- Close button (pinned / tap mode only) ---------- */

.mb-qs-preview__close {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: #f1f1f1;
    color: #222;
    font-size: 22px;
    line-height: 34px;
    text-align: center;
    cursor: pointer;
}

.mb-qs-preview.is-pinned .mb-qs-preview__close {
    display: block;
}

.mb-qs-preview__close:hover {
    background: #e4e4e4;
}

.mb-qs-preview__close:focus-visible {
    outline: 2px solid #008345;
    outline-offset: 2px;
}

/* ---------- Small screens ---------- */

@media (max-width: 767px) {
    .mb-qs-preview .mb-qs-preview__title {
        font-size: 22px;
        line-height: 34px;
    }
    .mb-qs-preview .mb-qs-preview__spec {
        font-size: 13px;
        line-height: 22px;
    }
    .mb-qs-preview__spec + .mb-qs-preview__spec {
        margin-top: 4px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mb-qs-preview,
    .mb-qs-preview__card,
    .mb-qs-preview__img {
        transition: none;
    }
    .mb-qs-preview__card {
        transform: none;
    }
}
