/**
 * Search Widget v3 — Autocomplete s facety
 * Bez scrollování, badges na fotkách, gradient košík, mobile fullscreen
 */

/* ── CSS Variables (přepsatelné per-shop) ── */
:root {
    --sw-primary: #e67a00;
    --sw-primary-hover: #cc6b00;
    --sw-primary-light: rgba(230, 122, 0, 0.07);
    --sw-bg: #ffffff;
    --sw-bg-hover: #f8f8f8;
    --sw-border: #ebebeb;
    --sw-text: #1a1a1a;
    --sw-text-dim: #555;
    --sw-text-faint: #999;
    --sw-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    --sw-radius: 12px;
    --sw-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --sw-mark-bg: #fff3e0;
    --sw-mark-color: #e67a00;
    --sw-green: #16a34a;
    --sw-orange: #d97706;
    --sw-red: #dc2626;
    --sw-z-index: 99999;
}

/* ── Overlay (jen ztmavení, BEZ blur — aby stránka nebyla rozmazaná) ── */
.sw-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.15);
    z-index: calc(var(--sw-z-index) - 1);
    opacity: 0;
    transition: opacity 0.2s;
}
.sw-overlay.sw-visible {
    display: block;
    opacity: 1;
}
@media (min-width: 769px) {
    .sw-overlay.sw-visible {
        pointer-events: none;
        background: transparent;
    }
}

/* ── Dropdown kontejner ── */
.sw-dropdown {
    display: none;
    position: fixed;
    left: 2.5%;
    width: 95%;
    max-height: calc(100vh - 80px);
    background: var(--sw-bg);
    border: 1px solid var(--sw-border);
    border-top: 3px solid var(--sw-primary);
    border-bottom: 3px solid var(--sw-primary);
    border-radius: var(--sw-radius);
    box-shadow: 0 8px 30px rgba(0,0,0,0.15);
    z-index: var(--sw-z-index);
    font-family: var(--sw-font);
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
}
/* Desktop scroll lock when search is open */
html.sw-scroll-lock {
    overflow: hidden !important;
}
html.sw-scroll-lock body {
    overflow: hidden !important;
}
.sw-dropdown.sw-visible {
    display: block;
    animation: sw-fadeIn 0.15s ease;
}
@keyframes sw-fadeIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Ukotvení pod hlavičkou (headerSelector) ── */
.sw-dropdown.sw-anchored-header {
    left: 5%;
    width: 90%;
    border-radius: 0 0 var(--sw-radius) var(--sw-radius);
    border-top: none;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

/* ── Dvousloupcový layout ── */
.sw-layout {
    display: flex;
}

/* ── Sidebar (facety: kategorie + značky) ── */
.sw-sidebar {
    width: 190px;
    flex-shrink: 0;
    border-right: 1px solid var(--sw-border);
    background: #fafafa;
    padding: 4px 0;
}

.sw-sidebar-section {
    padding: 4px 0;
}
.sw-sidebar-section + .sw-sidebar-section {
    border-top: 1px solid var(--sw-border);
}

.sw-sidebar-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sw-text);
    padding: 10px 14px 6px;
}

.sw-sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 14px;
    font-size: 13px;
    color: var(--sw-text-dim);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.1s;
    line-height: 1.35;
}
.sw-sidebar-item:hover,
.sw-sidebar-item.sw-active {
    background: var(--sw-primary-light);
    color: var(--sw-primary);
}

.sw-sidebar-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.sw-sidebar-count {
    font-size: 11px;
    color: var(--sw-text-faint);
    font-weight: 500;
    flex-shrink: 0;
}
.sw-sidebar-item:hover .sw-sidebar-count {
    color: var(--sw-primary);
}

/* ── Hlavní oblast ── */
.sw-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.sw-main-title {
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sw-text);
    padding: 10px 12px 4px;
}

/* ── Produkty grid (2 řady × 4 sloupce) ── */
.sw-products-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2px;
    padding: 8px 6px 4px;
}

/* ── Produktová karta ── */
.sw-product-card {
    cursor: pointer;
    transition: background 0.1s;
    border-radius: 8px;
}
.sw-product-card:hover,
.sw-product-card.sw-active {
    background: var(--sw-bg-hover);
    box-shadow: none;
}
.sw-product-card:hover .sw-card-link,
.sw-product-card:hover .sw-card-title {
    text-decoration: none !important;
}

.sw-card-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 6px;
    text-align: center;
    height: 100%;
}

.sw-card-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: inherit;
    flex: 1;
    width: 100%;
}

