/* Плавающий виртуальный помощник */
:root { --cbw-size: 90px; }   /* РАЗМЕР КНОПКИ С БОТОМ — меняйте только это число (на телефоне — ниже, в @media) */
.cbw {
    --cbw-gap: 14px;           /* зазор между кнопкой и окном */
    --cbw-offset: calc(var(--cbw-size) + var(--cbw-gap));
    position: fixed; right: 20px; bottom: 20px; z-index: 1060; font-family: inherit;
}
.cbw[hidden], .cbw [hidden] { display: none !important; }

/* Кнопка «наверх» поднимаем над кнопкой чата */
body:has(.cbw) .back-to-top { bottom: calc(20px + var(--cbw-size) + 18px) !important; right: 28px !important; }

.cbw-toggle {
    width: var(--cbw-size); height: var(--cbw-size); border-radius: 50%; border: 0; cursor: pointer;
    background: linear-gradient(135deg, #2a86d0 0%, #14407a 100%); color: #fff; font-size: 1.5rem;
    display: flex; align-items: center; justify-content: center;
    box-shadow: 0 8px 24px rgba(31, 111, 181, .5);
    transition: transform .2s ease, box-shadow .2s ease;
    position: relative; margin-left: auto;
}
.cbw-toggle:hover, .cbw-toggle:focus-visible { transform: scale(1.07); box-shadow: 0 10px 28px rgba(31, 111, 181, .65); }
.cbw-toggle:focus-visible { outline: 3px solid #172b4d; outline-offset: 3px; }
.cbw-toggle { padding: 0; border: 3px solid #fff; background: #5dafdf; overflow: visible; }
.cbw-toggle .cbw-toggle-img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.cbw-toggle .cbw-ico-close { display: none; }
.cbw-badge { position: absolute; right: 0; top: 0; width: 28px; height: 28px; border-radius: 50%; background: #f5a623; color: #fff;
    font-size: .8rem; display: flex; align-items: center; justify-content: center; border: 2px solid #fff; }
.cbw.is-open .cbw-toggle { background: #14407a; }
.cbw.is-open .cbw-toggle .cbw-toggle-img, .cbw.is-open .cbw-badge { display: none; }
.cbw.is-open .cbw-toggle .cbw-ico-close { display: inline; }
.cbw:not(.is-open) .cbw-toggle::after {
    content: ''; position: absolute; inset: 0; border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(31, 111, 181, .6); animation: cbwPulse 2.4s infinite;
}
@keyframes cbwPulse { 0% { box-shadow: 0 0 0 0 rgba(31, 111, 181, .55); } 70%, 100% { box-shadow: 0 0 0 18px rgba(31, 111, 181, 0); } }

.cbw-hint {
    position: absolute; right: 0; bottom: var(--cbw-offset); width: 250px; background: #fff; color: #212529;
    padding: 12px 30px 12px 14px; border-radius: 14px 14px 4px 14px; font-size: .9rem; line-height: 1.35;
    box-shadow: 0 6px 20px rgba(0, 0, 0, .18); animation: cbwIn .3s ease;
}
.cbw-hint-close { position: absolute; top: 2px; right: 6px; border: 0; background: none; font-size: 1.3rem; line-height: 1; color: #6c757d; cursor: pointer; }

.cbw-panel {
    position: absolute; right: 0; bottom: var(--cbw-offset); width: 420px; max-width: calc(100vw - 40px);
    height: 620px; max-height: calc(100vh - var(--cbw-offset) - 40px);
    padding: 0; margin: 0; /* сайт задаёт section { padding: 80px 0 } — здесь отступы не нужны */
    background: #fff; color: #212529; border-radius: 16px; overflow: hidden;
    display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
    animation: cbwIn .25s ease;
}
@keyframes cbwIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

.cbw-header { display: flex; align-items: center; gap: 12px; padding: 14px 16px; color: #fff; background: linear-gradient(135deg, #2a86d0 0%, #14407a 100%); }
.cbw-avatar { width: 56px; height: 56px; flex: 0 0 56px; border-radius: 50%; background: #5dafdf; border: 2px solid rgba(255, 255, 255, .85); overflow: hidden; }
.cbw-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cbw-title { flex: 1 1 auto; min-width: 0; line-height: 1.2; }
.cbw-title strong { display: block; font-size: 1.1rem; }
.cbw-title small { opacity: .9; }
.cbw-title small i { color: #4cd964; font-size: .55rem; margin-right: 4px; vertical-align: middle; }
.cbw-close { border: 0; background: rgba(255, 255, 255, .18); color: #fff; width: 34px; height: 34px; border-radius: 8px; cursor: pointer; }
.cbw-close:hover { background: rgba(255, 255, 255, .3); }

.cbw-messages { flex: 1 1 auto; overflow-y: auto; padding: 14px; background: #eaf3fb; }
.cbw-msg { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 12px; animation: cbwIn .25s ease; }
.cbw-mini { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 50%; object-fit: cover; background: #5dafdf; border: 1px solid #cfe3f5; }
.cbw-msg.user { justify-content: flex-end; }
.cbw-bubble { max-width: 78%; padding: 11px 14px; border-radius: 14px; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, .1); font-size: 1rem; line-height: 1.4; white-space: pre-line; overflow-wrap: anywhere; }
.cbw-msg.bot .cbw-bubble { border-bottom-left-radius: 4px; }
.cbw-msg.user .cbw-bubble { border-bottom-right-radius: 4px; background: #1f6fb5; color: #fff; }
.cbw-time { display: block; margin-top: 4px; font-size: .7rem; text-align: right; color: #8a94a6; }
.cbw-msg.user .cbw-time { color: rgba(255, 255, 255, .75); }

.cbw-typing { display: inline-flex; gap: 4px; padding: 4px 2px; }
.cbw-typing i { width: 7px; height: 7px; border-radius: 50%; background: #8a94a6; animation: cbwDot 1.2s infinite; }
.cbw-typing i:nth-child(2) { animation-delay: .2s; }
.cbw-typing i:nth-child(3) { animation-delay: .4s; }
@keyframes cbwDot { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

.cbw-quick { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto; border-top: 1px solid #e9ecef; background: #fff; scrollbar-width: thin; }
.cbw-quick button { flex: 0 0 auto; border: 1px solid #1f6fb5; color: #1f6fb5; background: #fff; border-radius: 50px; padding: 5px 12px; font-size: .8rem; cursor: pointer; white-space: nowrap; }
.cbw-quick button:hover { background: #1f6fb5; color: #fff; }

.cbw-form { display: flex; gap: 8px; padding: 10px 12px 12px; background: #fff; border-top: 1px solid #e9ecef; }
.cbw-form input { flex: 1 1 auto; min-width: 0; border: 1px solid #ced4da; border-radius: 50px; padding: 9px 14px; font-size: .93rem; }
.cbw-form input:focus { outline: 0; border-color: #1f6fb5; box-shadow: 0 0 0 3px rgba(31, 111, 181, .25); }
.cbw-form button { flex: 0 0 42px; height: 42px; border: 0; border-radius: 50%; background: #1f6fb5; color: #fff; cursor: pointer; }
.cbw-form button:disabled { opacity: .55; cursor: default; }

@media (max-width: 575.98px) {
    :root { --cbw-size: 72px; }   /* размер кнопки на телефоне */
    .cbw { right: 14px; bottom: 14px; }
    body:has(.cbw) .back-to-top { bottom: calc(14px + var(--cbw-size) + 14px) !important; right: 22px !important; }
    .cbw-panel { position: fixed; right: 10px; left: 10px; bottom: calc(14px + var(--cbw-offset)); width: auto; max-width: none; height: min(620px, calc(100vh - var(--cbw-offset) - 40px)); }
    .cbw-hint { width: 210px; }
}
@media (prefers-reduced-motion: reduce) {
    .cbw *, .cbw *::before, .cbw *::after { animation: none !important; transition: none !important; }
}
