/* ================================================================
   MLK SearchAI — стили компонента
   ================================================================ */

/* --- Контейнер --- */
.mlk-search-container {
    position: relative;
    width: 100%;
    max-width: 620px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
}

/* --- Строка поиска (pill) --- */
.mlk-search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 6px 6px 14px;
    background: #fff;
    border: 2px solid #e0e6ef;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    transition: border-color .25s, box-shadow .25s, background .25s;
}

.mlk-search-bar:focus-within {
    border-color: #b3d4f5;
    box-shadow: 0 2px 12px rgba(24,144,255,.12);
}

.mlk-search-bar.ai-mode {
    border-color: #1890ff;
    box-shadow: 0 0 0 3px rgba(24,144,255,.15), 0 2px 14px rgba(24,144,255,.22);
    background: linear-gradient(90deg, #f0f8ff 0%, #e8f3ff 100%);
    animation: mlk-ai-pulse 2.5s ease-in-out infinite;
}

@keyframes mlk-ai-pulse {
    0%, 100% { box-shadow: 0 0 0 3px rgba(24,144,255,.15), 0 2px 14px rgba(24,144,255,.22); }
    50%       { box-shadow: 0 0 0 5px rgba(24,144,255,.10), 0 2px 20px rgba(24,144,255,.32); }
}

/* Иконка лупы меняет цвет в AI-режиме */
.mlk-search-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: .55;
    transition: opacity .2s;
}
.mlk-search-icon circle,
.mlk-search-icon path { transition: stroke .25s; }

.mlk-search-bar:focus-within .mlk-search-icon { opacity: .8; }

.mlk-search-bar.ai-mode .mlk-search-icon { opacity: 1; }
.mlk-search-bar.ai-mode .mlk-search-icon circle,
.mlk-search-bar.ai-mode .mlk-search-icon path { stroke: #1890ff; }

/* Поле ввода — в AI-режиме синяя тема */
.mlk-search-input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    font-size: 15px;
    color: #222;
    padding: 6px 0;
    line-height: 1.4;
    caret-color: #555;
    transition: color .25s, caret-color .25s;
}

.mlk-search-input::placeholder {
    color: #aab;
    transition: color .25s;
}

.mlk-search-bar.ai-mode .mlk-search-input {
    color: #0a3d7a;
    caret-color: #1890ff;
}

.mlk-search-bar.ai-mode .mlk-search-input::placeholder {
    color: #6ea8d8;
}

/* --- Свич AI (внутри строки) --- */
.mlk-ai-switch {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 6px 4px 8px;
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    color: #9aa5b4;
    border-radius: 20px;
    transition: color .2s;
    -webkit-tap-highlight-color: transparent;
}

.mlk-ai-switch:hover { color: #1890ff; }
.mlk-ai-switch.active { color: #1890ff; }

.mlk-ai-switch-icon {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
    transition: opacity .2s, transform .3s;
    opacity: .45;
}
.mlk-ai-switch.active .mlk-ai-switch-icon {
    opacity: 1;
    transform: rotate(15deg) scale(1.1);
}

.mlk-ai-switch-label {
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .5px;
    line-height: 1;
    transition: color .2s;
}

/* Трек */
.mlk-ai-switch-track {
    position: relative;
    width: 34px;
    height: 19px;
    background: #d0d9e4;
    border-radius: 10px;
    flex-shrink: 0;
    transition: background .2s;
}
.mlk-ai-switch.active .mlk-ai-switch-track {
    background: linear-gradient(135deg, #1890ff, #096dd9);
    box-shadow: 0 0 0 2px rgba(24,144,255,.2);
}

/* Ползунок */
.mlk-ai-switch-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 15px;
    height: 15px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0,0,0,.22);
    transition: transform .22s cubic-bezier(.34,1.56,.64,1);
}
.mlk-ai-switch.active .mlk-ai-switch-thumb {
    transform: translateX(15px);
}

/* Иконка внутри ползунка (показывается только в активном состоянии) */
.mlk-ai-switch-thumb::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: radial-gradient(circle, #1890ff 0%, transparent 70%);
    opacity: 0;
    transition: opacity .2s;
}
.mlk-ai-switch.active .mlk-ai-switch-thumb::after {
    opacity: .6;
}

/* Иконка свича в AI-режиме превращается в «найти» (submit-режим) */
.mlk-search-bar.ai-mode .mlk-ai-switch-label::before {
    content: '';
}

/* ================================================================
   Выпадающий список
   ================================================================ */

.mlk-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 360px;
    background: #fff;
    border: 1px solid #e0e6ef;
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(0,0,0,.1);
    z-index: 10000;
    /* Высота — относительно viewport, чтобы влезало больше результатов на больших экранах. */
    max-height: min(720px, calc(100vh - 120px));
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Прокручиваемая часть — товары/категории/марки. Подсказки и футер остаются видимыми. */
.mlk-search-items {
    overflow-y: auto;
    overscroll-behavior: contain;
    flex: 1 1 auto;
    min-height: 0;
}

/* --- Загрузка --- */
.mlk-search-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    color: #888;
    font-size: 14px;
}

