/* ============================================================
   Чат-виджет — плавающая кнопка + всплывающее окно
   ============================================================ */

/* ---------- Плавающая кнопка ---------- */
.chat-fab {
    position: fixed;
    right: 24px;
    bottom: 84px;
    z-index: 1200;
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: var(--grad-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--c-shadow-md);
    transition: transform var(--tr), box-shadow var(--tr), opacity var(--tr);
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: var(--c-shadow-lg);
}

.chat-fab.is-hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(.6);
}

.chat-fab-icon {
    width: 26px;
    height: 26px;
}

.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--c-danger);
    color: #fff;
    font-size: .75rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(214, 69, 69, .4);
}

/* ---------- Окно чата ---------- */
.chat-widget {
    position: fixed;
    right: 24px;
    bottom: 84px;
    z-index: 1210;
    width: min(380px, calc(100vw - 32px));
    max-height: min(560px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--c-shadow-lg);
    overflow: hidden;
    animation: chat-widget-in .28s cubic-bezier(.16, 1, .3, 1);
}

@keyframes chat-widget-in {
    from { opacity: 0; transform: translateY(16px) scale(.96); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* display:flex выше перекрывает браузерный [hidden] — восстанавливаем скрытие */
.chat-widget[hidden] { display: none; }

.chat-widget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--grad-primary);
    color: #fff;
}

.chat-widget-title {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: .01em;
}

.chat-widget-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1rem;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--tr);
}

.chat-widget-close:hover {
    background: rgba(255, 255, 255, .22);
}

.chat-widget-info {
    padding: 10px 16px;
    font-size: .82rem;
    color: var(--c-muted);
    background: var(--c-primary-faint);
    border-bottom: 1px solid var(--c-border);
}

.chat-guest-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--c-border);
    background: var(--c-bg);
}

.chat-guest-fields[hidden] { display: none; }

.chat-guest-fields input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    font-size: .88rem;
    background: var(--c-bg-alt);
    transition: border-color var(--tr);
}

.chat-guest-fields input:focus {
    outline: none;
    border-color: var(--c-primary);
    background: #fff;
}

/* ---------- Лента сообщений ---------- */
.chat-widget-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--c-bg);
    min-height: 180px;
}

