/* Чат поддержки — виджет на сайте */
.scw {
    --scw-accent-base: var(--theme-color, #1a1a1a);
    --scw-bg: #fff;
    --scw-text: #1a1a1a;
    --scw-muted: #858585;
    --scw-line: #ececea;
    --scw-soft: #f4f4f2;
    --scw-radius: 18px;
    font-family: var(--main-font, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif);
    font-size: 15px;
    line-height: 1.4;
    color: var(--scw-text);
}
.scw *, .scw *::before, .scw *::after { box-sizing: border-box; }
.scw { --scw-a: var(--scw-accent, var(--scw-accent-base)); }

/* ---------- кнопка ---------- */
.scw-btn {
    position: fixed;
    right: var(--scw-right, 20px);
    bottom: var(--scw-bottom, 20px);
    z-index: 10000;
    width: 60px;
    height: 60px;
    border: 0;
    border-radius: 50%;
    background: var(--scw-a);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
    transition: transform .2s ease, box-shadow .2s ease;
    padding: 0;
}
.scw-btn:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 28px rgba(0, 0, 0, .26); }
.scw-btn:focus-visible { outline: 3px solid rgba(0, 0, 0, .35); outline-offset: 3px; }
.scw-btn svg { width: 28px; height: 28px; transition: transform .25s ease, opacity .2s ease; }
.scw-btn .scw-ico-close { position: absolute; opacity: 0; transform: rotate(-90deg) scale(.6); }
.scw.is-open .scw-btn .scw-ico-chat { opacity: 0; transform: rotate(90deg) scale(.6); }
.scw.is-open .scw-btn .scw-ico-close { opacity: 1; transform: none; }
.scw-btn::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--scw-a);
    opacity: 0;
    animation: scw-pulse 2.6s ease-out 3s 3;
    pointer-events: none;
}
@keyframes scw-pulse { 0% { transform: scale(1); opacity: .55; } 100% { transform: scale(1.55); opacity: 0; } }

.scw-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: #E12D06;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    border: 2px solid #fff;
}
.scw-badge[hidden] { display: none; }

/* ---------- подсказка у кнопки ---------- */
.scw-teaser {
    position: fixed;
    right: calc(var(--scw-right, 20px) + 4px);
    bottom: calc(var(--scw-bottom, 20px) + 72px);
    z-index: 10000;
    max-width: 260px;
    padding: 12px 34px 12px 14px;
    background: #fff;
    color: var(--scw-text);
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .16);
    font-size: 14px;
    cursor: pointer;
    animation: scw-in .3s ease;
}
.scw-teaser[hidden] { display: none; }
.scw-teaser__close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: 0;
    background: transparent;
    color: var(--scw-muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}
.scw-teaser__who { display: block; font-size: 12px; color: var(--scw-muted); margin-bottom: 2px; }

/* ---------- окно ---------- */
.scw-panel {
    position: fixed;
    right: var(--scw-right, 20px);
    bottom: calc(var(--scw-bottom, 20px) + 76px);
    z-index: 10001;
    width: 380px;
    height: min(620px, calc(100vh - var(--scw-bottom, 20px) - 110px));
    background: var(--scw-bg);
    border-radius: var(--scw-radius);
    box-shadow: 0 18px 60px rgba(0, 0, 0, .22);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(.98);
    transform-origin: bottom right;
    transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}
