/* ==========================================================================
   Chat Widget — DiParfum
   Кнопка-пузырь (свёрнутый) + мини-окно (развёрнутый)
   ========================================================================== */

/* --- Пузырь (свёрнутый виджет) --- */
.dp-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10020;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #620a84;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(98, 10, 132, 0.35);
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    animation: dp-chat-bubble-in 0.3s ease-out;
}

.dp-chat-bubble:hover {
    background: hsl(283, 86%, 22%);
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(98, 10, 132, 0.45);
}

.dp-chat-bubble:active {
    transform: scale(0.97);
}

.dp-chat-bubble svg {
    width: 20px;
    height: 20px;
    fill: #fff;
}

/* Бейдж на пузыре */
.dp-chat-bubble__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ff5b8f;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    line-height: 20px;
    text-align: center;
    padding: 0 5px;
    display: none;
}

.dp-chat-bubble__badge.active {
    display: block;
}

@keyframes dp-chat-bubble-in {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* --- Мини-окно (развёрнутый виджет) --- */
.dp-chat-window {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10020;
    width: 370px;
    height: 520px;
    display: none;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15);
    background: #fff;
    animation: dp-chat-window-in 0.25s ease-out;
}

.dp-chat-window.open {
    display: flex;
}

@keyframes dp-chat-window-in {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Заголовок */
.dp-chat-window__header {
    background: #620a84;
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.dp-chat-window__header-info {
    flex: 1;
    min-width: 0;
}

.dp-chat-window__title {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
}

.dp-chat-window__status {
    font-size: 12px;
    opacity: 0.8;
    margin-top: 2px;
}

.dp-chat-window__actions {
    display: flex;
    gap: 8px;
    margin-left: 12px;
    flex-shrink: 0;
}

.dp-chat-window__btn {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    color: #fff;
    padding: 0;
}

.dp-chat-window__btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.dp-chat-window__btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

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

/* Отдельное сообщение */
.dp-chat-msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.45;
    color: #323744;
    word-wrap: break-word;
}

.dp-chat-msg--client {
    background: #f3ebf6;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.dp-chat-msg--admin {
    background: #f8f8fc;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.dp-chat-msg--bot {
    align-self: center;
    background: none;
    color: #9e9e9e;
    font-style: italic;
    font-size: 13px;
    text-align: center;
    max-width: 90%;
    padding: 6px 0;
}

.dp-chat-msg__name {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 3px;
    color: #620a84;
}

.dp-chat-msg--client .dp-chat-msg__name {
    text-align: right;
}

.dp-chat-msg__time {
    font-size: 11px;
    color: #787878;
    margin-top: 4px;
}

.dp-chat-msg--client .dp-chat-msg__time {
    text-align: right;
}

/* Метка канала */
.dp-chat-msg__channel {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-left: 4px;
    vertical-align: baseline;
}

.dp-chat-msg__channel--telegram { color: #2AABEE; }
.dp-chat-msg__channel--whatsapp { color: #25D366; }
.dp-chat-msg__channel--email { color: #EA4335; }

/* Ссылки в сообщениях */
.dp-chat-msg a {
    color: #620a84;
    text-decoration: underline;
    word-break: break-all;
}
.dp-chat-msg a:hover {
    color: #4a0663;
}

/* Разделитель даты */
.dp-chat-date-sep {
    text-align: center;
    font-size: 12px;
    color: #9e70b0;
    padding: 8px 0;
    position: relative;
}

.dp-chat-date-sep::before,
.dp-chat-date-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 30%;
    height: 1px;
    background: #ece2f0;
}

.dp-chat-date-sep::before { left: 0; }
.dp-chat-date-sep::after { right: 0; }

/* Индикатор загрузки */
.dp-chat-loading {
    text-align: center;
    padding: 12px;
    color: #9e9e9e;
    font-size: 13px;
}

/* Область ввода */
.dp-chat-window__input-area {
    border-top: 1px solid #ece2f0;
    padding: 10px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    background: #fff;
}

.dp-chat-window__input {
    flex: 1;
    border: 1px solid #dadada;
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    color: #323744;
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    transition: border-color 0.15s;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.dp-chat-window__input::-webkit-scrollbar {
    display: none;
}

.dp-chat-window__input:focus {
    border-color: #9e70b0;
}

.dp-chat-window__input::placeholder {
    color: #9e9e9e;
}

.dp-chat-window__send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #620a84;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
    padding: 0;
}

.dp-chat-window__send:hover {
    background: hsl(283, 86%, 22%);
}

.dp-chat-window__send:disabled {
    background: #dadada;
    cursor: default;
}

.dp-chat-window__send svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* Форма гостя */
.dp-chat-guest-form {
    padding: 16px;
    border-bottom: 1px solid #ece2f0;
    flex-shrink: 0;
}

.dp-chat-guest-form__title {
    font-size: 13px;
    color: #323744;
    margin-bottom: 10px;
}

.dp-chat-guest-form__field {
    width: 100%;
    border: 1px solid #dadada;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    color: #323744;
    outline: none;
    margin-bottom: 8px;
    box-sizing: border-box;
    transition: border-color 0.15s;
}

.dp-chat-guest-form__field:focus {
    border-color: #9e70b0;
}

.dp-chat-guest-form__field::placeholder {
    color: #9e9e9e;
}

/* --- Фото в сообщениях (виджет) --- */
.dp-chat-msg__image-wrap {
    margin-bottom: 4px;
}

.dp-chat-msg__image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 10px;
    cursor: pointer;
    display: block;
}

/* Кнопка-скрепка (виджет) */
.dp-chat-window__attach-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #620a84;
    cursor: pointer;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: background 0.15s;
}

.dp-chat-window__attach-btn:hover {
    background: hsl(283, 86%, 22%);
}

/* Превью вложения (виджет) */
.dp-chat-window__attach-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-top: 1px solid #ece2f0;
    background: #faf7fc;
}

