/* ============================================================
   Карел-Импэкс · Компонент ИИ-чата подбора шин
   Все селекторы изолированы классом .karelimpex-tires-chat
   ============================================================ */

/* ---------- Общий контейнер ---------- */
.karelimpex-tires-chat {
    --kic-primary: #0F549E;
    --kic-primary-light: #eef4ff;
    --kic-bot-bg: #f1f4f9;
    --kic-border: #dcdcdc;
    --kic-text: #222;
    --kic-muted: #888;
    --kic-danger: #e74c3c;
    --kic-radius: 12px;
    --kic-gap: 10px;

    color: var(--kic-text);
    line-height: 1.45;
}

/* ============================================================
   ЧАТ
   ============================================================ */
#ai-assistant-modal{
    z-index: 99999;
}
.karelimpex-tires-chat .assistant-panel {
    margin-bottom: 20px;
}

.karelimpex-tires-chat .chat-box {
}

/* ---------- Список сообщений ---------- */
.karelimpex-tires-chat .chat-messages {
    max-height: 500px;
    overflow-y: auto;
    padding: 10px 4px;
    display: flex;
    flex-direction: column;
    gap: var(--kic-gap);
    scroll-behavior: smooth;
}

/* Полоса прокрутки (WebKit) */
.karelimpex-tires-chat .chat-messages::-webkit-scrollbar {
    width: 8px;
}
.karelimpex-tires-chat .chat-messages::-webkit-scrollbar-thumb {
    background: #cfd6e0;
    border-radius: 4px;
}
.karelimpex-tires-chat .chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8b3c2;
}

/* ---------- Сообщения ---------- */
.karelimpex-tires-chat .chat-message {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    word-break: break-word;
    white-space: normal;
}

.karelimpex-tires-chat .chat-message-wrapper {
    max-width:100%;
}

.karelimpex-tires-chat .chat-message-wrapper--user {
    align-self: flex-end;
}

.karelimpex-tires-chat .chat-message-wrapper--bot {
    align-self: flex-start;
}

.karelimpex-tires-chat .chat-message.user {
    background: var(--kic-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.karelimpex-tires-chat .chat-message.bot {
    background: var(--kic-bot-bg);
    color: var(--kic-text);
    border-bottom-left-radius: 4px;
}

.karelimpex-tires-chat .chat-message--typing {
    color: var(--kic-muted);
    font-style: italic;
}

/* Форматирование внутри ответа бота */
.karelimpex-tires-chat .chat-message h1,
.karelimpex-tires-chat .chat-message h2,
.karelimpex-tires-chat .chat-message h3 {
    margin: 8px 0 6px;
    font-size: 1.05em;
    font-weight: 700;
}
.karelimpex-tires-chat .chat-message ul,
.karelimpex-tires-chat .chat-message ol {
    margin: 6px 0;
    padding-left: 20px;
}
.karelimpex-tires-chat .chat-message li {
    margin-bottom: 4px;
}
.karelimpex-tires-chat .chat-message strong {
    font-weight: 700;
}
.karelimpex-tires-chat .chat-message em {
    font-style: italic;
}

/* ---------- Поле ввода ---------- */
.karelimpex-tires-chat .chat-input-row {
    display: flex;
    gap: var(--kic-gap);
    margin-top: 16px;
}

.karelimpex-tires-chat .chat-input-row input[data-role="input"] {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--kic-border);
    border-radius: 10px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.karelimpex-tires-chat .chat-input-row input[data-role="input"]:focus {
    border-color: var(--kic-primary);
    box-shadow: 0 0 0 3px rgba(15, 84, 158, 0.1);
}

/* ---------- Аннотация под строкой ввода ---------- */
.karelimpex-tires-chat .chat-description {
    margin-top: 8px;
    font-size: 12px;
    color: var(--kic-muted);
    line-height: 1.3;
}

/* ---------- Ссылка «Показать N шин ниже» (устарело, оставлено для совместимости) ---------- */
.karelimpex-tires-chat .chat-results-link {
    margin-top: 10px;
}

.karelimpex-tires-chat .chat-results-link__btn {
    display: inline-block;
    padding: 8px 14px;
    background: var(--kic-primary-light);
    color: var(--kic-primary);
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
    transition: background-color 0.2s, transform 0.1s;
}

.karelimpex-tires-chat .chat-results-link__btn:hover {
    background: #dbe8ff;
    transform: translateY(-1px);
}

/* ============================================================
   РЕЗУЛЬТАТЫ (карточки товаров)
   ============================================================ */
.karelimpex-tires-chat .ai-results-wrapper {
    margin-top: 20px;
}

/* ---------- Карточка ---------- */
.karelimpex-tires-chat .filter-result-item {
    display: flex;
}

.karelimpex-tires-chat .product-card {
    display: flex;
    width: 100%;
    background: #fff;
    border: 1px solid #ebebeb;
    border-radius: var(--kic-radius);
    overflow: hidden;
    transition: box-shadow 0.2s, transform 0.2s;
}

.karelimpex-tires-chat .product-card:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
    transform: translateY(-2px);
}

.karelimpex-tires-chat a.product-card:hover,
.karelimpex-tires-chat a.product-card:focus,
.karelimpex-tires-chat a.product-card:active {
    text-decoration: none;
}

.karelimpex-tires-chat .product-card__image {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex: 0 0 35%;
}

.karelimpex-tires-chat .product-card__image img {
    max-width: 90%;
    max-height: 100px;
    object-fit: contain;
    display: block;
}

.karelimpex-tires-chat .product-card__info {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    flex: 1 1 65%;
    width:65%;
}

.karelimpex-tires-chat .product-card__title {
    margin: 0 0 8px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--kic-text);

    /* Обрезка длинных названий до 2 строк */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: calc(1.35em * 2);
}