.scw.is-open .scw-panel {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity .2s ease, transform .2s ease;
}
@keyframes scw-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.scw-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 14px;
    background: var(--scw-a);
    color: #fff;
    flex: none;
}
.scw-head__ava {
    position: relative;
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
}
.scw-head__dot {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #b5b5b5;
    border: 2px solid var(--scw-a);
}
.scw.is-online .scw-head__dot { background: #23A41F; }
.scw-head__info { flex: 1; min-width: 0; }
.scw-head__title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scw-head__sub { font-size: 12.5px; opacity: .85; margin-top: 1px; }
.scw-head__close {
    flex: none;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.scw-head__close:hover { background: rgba(255, 255, 255, .24); }
.scw-head__close svg { width: 18px; height: 18px; }

.scw-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px 8px;
    background: var(--scw-soft);
    -webkit-overflow-scrolling: touch;
}
.scw-day { text-align: center; font-size: 12px; color: var(--scw-muted); margin: 10px 0 8px; }
.scw-sys { text-align: center; font-size: 12.5px; color: var(--scw-muted); margin: 6px 12px 10px; }
.scw-sys--err { color: #E12D06; }

.scw-msg { display: flex; flex-direction: column; margin-bottom: 8px; max-width: 84%; animation: scw-in .2s ease; }
.scw-msg--in { align-items: flex-start; }
.scw-msg--out { align-items: flex-end; margin-left: auto; }
.scw-msg__who { font-size: 11.5px; color: var(--scw-muted); margin: 0 0 3px 4px; }
.scw-msg__bubble {
    padding: 9px 13px;
    border-radius: 16px;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.scw-msg--in .scw-msg__bubble { background: #fff; border-bottom-left-radius: 5px; box-shadow: 0 1px 2px rgba(0, 0, 0, .05); }
.scw-msg--out .scw-msg__bubble { background: var(--scw-a); color: #fff; border-bottom-right-radius: 5px; }
.scw-msg__bubble a { color: inherit; text-decoration: underline; }
.scw-msg__img {
    display: block;
    max-width: 100%;
    width: 240px;
    height: auto;
    border-radius: 12px;
    cursor: zoom-in;
    background: #e8e8e6;
}
.scw-msg__bubble--img { padding: 4px; }
.scw-msg__bubble--img .scw-msg__text { padding: 6px 8px 4px; }
.scw-msg__meta { font-size: 11px; color: var(--scw-muted); margin: 3px 6px 0; }
.scw-msg.is-pending { opacity: .6; }
.scw-msg.is-failed .scw-msg__bubble { background: #fbe4df; color: #9b1f04; }

.scw-foot {
    flex: none;
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 10px 12px;
    border-top: 1px solid var(--scw-line);
    background: #fff;
}
.scw-foot__btn {
    flex: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--scw-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background .15s, color .15s;
}
.scw-foot__btn:hover { background: var(--scw-soft); color: var(--scw-text); }
.scw-foot__btn svg { width: 22px; height: 22px; }
.scw-foot__send { background: var(--scw-a); color: #fff; }
.scw-foot__send:hover { background: var(--scw-a); color: #fff; opacity: .9; }
.scw-foot__send:disabled { opacity: .35; cursor: default; }
.scw-input {
    flex: 1;
    min-width: 0;
    min-height: 40px;
    max-height: 120px;
    padding: 9px 12px;
    border: 1px solid var(--scw-line);
    border-radius: 20px;
    background: var(--scw-soft);
    color: var(--scw-text);
    font: inherit;
    font-size: 15px;
    resize: none;
    outline: none;
    line-height: 1.35;
}
.scw-input:focus { border-color: #cfcfcc; background: #fff; }

.scw-attach {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px 0;
    background: #fff;
    font-size: 13px;
    color: var(--scw-muted);
}
.scw-attach[hidden] { display: none; }
.scw-attach img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; }
.scw-attach button { margin-left: auto; border: 0; background: none; color: var(--scw-muted); cursor: pointer; font-size: 20px; line-height: 1; }

.scw-drop {
    position: absolute;
    inset: 0;
    z-index: 3;
    background: rgba(255, 255, 255, .92);
    border: 2px dashed var(--scw-a);
    border-radius: var(--scw-radius);
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}
.scw-panel.is-drag .scw-drop { display: flex; }

.scw-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10010;
    background: rgba(0, 0, 0, .85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: zoom-out;
}
.scw-lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- телефон ---------- */
@media (max-width: 639px) {
    .scw-btn { right: 16px; bottom: var(--scw-bottom-m, 16px); width: 56px; height: 56px; }
    .scw-teaser { right: 16px; bottom: calc(var(--scw-bottom-m, 16px) + 68px); max-width: calc(100vw - 32px); }
    .scw-panel {
        inset: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
        transform: translateY(24px);
    }
    .scw.is-open .scw-btn { display: none; }
    .scw-head { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
    .scw-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
    .scw-input { font-size: 16px; } /* без автозума на iPhone */
    .scw-msg { max-width: 88%; }
}
html.scw-lock, html.scw-lock body { overflow: hidden !important; }

@media (prefers-reduced-motion: reduce) {
    .scw *, .scw *::before, .scw *::after { animation: none !important; transition: none !important; }
}
@media print { .scw { display: none !important; } }
