/* Floating site chat widget */
.site-chat-fab {
    position: fixed;
    right: 16px;
    bottom: calc(74px + env(safe-area-inset-bottom, 0px));
    z-index: 1110;
    display: none;
    align-items: center;
    gap: 8px;
    min-height: 46px;
    max-width: calc(100vw - 32px);
    padding: 0 15px 0 13px;
    border: 0;
    border-radius: 999px;
    background: #8b1f1f;
    color: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transform: translateY(14px);
    opacity: 0;
    transition: opacity 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.site-chat-fab.visible {
    display: inline-flex;
    opacity: 1;
    transform: translateY(0);
}

.site-chat-fab:active {
    transform: translateY(1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
}

.site-chat-fab-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    font-size: 17px;
    line-height: 1;
}

.site-chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border: 2px solid #fff;
    border-radius: 999px;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    line-height: 16px;
    text-align: center;
    box-sizing: border-box;
}

.site-chat-panel {
    position: fixed;
    right: 12px;
    bottom: calc(126px + env(safe-area-inset-bottom, 0px));
    z-index: 1120;
    display: none;
    flex-direction: column;
    width: min(370px, calc(100vw - 24px));
    max-height: min(570px, calc(100vh - 150px));
    min-width: 320px;
    min-height: 360px;
    overflow: hidden;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.28);
    border: 1px solid rgba(139, 31, 31, 0.12);
}

.site-chat-panel.open {
    display: flex;
}

.site-chat-panel.site-chat-fullscreen {
    left: 14px;
    right: 14px;
    top: var(--site-chat-fullscreen-top, 86px);
    bottom: var(--site-chat-fullscreen-bottom, 76px);
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    min-width: 0;
    min-height: 0;
    border-radius: 18px;
}

.site-chat-panel.site-chat-fullscreen .site-chat-expand {
    background: rgba(255, 255, 255, 0.28);
}

.site-chat-panel.site-chat-fullscreen .site-chat-resize-handle {
    display: none;
}

.site-chat-resize-handle {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 2;
    display: none;
    width: 24px;
    height: 24px;
    cursor: nwse-resize;
}

.site-chat-resize-handle::before {
    content: '';
    position: absolute;
    top: 7px;
    left: 7px;
    width: 9px;
    height: 9px;
    border-top: 2px solid rgba(255, 255, 255, 0.62);
    border-left: 2px solid rgba(255, 255, 255, 0.62);
    border-top-left-radius: 2px;
}

.site-chat-panel.site-chat-resizing,
.site-chat-panel.site-chat-resizing * {
    user-select: none;
}

@media (min-width: 769px) {
    .site-chat-resize-handle {
        display: block;
    }
}

.site-chat-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 14px 12px;
    background: linear-gradient(135deg, #8b1f1f, #b54a35);
    color: #fff;
}

.site-chat-title {
    font-size: 16px;
    font-weight: 800;
    line-height: 1.2;
}

.site-chat-status {
    margin-top: 3px;
    color: rgba(255, 255, 255, 0.84);
    font-size: 12px;
    line-height: 1.25;
}

.site-chat-status.waiting {
    color: #ffe6b0;
}

.site-chat-status.error {
    color: #ffe0e0;
}

.site-chat-header-actions {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.site-chat-header-btn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    cursor: pointer;
    transition: background 0.16s ease, transform 0.16s ease;
}

.site-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.24);
}

.site-chat-header-btn:active {
    transform: translateY(1px);
}

.site-chat-close {
    font-size: 24px;
    line-height: 28px;
}

.site-chat-expand {
    font-size: 16px;
    line-height: 1;
}

.site-chat-messages {
    flex: 1 1 auto;
    min-height: 190px;
    padding: 14px;
    overflow-y: auto;
    background: #fbf7f2;
}

.site-chat-empty {
    padding: 18px 14px;
    border-radius: 14px;
    background: rgba(139, 31, 31, 0.06);
    color: #6b5a50;
    font-size: 14px;
    line-height: 1.42;
}

.site-chat-message {
    display: flex;
    flex-direction: column;
    margin-bottom: 10px;
}

.site-chat-message-label {
    margin: 0 8px 4px;
    color: #8a7a70;
    font-size: 11px;
    font-weight: 700;
}

.site-chat-message-user {
    align-items: flex-end;
}

.site-chat-message-ai,
.site-chat-message-operator {
    align-items: flex-start;
}

.site-chat-message-bubble {
    max-width: 88%;
    padding: 10px 12px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.42;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.site-chat-message-user .site-chat-message-bubble {
    border-bottom-right-radius: 5px;
    background: #8b1f1f;
    color: #fff;
}

.site-chat-message-ai .site-chat-message-bubble,
.site-chat-message-operator .site-chat-message-bubble {
    border-bottom-left-radius: 5px;
    background: #fff;
    color: #2d2420;
}

.site-chat-message-status {
    margin-top: 4px;
    color: rgba(255, 255, 255, 0.75);
    font-size: 11px;
}

.site-chat-message-ai .site-chat-message-status,
.site-chat-message-operator .site-chat-message-status {
    color: #9a8b82;
}

.site-chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px;
    border-top: 1px solid rgba(139, 31, 31, 0.10);
    background: #fff;
}

