/**
 * Silsila Shop - Professional Search UI (Full Update 2026.3)
 * Финальная сборка: Кнопки в ряд + Все фильтры + Шторки + Синие ссылки.
 * Протокол: v2.0 (Isolation & Mobile-First)
 */

/* 1. БАЗОВЫЕ НАСТРОЙКИ СТРАНИЦЫ И СКРОЛЛА */
html {
    overflow-y: scroll; 
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    position: relative !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background-color: #fff;
}

/* КРИТИЧЕСКИЙ ФИКС: Системная разблокировка скролла через атрибуты данных */
[data-search-locked="true"],
html.modal-open, 
body.modal-open {
    overflow: hidden !important;
    height: 100vh !important;
    touch-action: none !important; /* Блокирует свайп фона */
}

/* Возвращаем скролл, когда атрибутов нет */
body:not([data-search-locked="true"]) {
    touch-action: auto !important;
}



/* 4. ИСТОРИЯ ПОИСКА И ПОДСКАЗКИ */
.search-history-box {
    background: #fff;
    padding: 18px 22px;
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    margin-bottom: 25px;
    border: 1px solid #f2f2f2;
    position: relative;
    z-index: 10;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.history-header span { font-weight: 800; font-size: 16px; }

.history-item {
    display: inline-flex;
    align-items: center;
    background: #f5f5f7;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    margin: 0 8px 8px 0;
    border: 1px solid transparent;
}

.remove-item {
    margin-left: 8px;
    cursor: pointer;
    color: #999;
    font-size: 18px;
}

.btn-clear-all {
    background: transparent;
    border: none;
    color: #999;
    font-size: 13px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.3s;
}

.btn-clear-all:hover {
    color: #ff4d4f;
    background-color: rgba(255, 77, 79, 0.08);
}

/* ТЕКСТ-ССЫЛКИ (История и Подсказки) */
.history-tag, 
.suggested-tag {
    color: #007bff !important;
    font-size: 14px !important;
    text-decoration: underline !important;
    text-decoration-color: rgba(0, 123, 255, 0.4) !important;
    text-underline-offset: 4px !important;
    transition: all 0.2s ease !important;
    cursor: pointer !important;
}

.history-tag:hover, 
.suggested-tag:hover {
    color: #0056b3 !important;
    text-decoration-color: #0056b3 !important;
}

/* 5. СЕТКА ТОВАРОВ И СКЕЛЕТОНЫ */
.myshop-products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 20px;
    transition: all 0.3s ease; /* Плавный сдвиг товаров вниз */
}

/* 6. МОБИЛЬНАЯ АДАПТАЦИЯ */
@media (max-width: 768px) {
    /* ОТКЛЮЧАЕМ фиксированную шторку снизу, оставляем сдвиг контента вниз */
    .toolbar-dropdown {
        position: relative !important;
        transform: none !important;
        bottom: auto !important;
        width: 100% !important;
        margin-bottom: 15px !important;
        border-radius: 16px !important;
        display: none;
    }

    .toolbar-dropdown.active {
        display: block !important;
    }

    .myshop-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .price-modal-form { width: 100%; }

    /* Убираем темный оверлей, так как контент просто уезжает вниз */
    body[data-search-locked="true"]::after { display: none; }
}

@keyframes ozonFadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}



/* --- ТУЛБАР (Compact & Professional Blue) --- */
.search-pro-toolbar {
    position: relative;
    padding: 6px 0; /* Минимальные отступы сверху/снизу */
    background: #fff;
    border-bottom: 1px solid #edf2f7;
    z-index: 100;
}

/* Контейнер со скроллом */
.toolbar-scroll-container {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px; /* Уменьшенное расстояние между кнопками */
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding: 0 15px;
    height: 40px; /* Фиксированная небольшая высота */
}

.toolbar-scroll-container::-webkit-scrollbar {
    display: none;
}

.toolbar-item {
    flex-shrink: 0;
    position: static !important; /* Окна привязаны к родителю .search-pro-toolbar */
}

/* Кнопка фильтра (Компактная) */
.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f8faff;
    border: 1px solid #e2e8f0;
    padding: 6px 12px; /* Уменьшенные внутренние отступы */
    border-radius: 10px; /* Чуть менее скругленные, современнее */
    font-weight: 500;
    font-size: 13px; /* Оптимальный размер текста */
    color: #4a5568;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.toolbar-btn i {
    font-size: 12px;
    color: #718096;
}

/* Активное состояние кнопки */
.toolbar-btn.is-active {
    border-color: #007aff;
    background-color: #f0f7ff;
    color: #0033ff;
}

.toolbar-btn.is-active i {
    color: #007aff;
}

.toolbar-btn:hover {
    border-color: #007aff;
    color: #007aff;
}

