/* Блок «Спросите о товаре» на карточке товара.
 *
 * Стоит сразу под кнопкой покупки — там, где у покупателя возникают сомнения.
 * Единственное место витрины, где уместно движение: это интерактивный помощник,
 * и он должен читаться как живой, а не как ещё один аккордеон.
 *
 * Правила, которых держится вся моторика:
 *   — анимируются только transform и opacity (кроме раскрытия через grid-rows),
 *     поэтому браузер не пересчитывает раскладку на каждом кадре;
 *   — ничего не двигается само по себе дольше пары секунд, кроме медленного
 *     блика рамки: страница не должна мельтешить в углу зрения;
 *   — при prefers-reduced-motion всё выключается разом (в самом низу файла).
 *
 * Палитра взята у витрины: глубокий синий #0b5e86 и мятный акцент.
 */

.ai-ask-shell {
    --ai-accent: var(--premium-accent-dark, #0b5e86);
    --ai-accent-2: #2f9e8f;
    --ai-line: rgba(11, 94, 134, 0.14);
    --ai-radius: 18px;

    position: relative;
    margin: 20px 0 24px;
    border-radius: var(--ai-radius);
    overflow: hidden;
    isolation: isolate;
    background: var(--ai-line);
}

.ai-ask {
    position: relative;
    z-index: 2;
    border-radius: var(--ai-radius);
    background: transparent;
}

/* Живая рамка: под карточкой медленно вращается коническая заливка, сверху лежит
   подложка с отступом в 1 px — видимой остаётся только кромка. Сделано вращением
   элемента, а не углом через @property: работает во всех браузерах. */
.ai-ask__glow {
    position: absolute;
    z-index: 0;
    left: 50%;
    top: 50%;
    width: 180%;
    aspect-ratio: 1;
    border-radius: 50%;
    background: conic-gradient(
        from 0deg,
        transparent 0deg,
        var(--ai-accent) 40deg,
        var(--ai-accent-2) 80deg,
        transparent 130deg,
        transparent 360deg
    );
    opacity: 0.55;
    transform: translate(-50%, -50%) rotate(0deg);
    animation: ai-ask-spin 9s linear infinite;
    pointer-events: none;
}

@keyframes ai-ask-spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Белая маска поверх вращающейся заливки: видна только кромка */
.ai-ask__glow-mask {
    position: absolute;
    z-index: 1;
    inset: 1px;
    border-radius: calc(var(--ai-radius) - 1px);
    background: linear-gradient(135deg, #f4f9fc 0%, #f0f8f5 100%);
    pointer-events: none;
}

/* ── свёрнутое состояние ─────────────────────────────────────────────────── */

.ai-ask__summary {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    cursor: pointer;
    list-style: none;
    border-radius: var(--ai-radius);
    transition: background-color 0.2s ease;
}

.ai-ask__summary::-webkit-details-marker,
.ai-ask__summary::marker {
    display: none;
    content: "";
}

.ai-ask__summary:hover {
    background: rgba(11, 94, 134, 0.045);
}

.ai-ask__summary:focus-visible {
    outline: 3px solid var(--ai-accent);
    outline-offset: -3px;
}

/* Метка AI. Ореол дышит, пока блок закрыт: это единственное, что подсказывает,
   что здесь можно спросить. Как только блок открыт — дыхание прекращается,
   чтобы не отвлекать от ввода. */
.ai-ask__mark {
    position: relative;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(140deg, var(--ai-accent) 0%, var(--ai-accent-2) 100%);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ai-ask__mark::after {
    content: "";
    position: absolute;
    inset: -6px;
    border-radius: 50%;
    border: 1px solid var(--ai-accent);
    opacity: 0;
    animation: ai-ask-halo 3.2s ease-out infinite;
}

.ai-ask[open] .ai-ask__mark::after {
    animation: none;
}

.ai-ask__summary:hover .ai-ask__mark {
    transform: scale(1.06);
}

@keyframes ai-ask-halo {
    0% { transform: scale(0.86); opacity: 0; }
    35% { opacity: 0.45; }
    100% { transform: scale(1.25); opacity: 0; }
}

.ai-ask__mark--small {
    width: 28px;
    height: 28px;
    font-size: 10px;
}

.ai-ask__mark--small::after {
    display: none;
}

.ai-ask__summary-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ai-ask__title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: #18201d;
    line-height: 1.25;
}

.ai-ask__hint {
    font-size: 0.875rem;
    color: #4a5157;
    line-height: 1.35;
}

.ai-ask__chevron {
    flex: 0 0 auto;
    width: 10px;
    height: 10px;
    margin-left: auto;
    border-right: 2px solid var(--ai-accent);
    border-bottom: 2px solid var(--ai-accent);
    transform: rotate(45deg) translate(-2px, -2px);
    transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.ai-ask[open] .ai-ask__chevron {
    transform: rotate(225deg) translate(-2px, -2px);
}

/* ── раскрытие ───────────────────────────────────────────────────────────── */

/* details по умолчанию просто прячет содержимое, поэтому анимировать нечего.
   Обёртка остаётся в потоке всегда и складывается через grid-строку 0fr → 1fr;
   visibility убирает содержимое из фокуса, пока блок закрыт. */
.ai-ask .ai-ask__reveal {
    position: relative;
    z-index: 2;
    display: grid;
    grid-template-rows: 0fr;
    visibility: hidden;
    transition:
        grid-template-rows 0.38s cubic-bezier(0.22, 1, 0.36, 1),
        visibility 0.38s;
}

.ai-ask[open] .ai-ask__reveal {
    grid-template-rows: 1fr;
    visibility: visible;
}

.ai-ask__body {
    min-height: 0;
    overflow: hidden;
    padding: 0 18px;
}

.ai-ask[open] .ai-ask__body {
    border-top: 1px solid var(--ai-line);
    padding-bottom: 18px;
}

/* Содержимое въезжает по очереди — сверху вниз, короткими шагами */
.ai-ask[open] .ai-ask__samples,
.ai-ask[open] .ai-ask__field,
.ai-ask[open] .ai-ask__captcha,
.ai-ask[open] .ai-ask__actions,
.ai-ask[open] .ai-ask__note {
    animation: ai-ask-rise 0.42s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.ai-ask[open] .ai-ask__field { animation-delay: 0.05s; }
.ai-ask[open] .ai-ask__captcha { animation-delay: 0.1s; }
.ai-ask[open] .ai-ask__actions { animation-delay: 0.14s; }
.ai-ask[open] .ai-ask__note { animation-delay: 0.18s; }

@keyframes ai-ask-rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

/* ── готовые вопросы ─────────────────────────────────────────────────────── */

.ai-ask__samples {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0;
}

.ai-ask__sample {
    position: relative;
    padding: 9px 15px;
    border: 1px solid var(--ai-line);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.75);
    color: var(--ai-accent);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition:
        transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1),
        border-color 0.18s ease,
        background-color 0.18s ease,
        box-shadow 0.18s ease;
}

.ai-ask__sample:hover,
.ai-ask__sample:focus-visible {
    transform: translateY(-2px);
    border-color: var(--ai-accent);
    background: #fff;
    box-shadow: 0 6px 16px rgba(11, 94, 134, 0.12);
}

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

/* ── поля ────────────────────────────────────────────────────────────────── */

.ai-ask__label {
    display: block;
    margin-bottom: 6px;
    color: #4a5157;
    font-size: 0.875rem;
    font-weight: 600;
}

.ai-ask__input {
    display: block;
    width: 100%;
    min-height: 96px;
    padding: 13px 15px;
    border: 1px solid rgba(24, 32, 29, 0.14);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.85);
    color: #18201d;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.45;
    resize: vertical;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}

.ai-ask__input:focus {
    outline: 0;
    background: #fff;
    border-color: var(--ai-accent);
    box-shadow: 0 0 0 4px rgba(11, 94, 134, 0.12);
}

.ai-ask__captcha {
    display: flex;
    align-items: flex-end;
    gap: 14px;
    margin-top: 16px;
}

.ai-ask__captcha-image {
    flex: 0 0 auto;
    height: 50px;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.ai-ask__captcha-image:hover {
    transform: scale(1.03);
    box-shadow: 0 6px 16px rgba(11, 94, 134, 0.16);
}

.ai-ask__captcha-field {
    flex: 1 1 auto;
    min-width: 0;
}

.ai-ask__captcha-input {
    display: block;
    width: 100%;
    max-width: 210px;
    min-height: 50px;
    padding: 0 15px;
    border: 1px solid rgba(24, 32, 29, 0.14);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.85);
    font-family: inherit;
    font-size: 1rem;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-ask__captcha-input:focus {
    outline: 0;
    border-color: var(--ai-accent);
    box-shadow: 0 0 0 4px rgba(11, 94, 134, 0.12);
}

/* ── кнопка ──────────────────────────────────────────────────────────────── */

.ai-ask__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-top: 18px;
}

.ai-ask__btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 50px;
    /* Ширина зафиксирована: в состоянии запроса подпись сменяется точками,
       и без этого кнопка схлопывалась в маленький квадрат. */
    min-width: 168px;
    padding: 0 28px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--ai-accent) 0%, var(--ai-accent-2) 140%);
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.16s ease, box-shadow 0.22s ease;
}

