/* Тортоделия — Онлайн-консультант (вдохновлён UX чата event-btq в фирменной палитре Тортоделии) */
.td-chat {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 95;
    font-family: var(--font-body, 'Onest', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
    font-size: 14.5px;
    line-height: 1.45;
    color: var(--text-main, #1F171A);
}
.td-chat *,
.td-chat *::before,
.td-chat *::after {
    box-sizing: border-box;
}
.td-chat button {
    font: inherit;
    cursor: pointer;
}

.td-chat__launcher {
    position: relative;
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: var(--pink, #FF2E8B);
    color: #fff;
    box-shadow: 0 8px 24px rgba(255, 46, 139, 0.36), 0 2px 8px rgba(31, 23, 26, 0.14);
    transition: transform 0.2s cubic-bezier(0.2, 0.7, 0.2, 1), box-shadow 0.2s ease, background-color 0.2s ease;
}
.td-chat__launcher:hover {
    transform: translateY(-2px) scale(1.04);
    background: var(--pink-hover, #E11B74);
}
.td-chat__launcher:active {
    transform: scale(0.95);
}
.td-chat__launcher:focus-visible,
.td-chat__icon:focus-visible,
.td-chat__send:focus-visible,
.td-chat__chip:focus-visible {
    outline: 3px solid rgba(255, 46, 139, 0.35);
    outline-offset: 2px;
}
.td-chat__launcher-ico {
    grid-area: 1 / 1;
    display: grid;
    place-items: center;
    transition: opacity 0.2s ease, transform 0.25s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.td-chat__launcher-close {
    opacity: 0;
    transform: rotate(-45deg) scale(0.6);
}
.td-chat.is-open .td-chat__launcher {
    background: var(--text-main, #1F171A);
    box-shadow: 0 8px 24px rgba(31, 23, 26, 0.28);
}
.td-chat.is-open .td-chat__launcher-open {
    opacity: 0;
    transform: rotate(45deg) scale(0.6);
}
.td-chat.is-open .td-chat__launcher-close {
    opacity: 1;
    transform: none;
}

.td-chat__badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: var(--mint, #12B5A3);
    border: 2px solid #fff;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}
.td-chat__badge[hidden] {
    display: none;
}

.td-chat__panel {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: #fff;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(16px);
    transition: opacity 0.22s ease, transform 0.28s cubic-bezier(0.2, 0.7, 0.2, 1), visibility 0s linear 0.28s;
}
.td-chat.is-open .td-chat__panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    transition-delay: 0s;
}

.td-chat__head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 13px 12px 13px 15px;
    background: linear-gradient(135deg, #FFF5F9 0%, #FFF8F3 100%);
    border-bottom: 1px solid var(--border-soft, #F1E4E9);
}
.td-chat__ava {
    flex: none;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border-radius: 13px;
    background: var(--bg-soft-pink, #FFF0F6);
    border: 1px solid rgba(255, 46, 139, 0.16);
    color: var(--pink, #FF2E8B);
}
.td-chat__titles {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.td-chat__titles strong {
    font-family: var(--font-head, 'Rubik', sans-serif);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.25;
    color: var(--text-main, #1F171A);
}
.td-chat__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text-muted, #6C5F65);
    margin-top: 2px;
}
.td-chat__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--mint, #12B5A3);
    flex: none;
}
.td-chat__icon {
    flex: none;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-muted, #6C5F65);
    transition: background-color 0.15s ease, color 0.15s ease;
}
.td-chat__icon:hover,
.td-chat__icon.is-active {
    background: rgba(255, 46, 139, 0.1);
    color: var(--pink-hover, #E11B74);
}

.td-chat__contact {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-soft-cream, #FFF4EC);
    border-bottom: 1px solid var(--border-soft, #F1E4E9);
}
.td-chat__contact[hidden] {
    display: none;
}
.td-chat__contact input {
    width: 100%;
    min-width: 0;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border-soft, #F1E4E9);
    border-radius: 10px;
    background: #fff;
    color: var(--text-main, #1F171A);
    font: inherit;
    font-size: 13px;
    outline: 0;
}
.td-chat__contact input:focus {
    border-color: var(--pink, #FF2E8B);
}

.td-chat__list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 14px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fff;
    scroll-behavior: smooth;
}
.td-chat__row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    animation: td-chat-in 0.24s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.td-chat__row--visitor {
    align-items: flex-end;
}
.td-chat__row--system {
    align-items: center;
}
.td-chat__bubble {
    max-width: 85%;
    padding: 9px 13px;
    border-radius: 16px;
    background: var(--bg-cream, #FFF8F3);
    border: 1px solid var(--border-soft, #F1E4E9);
    color: var(--text-main, #1F171A);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.td-chat__row--manager .td-chat__bubble {
    border-bottom-left-radius: 5px;
    background: #fff;
    border-color: var(--border-soft, #F1E4E9);
    box-shadow: 0 1px 4px rgba(31, 23, 26, 0.04);
}
.td-chat__row--visitor .td-chat__bubble {
    border-bottom-right-radius: 5px;
    background: var(--pink, #FF2E8B);
    border-color: transparent;
    color: #fff;
}
.td-chat__row--system .td-chat__bubble {
    max-width: 96%;
    padding: 7px 12px;
    border-radius: 12px;
    background: var(--bg-soft-cream, #FFF4EC);
    border-color: #F4E0D2;
    color: var(--text-muted, #6C5F65);
    font-size: 12.5px;
    text-align: center;
}
.td-chat__row--error .td-chat__bubble {
    background: #FFF1F4;
    border-color: #FAD2DC;
    color: #9F1239;
}
.td-chat__meta {
    margin-top: 3px;
    padding: 0 4px;
    font-size: 11px;
    color: #9C8E94;
}

.td-chat__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 4px 14px 10px;
}
.td-chat__chips[hidden] {
    display: none;
}
.td-chat__chip {
    padding: 7px 11px;
    border: 1px solid var(--border-soft, #F1E4E9);
    border-radius: 11px;
    background: #fff;
    color: var(--text-main, #1F171A);
    font-size: 13px;
    line-height: 1.3;
    text-align: left;
    transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.td-chat__chip:hover {
    border-color: var(--pink, #FF2E8B);
    color: var(--pink-hover, #E11B74);
    background: var(--bg-soft-pink, #FFF0F6);
}

.td-chat__form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin: 0 12px;
    padding: 6px 6px 6px 13px;
    border-radius: 16px;
    border: 1px solid var(--border-soft, #F1E4E9);
    background: var(--bg-cream, #FFF8F3);
    transition: box-shadow 0.2s ease, background-color 0.2s ease, border-color 0.2s ease;
}
.td-chat__form:focus-within {
    background: #fff;
    border-color: var(--pink, #FF2E8B);
    box-shadow: 0 0 0 2px rgba(255, 46, 139, 0.18);
}
.td-chat .td-chat__input {
    flex: 1;
    min-width: 0;
    width: auto;
    min-height: 38px;
    max-height: 110px;
    margin: 0;
    padding: 8px 0;
    border: 0 !important;
    border-radius: 0;
    background: transparent !important;
    box-shadow: none !important;
    color: var(--text-main, #1F171A);
    font: inherit;
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    outline: 0;
}
.td-chat__input::placeholder {
    color: #9C8E94;
}
.td-chat__send {
    flex: none;
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 11px;
    background: var(--pink, #FF2E8B);
    color: #fff;
    transition: transform 0.15s ease, background-color 0.15s ease;
}
.td-chat__send:disabled {
    background: #D6CBD0;
    cursor: default;
}
.td-chat__send:not(:disabled):hover {
    background: var(--pink-hover, #E11B74);
}
.td-chat__send:not(:disabled):active {
    transform: scale(0.94);
}

.td-chat__foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 16px calc(10px + env(safe-area-inset-bottom, 0px));
    font-size: 12px;
    color: var(--text-muted, #6C5F65);
}
.td-chat__foot a {
    color: inherit;
    text-decoration: none;
    font-weight: 600;
}
.td-chat__foot a:hover {
    color: var(--pink, #FF2E8B);
}

@keyframes td-chat-in {
    from { opacity: 0; transform: translateY(7px); }
    to { opacity: 1; transform: none; }
}

@media (max-width: 767.98px) {
    .td-chat {
        right: 16px;
        bottom: 16px;
    }
    .td-chat.is-open {
        z-index: 150;
    }
    .td-chat.is-open .td-chat__launcher {
        display: none;
    }
    html.td-chat-open,
    html.td-chat-open body {
        overflow: hidden;
    }
    .td-chat__input {
        font-size: 16px;
    }
    .td-cart-toast {
        bottom: 86px;
    }
}

@media (min-width: 768px) {
    .td-chat__panel {
        inset: auto 20px 92px auto;
        width: 392px;
        height: min(580px, calc(100vh - 110px));
        border-radius: 22px;
        border: 1px solid var(--border-soft, #F1E4E9);
        box-shadow: 0 4px 14px rgba(31, 23, 26, 0.08), 0 24px 64px rgba(31, 23, 26, 0.18);
        overflow: hidden;
        transform: translateY(12px) scale(0.98);
        transform-origin: bottom right;
    }
    .td-cart-toast {
        right: 92px;
    }
}