.karelimpex-tires-chat .product-card__specs {
    list-style: none;
    margin: 0 0 10px;
    padding: 0;
    font-size: 12px;
    color: #555;
}

.karelimpex-tires-chat .product-card__specs li {
    margin-bottom: 3px;
}

.karelimpex-tires-chat .product-card__action {
    margin-bottom: 8px;
    max-width: 80%;
    overflow: hidden;
}

.karelimpex-tires-chat .product-card__action span {
    display: block;
    max-width: 100%;
    padding: 3px 8px;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.3;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.02em;

    /* Ellipsis в одну строку */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}

.karelimpex-tires-chat .product-card-price-row {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.karelimpex-tires-chat .product-card__price {
    font-size: 17px;
    font-weight: 700;
    color: var(--kic-primary);
    white-space: nowrap;
}

.karelimpex-tires-chat .product-card__old-price {
    font-size: 13px;
}

/* ============================================================
   Индикатор загрузки
   ============================================================ */
.karelimpex-tires-chat .loader {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================================
   АККОРДЕОН РЕЗУЛЬТАТОВ
   ============================================================ */
.karelimpex-tires-chat .filter-results-items {
    background: var(--kic-bot-bg);
    border-radius: 12px;
    margin-top: 16px;
    margin-bottom: 16px;
    overflow: hidden;
    transition: box-shadow 0.2s;
}

.karelimpex-tires-chat .filter-results-items:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

/* ---------- Заголовок-переключатель ---------- */
.karelimpex-tires-chat .filter-results-items__toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 14px 18px;
    background: transparent;
    border: none;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    font-weight: 600;
    color: var(--kic-text);
    transition: background-color 0.15s;
    font-family: inherit;
}

.karelimpex-tires-chat .filter-results-items__toggle:hover {
    background: #f7f8fa;
}

.karelimpex-tires-chat .filter-results-items__toggle:focus-visible {
    outline: 2px solid var(--kic-primary);
    outline-offset: -2px;
}

.karelimpex-tires-chat .filter-results-items__toggle-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--kic-muted);
    transition: transform 0.2s;
}

.karelimpex-tires-chat .filter-results-items__toggle[aria-expanded="false"] .filter-results-items__toggle-icon {
    transform: rotate(-90deg);
}

.karelimpex-tires-chat .filter-results-items-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.karelimpex-tires-chat .filter-results-items__toggle-count {
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 500;
    color: var(--kic-muted);
}

/* ---------- Тело аккордеона (десктоп — сетка) ---------- */
.karelimpex-tires-chat .filter-results-items-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
    padding: 18px;
    overflow: hidden;
    max-height: 9999px;
    transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
    opacity: 1;
}

.karelimpex-tires-chat .filter-results-items[data-collapsed="true"] .filter-results-items-list {
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    opacity: 0;
}

/* ============================================================
   АДАПТИВ
   ============================================================ */
