/* Виджет чата поддержки (панель). Кнопка «НАЧАТЬ ЧАТ» — в main.css */

.support-chat {
    --sc-w: min(400px, calc(100vw - 32px));
    --sc-h: min(640px, calc(100vh - 100px));
    --sc-blue: #1f64b7;
    --sc-blue-dark: #124b97;
    --sc-surface: #e8edf3;
    --sc-radius: 20px;
    position: absolute;
    right: 0;
    bottom: 0;
    z-index: 1;
    width: var(--sc-w);
    pointer-events: none;
}

.support-chat__panel {
    --sc-r: var(--sc-radius);
    position: relative;
    width: 100%;
    height: var(--sc-h);
    max-height: var(--sc-h);
    display: flex;
    flex-direction: column;
    border-radius: var(--sc-r);
    background: var(--sc-surface);
    box-shadow:
        0 0 0 1px rgba(18, 75, 151, 0.08),
        0 24px 48px rgba(15, 23, 42, 0.18),
        0 8px 24px rgba(31, 100, 183, 0.12);
    overflow: hidden;
    isolation: isolate;
    transform-origin: bottom right;
    transform: scale(0.12) translateZ(0);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        transform 0.48s cubic-bezier(0.34, 1.25, 0.52, 1),
        opacity 0.35s cubic-bezier(0.22, 0.61, 0.36, 1),
        visibility 0.35s,
        box-shadow 0.35s ease;
    will-change: transform;
}

.support-chat.is-open .support-chat__panel {
    transform: scale(1) translateZ(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* ——— Шапка ——— */
.support-chat .support-chat__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 14px 12px 16px;
    background: linear-gradient(125deg, #1a5fad 0%, #124b97 48%, #0f3d7a 100%);
    color: #fff;
    border: none;
    box-shadow: none;
    flex-shrink: 0;
}

.support-chat .support-chat__title,
.support-chat .support-chat__status,
.support-chat .support-chat__head-text {
    color: #fff;
}

.support-chat__head-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.support-chat__avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.support-chat__title {
    margin: 0;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.01em;
    line-height: 1.2;
}

.support-chat__status {
    margin: 4px 0 0;
    font-size: 12px;
    font-weight: 500;
    opacity: 0.92;
    display: flex;
    align-items: center;
    gap: 6px;
}

.support-chat__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.35);
    flex-shrink: 0;
}

.support-chat__dot--offline {
    background: #fbbf24;
    box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.35);
    animation: none;
}

.support-chat__dot:not(.support-chat__dot--offline) {
    animation: sc-dot-pulse 2s ease-in-out infinite;
}

@keyframes sc-dot-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.85; transform: scale(0.92); }
}

.support-chat__head-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.support-chat__head-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s, transform 0.12s;
}

.support-chat__head-btn:hover {
    background: rgba(255, 255, 255, 0.26);
    color: #fff;
}

.support-chat__head-btn:active {
    transform: scale(0.94);
}

/* ——— Баннер графика ——— */
.support-chat__banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 12px;
    font-weight: 600;
    color: #3d5a7a;
    background: rgba(255, 255, 255, 0.55);
    border-bottom: 1px solid rgba(18, 75, 151, 0.06);
    flex-shrink: 0;
}

.support-chat__banner i {
    color: var(--sc-blue);
    font-size: 13px;
}

.support-chat__banner[hidden] {
    display: none !important;
}

.support-chat__head-btn[hidden],
.support-chat__starter--call[hidden] {
    display: none !important;
}

/* ——— Лента сообщений ——— */
.support-chat__scroll {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    padding: 12px 0 8px;
    background:
        radial-gradient(ellipse 120% 80% at 50% 0%, rgba(255, 255, 255, 0.45) 0%, transparent 55%),
        var(--sc-surface);
}

.support-chat__scroll::-webkit-scrollbar {
    width: 5px;
}

.support-chat__scroll::-webkit-scrollbar-thumb {
    background: rgba(31, 100, 183, 0.25);
    border-radius: 8px;
}

.support-chat__messages {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 0 14px 8px;
}

.support-chat__date {
    align-self: center;
    margin: 10px 0 4px;
    padding: 4px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.72);
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.support-chat__row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 92%;
    animation: sc-msg-in 0.28s cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

@keyframes sc-msg-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

.support-chat__row--user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.support-chat__row--agent {
    align-self: flex-start;
}

.support-chat__msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(145deg, var(--sc-blue), var(--sc-blue-dark));
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 18px;
    box-shadow: 0 2px 8px rgba(31, 100, 183, 0.3);
}

.support-chat__msg-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 100%;
}

.support-chat__row--user .support-chat__msg-col {
    align-items: flex-end;
}

.support-chat__sender {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    padding: 0 4px;
}

.support-chat__bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    max-width: 100%;
}

.support-chat__bubble a {
    color: inherit;
    font-weight: 600;
    text-underline-offset: 2px;
}

.support-chat__bubble--agent {
    background: #fff;
    color: #1e293b;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 12px rgba(15, 23, 42, 0.04);
}