/* Точка активного фильтра */
.filter-dot {
    width: 5px;
    height: 5px;
    background: #007aff;
    border-radius: 50%;
    margin-left: 2px;
}

/* --- ВЫПАДАЮЩИЕ ОКНА (Full Width) --- */
.toolbar-dropdown {
    display: none;
    position: absolute !important; 
    left: 10px !important;
    right: 10px !important;
    width: auto !important; /* Автоматический зазор от краев */
    top: 50px !important; /* Сразу под тулбаром */
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 51, 255, 0.1); 
    z-index: 9999;
    border: 1px solid #e2e8f0;
    padding: 8px 0;
    overflow: hidden;
}

.toolbar-dropdown.active {
    display: block !important;
    animation: slideDown 0.2s ease-out;
}

/* Пункты меню */
.toolbar-dropdown a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    text-decoration: none;
    color: #2d3748;
    font-size: 14px;
    border-bottom: 1px solid #f7fafc;
    transition: background 0.2s;
}

.toolbar-dropdown a:last-child {
    border-bottom: none;
}

.toolbar-dropdown a:hover {
    background: #f0f7ff;
    color: #007aff;
}

/* Выбранный пункт */
.toolbar-dropdown a.is-selected {
    color: #0033ff;
    font-weight: 600;
    background: #f0f7ff;
}

.toolbar-dropdown a.is-selected::after {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
    font-size: 11px;
}

/* --- ФОРМА ЦЕНЫ (Компактная) --- */
.price-modal-form {
    padding: 12px 16px;
}

.price-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.price-inputs input {
    flex: 1; 
    border: 1px solid #cbd5e0;
    border-radius: 8px;
    padding: 10px;
    font-size: 14px;
    outline: none;
    background: #fcfdfe;
    text-align: center;
    color: #0033ff;
    font-weight: 600;
}

.price-inputs input:focus {
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.1);
}

/* Кнопка "Применить" (Синий градиент) */
.apply-btn {
    width: 100%;
    background: linear-gradient(135deg, #0088ff 0%, #0033ff 100%);
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 51, 255, 0.15);
    transition: all 0.2s;
}

.apply-btn:active {
    transform: scale(0.98);
}

/* Анимация появления */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Адаптация под очень маленькие экраны */
@media (max-width: 360px) {
    .toolbar-btn {
        padding: 5px 10px;
        font-size: 12px;
    }
}




/* 7. ЖИВЫЕ ПОДСКАЗКИ: FULL-WIDTH (2026 Edition) */

/* Панель подсказок перенесена в body; родительские блоки шапки не переопределяем. */
/* Сам блок подсказок закрепляем относительно окна браузера. */
#search-suggestions-results {
    display: none; /* Управляется через JS */
    position: fixed !important; /* Fixed гарантирует привязку к окну браузера */
    
    /* Точные координаты: под хедером на весь экран */
    top: 80px !important; /* Настройте это число под высоту вашей синей шапки */
    left: 0 !important;
    width: 100vw !important;
    height: auto !important;
    max-height: 85vh !important;
    
    /* Стилизация */
    background: #ffffff !important;
    z-index: 999999 !important;
    border-radius: 0 0 24px 24px !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4) !important;
    border-top: 1px solid #f0f2f5 !important;
    
    /* Внутренности */
    overflow-y: auto;
    padding: 8px 0 !important;
    -webkit-overflow-scrolling: touch;
}

/* ШАГ 3: Красивые строки (Ozon Style) */
.suggestion-row {
    padding: 16px 20px !important; /* 20px - отступ текста от края экрана */
    display: flex !important;
    align-items: center !important;
    gap: 14px !important;
    border-bottom: 1px solid #f5f5f5 !important;
    transition: all 0.2s ease !important;
    cursor: pointer;
}

.suggestion-row:last-child {
    border-bottom: none !important;
}

/* Эффект при клике/тапе */
.suggestion-row:active {
    background-color: #f0f7ff !important;
}

/* Текст подсказки */
.suggestion-row a {
    color: #333 !important;
    text-decoration: none !important;
    font-size: 16px !important;
    font-weight: 500 !important;
    display: flex !important;
    width: 100% !important;
    align-items: center !important;
}

/* Подсветка совпадения синим */
.suggestion-row b, 
.suggestion-row strong {
    color: #007aff !important;
    font-weight: 700 !important;
    margin-right: 2px;
}



/* Фикс для предотвращения дергания экрана */
body.search-active {
    overflow: hidden !important;
}

/* Фильтры открываются как нижняя шторка на всех размерах экрана. */
.toolbar-dropdown.toolbar-bottom-sheet {
    display: none !important;
    position: fixed !important;
    inset: 0 !important;
    z-index: 120000 !important;
    width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    margin: 0 !important;
    padding: 0 !important;
    left: 0 !important;
    right: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    overflow: hidden !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: rgba(18, 27, 42, .42) !important;
    box-shadow: none !important;
    align-items: flex-end;
    justify-content: center;
}

