/* Онлайн-чат: виджет витрины. Цвет — --chatcst-color (настройка плагина) */

.chatcst {
    --chatcst-color: #ff5a1f;
    --chatcst-ink: #1f2328;
    --chatcst-muted: #6b7280;
    --chatcst-bg: #ffffff;
    --chatcst-soft: #f3f4f6;
    --chatcst-online: #22c55e;
    position: fixed;
    bottom: var(--chatcst-offset, 20px);
    right: 20px;
    z-index: 2147483000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--chatcst-ink);
    -webkit-font-smoothing: antialiased;
}
.chatcst--left { right: auto; left: 20px; align-items: flex-start; }
.chatcst[hidden], .chatcst [hidden] { display: none !important; }
.chatcst *, .chatcst *::before, .chatcst *::after { box-sizing: border-box; }
.chatcst button { font: inherit; cursor: pointer; }
.chatcst svg { fill: currentColor; }

/* ---------------------------------------------------- Кнопка */

.chatcst-launcher {
    position: relative;
    width: 64px;
    height: 64px;
    border: 0;
    border-radius: 50%;
    background: var(--chatcst-color);
    color: #fff;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22), 0 2px 6px rgba(0, 0, 0, .12);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease;
    padding: 0;
    flex: none;
}
.chatcst-launcher:hover { transform: scale(1.07); }
.chatcst-launcher__icon, .chatcst-launcher__close { width: 32px; height: 32px; transition: transform .25s, opacity .25s; }
.chatcst-launcher__close { position: absolute; width: 26px; height: 26px; opacity: 0; transform: rotate(-90deg); }
.chatcst.is-open .chatcst-launcher__icon { opacity: 0; transform: rotate(90deg); }
.chatcst.is-open .chatcst-launcher__close { opacity: 1; transform: none; }

/* Пульсирующее кольцо — главное, что привлекает взгляд */
.chatcst-launcher__ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 3px solid var(--chatcst-color);
    animation: chatcst-ring 2.4s cubic-bezier(.2, .6, .4, 1) infinite;
    pointer-events: none;
}
.chatcst.is-open .chatcst-launcher__ring { display: none; }
@keyframes chatcst-ring {
    0% { transform: scale(1); opacity: .7; }
    70%, 100% { transform: scale(1.6); opacity: 0; }
}

.chatcst-launcher__online {
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: var(--chatcst-online);
    border: 3px solid #fff;
    display: none;
}
.chatcst.is-online .chatcst-launcher__online { display: block; }
.chatcst.is-open .chatcst-launcher__online { display: none; }

.chatcst-launcher__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    box-sizing: border-box;
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border-radius: 11px;
    background: #ef4444;
    color: #fff;
    font: 700 12px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    /* Цифра ровно по центру — flex, а не line-height (мешала рамка) */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-variant-numeric: tabular-nums;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
    z-index: 2;
    animation: chatcst-pop .3s ease-out;
}
.chatcst-launcher__badge[hidden] { display: none; }

.chatcst.is-teasing .chatcst-launcher { animation: chatcst-shake 3s ease-in-out infinite; }
@keyframes chatcst-shake {
    0%, 86%, 100% { transform: rotate(0); }
    88% { transform: rotate(-12deg); }
    90% { transform: rotate(12deg); }
    92% { transform: rotate(-8deg); }
    94% { transform: rotate(8deg); }
}
@keyframes chatcst-pop { from { transform: scale(.4); } to { transform: scale(1); } }

/* ---------------------------------------------------- Подпись у кнопки */