.support-chat__bubble--welcome {
    border: 1px solid rgba(31, 100, 183, 0.12);
    background: linear-gradient(180deg, #fff 0%, #f5f9fd 100%);
}

.support-chat__bubble--user {
    background: linear-gradient(145deg, #2a73c4 0%, var(--sc-blue-dark) 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 14px rgba(31, 100, 183, 0.35);
}

.support-chat__bubble--user a {
    color: #e0f2fe;
}

.support-chat__bubble--user .support-chat__msg-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 6px;
    padding-top: 2px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    color: rgba(255, 255, 255, 0.92);
}

.support-chat__bubble--user .support-chat__msg-footer .support-chat__msg-time {
    padding: 0;
    color: rgba(255, 255, 255, 0.88);
    font-size: 11px;
}

.support-chat__bubble--typing {
    display: inline-flex;
    gap: 5px;
    align-items: center;
    padding: 14px 18px;
    min-height: 44px;
}

.support-chat__typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: sc-typing 1.1s ease-in-out infinite;
}

.support-chat__typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.support-chat__typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes sc-typing {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.45;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

.support-chat__msg-time {
    font-size: 10px;
    font-weight: 600;
    color: #94a3b8;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.support-chat__bubble--copied {
    outline: 2px solid rgba(74, 222, 128, 0.65);
    outline-offset: 2px;
}

.support-chat__jump {
    position: sticky;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #fff;
    color: var(--sc-blue);
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.15);
    cursor: pointer;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s, box-shadow 0.15s;
    /* containing block for .support-chat__jump-badge */
    isolation: isolate;
}

.support-chat__jump:hover {
    transform: translateX(-50%) scale(1.05);
    box-shadow: 0 6px 24px rgba(31, 100, 183, 0.2);
}

.support-chat__jump[hidden] {
    display: none !important;
}

.support-chat__jump-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.45);
}

/* ——— Низ: подсказки + ввод ——— */
.support-chat__footer {
    flex-shrink: 0;
    background: #fff;
    border-top: 1px solid rgba(18, 75, 151, 0.08);
    box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.04);
}

.support-chat__starters {
    padding: 12px 14px 4px;
    transition: opacity 0.2s, max-height 0.25s;
}

.support-chat__starters.is-hidden {
    display: none;
}

.support-chat__starters-label {
    margin: 0 0 8px 2px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #94a3b8;
}

.support-chat__starter-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.support-chat__starter {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #f8fafc;
    color: #1e293b;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.support-chat__starter i {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #eef4fc;
    color: var(--sc-blue);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
}

.support-chat__starter:hover {
    border-color: #b8d4f0;
    background: #fff;
    box-shadow: 0 2px 8px rgba(31, 100, 183, 0.08);
}

.support-chat__starter--call {
    grid-column: 1 / -1;
    justify-content: center;
    background: #eef5fc;
    border-color: #c5daf2;
    color: var(--sc-blue);
}

.support-chat__starter--muted {
    color: #475569;
}

.support-chat__starter--muted:hover {
    border-color: #cbd5e1;
    background: #f1f5f9;
}

.support-chat__starter--call i {
    background: var(--sc-blue);
    color: #fff;
}

.support-chat__composer {
    padding: 10px 12px 14px;
}

.support-chat__composer-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 14px;
    border-radius: 16px;
    background: #f1f5f9;
    border: 1.5px solid transparent;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}

.support-chat__composer-box:focus-within {
    background: #fff;
    border-color: var(--sc-blue);
    box-shadow: 0 0 0 3px rgba(31, 100, 183, 0.12);
}

.support-chat__attach {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: none;
    border-radius: 12px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    transition: color 0.2s ease, background 0.2s ease;
}

.support-chat__attach:hover:not(:disabled) {
    color: var(--sc-blue);
    background: rgba(31, 100, 183, 0.08);
}

.support-chat__attach:disabled,
.support-chat__attach.is-busy {
    opacity: 0.45;
    cursor: wait;
}

.support-chat__bubble--image {
    padding: 6px;
    max-width: min(100%, 260px);
    width: fit-content;
}

.support-chat__img-link {
    display: block;
    border-radius: 10px;
    overflow: hidden;
    line-height: 0;
}

.support-chat__img {
    display: block;
    width: auto;
    height: auto;
    max-width: min(240px, 100%);
    max-height: min(320px, 38vh);
    object-fit: contain;
    object-position: top center;
    background: #e2e8f0;
}

.support-chat__caption {
    margin: 8px 4px 2px;
    font-size: 14px;
    line-height: 1.45;
}

.support-chat__bubble--user .support-chat__caption {
    margin-bottom: 0;
}

.support-chat__input {
    flex: 1;
    min-width: 0;
    min-height: 24px;
    max-height: 120px;
    padding: 8px 0;
    border: none;
    background: transparent;
    font-size: 15px;
    line-height: 1.45;
    font-family: inherit;
    color: #0f172a;
    resize: none;
    outline: none;
}

.support-chat__input::placeholder {
    color: #94a3b8;
}

