/**
 * BMS Search - Overlay Styles
 * Best for Pets - Doofinder replacement
 */

/* Variables */
:root {
    --bms-primary: #f5a623;
    --bms-primary-hover: #e09100;
    --bms-danger: #e74c3c;
    --bms-success: #4a8c5c;
    --bms-text: #333;
    --bms-text-light: #888;
    --bms-text-muted: #bbb;
    --bms-bg: #fff;
    --bms-bg-soft: #fafaf7;
    --bms-bg-warm: #fef9ee;
    --bms-border: #f0efe9;
    --bms-radius: 12px;
    --bms-radius-sm: 8px;
    --bms-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
    --bms-font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Overlay backdrop */
.bms-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    animation: bmsFadeIn 0.2s ease;
    font-family: var(--bms-font);
}

/* Main container */
.bms-container {
    width: 96%;
    max-width: 1120px;
    max-height: 92vh;
    margin-top: 3vh;
    background: var(--bms-bg);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--bms-shadow);
    animation: bmsSlideUp 0.25s ease;
}

/* Search input bar */
.bms-search-bar {
    padding: 14px 20px;
    border-bottom: 1px solid var(--bms-border);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}

.bms-search-bar input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 17px;
    font-weight: 500;
    color: var(--bms-text);
    font-family: var(--bms-font);
    background: transparent;
}

.bms-search-bar input::placeholder {
    color: var(--bms-text-muted);
}

/* Body (re-renders on each search; search bar stays put above it) */
.bms-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Results layout */
.bms-results-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.bms-products-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bms-filters-panel {
    width: 250px;
    border-right: 1px solid var(--bms-border);
    overflow-y: auto;
    flex-shrink: 0;
    background: var(--bms-bg-soft);
    order: -1;
}

/* Collapsible filter sections (Doofinder-style, collapsed by default) */
.bms-facet {
    border-bottom: 1px solid var(--bms-border);
}
.bms-facet > summary {
    list-style: none;
    cursor: pointer;
    padding: 13px 18px;
    font-size: 11px;
    font-weight: 700;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    user-select: none;
}
.bms-facet > summary::-webkit-details-marker { display: none; }
.bms-facet > summary::after {
    content: '+';
    font-size: 16px;
    font-weight: 400;
    color: #bbb;
}
.bms-facet[open] > summary::after { content: '\2212'; } /* − */
.bms-facet-body {
    padding: 0 18px 14px;
    max-height: 230px;
    overflow-y: auto;
}

.bms-filter-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 6px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 1px;
}
.bms-filter-item.on { background: var(--bms-bg-warm); }
.bms-filter-item input[type="checkbox"] {
    accent-color: var(--bms-primary);
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}
.bms-filter-name {
    flex: 1;
    font-size: 13px;
    color: #555;
}
.bms-filter-item.on .bms-filter-name { color: var(--bms-text); font-weight: 600; }
.bms-filter-count { font-size: 11px; color: #c0bdb4; }

/* Price range slider */
.bms-price-vals {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 700;
    color: var(--bms-text);
    margin: 4px 0 12px;
}
.bms-range {
    position: relative;
    height: 26px;
}
.bms-range-track,
.bms-range-fill {
    position: absolute;
    top: 11px;
    height: 4px;
    border-radius: 2px;
}
.bms-range-track {
    left: 0;
    right: 0;
    background: #e6e4dc;
}
.bms-range-fill {
    background: var(--bms-primary);
}
.bms-range input[type="range"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 26px;
    margin: 0;
    background: none;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
}
.bms-range input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    pointer-events: auto;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--bms-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: pointer;
}
.bms-range input[type="range"]::-moz-range-thumb {
    pointer-events: auto;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--bms-primary);
    box-shadow: 0 1px 4px rgba(0,0,0,0.2);
    cursor: pointer;
}
.bms-range-ends {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: #b3b0a6;
    margin-top: 4px;
}

/* Suggestions row (Doofinder-style: horizontal chips on top) */
.bms-suggestions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--bms-border);
    flex-shrink: 0;
}
.bms-sugg-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--bms-text-light);
    margin-right: 2px;
}
.bms-suggestion {
    background: var(--bms-bg-soft);
    border: 1px solid var(--bms-border);
    border-radius: 16px;
    padding: 5px 12px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
    white-space: nowrap;
}
.bms-suggestion:hover,
.bms-suggestion.active {
    background: var(--bms-bg-warm);
    border-color: var(--bms-primary);
    color: var(--bms-text);
}