/* ── Obrázek s badges ── */
.sw-card-img-wrap {
    position: relative;
    width: 90px;
    height: 90px;
    margin-bottom: 6px;
    flex-shrink: 0;
}

.sw-card-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 0;
    mix-blend-mode: multiply;
}
.sw-card-img-empty {
    background: #f0f0f0;
    border-radius: 4px;
}

/* ── Badges (nad názvem) ── */
.sw-badges {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 3px;
    justify-content: center;
    margin-bottom: 2px;
    min-height: 18px;
}

.sw-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    line-height: 1.2;
    padding: 4px 7px;
    border-radius: 4px;
    white-space: nowrap;
}

.sw-badge-discount {
    background: var(--sw-primary);
    color: #fff;
}
.sw-badge-shipping {
    background: var(--sw-green);
    color: #fff;
}
.sw-badge-engraving {
    background: var(--sw-primary);
    color: #fff;
}
.sw-badge-gift {
    background: #2c3e50;
    color: #fff;
}

/* ── Karta: text ── */
.sw-card-title {
    font-size: 12px;
    color: var(--sw-text);
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
    max-width: 90%;
    min-height: 2.8em;
}

.sw-card-stock {
    font-size: 10px;
    font-weight: 600;
    margin-bottom: 2px;
}
.sw-card-stock.sw-in-stock    { color: var(--sw-green); }
.sw-card-stock.sw-out-of-stock { color: var(--sw-red); }
.sw-card-stock.sw-few-days    { color: var(--sw-orange); }

.sw-card-prices {
    display: flex;
    align-items: baseline;
    gap: 4px;
    flex-wrap: wrap;
    justify-content: center;
}

.sw-price {
    font-size: 14px;
    font-weight: 700;
    color: var(--sw-text);
}
.sw-price.sw-discounted {
    color: var(--sw-red);
}
.sw-price-old {
    font-size: 11px;
    color: var(--sw-text-faint);
    text-decoration: line-through;
}

/* ── Košík tlačítko (gradient oranžovo-červený, ikona tašky) ── */
.sw-cart-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: #eaf3f9;
    color: #1d3557;
    border: none;
    cursor: pointer;
    margin-top: 4px;
    transition: opacity 0.15s, transform 0.1s;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
}
.sw-cart-btn:hover {
    background: #d4e8f4;
    transform: scale(1.05);
}
.sw-cart-btn.sw-cart-added {
    background: var(--sw-green);
}
.sw-cart-btn svg {
    width: 16px;
    height: 16px;
}

/* ── "Všechny produkty" tlačítko ── */
.sw-show-all-wrap {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: linear-gradient(to bottom, rgba(255,255,255,0) 0%, rgba(255,255,255,1) 30%);
    padding: 20px 0 8px;
    text-align: center;
}
.sw-show-all {
    display: inline-block;
    width: 70%;
    padding: 10px 8px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, #e67a00, #cc6b00);
    border-radius: 8px;
    text-decoration: none;
    cursor: pointer;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.sw-show-all:hover {
    opacity: 0.9;
}

/* ── Highlight (match) ── */
.sw-dropdown mark {
    background: var(--sw-mark-bg);
    color: var(--sw-mark-color);
    border-radius: 2px;
    padding: 0 1px;
    font-weight: 600;
}

/* ── Loading / žádné výsledky ── */
.sw-loading,
.sw-no-results {
    padding: 40px 16px;
    text-align: center;
    font-size: 13px;
    color: var(--sw-text-faint);
}

/* ── Křížek pro zavření (uvnitř search wrapperu) ── */
.sw-close-btn {
    display: none !important;
}

/* ── Trending chipy ── */
.sw-trending {
    padding: 8px 12px 4px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}
.sw-trending-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--sw-text-faint);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 2px;
}
.sw-trending-chip {
    display: inline-block;
    padding: 4px 12px;
    background: var(--sw-primary-light);
    border: 1px solid transparent;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--sw-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s;
}
.sw-trending-chip:hover {
    background: var(--sw-primary);
    color: #fff;
}

.sw-fallback-msg {
    padding: 10px 12px 6px;
    font-size: 12px;
    color: var(--sw-text-faint);
    font-style: italic;
}
.sw-loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--sw-border);
    border-top-color: var(--sw-primary);
    border-radius: 50%;
    animation: sw-spin 0.6s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}
@keyframes sw-spin {
    to { transform: rotate(360deg); }
}