.chat-empty {
    margin: auto;
    color: var(--c-muted);
    font-size: .88rem;
    text-align: center;
    padding: 24px 12px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

.chat-msg-user {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-msg-admin {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-msg-bubble {
    padding: 9px 13px;
    border-radius: 14px;
    font-size: .9rem;
    line-height: 1.45;
    word-break: break-word;
    white-space: pre-wrap;
}

.chat-msg-user .chat-msg-bubble {
    background: var(--grad-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-admin .chat-msg-bubble {
    background: var(--c-bg-alt);
    color: var(--c-ink);
    border: 1px solid var(--c-border);
    border-bottom-left-radius: 4px;
}

.chat-msg-time {
    margin-top: 3px;
    font-size: .7rem;
    color: var(--c-muted);
}

/* ---------- Форма отправки ---------- */
.chat-widget-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--c-border);
    background: var(--c-bg);
}

.chat-widget-form textarea {
    flex: 1 1 auto;
    resize: none;
    border: 1px solid var(--c-border);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font-size: .9rem;
    max-height: 120px;
    background: var(--c-bg-alt);
    transition: border-color var(--tr);
}

.chat-widget-form textarea:focus {
    outline: none;
    border-color: var(--c-primary);
    background: #fff;
}

.chat-widget-send {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--grad-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform var(--tr), opacity var(--tr);
}

.chat-widget-send svg {
    width: 18px;
    height: 18px;
}

.chat-widget-send:hover {
    transform: scale(1.06);
}

.chat-widget-send:disabled {
    opacity: .55;
    cursor: wait;
}

/* ---------- Мобильная версия ---------- */
@media (max-width: 640px) {
    .chat-fab {
        right: 12px;
        bottom: 72px;
        width: 52px;
        height: 52px;
    }

    /* Кнопка-«язычок», прилепленная к правому краю (в пределах экрана) */
    .chat-fab.is-docked {
        right: 0;
        width: 48px;
        height: 44px;
        border-radius: 22px 0 0 22px;
    }

    .chat-fab.is-docked:hover {
        transform: none;
    }

    .chat-fab.is-docked .chat-fab-badge {
        right: auto;
        left: 2px;
        top: -4px;
    }

    .chat-widget {
        /* Полноэкранный bottom sheet */
        right: 0;
        left: 0;
        bottom: 0;
        width: 100vw;
        max-width: none;
        max-height: calc(100dvh - 60px);
        height: calc(100dvh - 60px);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-left: none;
        border-right: none;
        border-bottom: none;
        animation: chat-widget-sheet-in .28s cubic-bezier(.16, 1, .3, 1);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .chat-widget-head {
        padding: 14px 16px;
        padding-top: calc(14px + env(safe-area-inset-top, 0));
    }

    .chat-widget-close {
        width: 36px;
        height: 36px;
        font-size: 1.15rem;
    }

    .chat-widget-info {
        font-size: .8rem;
        padding: 8px 14px;
    }

    .chat-guest-fields input {
        font-size: 16px; /* против авто-зума iOS */
    }

    .chat-widget-form {
        padding: 10px 12px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0));
    }

    .chat-widget-form textarea {
        font-size: 16px; /* против авто-зума iOS */
        min-height: 44px; /* комфортная высота тапа */
    }

    .chat-widget-send {
        width: 44px;
        height: 44px;
    }

    .chat-widget-form,
    .chat-widget-head {
        padding-left: max(12px, env(safe-area-inset-left, 0));
        padding-right: max(12px, env(safe-area-inset-right, 0));
    }
}

@keyframes chat-widget-sheet-in {
    from { opacity: 0; transform: translateY(40px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ---------- Тизер «Есть вопрос?» (только главная) ---------- */
.chat-teaser {
    position: fixed;
    right: 24px;
    bottom: 152px; /* над кнопкой чата (84 + 56 + 12) */
    z-index: 1190;
    max-width: 230px;
    padding: 14px 34px 14px 16px;
    border-radius: var(--radius-lg);
    border-bottom-right-radius: 6px;
    background: var(--c-bg);
    border: 1px solid var(--c-border);
    box-shadow: var(--c-shadow-lg);
    font-size: .85rem;
    line-height: 1.4;
    color: var(--c-ink);
    cursor: pointer;
    animation: chat-teaser-in .3s cubic-bezier(.16, 1, .3, 1);
}

.chat-teaser strong {
    display: block;
    margin-bottom: 2px;
    font-size: .92rem;
}

.chat-teaser-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--c-muted);
    font-size: .72rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--tr), color var(--tr);
}

.chat-teaser-close:hover {
    background: var(--c-bg-alt);
    color: var(--c-ink);
}

.chat-teaser[hidden] { display: none; }

@keyframes chat-teaser-in {
    from { opacity: 0; transform: translateY(12px) scale(.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Мобильная версия тизера */
@media (max-width: 640px) {
    .chat-teaser {
        right: 12px;
        bottom: 132px; /* над кнопкой чата */
        left: 12px;
        max-width: none;
        font-size: .82rem;
    }

    .chat-teaser-close {
        width: 28px;
        height: 28px;
        font-size: .85rem;
    }
}

/* ---------- Стрелка «наверх» не должна перекрывать чат ---------- */
@media (max-width: 640px) {
    .scroll-top {
        right: 14px;
        bottom: 136px; /* над кнопкой чата (72 + 52 + 12) */
    }
}


.chat-fab, .chat-widget-head { color: #203014; }
.chat-widget-close { color: #203014; width: 40px; height: 40px; }
.chat-widget-send { min-width: 44px; min-height: 44px; }
.chat-teaser-close { min-width: 40px; min-height: 40px; }
.chat-guest-fields input { min-height: 44px; }


.chat-widget-head {
    padding-top: 14px;
    padding-right: 16px;
    padding-bottom: 14px;
    padding-left: 16px;
}