.chatcst-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 8px 8px;
    background: var(--chatcst-bg);
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .14);
    animation: chatcst-in .35s ease-out;
    max-width: 360px;
    margin-bottom: -4px;
}
.chatcst-label__text { font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chatcst-label__avas { display: flex; cursor: pointer; }
.chatcst-label__avas .chatcst-ava { width: 30px; height: 30px; margin-left: -8px; border: 2px solid #fff; }
.chatcst-label__avas .chatcst-ava:first-child { margin-left: 0; }
.chatcst-label__x { border: 0; background: none; color: var(--chatcst-muted); font-size: 18px; line-height: 1; padding: 0 4px; }

/* ---------------------------------------------------- Приглашение */

.chatcst-teaser {
    position: relative;
    width: 300px;
    max-width: calc(100vw - 40px);
    padding: 16px;
    background: var(--chatcst-bg);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .2);
    animation: chatcst-in .4s cubic-bezier(.2, 1.2, .4, 1);
}
.chatcst-teaser::after {
    content: "";
    position: absolute;
    bottom: -8px;
    right: 26px;
    border: 8px solid transparent;
    border-bottom: 0;
    border-top-color: var(--chatcst-bg);
}
.chatcst--left .chatcst-teaser::after { right: auto; left: 26px; }
.chatcst-teaser__x { position: absolute; top: 6px; right: 8px; border: 0; background: none; font-size: 20px; color: var(--chatcst-muted); line-height: 1; }
.chatcst-teaser__head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.chatcst-teaser__head b { display: block; font-size: 14px; }
.chatcst-teaser__head small { color: var(--chatcst-online); font-size: 12px; }
.chatcst-teaser__head small:not(:empty)::before { content: "● "; }
.chatcst-teaser__text { font-size: 15px; margin-bottom: 12px; }
.chatcst-teaser__btn {
    width: 100%;
    border: 0;
    border-radius: 10px;
    padding: 10px;
    background: var(--chatcst-color);
    color: #fff;
    font-weight: 600;
}

/* ---------------------------------------------------- Аватарки */

.chatcst-ava {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e5e7eb;
    color: #374151;
    font-weight: 700;
}
.chatcst-ava img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chatcst-ava--lg { width: 44px; height: 44px; font-size: 18px; }
.chatcst-ava.is-letter { background: color-mix(in srgb, var(--chatcst-color) 18%, #fff); color: var(--chatcst-color); }

/* ---------------------------------------------------- Окно */

.chatcst-panel {
    width: 380px;
    height: min(620px, calc(100vh - var(--chatcst-offset, 20px) - 100px));
    background: var(--chatcst-bg);
    border-radius: 18px;
    box-shadow: 0 18px 60px rgba(0, 0, 0, .25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatcst-in .25s ease-out;
    /* В разметке окно после кнопки — показываем над ней */
    order: -1;
}
@keyframes chatcst-in { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }

.chatcst-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 14px 14px 16px;
    background: var(--chatcst-color);
    color: #fff;
    flex: none;
}
.chatcst-head__avas { display: flex; }
.chatcst-head__avas .chatcst-ava { width: 40px; height: 40px; margin-left: -10px; border: 2px solid rgba(255, 255, 255, .9); }
.chatcst-head__avas .chatcst-ava:first-child { margin-left: 0; }
.chatcst-head__text { flex: 1; min-width: 0; }
.chatcst-head__text b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatcst-head__text small { display: block; font-size: 13px; opacity: .9; }
.chatcst.is-online .chatcst-head__text small::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #86efac; margin-right: 6px; vertical-align: 1px; }
.chatcst-head__x { width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .15); color: #fff; display: flex; align-items: center; justify-content: center; padding: 0; }
.chatcst-head__x:hover { background: rgba(255, 255, 255, .28); }
.chatcst-head__x svg { width: 20px; height: 20px; }

.chatcst-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px 8px;
    background: #f7f7f8;
    overscroll-behavior: contain;
}

/* ---------------------------------------------------- Сообщения */

.chatcst-msg { display: flex; align-items: flex-end; gap: 8px; margin: 0 0 10px; }
.chatcst-msg--visitor { justify-content: flex-end; }
.chatcst-msg__ava { width: 28px; height: 28px; border-radius: 50%; overflow: hidden; flex: none; display: inline-flex; align-items: center; justify-content: center; background: #e5e7eb; font-size: 13px; font-weight: 700; color: #374151; }
.chatcst-msg__ava img { width: 100%; height: 100%; object-fit: cover; }
.chatcst-msg__ava.is-letter { background: color-mix(in srgb, var(--chatcst-color) 18%, #fff); color: var(--chatcst-color); }
.chatcst-msg__bubble {
    max-width: 78%;
    padding: 9px 12px 6px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.chatcst-msg--operator .chatcst-msg__bubble { border-bottom-left-radius: 4px; }
.chatcst-msg--visitor .chatcst-msg__bubble { background: var(--chatcst-color); color: #fff; border-bottom-right-radius: 4px; }
.chatcst-msg--visitor a { color: #fff; }
.chatcst-msg.is-pending { opacity: .6; }
.chatcst-msg__time { display: block; text-align: right; font-size: 11px; opacity: .6; margin-top: 2px; }
.chatcst-tick { font-style: normal; margin-left: 4px; letter-spacing: -3px; }
.chatcst-tick.is-read { opacity: 1; }
.chatcst-msg__img img { display: block; max-width: 100%; max-height: 220px; border-radius: 10px; margin: 2px 0; }
.chatcst-msg__file { display: inline-block; padding: 6px 0; font-weight: 600; }

.chatcst-product {
    display: flex;
    gap: 10px;
    margin: 4px 0;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    color: var(--chatcst-ink) !important;
    text-decoration: none !important;
}
.chatcst-product img { width: 64px; height: 64px; object-fit: contain; flex: none; }
.chatcst-product b { display: block; font-size: 14px; line-height: 1.3; }
.chatcst-product__price { display: block; font-weight: 700; margin-top: 4px; }
.chatcst-product small { display: block; color: var(--chatcst-muted); }
.chatcst-product__go { display: block; margin-top: 4px; color: var(--chatcst-color); font-weight: 600; font-size: 13px; }

.chatcst-quick { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px 36px; }
.chatcst-quick button {
    border: 1.5px solid var(--chatcst-color);
    background: #fff;
    color: var(--chatcst-color);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
}
.chatcst-quick button:hover { background: var(--chatcst-color); color: #fff; }

.chatcst-typing { display: inline-flex; gap: 4px; padding: 10px 14px; margin: 0 0 10px 36px; background: #fff; border-radius: 16px; }
.chatcst-typing span { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; animation: chatcst-dot 1.2s infinite; }
.chatcst-typing span:nth-child(2) { animation-delay: .2s; }
.chatcst-typing span:nth-child(3) { animation-delay: .4s; }
@keyframes chatcst-dot { 0%, 60%, 100% { transform: none; opacity: .5; } 30% { transform: translateY(-4px); opacity: 1; } }

.chatcst-card { margin: 6px 0 12px; padding: 12px; background: #fff; border-radius: 14px; border: 1px solid #ececec; }
.chatcst-card p { margin: 0 0 8px; }
.chatcst-card__hint { color: var(--chatcst-muted); font-size: 13px; margin: 8px 0 0 !important; }
.chatcst-contacts input {
    display: block;
    width: 100%;
    margin: 0 0 8px;
    padding: 9px 11px;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    font: inherit;
    font-size: 16px; /* иначе iOS увеличивает страницу при фокусе */
}
.chatcst-contacts__bar { display: flex; align-items: center; gap: 10px; }
.chatcst-contacts__bar button, .chatcst-rate button {
    border: 0;
    border-radius: 10px;
    padding: 8px 14px;
    background: var(--chatcst-color);
    color: #fff;
    font-weight: 600;
}
.chatcst-contacts__bar .is-link { background: none; color: var(--chatcst-muted); font-weight: 400; padding: 8px 4px; }
.chatcst-rate { display: flex; gap: 8px; }
.chatcst-rate button { background: var(--chatcst-soft); color: var(--chatcst-ink); }

.chatcst-error { padding: 8px 14px; background: #fef2f2; color: #b91c1c; font-size: 13px; flex: none; }

/* ---------------------------------------------------- Ввод */

.chatcst-compose {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 10px 10px 12px;
    border-top: 1px solid #ececec;
    background: #fff;
    flex: none;
    margin: 0;
}
.chatcst-compose textarea {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 9px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    resize: none;
    overflow-y: hidden;
    font: inherit;
    font-size: 16px;
    line-height: 1.35;
    background: var(--chatcst-soft);
    color: var(--chatcst-ink);
    outline: none;
    box-shadow: none;
    margin: 0;
}
.chatcst-compose textarea:focus { border-color: var(--chatcst-color); background: #fff; }
.chatcst-attach, .chatcst-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    border: 0;
    padding: 0;
    margin: 0;
}
.chatcst-attach { color: var(--chatcst-muted); cursor: pointer; }
.chatcst-attach:hover { background: var(--chatcst-soft); }
.chatcst-attach svg { width: 22px; height: 22px; }
.chatcst-send { background: var(--chatcst-color); color: #fff; }
.chatcst-send:disabled { opacity: .5; }
.chatcst-send svg { width: 20px; height: 20px; margin-left: 2px; }

/* ---------------------------------------------------- Телефон */

@media (max-width: 639px) {
    .chatcst { bottom: var(--chatcst-offset-m, 76px); right: 14px; }
    .chatcst--left { left: 14px; }
    .chatcst-launcher { width: 58px; height: 58px; }
    .chatcst-panel {
        position: fixed;
        inset: 0;
        width: auto;
        height: auto;
        height: 100dvh;
        border-radius: 0;
    }
    .chatcst.is-open .chatcst-launcher { display: none; }
    html.chatcst-lock, html.chatcst-lock body { overflow: hidden; }
    .chatcst-teaser { width: calc(100vw - 28px); }
}

@media (prefers-reduced-motion: reduce) {
    .chatcst-launcher__ring, .chatcst.is-teasing .chatcst-launcher { animation: none; }
}

@media print { .chatcst { display: none !important; } }

/* ---------------------------------------------------- Ассистент */

.chatcst-ava.is-bot, .chatcst-msg__ava.is-bot {
    background: color-mix(in srgb, var(--chatcst-color) 14%, #fff);
    color: var(--chatcst-color);
}
.chatcst-head .chatcst-ava.is-bot { background: rgba(255, 255, 255, .22); color: #fff; }
.chatcst-ava.is-bot svg, .chatcst-msg__ava.is-bot svg { width: 62%; height: 62%; }
.chatcst-msg + .chatcst-quick, div > .chatcst-quick[data-msg-buttons] { margin-top: -4px; }
.chatcst-products { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.chatcst-products .chatcst-product { margin: 0; }
.chatcst-products__all { display: inline-block; margin-top: 6px; font-weight: 600; color: var(--chatcst-color); text-decoration: none; }
.chatcst-msg--bot .chatcst-msg__bubble { max-width: 86%; }
.chatcst.is-human [data-msg-buttons],
.chatcst.is-human [data-quick-text="Позвать оператора"] { display: none; }

/* ---------------------------------------------------- Карточки ассистента */

.chatcst-msg__bubble:has(.chatcst-ocard) { padding: 6px; max-width: 92%; background: transparent; box-shadow: none; }
.chatcst-ocard {
    min-width: 230px;
    background: #fff;
    border: 1px solid #ececec;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .06);
}
.chatcst-ocard__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--chatcst-color) 8%, #fff);
    border-bottom: 1px solid #f0f0f0;
}
.chatcst-ocard__head b { font-size: 16px; }
.chatcst-ocard__status {
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--chatcst-color);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}
.chatcst-card__row { display: flex; gap: 10px; padding: 9px 12px; border-top: 1px solid #f5f5f5; }
.chatcst-card__row:first-of-type { border-top: 0; }
.chatcst-card__row i { width: 20px; height: 20px; flex: none; color: #9ca3af; margin-top: 2px; }
.chatcst-card__row i svg { width: 20px; height: 20px; }
.chatcst-card__row small { display: block; font-size: 12px; color: var(--chatcst-muted); }
.chatcst-card__row span { font-size: 14px; line-height: 1.35; }
.chatcst-card__row.is-accent { background: #f0fdf4; }
.chatcst-card__row.is-accent i { color: #16a34a; }
.chatcst-card__row.is-accent small { color: #15803d; }
.chatcst-ocard__title { padding: 10px 12px 4px; font-weight: 600; font-size: 14px; line-height: 1.3; }
.chatcst-ocard__stock { display: flex; align-items: center; gap: 8px; margin: 6px 12px; padding: 7px 10px; border-radius: 10px; background: #f0fdf4; color: #15803d; font-size: 13px; font-weight: 600; }
.chatcst-ocard__stock svg { width: 18px; height: 18px; flex: none; }
.chatcst-ocard__sub { padding: 6px 12px 2px; font-size: 12px; color: var(--chatcst-muted); text-transform: uppercase; letter-spacing: .03em; }
.chatcst-dtable { width: 100%; border-collapse: collapse; margin: 0 0 6px; font-size: 13px; }
.chatcst-dtable th, .chatcst-dtable td { padding: 7px 12px; border-top: 1px solid #f5f5f5; text-align: left; vertical-align: top; }
.chatcst-dtable th { font-weight: 600; white-space: nowrap; width: 1%; }
.chatcst-dtable td { color: #374151; }
.chatcst-ocard__note { padding: 9px 12px; border-top: 1px solid #f0f0f0; font-size: 13px; color: #374151; }

/* «Оператор Виктория присоединилась к чату» */
.chatcst-join { text-align: center; margin: 4px 0 12px; }
.chatcst-join span { display: inline-block; padding: 4px 12px; border-radius: 999px; background: #e8f5ee; color: #166534; font-size: 12.5px; }

/* Постоянная кнопка «Позвать оператора» */
.chatcst-callop { padding: 6px 12px 0; background: #fff; border-top: 1px solid #ececec; flex: none; }
.chatcst-callop button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid #e5e7eb;
    background: #fff;
    color: var(--chatcst-ink);
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 13px;
}
.chatcst-callop button:hover { border-color: var(--chatcst-color); color: var(--chatcst-color); }
.chatcst-callop svg { width: 16px; height: 16px; }
.chatcst-callop + .chatcst-compose { border-top: 0; }
.chatcst.is-human .chatcst-callop { display: none; }
.chatcst-disclaimer {
    flex: none;
    padding: 0 12px 8px;
    margin-top: -4px;
    background: #fff;
    color: #9ca3af;
    font-size: 11px;
    line-height: 1.3;
    text-align: center;
}
.chatcst-disclaimer[hidden] { display: none; }
.chatcst.is-human .chatcst-callop + .chatcst-compose { border-top: 1px solid #ececec; }
.chatcst-ocard__head--product { align-items: flex-start; }
.chatcst-ocard__name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.chatcst-ocard__status { flex: none; white-space: nowrap; }
.chatcst-ocard__status.is-ok { background: #16a34a; }
.chatcst-ocard__status.is-muted { background: #9ca3af; }
a.chatcst-ocard__name { color: var(--chatcst-ink); text-decoration: none; }
a.chatcst-ocard__name:hover { color: var(--chatcst-color); text-decoration: underline; }
/* Не оплачен — кнопка оплаты в карточке заказа */
.chatcst-ocard__pay { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid #f0f0f0; background: #fff7ed; }
.chatcst-ocard__pay span { font-size: 13px; color: #9a3412; font-weight: 600; }
.chatcst-ocard__pay a {
    display: block;
    text-align: center;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--chatcst-color);
    color: #fff !important;
    font-weight: 700;
    text-decoration: none !important;
}
.chatcst-ocard__pay a:hover { filter: brightness(1.06); }
.chatcst-ocard__pay a { display: flex; align-items: center; justify-content: center; gap: 6px; }
.chatcst-ocard__payicon { width: 16px; height: 16px; }
/* Группы сроков: часть в магазине — раньше, остальное у поставщика */
.chatcst-ocard__group { padding: 8px 12px 4px; border-top: 1px solid #f0f0f0; font-size: 12.5px; font-weight: 700; color: #374151; background: #fafafa; }
.chatcst-ocard__group.is-accent { color: #15803d; background: #f0fdf4; }
.chatcst-ocard__group + .chatcst-card__row { border-top: 0; }