.ai-ask__btn:hover,
.ai-ask__btn:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 10px 22px rgba(11, 94, 134, 0.26);
}

.ai-ask__btn:active {
    transform: translateY(1px);
    box-shadow: 0 4px 10px rgba(11, 94, 134, 0.2);
}

/* Блик пробегает по кнопке при наведении */
.ai-ask__btn::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: -60%;
    width: 40%;
    background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.32), transparent);
    transform: skewX(-18deg);
    transition: left 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.ai-ask__btn:hover::before {
    left: 130%;
}

.ai-ask__btn[disabled] {
    opacity: 0.75;
    cursor: default;
    transform: none;
    box-shadow: none;
}

.ai-ask__btn[disabled]::before {
    display: none;
}

/* Точки в кнопке вместо подписи, пока идёт запрос */
.ai-ask__dots {
    display: none;
    align-items: center;
    gap: 5px;
}

.ai-ask__dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #fff;
    animation: ai-ask-bounce 1.1s ease-in-out infinite;
}

.ai-ask__dots i:nth-child(2) { animation-delay: 0.16s; }
.ai-ask__dots i:nth-child(3) { animation-delay: 0.32s; }

@keyframes ai-ask-bounce {
    0%, 70%, 100% { transform: translateY(0); opacity: 0.55; }
    35% { transform: translateY(-5px); opacity: 1; }
}