.support-chat__send {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: 12px;
    background: linear-gradient(145deg, #2a73c4 0%, var(--sc-blue-dark) 100%);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(31, 100, 183, 0.28);
    transition: transform 0.15s, opacity 0.2s, box-shadow 0.2s;
}

.support-chat__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.support-chat__send:not(:disabled):hover {
    transform: translateY(-1px);
}

.support-chat__send:not(:disabled):active {
    transform: scale(0.94);
}

.support-chat__composer-meta {
    margin: 0;
    padding: 0 16px 8px;
    text-align: right;
}

.support-chat__composer-meta[hidden] {
    display: none !important;
}

.support-chat__char-count {
    font-size: 10px;
    font-weight: 700;
    color: #f59e0b;
    font-variant-numeric: tabular-nums;
}

/* Точка «новое» на кнопке «НАЧАТЬ ЧАТ» */
.support-chat-dock .help-widget {
    position: relative;
}

.help-widget-unread {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.35);
    pointer-events: none;
    font-size: 11px;
    font-weight: 800;
    line-height: 16px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    animation: supportChatBadgePop 0.35s ease;
}

@keyframes supportChatBadgePop {
    0% { transform: scale(0.4); opacity: 0; }
    70% { transform: scale(1.12); }
    100% { transform: scale(1); opacity: 1; }
}

.help-widget[data-support-unread="1"] {
    animation: supportChatLaunchPulse 1.6s ease-in-out infinite;
    box-shadow:
        0 0 0 0 rgba(239, 68, 68, 0.55),
        0 8px 24px rgba(31, 100, 183, 0.35);
}

@keyframes supportChatLaunchPulse {
    0%, 100% {
        box-shadow:
            0 0 0 0 rgba(239, 68, 68, 0.45),
            0 8px 24px rgba(31, 100, 183, 0.35);
    }
    50% {
        box-shadow:
            0 0 0 10px rgba(239, 68, 68, 0),
            0 8px 28px rgba(239, 68, 68, 0.28);
    }
}

.help-widget-unread[hidden] {
    display: none !important;
}

.support-chat-dock.is-open .help-widget-unread {
    display: none !important;
}

.support-chat-dock.is-open .help-widget[data-support-unread="1"] {
    animation: none;
}

/* ——— Мобильный ——— */
.support-chat-backdrop {
    display: none;
}

@media (max-width: 768px) {
    .support-chat-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 0;
        border: none;
        margin: 0;
        padding: 0;
        background: rgba(15, 23, 42, 0.48);
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
        transition: opacity 0.28s ease, visibility 0.28s;
    }

    .support-chat-dock.is-open {
        position: fixed;
        inset: 0;
        z-index: 12500;
        pointer-events: auto;
    }

    .support-chat-dock.is-open .support-chat-backdrop {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .support-chat-dock {
        right: 12px;
        left: auto;
        bottom: max(16px, env(safe-area-inset-bottom, 0px));
        width: auto;
    }

    .support-chat {
        --sc-w: 100%;
        --sc-h: min(88dvh, calc(100dvh - env(safe-area-inset-top, 0px) - 8px));
        --sc-radius: 18px 18px 0 0;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        width: 100%;
        max-width: none;
        z-index: 1;
        pointer-events: none;
    }

    .support-chat.is-open {
        pointer-events: auto;
    }

    .support-chat__panel {
        transform: translate3d(0, 105%, 0);
        transform-origin: bottom center;
        max-height: var(--sc-h);
        height: var(--sc-h);
        transition:
            transform 0.34s cubic-bezier(0.32, 0.72, 0, 1),
            opacity 0.28s ease,
            visibility 0.28s,
            height 0.2s ease,
            max-height 0.2s ease;
    }

    .support-chat.is-open .support-chat__panel {
        transform: translate3d(0, 0, 0);
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }

    .support-chat:not(.is-open) .support-chat__panel {
        transform: translate3d(0, 105%, 0) scale(1);
    }

    .support-chat.is-keyboard-open .support-chat__panel {
        height: var(--sc-visual-height, var(--sc-h));
        max-height: var(--sc-visual-height, var(--sc-h));
        border-radius: 14px 14px 0 0;
    }

    .support-chat__scroll {
        padding-top: 8px;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .support-chat__input {
        font-size: 16px;
    }

    .support-chat__footer {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .support-chat__composer {
        padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
    }

    .support-chat__starter-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 520px) {
    .support-chat-dock:not(.is-open) {
        right: 12px;
        left: auto;
        bottom: max(16px, env(safe-area-inset-bottom, 0px));
        width: auto;
    }
}

body.support-chat-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    body.support-chat-open {
        overflow: hidden;
        touch-action: none;
    }
}

@media (min-width: 769px) {
    body.support-chat-open {
        overflow: auto;
    }
}

@media (prefers-reduced-motion: reduce) {
    .support-chat__panel {
        transition: none !important;
    }

    .support-chat:not(.is-open) .support-chat__panel {
        transform: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    .support-chat.is-open .support-chat__panel {
        transform: none !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    @media (max-width: 768px) {
        .support-chat-backdrop {
            transition: none !important;
        }
    }

    .support-chat__row,
    .support-chat__dot,
    .support-chat__typing-dot {
        animation: none !important;
    }
}