.mlk-search-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top-color: #1890ff;
    border-radius: 50%;
    animation: mlk-spin .7s linear infinite;
    flex-shrink: 0;
}

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

/* --- Исправление раскладки --- */
.mlk-search-brand {
    padding: 8px 18px;
    background: #f0f7ff;
    border-bottom: 1px solid #cfe4ff;
    font-size: 13px;
    color: #14508c;
}

.mlk-search-corrected {
    padding: 8px 18px;
    background: #fffbe6;
    border-bottom: 1px solid #ffe58f;
    font-size: 13px;
    color: #7a5800;
}

.mlk-corrected-link {
    color: #1890ff;
    font-weight: 600;
    text-decoration: none;
    margin-left: 3px;
}

.mlk-corrected-link:hover { text-decoration: underline; }

/* --- Закреплённый редирект сверху выпадашки --- */
.mlk-search-redirects { display: none; }
.mlk-search-redirect {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 18px;
    background: linear-gradient(90deg, #eef5ff 0%, #f7faff 100%);
    border-bottom: 1px solid #d6e4ff;
    color: #1a4d8f;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background .15s;
}
.mlk-search-redirect:hover { background: #e3eeff; }
.mlk-search-redirects .mlk-search-redirect + .mlk-search-redirect {
    background: #f7faff;
    font-weight: 500;
}
.mlk-search-redirect--product { align-items: flex-start; gap: 10px; }
.mlk-search-redirect__img {
    width: 44px;
    height: 44px;
    flex: 0 0 auto;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
}
.mlk-search-redirect__text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mlk-search-redirect__label { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: #5b7fae; }
.mlk-search-redirect__name { font-size: 14px; font-weight: 600; color: #1a4d8f; line-height: 1.3;
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; }
.mlk-search-redirect__art { font-size: 12px; font-weight: 500; color: #7a8699; }
.mlk-search-redirect__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #2C7BE5;
    color: #fff;
    font-size: 13px;
    flex: 0 0 auto;
}

/* Запиненные/поднятые товары — лёгкая метка слева */
.mlk-search-item--pinned { box-shadow: inset 3px 0 0 #2C7BE5; }
.mlk-search-item--boosted { box-shadow: inset 3px 0 0 #b7d3ff; }

/* --- AI-режим хинт --- */
.mlk-ai-mode-hint {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 7px 18px;
    background: linear-gradient(to right, #e6f4ff, #f0faff);
    border-bottom: 1px solid #bae0ff;
    font-size: 13px;
    color: #0958d9;
    font-weight: 500;
}

.mlk-ai-mode-hint svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* Подсказка «введите запрос и нажмите Enter» в AI-режиме до запуска поиска */
.mlk-search-ai-hint-inner {
    padding: 18px 20px;
    text-align: center;
    color: #5a6e8c;
    font-size: 13px;
    line-height: 1.5;
}

.mlk-search-ai-hint-inner kbd {
    display: inline-block;
    padding: 2px 7px;
    margin: 0 2px;
    background: #f0f4f9;
    border: 1px solid #d0dae8;
    border-bottom-width: 2px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 11px;
    font-weight: 600;
    color: #1656C9;
}

/* --- Список товаров (правила выше, в блоке .mlk-search-results) --- */
.mlk-search-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background .15s;
    border-bottom: 1px solid #f5f5f5;
}

.mlk-search-item:last-child { border-bottom: none; }

.mlk-search-item:hover,
.mlk-search-item--selected {
    background: #f0f8ff;
}

.mlk-item-img {
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f5f5f5;
}

.mlk-item-info { flex: 1; min-width: 0; }

.mlk-item-name {
    font-size: 14px;
    font-weight: 500;
    color: #222;
    line-height: 1.3;
    /* Две строки, а не одна: в конце названия стоит объём («…, 250 мл»),
       и однострочное многоточие отрезало ровно то, по чему товар выбирают. */
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
}

.mlk-item-article {
    font-size: 12px;
    color: #999;
    margin-top: 2px;
}

.mlk-item-price {
    font-size: 14px;
    font-weight: 600;
    color: #222;
    margin-top: 2px;
    white-space: nowrap;
}

.mlk-item-price-old {
    font-size: 12px;
    font-weight: 400;
    color: #999;
    text-decoration: line-through;
    margin-left: 6px;
}

/* AI-обоснование под товаром */
.mlk-item-reason {
    font-size: 12px;
    color: #5a6e8c;
    margin-top: 4px;
    padding: 4px 8px;
    background: linear-gradient(to right, #f0f8ff, #e6f4ff);
    border-left: 2px solid #1890ff;
    border-radius: 4px;
    line-height: 1.4;
    font-style: italic;
}

/* AI-метка на товаре, выбранном LLM. Inline-flex + фиксированные размеры,
   чтобы бейдж не «расплывался» при переносе многострочных заголовков. */
.mlk-item-ai-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 16px;
    min-width: 24px;
    padding: 0 6px;
    background: linear-gradient(135deg, #2C7BE5, #1656C9);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    border-radius: 8px;
    margin-right: 6px;
    vertical-align: 1px;
    letter-spacing: 0.4px;
    white-space: nowrap;
    flex-shrink: 0;
    box-shadow: 0 1px 3px rgba(44, 123, 229, 0.3);
}

.mlk-search-item--ai-picked {
    background: linear-gradient(to right, #fafdff, #fff);
}
.mlk-search-item--ai-picked:hover,
.mlk-search-item--ai-picked.mlk-search-item--selected {
    background: #e6f4ff;
}

/* --- Пусто --- */
.mlk-search-empty {
    padding: 16px 18px;
    font-size: 14px;
    color: #aaa;
    text-align: center;
}

/* --- Подсказки следующего слова --- */
.mlk-search-suggestions {
    padding: 10px 18px 12px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
}

.mlk-search-suggestions__title {
    font-size: 12px;
    color: #bbb;
    display: block;
    margin-bottom: 6px;
}

.mlk-suggestion-chip {
    display: inline-block;
    margin: 0 6px 4px 0;
    padding: 4px 10px;
    background: #f0f0f0;
    border-radius: 12px;
    font-size: 13px;
    color: #555;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.mlk-suggestion-chip:hover {
    background: #e0edff;
    color: #1890ff;
}

/* --- Футер (всегда видимый) --- */
.mlk-search-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
    flex-shrink: 0;
}

.mlk-search-all-link {
    font-size: 13px;
    color: #1890ff;
    text-decoration: none;
    font-weight: 500;
}

.mlk-search-all-link:hover { text-decoration: underline; }

/* ================================================================
   Адаптив
   ================================================================ */

@media (max-width: 480px) {
    .mlk-ai-switch-label { display: none; }
    .mlk-ai-switch { padding: 4px 4px; gap: 3px; }
}

/* ── Результаты: категории, марки, гаммы ────────────────────────────── */
.mlk-search-item--category,
.mlk-search-item--brand,
.mlk-search-item--gamma {
    gap: 10px;
}

.mlk-item-type-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #f0f4ff;
    color: #1890ff;
}

.mlk-search-item--brand .mlk-item-type-icon {
    background: #fff4f0;
    color: #fa541c;
}

.mlk-search-item--gamma .mlk-item-type-icon {
    background: #f6ffed;
    color: #389e0d;
}

.mlk-item-type-icon svg {
    width: 16px;
    height: 16px;
}

.mlk-item-badge {
    font-size: 10px;
    color: #8c8c8c;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.mlk-search-item--category .mlk-item-name,
.mlk-search-item--brand .mlk-item-name,
.mlk-search-item--gamma .mlk-item-name {
    font-weight: 500;
}

/* ================================================================
   COMPACT-режим: встроенный поиск в каталоге.
   Без AI-кнопки, без чата, узкий вид.
   ================================================================ */
.mlk-search-container--compact {
    max-width: 320px;
    margin-left: auto;
}

.mlk-search-container--compact .mlk-search-bar {
    padding: 4px 4px 4px 14px;
    border-radius: 999px;
    box-shadow: none;
    border-width: 1px;
}

.mlk-search-container--compact .mlk-search-input {
    font-size: 14px;
    padding: 5px 0;
}

.mlk-search-container--compact .mlk-search-results {
    max-height: min(560px, calc(100vh - 200px));
}