.toolbar-dropdown.toolbar-bottom-sheet.active {
    display: flex !important;
    animation: none !important;
}

.toolbar-sheet-inner {
    width: min(100%, 560px);
    max-height: min(82vh, 680px);
    max-height: min(82dvh, 680px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
    border-radius: 22px 22px 0 0;
    background: #fff;
    box-shadow: 0 -12px 36px rgba(16, 32, 56, .18);
    animation: toolbarSheetIn .22s ease-out;
}

.toolbar-sheet-grabber {
    display: block;
    flex: 0 0 auto;
    width: 38px;
    height: 4px;
    margin: 0 auto 12px;
    border-radius: 999px;
    background: #d9dee7;
}

.toolbar-sheet-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 12px;
    padding: 4px 0 12px;
    border-bottom: 1px solid #edf1f6;
}

.toolbar-sheet-header h2 {
    margin: 0;
    color: #172033;
    font-size: 18px;
    font-weight: 700;
}

.toolbar-sheet-close {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: #f2f4f7;
    color: #485467;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
}

.toolbar-sheet-options a {
    min-height: 48px;
    padding: 13px 4px;
    border-bottom: 1px solid #f0f2f5;
    background: #fff;
    color: #2d3748;
    font-size: 15px;
}

.toolbar-sheet-options {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.toolbar-sheet-options a:last-child { border-bottom: 0; }
.toolbar-sheet-options a.is-selected { background: #f3f8ff; color: #075bd8; }
.toolbar-sheet-options a.is-selected::after { content: "\f00c"; }
.rating-options a span:last-child { color: #f5a623; }

.toolbar-sheet-footer {
    display: flex;
    flex: 0 0 auto;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid #edf1f6;
    background: #fff;
}

.toolbar-sheet-reset,
.toolbar-sheet-apply {
    min-height: 48px;
    flex: 1;
    border-radius: 13px;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.toolbar-sheet-reset {
    border: 1px solid #dfe5ed;
    background: #fff;
    color: #566174;
}

.toolbar-sheet-apply {
    border: 0;
    background: #007aff;
    color: #fff;
}

.toolbar-sheet-reset:focus-visible,
.toolbar-sheet-apply:focus-visible,
.toolbar-reset-chip:focus-visible {
    outline: 3px solid rgba(0, 122, 255, .35);
    outline-offset: 2px;
}

.toolbar-validation-message {
    margin: 0 0 12px;
    color: #b42318;
    font-size: 13px;
    line-height: 1.45;
}

.toolbar-validation-message[hidden] { display: none !important; }

.price-inputs label {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 6px;
    color: #687386;
    font-size: 12px;
}

.price-inputs input { width: 100%; box-sizing: border-box; }
.price-actions { display: flex; gap: 10px; }
.price-actions .reset-btn,
.price-actions .apply-btn {
    min-height: 46px;
    flex: 1;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 650;
    cursor: pointer;
}
.price-actions .reset-btn { border: 1px solid #e2e6ed; background: #fff; color: #4e596b; }
.price-actions .apply-btn { flex: 1.35; }
body.modal-open { overflow: hidden !important; }
.toolbar-reset-chip[hidden] { display: none !important; }

@media (max-width: 768px) {
    .toolbar-scroll-container {
        gap: 7px;
        padding: 0 12px;
    }

    .toolbar-btn {
        min-height: 36px;
        border-radius: 18px;
        background: #fff;
    }

    .toolbar-btn.is-active {
        border-color: #007aff;
        background: #edf5ff;
        color: #075bd8;
    }

    .toolbar-reset-chip {
        border-color: transparent;
        background: transparent;
        color: #007aff;
        font-weight: 700;
    }

    .toolbar-dropdown.toolbar-bottom-sheet {
        z-index: 120000 !important;
    }

    .toolbar-sheet-inner {
        width: 100%;
        max-height: min(82dvh, 680px);
        padding: 8px 16px calc(12px + env(safe-area-inset-bottom));
        border-radius: 22px 22px 0 0;
    }

    .toolbar-sheet-options a {
        min-height: 48px;
        align-items: center;
        padding: 13px 4px;
        font-size: 15px;
    }

    .price-actions .reset-btn,
    .price-actions .apply-btn {
        min-height: 48px;
        border-radius: 13px;
    }
}

@keyframes toolbarSheetIn {
    from { opacity: .7; transform: translateY(22px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 769px) {
    .toolbar-sheet-inner { margin-bottom: 0; border-radius: 22px; }
    .toolbar-dropdown.toolbar-bottom-sheet { align-items: center; }
}