.dp-chat-window__attach-preview-img {
    max-width: 60px;
    max-height: 60px;
    border-radius: 6px;
    object-fit: cover;
}

.dp-chat-window__attach-preview-close {
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0,0,0,0.1);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dp-chat-window__attach-preview-close:hover {
    background: rgba(0,0,0,0.2);
}

/* --- Мобильная версия --- */
@media (max-width: 991px) {
    .dp-chat-bubble {
        bottom: calc(78px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }

    .dp-chat-window {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        animation: none;
        position: fixed;
    }

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

/* --- Focus-visible для доступности --- */
.dp-chat-bubble:focus-visible,
.dp-chat-window__btn:focus-visible,
.dp-chat-window__send:focus-visible,
.dp-chat-window__attach-btn:focus-visible,
.dp-chat-window__attach-preview-close:focus-visible {
    outline: 2px solid #9e70b0;
    outline-offset: 2px;
}

.dp-chat-window__input:focus-visible {
    border-color: #620a84;
    box-shadow: 0 0 0 2px rgba(98, 10, 132, 0.2);
}

.dp-chat-guest-form__field:focus-visible {
    border-color: #620a84;
    box-shadow: 0 0 0 2px rgba(98, 10, 132, 0.2);
}

/* --- Lightbox (виджет) --- */
.dp-chat-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.85);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.dp-chat-lightbox__img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 4px;
    cursor: default;
}

.dp-chat-lightbox__close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.15);
    border: none;
    border-radius: 50%;
    padding: 0;
}

.dp-chat-lightbox__close:hover {
    background: rgba(255,255,255,0.3);
}

.dp-chat-lightbox__close:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* --- Приглашение авторизоваться (для гостей) --- */
.dp-chat-login-prompt,
.dp-chat-msg--bot.dp-chat-login-prompt {
    text-align: center;
    font-style: normal;
    color: #323744;
    max-width: 100%;
    padding: 20px 16px;
    background: none;
}

.dp-chat-login-prompt__text {
    font-size: 14px;
    line-height: 1.5;
    color: #555;
    margin-bottom: 16px;
}

.dp-chat-login-prompt .dp-chat-login-prompt__buttons {
    display: flex !important;
    flex-direction: column !important;
    gap: 10px;
    align-items: center;
}

.dp-chat-login-prompt__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 24px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, box-shadow 0.2s, transform 0.15s;
    width: 240px;
    box-sizing: border-box;
    letter-spacing: 0.01em;
}

.dp-chat-login-prompt__btn:active {
    transform: scale(0.97);
}

.dp-chat-login-prompt__btn svg {
    flex-shrink: 0;
}

.dp-chat-login-prompt__btn--tg,
.dp-chat-msg .dp-chat-login-prompt__btn--tg {
    background: #2AABEE;
    color: #fff;
    box-shadow: 0 2px 8px rgba(42, 171, 238, 0.3);
    text-decoration: none;
    border: 1.5px solid #2AABEE;
}

.dp-chat-login-prompt__btn--tg:hover,
.dp-chat-msg .dp-chat-login-prompt__btn--tg:hover {
    background: #1E9AD8;
    color: #fff;
    box-shadow: 0 4px 12px rgba(42, 171, 238, 0.4);
    text-decoration: none;
}

.dp-chat-login-prompt__btn--email,
.dp-chat-msg .dp-chat-login-prompt__btn--email {
    background: #fff;
    color: #620a84;
    border: 1.5px solid #d9c4e3;
    text-decoration: none;
}

.dp-chat-login-prompt__btn--email:hover,
.dp-chat-msg .dp-chat-login-prompt__btn--email:hover {
    background: #f8f2fb;
    color: #4a0663;
    border-color: #b896cc;
    text-decoration: none;
}

.dp-chat-login-prompt__hint {
    font-size: 12px;
    color: #aaa;
    margin-top: 14px;
}

/* Compact-версия (подсказка после отправки) */
.dp-chat-login-prompt__links {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    flex-wrap: wrap;
}

.dp-chat-login-prompt__link {
    font-size: 13px;
    color: #620a84;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-weight: 500;
}

.dp-chat-login-prompt__link:hover {
    text-decoration: underline;
}

.dp-chat-login-prompt__link--tg {
    color: #2AABEE;
}

.dp-chat-login-prompt__link--tg:hover {
    color: #1E9AD8;
}

.dp-chat-login-prompt__sep {
    color: #bbb;
    font-size: 13px;
}

/* Скрываем виджет на странице /chat/ */
body.dp-chat-page-active .dp-chat-bubble,
body.dp-chat-page-active .dp-chat-window {
    display: none !important;
}
