/* Кнопка вызова (FAB) */
.chat-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #111827;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 999;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-fab:hover {
    background: #DD0000;
    border-color: #DD0000;
    transform: scale(1.08);
}

.chat-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #DD0000;
    color: #ffffff;
    font-size: 10px;
    font-weight: 800;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
}

/* Окно чата */
.chat-window {
    position: fixed;
    bottom: 96px;
    right: 28px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: rgba(18, 18, 22, 0.96);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.3s ease-out;
}

@keyframes chatSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Шапка чата */
.chat-header {
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-status-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #34D399;
    box-shadow: 0 0 8px #34D399;
}

.chat-header-title {
    font-size: 13px;
    font-weight: 700;
    color: #ffffff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-header-subtitle {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-quick-link {
    color: rgba(255, 255, 255, 0.6);
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s;
}

.chat-quick-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.chat-close-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    margin-left: 4px;
}

.chat-close-btn:hover {
    color: #DD0000;
}

/* Верхняя плашка для гостей */
.chat-guest-banner {
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    padding: 8px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.7);
}

.chat-banner-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #ffffff;
    font-size: 10.5px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.chat-banner-btn:hover {
    border-color: #DD0000;
    color: #DD0000;
}

/* Раскрывающаяся шторка ввода контактов */
.chat-contact-drawer {
    background: #1A1A22;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    animation: drawerDown 0.2s ease-out;
}

@keyframes drawerDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-drawer-input {
    width: 100%;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    color: #ffffff;
    font-size: 12.5px;
    outline: none;
    box-sizing: border-box;
}

.chat-drawer-input:focus {
    border-color: rgba(255, 255, 255, 0.4);
}

.chat-consent-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 10.5px;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.35;
    cursor: pointer;
}

.chat-consent-row.error-highlight {
    color: #F87171;
}

.chat-consent-row input[type="checkbox"] {
    margin-top: 2px;
    accent-color: #DD0000;
    cursor: pointer;
}

.chat-privacy-link {
    color: rgba(255, 255, 255, 0.75);
    text-decoration: underline;
}

.chat-drawer-save-btn {
    padding: 7px 12px;
    background: #DD0000;
    color: #ffffff;
    border: none;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    align-self: flex-end;
    transition: opacity 0.2s ease;
}

.chat-drawer-save-btn:hover {
    opacity: 0.9;
}

/* Область сообщений */
.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

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

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

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

.chat-msg-system {
    align-self: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px dashed rgba(255, 255, 255, 0.18);
    color: rgba(255, 255, 255, 0.65);
    font-size: 11px;
    padding: 7px 12px;
    border-radius: 6px;
    text-align: center;
    max-width: 90%;
    line-height: 1.35;
}

.chat-bubble {
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.45;
    border-radius: 8px;
}

.chat-msg-manager .chat-bubble {
    background: rgba(255, 255, 255, 0.08);
    color: #F3F4F6;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-left-radius: 2px;
}

.chat-msg-client .chat-bubble {
    background: #DD0000;
    color: #ffffff;
    border-bottom-right-radius: 2px;
}

.chat-msg-time {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.4);
    margin-top: 4px;
    align-self: flex-end;
}

/* Строка ввода */
.chat-input-row {
    display: flex;
    align-items: center;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    gap: 8px;
}

.chat-input-field {
    flex: 1;
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 13.5px;
    outline: none;
}

.chat-input-field::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.chat-send-btn {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, transform 0.2s;
}

.chat-send-btn:hover {
    color: #DD0000;
    transform: scale(1.1);
}

/* Адаптив для смартфонов */
@media (max-width: 600px) {
    .chat-fab {
        bottom: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
    }

    .chat-window {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }

    .chat-header {
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chat-input-row {
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
}

/* Кнопка скрепки */
.chat-attach-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s ease;
}

.chat-attach-btn:hover {
    color: #ffffff;
}

/* Полоса прикрепленного файла в виджете */
.client-file-preview {
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.08);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.client-file-name {
    font-size: 11.5px;
    color: #ffffff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 85%;
}

.client-file-cancel {
    background: none;
    border: none;
    color: #F87171;
    font-size: 13px;
    cursor: pointer;
}

/* Карточка вложенного файла в сообщении клиента */
.chat-file-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    margin-top: 6px;
    text-decoration: none;
    color: #ffffff;
    font-size: 12px;
}

.chat-file-card:hover {
    background: rgba(0, 0, 0, 0.3);
}

.chat-msg-manager .chat-file-card {
    background: rgba(255, 255, 255, 0.08);
}