@media (min-width: 641px) {
    .karelimpex-tires-chat .chat-messages{
        min-height:500px;
    }
}
@media (max-width: 640px) {

    /* ---------- Модалка на весь экран ---------- */
    #ai-assistant-modal .modal-dialog {
        width: 100%;
        max-width: 100%;
        height: 100%;
        margin: 0;
    }

    #ai-assistant-modal .modal-content {
        display: flex;
        flex-direction: column;
        height: 100%;
        border-radius: 0;
    }

    #ai-assistant-modal .modal-header {
        flex-shrink: 0;
    }

    #ai-assistant-modal .modal-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow: hidden;
        padding: 0;
    }

    /* ---------- Чат — на всю высоту ---------- */
    .karelimpex-tires-chat,
    .karelimpex-tires-chat .assistant-panel,
    .karelimpex-tires-chat .chat-box {
        height: 100%;
    }

    .karelimpex-tires-chat .assistant-panel {
        margin-bottom: 0;
    }

    .karelimpex-tires-chat .chat-box {
        display: flex;
        flex-direction: column;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
    }

    /* ---------- Сообщения — растягиваются ---------- */
    .karelimpex-tires-chat .chat-messages {
        flex: 1 1 auto;
        min-height: 0;          /* КРИТИЧНО для overflow-y */
        max-height: none;       /* перебить max-height: 480px */
        overflow-y: auto;
        padding: 10px 12px;
    }

    .karelimpex-tires-chat .chat-message {
        max-width: 92%;
        font-size: 13.5px;
    }

    /* ---------- Поле ввода — фиксированной высоты ---------- */
    .karelimpex-tires-chat .chat-input-row {
        flex-shrink: 0;
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px 12px;
        margin-top: 0;
    }

    .karelimpex-tires-chat .chat-input-row input[data-role="input"] {
        flex: 1 1 100%;
    }

    .karelimpex-tires-chat .chat-input-row button[data-role="send"] {
        flex: 1 1 100%;
    }

    .karelimpex-tires-chat .chat-description {
        flex-shrink: 0;
        font-size: 11px;
        margin: 0;
        padding: 0 12px 10px;
    }

    /* ---------- Слайдер карточек ---------- */
    .karelimpex-tires-chat .filter-results-items-list {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
        gap: 12px;
        padding: 16px;
        max-height: none;
        scrollbar-width: none;
    }

    .karelimpex-tires-chat .filter-results-items-list::-webkit-scrollbar {
        display: none;
    }

    .karelimpex-tires-chat .filter-results-items-list .filter-result-item {
        flex: 0 0 90%;
        scroll-snap-align: center;
        max-width: 90%;
    }

    .karelimpex-tires-chat .filter-results-items-list .product-card {
        width: 100%;
    }

    .karelimpex-tires-chat .filter-results-items[data-collapsed="true"] .filter-results-items-list {
        max-height: 0;
        padding-top: 0;
        padding-bottom: 0;
        opacity: 0;
    }
}

/* ============================================================
   Кнопка «AI» (внешняя, не зависит от чата)
   ============================================================ */
.ai-button-container {}

.ai-button-container .ai-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    padding: 8px 16px;

    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: 0.01em;

    color: #ffffff;

    background: linear-gradient(90deg, #0082ce 0%, #0c54a0 50%, #0082ce 100%);
    background-size: 200% 100%;
    background-position: 0% 50%;

    border-radius: 999px;

    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    overflow: hidden;

    transition:
        background-position 0.6s ease,
        transform 0.15s linear;

    animation: ai-button-breathe 4s ease-in-out infinite;
}

@keyframes ai-button-breathe {
    0%,
    100% { background-position:   0% 50%; }
    50%  { background-position: 100% 50%; }
}

.ai-button-container .ai-button::before {
    content: '';
    display: block;
    width: 14px;
    height: 14px;
    flex: 0 0 auto;

    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M12 3l1.9 5.1L19 10l-5.1 1.9L12 17l-1.9-5.1L5 10l5.1-1.9L12 3z'/><path d='M19 15l.9 2.4L22 18l-2.1.6L19 21l-.9-2.4L16 18l2.1-.6L19 15z'/></svg>");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;

    animation: ai-button-spark 2.4s ease-in-out infinite;
}

@keyframes ai-button-spark {
    0%,
    100% { transform: scale(1);    opacity: 1;   }
    50%  { transform: scale(1.15); opacity: 0.8; }
}

.ai-button-container .ai-button::after {
    content: '';
    position: absolute;
    top: 0;
    left: -150%;
    width: 100%;
    height: 100%;
    pointer-events: none;

    background: linear-gradient(
        100deg,
        transparent 20%,
        rgba(255, 255, 255, 0.35) 50%,
        transparent 80%
    );

    animation: ai-button-shine 5s ease-in-out infinite;
}

@keyframes ai-button-shine {
    0%   { left: -150%; }
    20%  { left: 150%;  }
    100% { left: 150%;  }
}

.ai-button-container .ai-button:hover,
.ai-button-container .ai-button:focus-visible {
    background-position: 100% 50%;
    transform: translateY(-1px);
    animation-play-state: paused;
    text-decoration: none;
}

.ai-button-container .ai-button:active {
    transform: translateY(0);
}

.ai-button-container .ai-button:focus-visible {
    outline: 2px solid #0082ce;
    outline-offset: 2px;
}

/* ============================================================
   FALLBACK для кнопки .btn--primary
   Раскомментируйте, если на сайте нет своих стилей
   ============================================================ */
/*
.karelimpex-tires-chat .btn {
    display: inline-block;
    padding: 12px 22px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    text-decoration: none;
    text-align: center;
    white-space: nowrap;
}

.karelimpex-tires-chat .btn--primary {
    background: var(--kic-primary);
    color: #fff;
}

.karelimpex-tires-chat .btn--primary:hover {
    background: #0d4787;
    transform: translateY(-1px);
}

.karelimpex-tires-chat .btn--small {
    padding: 8px 14px;
    font-size: 13px;
}
*/