/* Toolbar */
.bms-toolbar {
    padding: 0 20px;
    border-bottom: 1px solid var(--bms-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

/* Product grid */
.bms-product-grid {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    align-content: start;
}

.bms-product-grid.list-view {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Product card */
.bms-product-card {
    background: var(--bms-bg);
    border-radius: var(--bms-radius);
    overflow: hidden;
    border: 1px solid var(--bms-border);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.15s;
}

.bms-product-card:hover {
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

/* Card internals — use !important to beat the dekora theme's global rules
   (which collapse our inline-styled divs, e.g. height/img resets). */
.bms-product-grid {
    grid-auto-rows: max-content;
}
.bms-product-card {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    max-height: none !important;
}
.bms-card-img {
    position: relative !important;
    height: 150px !important;
    min-height: 150px !important;
    flex: 0 0 auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    background: var(--bms-bg-soft);
    overflow: hidden;
}
.bms-card-photo {
    width: auto !important;
    max-width: 88% !important;
    height: 88% !important;
    max-height: 88% !important;
    object-fit: contain !important;
    border-radius: 6px;
}
.bms-card-body {
    padding: 10px 12px 12px !important;
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 auto;
}
.bms-card-brand {
    font-size: 10px;
    color: var(--bms-primary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 3px;
}
.bms-card-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--bms-text);
    line-height: 1.3;
    min-height: 34px;
    margin-bottom: 8px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Add to cart button — pinned to the bottom so all cards in a row align */
.bms-btn-cart {
    width: 100%;
    margin-top: auto;
    background: var(--bms-primary);
    color: #fff;
    border: none;
    border-radius: var(--bms-radius-sm);
    padding: 8px 0;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--bms-font);
    transition: background 0.15s;
}

.bms-btn-cart:hover {
    background: var(--bms-primary-hover);
}

/* Discount badge */
.bms-badge-discount {
    position: absolute;
    top: 8px;
    left: 8px;
    background: var(--bms-danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 4px;
}

/* Low-stock badge */
.bms-badge-stock {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #fff3e0;
    color: #e65100;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
}

/* Out-of-stock badge + dimmed card (in-stock products always rank first) */
.bms-badge-oos {
    position: absolute;
    top: 8px;
    left: 8px;
    background: #efefef;
    color: #888;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 2px 6px;
    border-radius: 4px;
}
.bms-card-oos .bms-card-photo { opacity: .55; filter: grayscale(60%); }
.bms-card-oos .bms-card-title { color: #888; }

/* Instant custom tooltip for truncated product titles */
.bms-title-tip {
    position: fixed;
    z-index: 2147483000;
    max-width: 280px;
    background: #2b2b2b;
    color: #fff;
    font-size: 12px;
    line-height: 1.35;
    padding: 7px 10px;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .25);
    pointer-events: none;
}

/* Infinite scroll — sentinel/loading row spanning the full grid width */
.bms-infinite {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px 0;
    min-height: 44px;
}
.bms-infinite-dots {
    color: #bbb;
    font-size: 12px;
    position: relative;
    padding-left: 22px;
}
.bms-infinite-dots::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    width: 14px;
    height: 14px;
    margin-top: -7px;
    border: 2px solid #eee;
    border-top-color: #f5a623;
    border-radius: 50%;
    animation: bmsSpin .7s linear infinite;
}
@keyframes bmsSpin { to { transform: rotate(360deg); } }

/* Decision tags under the title (price/kg, flavor, attrs, stock, popular) */
.bms-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 6px 0 4px;
}
.bms-tag {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 7px;
    line-height: 1.5;
    white-space: nowrap;
}
.bms-tag.t-attr { background: #eef3ec; color: #4f7a3d; }
.bms-tag.t-flavor { background: #fdf2e6; color: #b5740c; }
.bms-tag.t-stock { background: #fdeaea; color: #c0392b; }
.bms-tag.t-pop { background: #fff6e5; color: #b5740c; border: 1px solid #f3d9a6; }
.bms-perkg { font-size: 11px; color: #888; margin: 2px 0 0; }

/* Price zone */
.bms-price-zone {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 10px;
}
.bms-price-single {
    font-size: 15px;
    font-weight: 700;
    color: var(--bms-text);
}
.bms-price-old {
    font-size: 11px;
    color: #ccc;
    text-decoration: line-through;
}
.bms-price-now {
    font-size: 15px;
    font-weight: 700;
    color: var(--bms-danger);
}

/* Combination selector (button cards) */
.bms-combi {
    margin-bottom: 10px;
}
.bms-combi-head {
    font-size: 11px;
    color: var(--bms-text-light);
    margin-bottom: 6px;
}
.bms-combi-sel {
    color: var(--bms-text);
    font-weight: 700;
}
.bms-combi-opts {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.bms-combi-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bms-bg);
    border: 1.5px solid var(--bms-border);
    border-radius: var(--bms-radius-sm);
    padding: 6px 12px;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
    line-height: 1.2;
}
.bms-combi-btn:hover {
    border-color: var(--bms-primary);
}
.bms-combi-btn.selected {
    border-color: var(--bms-primary);
    background: var(--bms-bg-warm);
    box-shadow: 0 0 0 3px rgba(245, 166, 35, 0.18);
}
.bms-combi-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--bms-text);
    white-space: nowrap;
}

/* Combination dropdown (4+ variants) */
.bms-combi-select {
    width: 100%;
    padding: 7px 10px;
    border: 1.5px solid var(--bms-border);
    border-radius: var(--bms-radius-sm);
    font-size: 13px;
    color: var(--bms-text);
    background: var(--bms-bg);
    cursor: pointer;
    font-family: var(--bms-font);
}
.bms-combi-select:focus {
    outline: none;
    border-color: var(--bms-primary);
}

/* Blog card */
.bms-blog-card {
    background: var(--bms-bg);
    border-radius: var(--bms-radius);
    overflow: hidden;
    border: 1px solid var(--bms-border);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.15s;
}

.bms-blog-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.bms-badge-blog {
    background: var(--bms-success);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Footer */
.bms-footer {
    padding: 8px 20px;
    border-top: 1px solid var(--bms-border);
    text-align: center;
    font-size: 11px;
    color: #d0cfc8;
    flex-shrink: 0;
}

.bms-footer b {
    color: var(--bms-primary);
}

/* Animations */
@keyframes bmsFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes bmsCartPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.12); }
    100% { transform: scale(1); }
}

/* Mobile-only filter UI — hidden on desktop */
.bms-filters-toggle,
.bms-mfilters-head,
.bms-mfilters-foot,
.bms-mfilters-backdrop { display: none; }
.bms-filters-toggle {
    background: #fff;
    border: 1px solid #e0dfd8;
    border-radius: 18px;
    font-size: 12px;
    font-weight: 600;
    color: #555;
    padding: 5px 12px;
    cursor: pointer;
}
.bms-ft-badge {
    background: #f5a623;
    color: #fff;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    margin-left: 2px;
}

/* Responsive */
@media (max-width: 768px) {
    .bms-container {
        width: 100%;
        max-height: 100vh;
        margin-top: 0;
        border-radius: 0;
    }

    /* Filters become a slide-in drawer (off-canvas by default) */
    .bms-filters-panel {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        width: 84%;
        max-width: 330px;
        background: #fff;
        z-index: 100050;
        transform: translateX(-100%);
        transition: transform .25s ease;
        overflow-y: auto;
        box-shadow: 2px 0 16px rgba(0, 0, 0, .2);
        -webkit-overflow-scrolling: touch;
    }
    .bms-filters-panel.open { transform: translateX(0); }
    .bms-mfilters-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .45);
        z-index: 100040;
    }
    .bms-mfilters-head {
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: sticky;
        top: 0;
        background: #fff;
        padding: 14px 16px;
        border-bottom: 1px solid #eee;
        font-weight: 700;
        font-size: 15px;
        z-index: 1;
    }
    .bms-mfilters-close {
        background: none;
        border: none;
        font-size: 18px;
        cursor: pointer;
        color: #888;
        line-height: 1;
    }
    .bms-mfilters-foot {
        display: block;
        position: sticky;
        bottom: 0;
        background: #fff;
        padding: 12px 16px;
        border-top: 1px solid #eee;
    }
    .bms-mfilters-apply {
        width: 100%;
        background: #f5a623;
        color: #fff;
        border: none;
        border-radius: 8px;
        padding: 12px;
        font-weight: 700;
        font-size: 14px;
        cursor: pointer;
    }
    .bms-filters-toggle { display: inline-flex; align-items: center; gap: 4px; }

    /* No hover on touch → show the full product name instead of truncating */
    .bms-card-title {
        -webkit-line-clamp: unset;
        display: block;
        overflow: visible;
        min-height: 0;
    }

    .bms-product-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 8px;
        padding: 10px;
    }
}

/* Scrollbar */
.bms-container ::-webkit-scrollbar {
    width: 5px;
}

.bms-container ::-webkit-scrollbar-track {
    background: transparent;
}

.bms-container ::-webkit-scrollbar-thumb {
    background: #e0dfd8;
    border-radius: 3px;
}