/* ── Mobilní taby (mobileLayout: 'tabs') ── */
.sw-mobile-tabs { display: none; }
@media (min-width: 769px) {
    .sw-mobile-tabs { display: none !important; }
}

.sw-tab-bar {
    display: flex;
    border-bottom: 2px solid var(--sw-border);
    background: #fafafa;
    position: sticky;
    top: 0;
    z-index: 3;
}
.sw-tab-btn {
    flex: 1;
    padding: 10px 6px;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    border: none;
    background: none;
    color: var(--sw-text-faint);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    white-space: nowrap;
}
.sw-tab-btn.sw-tab-active {
    color: var(--sw-text);
    font-weight: 700;
    border-bottom-color: var(--sw-primary);
}
.sw-tab-panel { display: none; }
.sw-tab-panel.sw-tab-active { display: block; }

/* Řádkový seznam v tabu kategorií/značek */
.sw-tab-list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none;
    color: var(--sw-text);
    transition: background 0.1s;
}
.sw-tab-list-item:active {
    background: var(--sw-primary-light);
}
.sw-tab-list-item:last-child {
    border-bottom: none;
}
.sw-tab-list-img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 4px;
    flex-shrink: 0;
    mix-blend-mode: multiply;
}
.sw-tab-list-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sw-tab-list-count {
    font-size: 12px;
    color: var(--sw-text-faint);
    font-weight: 500;
    flex-shrink: 0;
}

