/*
 * Онлайн-чат Pro — the storefront widget (doc/chat-pro.md).
 * The theme's own tokens with fallbacks; the accent from the module's
 * settings (--chp-accent, set on .chp) wins. Everything is scoped to .chp.
 */
.chp {
    --chp-surface: var(--c-surface, #ffffff);
    --chp-sunk: var(--c-surface-sunk, color-mix(in srgb, var(--chp-surface) 94%, #64748b));
    --chp-text: var(--c-text-strong, var(--c-text, #111827));
    --chp-muted: var(--c-text-muted, #6b7280);
    --chp-border: var(--c-border, rgb(15 23 42 / 0.1));
    --chp-radius: var(--r-lg, 18px);
    --chp-font: var(--font-ui, var(--font-body, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif));
    --chp-soft: color-mix(in srgb, var(--chp-accent) 12%, var(--chp-surface));
    --chp-shadow: 0 24px 60px -18px rgb(15 23 42 / 0.35), 0 8px 20px -8px rgb(15 23 42 / 0.18);
    --chp-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
    --chp-lift: 0px;
    position: fixed;
    z-index: 9000;
    bottom: calc(var(--chp-y) + var(--chp-lift) + env(safe-area-inset-bottom, 0px));
    font: 15px/1.45 var(--chp-font);
    color: var(--chp-text);
    -webkit-font-smoothing: antialiased;
    /* Opacity only: a transform here would make the phone's full-screen
       window (position: fixed) relative to this box instead of the screen. */
    opacity: 0;
    transition: opacity 0.3s var(--chp-ease);
}
.chp--ready { opacity: 1; }
.chp--right { right: var(--chp-x); display: flex; justify-content: flex-end; }
.chp--left { left: var(--chp-x); display: flex; justify-content: flex-start; }
.chp *, .chp *::before, .chp *::after { box-sizing: border-box; }
.chp [hidden] { display: none !important; }
/* Resets without weight: the widget's own classes (.chp-send…) always win. */
.chp :where(button) { font: inherit; color: inherit; cursor: pointer; }
.chp :where(a) { color: inherit; }
.chp-i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

@media (max-width: 63.99rem) {
    body:has(.cms-mbar) .chp { --chp-lift: 4.25rem; }
}

/* ---- the button ---------------------------------------------------------- */
.chp-launcher {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 60px;
    min-width: 60px;
    padding: 0 18px;
    border: 0;
    border-radius: 999px;
    background: var(--chp-accent);
    color: var(--chp-on-accent);
    box-shadow: 0 10px 28px -8px color-mix(in srgb, var(--chp-accent) 70%, transparent), 0 3px 8px rgb(15 23 42 / 0.18);
    transition: transform 0.2s var(--chp-ease), box-shadow 0.2s var(--chp-ease);
}
.chp-launcher:not(.chp-launcher--label) { width: 60px; padding: 0; justify-content: center; }
.chp-launcher:hover { transform: translateY(-2px); box-shadow: 0 14px 32px -8px color-mix(in srgb, var(--chp-accent) 75%, transparent), 0 4px 10px rgb(15 23 42 / 0.2); }
.chp-launcher:active { transform: scale(0.97); }
/* The message box shows focus by its own border (.chp-input:focus), not a second ring. */
.chp-launcher:focus-visible, .chp button:focus-visible, .chp a:focus-visible, .chp input:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--chp-accent) 45%, transparent);
    outline-offset: 2px;
}
.chp-launcher__icons { position: relative; width: 26px; height: 26px; }
.chp-launcher__icons .chp-i { position: absolute; inset: 0; width: 26px; height: 26px; stroke-width: 1.9; transition: opacity 0.2s, transform 0.25s var(--chp-ease); }
.chp-launcher__close { opacity: 0; transform: rotate(-90deg) scale(0.6); }
.chp--open .chp-launcher__open, .chp--menu .chp-launcher__open { opacity: 0; transform: rotate(90deg) scale(0.6); }
.chp--open .chp-launcher__close, .chp--menu .chp-launcher__close { opacity: 1; transform: none; }
.chp-launcher__label { font-weight: 600; font-size: 15px; white-space: nowrap; }
.chp--open .chp-launcher__label, .chp--menu .chp-launcher__label { display: none; }
.chp--open .chp-launcher--label, .chp--menu .chp-launcher--label { width: 60px; padding: 0; justify-content: center; }
.chp-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border: 2px solid var(--chp-surface);
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    animation: chp-pop 0.3s var(--chp-ease);
}

/* ---- the greeting bubble ------------------------------------------------- */
.chp-bubble {
    position: absolute;
    bottom: 76px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: max-content;
    max-width: min(320px, calc(100vw - 2 * var(--chp-x) - 8px));
    padding: 12px 34px 12px 12px;
    border: 1px solid var(--chp-border);
    border-radius: 16px;
    background: var(--chp-surface);
    box-shadow: var(--chp-shadow);
    cursor: pointer;
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.2s var(--chp-ease), transform 0.25s var(--chp-ease);
}
.chp--right .chp-bubble { right: 0; }
.chp--left .chp-bubble { left: 0; transform-origin: bottom left; }
.chp-bubble--in { opacity: 1; transform: none; }
.chp-bubble__body { min-width: 0; }
.chp-bubble__name { display: block; font-size: 13px; margin-bottom: 2px; }
.chp-bubble__text { margin: 0; font-size: 14px; color: var(--chp-text); }
.chp-bubble__close {
    position: absolute;
    top: 6px;
    right: 6px;
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--chp-muted);
}
.chp-bubble__close:hover { background: var(--chp-sunk); color: var(--chp-text); }
.chp-bubble__close .chp-i { width: 14px; height: 14px; }

/* ---- avatars ------------------------------------------------------------- */
.chp-avatar {
    display: inline-grid;
    place-items: center;
    flex: none;
    width: 36px;
    height: 36px;
    overflow: hidden;
    border-radius: 50%;
    background: var(--chp-soft);
    color: var(--chp-accent);
    font-weight: 700;
    font-size: 15px;
}
.chp-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---- the multibutton ----------------------------------------------------- */
.chp-menu {
    position: absolute;
    bottom: 74px;
    display: grid;
    gap: 8px;
    min-width: 220px;
    padding: 8px;
    border: 1px solid var(--chp-border);
    border-radius: 18px;
    background: var(--chp-surface);
    box-shadow: var(--chp-shadow);
    animation: chp-rise 0.22s var(--chp-ease);
}
.chp--right .chp-menu { right: 0; }
.chp--left .chp-menu { left: 0; }
.chp-menu__item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 14px 8px 8px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--chp-text);
    font-weight: 500;
    text-decoration: none;
    text-align: left;
    transition: background 0.15s;
}
.chp-menu__item:hover { background: var(--chp-sunk); }
.chp-menu__icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; background: var(--chp-accent); color: var(--chp-on-accent); }
.chp-menu__item--telegram .chp-menu__icon { background: #229ed9; color: #fff; }
.chp-menu__item--whatsapp .chp-menu__icon { background: #25d366; color: #fff; }
.chp-menu__item--vk .chp-menu__icon { background: #0077ff; color: #fff; }
.chp-menu__item--max .chp-menu__icon { background: linear-gradient(135deg, #3f6bff, #a24bff); color: #fff; }
.chp-menu__item--phone .chp-menu__icon { background: #16a34a; color: #fff; }
.chp-menu__item--email .chp-menu__icon, .chp-menu__item--link .chp-menu__icon { background: #475569; color: #fff; }

/* ---- the window ---------------------------------------------------------- */
.chp-panel {
    position: absolute;
    bottom: 76px;
    display: flex;
    flex-direction: column;
    width: 380px;
    height: min(640px, calc(100vh - var(--chp-y) - var(--chp-lift) - 100px));
    height: min(640px, calc(100dvh - var(--chp-y) - var(--chp-lift) - 100px));
    min-height: 360px;
    overflow: hidden;
    border: 1px solid var(--chp-border);
    border-radius: var(--chp-radius);
    background: var(--chp-surface);
    box-shadow: var(--chp-shadow);
    opacity: 0;
    transform: translateY(14px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.2s var(--chp-ease), transform 0.25s var(--chp-ease);
}
.chp--right .chp-panel { right: 0; }
.chp--left .chp-panel { left: 0; transform-origin: bottom left; }
.chp-panel--in { opacity: 1; transform: none; }

.chp-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 10px 14px 16px;
    background: var(--chp-accent);
    color: var(--chp-on-accent);
}
.chp-head .chp-avatar { width: 42px; height: 42px; background: color-mix(in srgb, var(--chp-on-accent) 18%, transparent); color: var(--chp-on-accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--chp-on-accent) 30%, transparent); }
.chp-head__avatar { display: inline-flex; }
.chp-head__text { display: grid; min-width: 0; flex: 1; }
.chp-head__title { font-size: 16px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chp-head__status { display: flex; align-items: center; gap: 6px; font-size: 13px; opacity: 0.88; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chp-dot { width: 8px; height: 8px; border-radius: 50%; background: color-mix(in srgb, var(--chp-on-accent) 45%, transparent); flex: none; }
.chp-dot--on { background: #4ade80; box-shadow: 0 0 0 3px rgb(74 222 128 / 0.25); }
.chp-iconbtn {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    flex: none;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: inherit;
    transition: background 0.15s;
}
.chp-head__btn:hover { background: color-mix(in srgb, var(--chp-on-accent) 16%, transparent); }

.chp-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px 8px;
    background: var(--chp-sunk);
    scroll-behavior: smooth;
}
.chp-log { display: grid; gap: 10px; }

.chp-msg { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; animation: chp-rise 0.22s var(--chp-ease); }
.chp-msg--visitor { justify-content: flex-end; }
.chp-msg--bot, .chp-msg--operator { flex-wrap: wrap; }
.chp-msg__avatar { width: 28px; height: 28px; font-size: 12px; }
.chp-msg__bubble {
    position: relative;
    max-width: calc(100% - 44px);
    padding: 9px 12px 6px;
    border-radius: 16px 16px 16px 6px;
    background: var(--chp-surface);
    border: 1px solid var(--chp-border);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.chp-msg--visitor .chp-msg__bubble {
    max-width: 82%;
    border: 0;
    border-radius: 16px 16px 6px 16px;
    background: var(--chp-accent);
    color: var(--chp-on-accent);
}
.chp-msg--pending .chp-msg__bubble { opacity: 0.6; }
.chp-msg__name { display: block; margin-bottom: 2px; font-size: 12px; font-weight: 650; color: var(--chp-accent); }
.chp-msg__text { margin: 0; white-space: pre-wrap; }
.chp-msg__text a { text-decoration: underline; text-underline-offset: 2px; }
.chp-msg__meta { display: flex; align-items: center; justify-content: flex-end; gap: 2px; margin-top: 2px; font-size: 11px; opacity: 0.65; }
.chp-msg__read { display: inline-flex; margin-left: 3px; }
.chp-msg__read .chp-i { width: 13px; height: 13px; stroke-width: 2.4; }
.chp-msg__read .chp-i + .chp-i { margin-left: -8px; }
.chp-msg__system { width: 100%; margin: 4px 0; font-size: 12.5px; text-align: center; color: var(--chp-muted); }
.chp-msg__image { display: block; margin: -3px -6px 6px; }
.chp-msg__image img { display: block; max-width: 100%; max-height: 220px; border-radius: 10px; object-fit: cover; }
.chp-msg__file { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; padding: 6px 8px; border-radius: 10px; background: color-mix(in srgb, currentColor 8%, transparent); text-decoration: none; }
.chp-msg__file span { display: grid; min-width: 0; }
.chp-msg__file b { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chp-msg__file small { opacity: 0.7; font-size: 12px; }

.chp-choices { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; padding-left: 36px; }
.chp-choice {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 6px 14px;
    border: 1.5px solid color-mix(in srgb, var(--chp-accent) 55%, transparent);
    border-radius: 999px;
    background: var(--chp-surface);
    color: var(--chp-accent);
    font-weight: 600;
    font-size: 14px;
    text-decoration: none;
    transition: background 0.15s, color 0.15s, transform 0.15s;
}
.chp-choice:hover { background: var(--chp-accent); color: var(--chp-on-accent); }
.chp-choice:active { transform: scale(0.97); }

.chp-typing { display: flex; gap: 4px; width: max-content; margin: 8px 0 4px 36px; padding: 10px 12px; border-radius: 14px; background: var(--chp-surface); border: 1px solid var(--chp-border); }
.chp-typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--chp-muted); animation: chp-blink 1.2s infinite; }
.chp-typing span:nth-child(2) { animation-delay: 0.2s; }
.chp-typing span:nth-child(3) { animation-delay: 0.4s; }

.chp-notice { margin: 0; padding: 8px 14px; background: #fef3c7; color: #78350f; font-size: 13px; }

/* ---- composer ------------------------------------------------------------ */
.chp-compose {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 10px 10px 8px;
    border-top: 1px solid var(--chp-border);
    background: var(--chp-surface);
}
.chp-file { display: none; }
.chp-attach { color: var(--chp-muted); }
.chp-attach:hover { background: var(--chp-sunk); color: var(--chp-text); }
.chp-input {
    flex: 1;
    min-height: 40px;
    max-height: 140px;
    padding: 9px 12px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: var(--chp-sunk);
    color: var(--chp-text);
    font: inherit;
    resize: none;
    overflow-y: hidden;
    line-height: 1.4;
}
.chp-input:focus, .chp-input:focus-visible { outline: none; border-color: color-mix(in srgb, var(--chp-accent) 55%, transparent); background: var(--chp-surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--chp-accent) 14%, transparent); }
.chp-send {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: none;
    border: 0;
    border-radius: 50%;
    background: var(--chp-accent);
    color: var(--chp-on-accent);
    transition: opacity 0.15s, transform 0.15s;
}
.chp-send:disabled { opacity: 0.35; cursor: default; }
.chp-send:not(:disabled):hover { transform: scale(1.06); }

.chp-foot { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; padding: 0 12px 10px; background: var(--chp-surface); }
.chp-foot:empty { display: none; }
.chp-panel--sheet .chp-foot { display: none; }
.chp-link { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px; border: 0; border-radius: 8px; background: none; color: var(--chp-muted); font-size: 13px; }
.chp-link .chp-i { width: 15px; height: 15px; }
.chp-link:hover { color: var(--chp-accent); }

/* ---- forms --------------------------------------------------------------- */
.chp-sheet { max-height: 75%; overflow-y: auto; border-top: 1px solid var(--chp-border); background: var(--chp-surface); animation: chp-rise 0.22s var(--chp-ease); }
.chp-panel--sheet .chp-scroll { flex: 1; }
.chp-form { display: grid; gap: 10px; padding: 14px 16px 16px; }
.chp-form__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chp-form__head .chp-iconbtn { width: 32px; height: 32px; color: var(--chp-muted); }
.chp-form__head .chp-iconbtn:hover { background: var(--chp-sunk); }
.chp-form__title { margin: 0; font-size: 16px; font-weight: 650; color: var(--chp-text); }
.chp-form__lead { margin: -4px 0 0; font-size: 13.5px; color: var(--chp-muted); }
.chp-form__status { margin: 0; font-size: 13px; color: #b91c1c; }
.chp-form__status:empty { display: none; }
.chp-field { display: grid; gap: 4px; font-size: 13px; }
.chp-field__label { color: var(--chp-muted); font-weight: 500; }
.chp-req { color: #dc2626; }
.chp-field input, .chp-field textarea, .chp-rate__comment {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--chp-border);
    border-radius: 10px;
    background: var(--chp-surface);
    color: var(--chp-text);
    font: inherit;
    font-size: 15px;
}
.chp-field textarea, .chp-rate__comment { resize: vertical; }
.chp-field input:focus, .chp-field textarea:focus, .chp-rate__comment:focus { outline: none; border-color: var(--chp-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--chp-accent) 18%, transparent); }
.chp-field [aria-invalid="true"] { border-color: #dc2626; }
.chp-field__error { color: #b91c1c; font-size: 12px; }
.chp-field__error:empty { display: none; }
.chp-consent { display: grid; grid-template-columns: auto 1fr; gap: 4px 8px; align-items: start; font-size: 12.5px; color: var(--chp-muted); }
.chp-consent input { width: 17px; height: 17px; margin: 1px 0 0; accent-color: var(--chp-accent); }
.chp-consent .chp-field__error { grid-column: 2; }
.chp-consent a { color: var(--chp-accent); }
.chp-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.chp-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 18px;
    border: 0;
    border-radius: 12px;
    background: var(--chp-accent);
    color: var(--chp-on-accent);
    font-weight: 650;
    transition: filter 0.15s, transform 0.15s;
}
.chp-btn:hover { filter: brightness(1.06); }
.chp-btn:active { transform: scale(0.98); }
.chp-btn:disabled { opacity: 0.6; cursor: progress; }
.chp-btn--sm { min-height: 38px; padding: 8px 14px; }
.chp-btn--ghost { background: var(--chp-sunk); color: var(--chp-text); }
.chp-done { display: grid; justify-items: center; gap: 10px; padding: 12px 0; text-align: center; }
.chp-done p { margin: 0; }
.chp-done__icon { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: var(--chp-soft); color: var(--chp-accent); }
.chp-done__icon .chp-i { width: 26px; height: 26px; stroke-width: 2.4; }

.chp-inline { display: grid; gap: 8px; width: calc(100% - 36px); margin: 2px 0 0 36px; padding: 12px; border: 1px solid var(--chp-border); border-radius: 14px; background: var(--chp-surface); }
.chp-inline .chp-btn { justify-self: start; }

.chp-rate { display: grid; gap: 8px; justify-items: center; margin: 8px 0; padding: 14px; border-radius: 14px; background: var(--chp-surface); border: 1px solid var(--chp-border); text-align: center; }
.chp-rate__title { margin: 0; font-weight: 600; }
.chp-rate__row { display: flex; gap: 8px; }
.chp-rate__btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1.5px solid var(--chp-border); border-radius: 999px; background: var(--chp-surface); }
.chp-rate__btn[aria-pressed="true"] { border-color: var(--chp-accent); background: var(--chp-soft); color: var(--chp-accent); }

/* ---- phones: the whole screen -------------------------------------------- */
@media (max-width: 600px) {
    .chp-panel {
        position: fixed;
        inset: 0;
        width: auto;
        height: 100%;
        min-height: 0;
        border: 0;
        border-radius: 0;
        transform: translateY(24px);
    }
    .chp-head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
    .chp-compose { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
    .chp--open .chp-launcher, .chp--open .chp-bubble { visibility: hidden; }
    .chp-input { font-size: 16px; }
    .chp-field input, .chp-field textarea { font-size: 16px; }
    .chp-bubble { max-width: calc(100vw - 2 * var(--chp-x)); }
}
html.chp-lock, html.chp-lock body { overflow: hidden; }

@keyframes chp-rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes chp-pop { from { transform: scale(0.4); } to { transform: scale(1); } }
@keyframes chp-blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
    .chp, .chp *, .chp *::before, .chp *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

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