.site-chat-input {
    flex: 1 1 auto;
    min-height: 42px;
    max-height: 120px;
    resize: none;
    padding: 10px 12px;
    border: 1px solid #e0d6cf;
    border-radius: 14px;
    outline: none;
    font-size: 15px;
    line-height: 1.35;
    font-family: inherit;
}

.site-chat-input:focus {
    border-color: #8b1f1f;
    box-shadow: 0 0 0 3px rgba(139, 31, 31, 0.10);
}

.site-chat-send {
    flex: 0 0 auto;
    min-height: 42px;
    padding: 0 13px;
    border: 0;
    border-radius: 14px;
    background: #8b1f1f;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.site-chat-send:disabled {
    opacity: 0.55;
    cursor: default;
}

@media (max-width: 480px) {
    .site-chat-fab {
        right: 12px;
        bottom: calc(72px + env(safe-area-inset-bottom, 0px));
        min-height: 44px;
        padding: 0 13px;
    }

    .site-chat-fab-text {
        display: none;
    }

    .site-chat-panel {
        right: 8px;
        left: 8px;
        width: auto;
        min-width: 0;
        min-height: 0;
        bottom: calc(122px + env(safe-area-inset-bottom, 0px));
        max-height: min(560px, calc(100vh - 145px));
        border-radius: 18px;
    }

    .site-chat-expand,
    .site-chat-resize-handle {
        display: none;
    }

    .site-chat-panel.site-chat-fullscreen {
        left: 8px;
        right: 8px;
        top: auto;
        bottom: calc(122px + env(safe-area-inset-bottom, 0px));
        width: auto !important;
        height: auto !important;
        max-height: min(560px, calc(100vh - 145px)) !important;
        border-radius: 18px;
    }

    .site-chat-message-bubble {
        max-width: 92%;
    }
}

.site-chat-history-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 0 0 12px;
    padding: 9px 10px;
    border-radius: 12px;
    background: rgba(139, 31, 31, 0.07);
    color: #6b5a50;
    font-size: 12px;
    line-height: 1.3;
}

.site-chat-history-note {
    flex: 1 1 auto;
    min-width: 0;
}

.site-chat-load-more {
    flex: 0 0 auto;
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid rgba(139, 31, 31, 0.22);
    border-radius: 999px;
    background: #fff;
    color: #8b1f1f;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
}

.site-chat-load-more:disabled {
    opacity: 0.55;
    cursor: default;
}

@media (max-width: 480px) {
    .site-chat-history-bar {
        align-items: flex-start;
        flex-direction: column;
        gap: 7px;
    }

    .site-chat-load-more {
        width: 100%;
    }
}

/* Фильтры истории по адаптерам */
.site-chat-channel-filters {
    flex: 0 0 auto;
    padding: 8px 10px 7px;
    border-bottom: 1px solid rgba(139, 31, 31, 0.10);
    background: #fff7f2;
}

.site-chat-channel-scroll {
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 1px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.site-chat-channel-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 29px;
    padding: 0 10px;
    border: 1px solid rgba(139, 31, 31, 0.18);
    border-radius: 999px;
    background: #fff;
    color: #6b4036;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    white-space: nowrap;
}

.site-chat-channel-chip.active {
    border-color: #8b1f1f;
    background: #8b1f1f;
    color: #fff;
}

.site-chat-channel-icon {
    font-size: 13px;
    line-height: 1;
}

.site-chat-channel-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: rgba(139, 31, 31, 0.10);
    color: inherit;
    font-size: 10px;
    font-weight: 800;
}

.site-chat-channel-chip.active .site-chat-channel-count {
    background: rgba(255, 255, 255, 0.22);
}

.site-chat-auth-hint {
    margin-top: 6px;
    color: #8a7a70;
    font-size: 11px;
    line-height: 1.25;
}

.site-chat-message-label {
    display: flex;
    align-items: center;
    gap: 5px;
}

.site-chat-message-channel-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(139, 31, 31, 0.09);
    color: #7a4a3f;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.1;
}

.site-chat-message-user .site-chat-message-channel-badge {
    background: rgba(255, 255, 255, 0.20);
    color: rgba(255, 255, 255, 0.92);
}

@media (max-width: 480px) {
    .site-chat-channel-filters {
        padding: 7px 8px 6px;
    }

    .site-chat-channel-chip {
        min-height: 28px;
        padding: 0 9px;
        font-size: 11px;
    }
}
