/* Плавающий виджет мессенджера (публичная часть сайта) */

.ucw {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9500;
    font-family: inherit;
}

/* ===== Плавающая кнопка ===== */
/* Скрыта, пока у посетителя нет диалогов/непрочитанных */
.ucw-fab { display: none; }
.ucw.ready .ucw-fab { display: flex; }

.ucw-fab {
    position: relative;
    width: 62px;
    height: 62px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: linear-gradient(135deg, #F6055B 0%, #8B5CF6 100%);
    color: #fff;
    box-shadow: 0 10px 26px rgba(246, 5, 91, 0.42);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: ucw-fab-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.ucw-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 32px rgba(246, 5, 91, 0.5); }
.ucw-fab:active { transform: scale(0.97); }

@keyframes ucw-fab-in {
    from { transform: scale(0) rotate(-30deg); opacity: 0; }
    to { transform: scale(1) rotate(0); opacity: 1; }
}

/* Пульсирующее кольцо */
.ucw-fab-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #F6055B 0%, #8B5CF6 100%);
    z-index: -1;
    animation: ucw-pulse 2.2s ease-out infinite;
}

@keyframes ucw-pulse {
    0% { transform: scale(1); opacity: 0.55; }
    70% { transform: scale(1.6); opacity: 0; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* Иконки (чат / крестик) */
.ucw-fab-icon {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.ucw-fab-icon svg { width: 27px; height: 27px; }
.ucw-fab-icon--close { transform: rotate(-90deg) scale(0.4); opacity: 0; }
.ucw.open .ucw-fab-icon--chat { transform: rotate(90deg) scale(0.4); opacity: 0; }
.ucw.open .ucw-fab-icon--close { transform: rotate(0) scale(1); opacity: 1; }
.ucw.open .ucw-fab-pulse { animation: none; opacity: 0; }

/* Анимированные точки (набор текста) */
.ucw-dot { animation: ucw-dot 1.4s infinite ease-in-out; transform-box: fill-box; transform-origin: center; }
.ucw-dot-2 { animation-delay: 0.2s; }
.ucw-dot-3 { animation-delay: 0.4s; }
@keyframes ucw-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
    30% { transform: translateY(-2.5px); opacity: 1; }
}

/* Бейдж непрочитанных */
.ucw-fab-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #fff;
    color: #F6055B;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    border: 2px solid #F6055B;
}

/* ===== Панель ===== */
.ucw-panel {
    position: absolute;
    right: 0;
    bottom: 78px;
    width: 380px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(17, 12, 34, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.25s ease, transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
}
.ucw.open .ucw-panel { opacity: 1; visibility: visible; transform: translateY(0) scale(1); }

.ucw-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ucw-view[hidden] { display: none; }

/* Шапка */
.ucw-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px 16px;
    background: linear-gradient(135deg, #F6055B 0%, #8B5CF6 100%);
    color: #fff;
    flex-shrink: 0;
}
.ucw-header-title { display: flex; align-items: center; gap: 9px; font-size: 17px; font-weight: 700; flex: 1; }
.ucw-close, .ucw-back {
    background: rgba(255,255,255,0.16);
    border: none; color: #fff;
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    transition: background 0.15s ease;
}
.ucw-close:hover, .ucw-back:hover { background: rgba(255,255,255,0.28); }

.ucw-conv-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.ucw-conv-avatar {
    width: 40px; height: 40px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
    background: rgba(255,255,255,0.22);
    display: flex; align-items: center; justify-content: center;
    font-size: 17px; font-weight: 700; border: 2px solid rgba(255,255,255,0.4);
}
.ucw-conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ucw-conv-name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.ucw-conv-sub { font-size: 14px; opacity: 0.85; }

/* Список диалогов */
.ucw-dialogs { flex: 1; overflow-y: auto; padding: 8px; background: #f7f7fb; }
.ucw-dialog-item {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 14px; cursor: pointer;
    transition: background 0.15s ease;
}
.ucw-dialog-item:hover { background: #fff; box-shadow: 0 1px 6px rgba(17,12,34,0.07); }
.ucw-dialog-avatar {
    width: 46px; height: 46px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
    background: linear-gradient(135deg, #e0e7ff 0%, #f3e8ff 100%);
    display: flex; align-items: center; justify-content: center;
    font-size: 19px; font-weight: 700; color: #8B5CF6;
    position: relative;
}
.ucw-dialog-avatar img { width: 100%; height: 100%; object-fit: cover; }
.ucw-dialog-content { flex: 1; min-width: 0; }
.ucw-dialog-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.ucw-dialog-name { font-size: 14.5px; font-weight: 600; color: #241f36; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ucw-dialog-time { font-size: 14px; color: #9a95ad; flex-shrink: 0; }
.ucw-dialog-preview { font-size: 14px; color: #7a7590; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.ucw-dialog-badge {
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
    background: linear-gradient(135deg, #F6055B 0%, #8B5CF6 100%);
    color: #fff; font-size: 14px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}

/* Пустое состояние / загрузка */
.ucw-empty, .ucw-loading { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: #8a86a0; text-align: center; padding: 24px; }
.ucw-empty-icon { width: 66px; height: 66px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; color: #8B5CF6; background: linear-gradient(135deg, rgba(246,5,91,0.1) 0%, rgba(139,92,246,0.1) 100%); }
.ucw-empty-title { font-size: 15px; font-weight: 700; color: #3a3552; margin-bottom: 5px; }
.ucw-empty-text { font-size: 14px; line-height: 1.5; max-width: 240px; }
.ucw-spinner { width: 30px; height: 30px; border: 3px solid rgba(139,92,246,0.2); border-top-color: #8B5CF6; border-radius: 50%; animation: ucw-spin 0.8s linear infinite; }
@keyframes ucw-spin { to { transform: rotate(360deg); } }

/* Сообщения */
.ucw-messages { flex: 1; overflow-y: auto; padding: 16px 14px; background: #f7f7fb; display: flex; flex-direction: column; gap: 8px; }
.ucw-msg { display: flex; max-width: 82%; }
.ucw-msg--sent { align-self: flex-end; justify-content: flex-end; }
.ucw-msg--received { align-self: flex-start; }
.ucw-msg-bubble { padding: 9px 13px 7px; border-radius: 18px; font-size: 14.5px; line-height: 1.4; word-break: break-word; }
.ucw-msg--sent .ucw-msg-bubble { background: linear-gradient(135deg, #F6055B 0%, #8B5CF6 100%); color: #fff; border-bottom-right-radius: 5px; }
.ucw-msg--received .ucw-msg-bubble { background: #fff; color: #241f36; border-bottom-left-radius: 5px; box-shadow: 0 1px 4px rgba(17,12,34,0.06); }
.ucw-msg-time { display: inline-block; font-size: 14px; opacity: 0.7; margin-left: 8px; white-space: nowrap; }
.ucw-msg--received .ucw-msg-time { color: #9a95ad; }
.ucw-msg-image img { max-width: 190px; border-radius: 12px; display: block; }
.ucw-msg-file { color: inherit; text-decoration: underline; }
.ucw-load-more {
    align-self: center;
    margin-bottom: 4px;
    padding: 7px 16px;
    border: 1px solid #e0dcf0;
    background: #fff;
    color: #8B5CF6;
    border-radius: 16px;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s ease;
}
.ucw-load-more:hover { background: #f4f2fb; }
.ucw-tick { font-size: 14px; letter-spacing: -2px; opacity: 0.75; }
.ucw-tick--read { color: #4ade80; opacity: 1; }

/* Блок/ошибка */
.ucw-blocked { padding: 10px 16px; background: #fff4f4; color: #d64545; font-size: 14px; text-align: center; border-top: 1px solid #f6d5d5; }
.ucw-error { padding: 9px 16px; background: #fff8e6; color: #b7791f; font-size: 14px; text-align: center; border-top: 1px solid #f3e0b3; }

/* Ввод */
.ucw-input-area { display: flex; align-items: flex-end; gap: 8px; padding: 12px 14px; background: #fff; border-top: 1px solid #ececf3; flex-shrink: 0; }
.ucw-input {
    flex: 1; border: 1px solid #e6e4ef; background: #f7f7fb; border-radius: 20px;
    padding: 10px 16px; font-size: 14.5px; font-family: inherit; resize: none; outline: none;
    max-height: 110px; line-height: 1.4; transition: border-color 0.15s ease, background 0.15s ease;
}
.ucw-input:focus { border-color: #8B5CF6; background: #fff; }
.ucw-send {
    width: 42px; height: 42px; flex-shrink: 0; border: none; border-radius: 50%;
    display: flex; align-items: center; justify-content: center; cursor: pointer; color: #fff;
    background: linear-gradient(135deg, #F6055B 0%, #8B5CF6 100%);
    box-shadow: 0 4px 12px rgba(246, 5, 91, 0.3); transition: transform 0.15s ease;
}
.ucw-send:hover { transform: scale(1.06); }
.ucw-send svg { width: 19px; height: 19px; }
.ucw-messages::-webkit-scrollbar, .ucw-dialogs::-webkit-scrollbar { width: 6px; }
.ucw-messages::-webkit-scrollbar-thumb, .ucw-dialogs::-webkit-scrollbar-thumb { background: rgba(139,92,246,0.25); border-radius: 6px; }

/* Мобильные */
@media (max-width: 600px) {
    .ucw { right: 16px; bottom: 16px; }
    /* Приподнимаем кнопку над sticky-баром детальной страницы */
    body:has(#sticky-cta) .ucw { bottom: 84px; }
    .ucw-panel {
        position: fixed;
        right: 0; left: 0; bottom: 0; top: 0;
        width: 100%; height: 100%; max-height: 100%;
        border-radius: 0;
    }
}
