/* AI-чат виджет: изолированные стили (корзина/каталог/заказ не затрагиваются) */

.ai-chat-fab {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 1080;
    width: 60px;
    height: 60px;
    border: none;
    border-radius: 50%;
    background: #6b4423;
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-chat-fab:hover,
.ai-chat-fab:focus-visible {
    transform: scale(1.06);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.3);
    outline: none;
}

.ai-chat-fab.is-hidden {
    visibility: hidden;
    pointer-events: none;
    opacity: 0;
}

.ai-chat-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1080;
    background: rgba(43, 28, 16, 0.18);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.ai-chat-backdrop.is-visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.ai-chat-window {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 1081;
    width: 400px;
    max-width: calc(100vw - 48px);
    height: 620px;
    max-height: min(700px, calc(100vh - 48px));
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 16px 48px rgba(61, 40, 24, 0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: inherit;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(12px);
    transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}

.ai-chat-window.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.ai-chat-header {
    background: #6b4423;
    color: #fff;
    min-height: 60px;
    padding: 10px 12px 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.ai-chat-header__avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    line-height: 1;
}

.ai-chat-header__text {
    flex: 1;
    min-width: 0;
}

.ai-chat-header__title {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    line-height: 1.2;
    color: #fff;
}

.ai-chat-header__subtitle {
    margin: 2px 0 0;
    font-size: 12px;
    line-height: 1.2;
    color: rgba(255, 255, 255, 0.82);
}

.ai-chat-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    flex-shrink: 0;
    padding: 0;
}

.ai-chat-close:hover,
.ai-chat-close:focus-visible {
    background: rgba(255, 255, 255, 0.14);
    outline: none;
}

.ai-chat-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
    padding: 14px 16px 20px;
    background: #faf7f4;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-chat-msg {
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.ai-chat-msg--user {
    max-width: 82%;
    align-self: flex-end;
    background: #6b4423;
    color: #fff;
    border-bottom-right-radius: 4px;
    white-space: pre-wrap;
}

.ai-chat-msg--bot {
    max-width: 88%;
    align-self: flex-start;
    background: #fff;
    color: #2b1c10;
    border: 1px solid #e6ddd4;
    border-bottom-left-radius: 4px;
    white-space: normal;
}

.ai-chat-msg--bot .ai-chat-md-p {
    margin: 0 0 0.45em;
}

.ai-chat-msg--bot .ai-chat-md-p:last-child {
    margin-bottom: 0;
}

.ai-chat-msg--bot ul,
.ai-chat-msg--bot ol {
    margin: 0.25em 0 0.45em;
    padding-left: 1.25em;
}

.ai-chat-msg--bot li {
    margin: 0.15em 0;
}

.ai-chat-msg--bot strong {
    font-weight: 700;
}

.ai-chat-msg--error {
    background: #fdecea;
    color: #b3261e;
    border-color: #f5c6c2;
}

.ai-chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 2px 0 4px;
}

.ai-chat-quick.is-hidden {
    display: none;
}

.ai-chat-chip {
    border: 1px solid #d8ccc0;
    background: #fff;
    color: #4a3420;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1.2;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}

.ai-chat-chip:hover,
.ai-chat-chip:focus-visible {
    border-color: #6b4423;
    background: #f3ebe3;
    outline: none;
}

.ai-chat-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #ece4db;
    background: #fff;
    flex-shrink: 0;
}

.ai-chat-input {
    flex: 1;
    min-width: 0;
    height: 46px;
    border: 1px solid #d8ccc0;
    border-radius: 14px;
    padding: 0 14px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    background: #fff;
    color: #2b1c10;
}

.ai-chat-input:focus {
    border-color: #6b4423;
}

.ai-chat-send {
    width: 46px;
    height: 46px;
    min-width: 46px;
    min-height: 46px;
    border: none;
    border-radius: 14px;
    background: #6b4423;
    color: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.ai-chat-send:hover,
.ai-chat-send:focus-visible {
    background: #5a381c;
    outline: none;
}

.ai-chat-send:disabled {
    opacity: 0.6;
    cursor: default;
}

/* На мобильных в правом нижнем углу есть кнопка корзины (.cart-fab) */
@media (max-width: 991.98px) {
    .ai-chat-fab {
        bottom: calc(150px + env(safe-area-inset-bottom, 0px));
    }
}

/* Мобильный плавающий чат */
@media (max-width: 768px) {
    .ai-chat-window {
        left: 50%;
        right: auto;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        width: calc(100% - 24px);
        max-width: 430px;
        height: 78vh;
        height: 78dvh;
        max-height: 720px;
        min-height: 480px;
        border-radius: 20px;
        box-shadow: 0 14px 40px rgba(61, 40, 24, 0.3);
        transform: translate(-50%, 12px);
    }

    .ai-chat-window.is-open {
        transform: translate(-50%, 0);
    }

    .ai-chat-body {
        padding: 14px 14px 22px;
        gap: 8px;
    }

    .ai-chat-footer {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}

/* Низкие экраны: не выходить за viewport */
@media (max-width: 768px) and (max-height: 620px) {
    .ai-chat-window {
        min-height: 0;
        height: calc(100vh - 24px - env(safe-area-inset-bottom, 0px));
        height: calc(100dvh - 24px - env(safe-area-inset-bottom, 0px));
        max-height: none;
    }
}