/* ════════════════════════════════════════════
   MOBILE (≤768px) — list layout jako Magrano
   ════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Přepínání desktop/mobile layoutu v tabs režimu */
    .sw-desktop-layout { display: none !important; }
    .sw-mobile-tabs { display: block !important; }
    /*
     * Shopion (main.css): .header__search-input má explicitní font-size až od min-width:768px.
     * Na iOS Safari < 16px u <input> při focusu automaticky zoomuje celou stránku → rozbité rozložení,
     * schované tlačítko košíku v hlavičce i náš panel. Fix: 16px na vyhledávacím poli.
     */
    #inp-search.header__search-input,
    .header__search .header__search-input,
    .header__search .form-item__input {
        font-size: 16px !important;
        line-height: 1.25 !important;
    }

    /*
     * Mobil: jeden scroll kontejner (.sw-results), panel bez vlastního overflow-y.
     * Dvojité scrollování (dropdown + results) způsobovalo „utíkání“ gesta na podklad.
     */
    .sw-dropdown {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: none !important;
        min-width: 0 !important;
        border-radius: 0 !important;
        border: none !important;
        margin: 0 !important;
        padding: 0 !important;
        display: none;
        flex-direction: column;
        box-shadow: none;
        overflow: hidden !important;
        touch-action: auto;
        -webkit-overflow-scrolling: auto;
    }
    .sw-dropdown.sw-visible {
        display: flex;
    }
    html.sw-mobile-open {
        overflow: hidden !important;
        width: 100% !important;
        height: 100% !important;
        overscroll-behavior: none;
    }
    html.sw-mobile-open body {
        overflow: hidden !important;
        width: 100% !important;
        position: fixed !important;
        /* none by blokovalo i přiblížení prsty; manipulation = scroll + pinch-zoom */
        touch-action: manipulation;
    }

    /* Jediná scrollovací plocha — min-height:0 je nutné pro flex + overflow v WebKitu */
    .sw-results {
        flex: 1 1 auto;
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
    }

    .sw-layout {
        flex-direction: column;
        width: 100% !important;
        max-width: 100vw !important;
    }

    /*
     * Kategorie + značky znovu na mobilu — omezená výška + vnitřní scroll,
     * aby hlavní seznam produktů zůstal hned pod blokem a „Všechny produkty“ dosažitelné.
     */
    .sw-sidebar {
        display: block !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 220px;
        max-height: min(32vh, 220px);
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
        flex-shrink: 0;
        border-right: none;
        border-bottom: 2px solid var(--sw-border);
        background: #fafafa;
        padding: 0;
    }

    .sw-sidebar-section {
        display: block;
        padding: 0 0 4px;
        border-bottom: 2px solid #e8e8e8;
    }
    .sw-sidebar-section + .sw-sidebar-section {
        border-top: none;
    }

    .sw-sidebar-title {
        font-size: 10px;
        font-weight: 800;
        text-align: center;
        padding: 6px 8px 2px;
        color: var(--sw-text);
        letter-spacing: 0.5px;
        text-transform: uppercase;
    }

    .sw-sidebar-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 5px 10px;
        font-size: 12px;
        background: none;
        border: none;
        border-radius: 0;
        border-bottom: 1px solid #f0f0f0;
        gap: 6px;
        white-space: normal;
        color: var(--sw-primary);
        text-decoration: none;
    }
    .sw-sidebar-item:last-child {
        border-bottom: none;
    }
    .sw-sidebar-item:active {
        background: var(--sw-primary-light);
    }

    .sw-sidebar-name {
        overflow: hidden;
        text-overflow: ellipsis;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-height: 1.2;
        min-width: 0;
    }

    .sw-sidebar-count {
        font-size: 11px;
        color: var(--sw-text-dim);
        flex-shrink: 0;
    }

    /* Nadpis PRODUKTY */
    .sw-main-title {
        font-size: 12px;
        font-weight: 700;
        text-align: center;
        padding: 6px 8px 4px;
        text-transform: none;
        letter-spacing: 0;
    }

    .sw-fallback-msg {
        padding: 6px 8px 4px;
        text-align: center;
        font-size: 11px;
    }

    .sw-main {
        flex: 0 0 auto;
        width: 100% !important;
        max-width: 100% !important;
        background: #fff;
    }

    /* ── Produkty: list jako Magrano — obrázek vlevo, text pod sebou, košík vpravo ── */
    .sw-products-grid {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 0;
    }

    .sw-product-card {
        border-radius: 0;
        border-bottom: 1px solid #ebebeb;
    }

    .sw-card-inner {
        display: grid;
        grid-template-columns: auto 1fr auto;
        grid-template-rows: auto auto auto;
        gap: 0 10px;
        align-items: start;
        padding: 10px 12px;
        text-align: left;
        overflow: hidden;
        max-width: 100%;
    }

    .sw-card-link {
        display: contents;
        text-decoration: none;
        color: inherit;
    }

    .sw-card-img-wrap {
        width: 64px;
        height: 64px;
        min-width: 64px;
        margin-bottom: 0;
        flex-shrink: 0;
        grid-row: 1 / 4;
        grid-column: 1;
        align-self: center;
    }

    .sw-card-title {
        grid-column: 2;
        grid-row: 1;
        font-size: 13px;
        line-height: 1.3;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        display: -webkit-box;
        text-align: left;
        margin-bottom: 2px;
        overflow: hidden;
        word-break: break-word;
        white-space: normal;
        max-width: 100%;
        min-height: auto;
    }

    .sw-card-stock {
        grid-column: 2;
        grid-row: 2;
        display: block;
        font-size: 11px;
        font-weight: 600;
        margin-bottom: 1px;
        white-space: normal;
    }

    .sw-card-prices {
        grid-column: 2;
        grid-row: 3;
        white-space: nowrap;
        justify-content: flex-start;
    }
    .sw-price { font-size: 14px; font-weight: 700; }
    .sw-price-old { font-size: 11px; }

    .sw-badge { font-size: 7px; padding: 2px 3px; }
    .sw-badges { top: -2px; left: -2px; }

    .sw-cart-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        margin: 0;
        flex-shrink: 0;
        border-radius: 8px;
        grid-column: 3;
        grid-row: 1 / 4;
        align-self: center;
    }
    .sw-cart-btn svg { width: 18px; height: 18px; }

    /* ── "Všechny produkty" — sticky dole, vždy viditelné ── */
    .sw-show-all-wrap {
        padding: 0;
        background: #fff;
    }
    .sw-show-all {
        display: block;
        width: 100%;
        position: sticky;
        bottom: 0;
        margin: 0;
        border-radius: 0;
        padding: 12px 12px;
        font-size: 13px;
        font-weight: 700;
        z-index: 2;
        box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    }

    .sw-overlay.sw-visible { display: none; }
}

/* ════════════════════════════════════════════
   TABLET (769px–900px)
   ════════════════════════════════════════════ */
@media (min-width: 769px) and (max-width: 900px) {
    .sw-dropdown {
        min-width: 500px;
    }
    .sw-sidebar {
        width: 160px;
    }
    .sw-products-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    .sw-card-img-wrap {
        width: 75px;
        height: 75px;
    }
}

/* ════════════════════════════════════════════
   LARGE DESKTOP (>1200px) — větší obsah
   ════════════════════════════════════════════ */
@media (min-width: 1200px) {
    .sw-sidebar {
        width: 220px;
    }
    .sw-card-img-wrap {
        width: 100px;
        height: 100px;
    }
    .sw-card-title {
        font-size: 13px;
    }
    .sw-price {
        font-size: 15px;
    }
}