.ai-ask.is-thinking .ai-ask__btn-label { display: none; }
.ai-ask.is-thinking .ai-ask__dots { display: inline-flex; }

.ai-ask__status {
    font-size: 0.9375rem;
    color: #4a5157;
}

.ai-ask__status[data-state="error"] { color: #b3261e; }
.ai-ask__status[data-state="success"] { color: #1a6b39; }

.ai-ask__note {
    margin: 14px 0 0;
    color: #606669;
    font-size: 0.8125rem;
    line-height: 1.45;
}

/* ── ожидание ответа ─────────────────────────────────────────────────────── */

/* Три строки-заглушки с бегущим бликом: видно, что ответ пишется */
.ai-ask__skeleton {
    display: none;
    margin-top: 18px;
    padding: 16px 18px;
    border: 1px solid var(--ai-line);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.7);
}

.ai-ask.is-thinking .ai-ask__skeleton {
    display: block;
    animation: ai-ask-rise 0.3s ease both;
}

.ai-ask__skeleton span {
    display: block;
    height: 12px;
    border-radius: 999px;
    background: linear-gradient(90deg, #e8eef2 25%, #f6fafc 50%, #e8eef2 75%);
    background-size: 200% 100%;
    animation: ai-ask-shimmer 1.4s linear infinite;
}

.ai-ask__skeleton span + span { margin-top: 10px; }
.ai-ask__skeleton span:nth-child(2) { width: 92%; animation-delay: 0.1s; }
.ai-ask__skeleton span:nth-child(3) { width: 64%; animation-delay: 0.2s; }

@keyframes ai-ask-shimmer {
    to { background-position: -200% 0; }
}

/* ── ответ ───────────────────────────────────────────────────────────────── */

.ai-ask__answer {
    margin-top: 18px;
    padding: 18px;
    border: 1px solid var(--ai-line);
    border-radius: 16px;
    background: linear-gradient(135deg, #f4f9fc 0%, #eef7f4 100%);
    animation: ai-ask-answer-in 0.45s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes ai-ask-answer-in {
    from { opacity: 0; transform: translateY(12px) scale(0.99); }
    to { opacity: 1; transform: none; }
}

.ai-ask__answer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.ai-ask__answer-title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #18201d;
}

.ai-ask__answer-text {
    color: #2b3531;
    font-size: 1rem;
    line-height: 1.55;
    white-space: pre-line;
}

/* Курсор набора: ответ приходит потоком, и видно, что он ещё пишется */
.ai-ask.is-thinking .ai-ask__answer-text::after {
    content: "";
    display: inline-block;
    width: 2px;
    height: 1.05em;
    margin-left: 2px;
    vertical-align: -0.16em;
    background: var(--ai-accent);
    animation: ai-ask-caret 1s steps(2, start) infinite;
}

@keyframes ai-ask-caret {
    to { opacity: 0; }
}

.ai-ask__rating {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--ai-line);
}

.ai-ask__rating-label {
    color: #4a5157;
    font-size: 0.875rem;
}

.ai-ask__rating-stars {
    display: flex;
    gap: 2px;
}

/* Класс is-selected навешивает скрипт карточки — не переименовывать */
.ai-ask__star {
    padding: 2px 3px;
    border: 0;
    background: none;
    color: #c8d2d8;
    font-size: 1.375rem;
    line-height: 1;
    cursor: pointer;
    transition: color 0.14s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.ai-ask__star:hover,
.ai-ask__star.is-selected {
    color: #e8a33d;
}

.ai-ask__star:hover {
    transform: scale(1.18) rotate(-6deg);
}

.ai-ask__rating-status {
    color: #1a6b39;
    font-size: 0.875rem;
}

@media (max-width: 575.98px) {
    .ai-ask__summary { padding: 14px; gap: 12px; }
    .ai-ask__body { padding: 0 14px; }
    .ai-ask[open] .ai-ask__body { padding-bottom: 16px; }
    .ai-ask__mark { width: 36px; height: 36px; font-size: 11px; }
    .ai-ask__title { font-size: 1rem; }
    .ai-ask__captcha { flex-wrap: wrap; }
    .ai-ask__captcha-input { max-width: none; }
    .ai-ask__btn { width: 100%; }
}

/* Полное выключение движения по системной настройке */
@media (prefers-reduced-motion: reduce) {
    .ai-ask *,
    .ai-ask *::before,
    .ai-ask *::after,
    .ai-ask__glow {
        animation: none !important;
        transition: none !important;
    }

    .ai-ask__glow { opacity: 0.3; }
}
