/* ==========================================================================
   SiteWidget 2.0 — слой виджетов (.afsw-* изоляция, как .wcalc-* у floating_calc)
   Поверхность/текст — собственные токены с dark-парой (паттерн style.css
   :root + [data-theme="dark"]). Z-карта: bottom-stack/cta 10020, snow 10030,
   social 10035, backdrop 10040, modal 10050 (floating_calc FAB 9999 — модалка
   поверх него, осознанно: модалка важнее).
   ========================================================================== */

.afsw-root {
    --afsw-surface: #ffffff;
    --afsw-surface-text: var(--text-main, #1a1a2e);
    --afsw-muted: var(--text-muted, #6a6a88);
    --afsw-border: var(--border, rgba(90, 82, 224, 0.12));
    --afsw-backdrop: rgba(20, 20, 40, 0.45);
}
html[data-theme="dark"] .afsw-root,
html[data-theme="dark"] .afsw-promo {
    --afsw-surface: #16162a;
    --afsw-surface-text: #e4e4f0;
    --afsw-muted: #8a8aa8;
    --afsw-border: rgba(255, 255, 255, 0.12);
    --afsw-backdrop: rgba(0, 0, 0, 0.6);
}
html[data-theme="dark"] .afsw-promo {
    --afsw-promo-bg: #16162a;
    --afsw-promo-text: #e4e4f0;
}

/* --- Общие элементы ------------------------------------------------------ */

/* Классовый display:* перебивает UA-правило [hidden]{display:none} — без этого
   hidden-виджеты перехватывают клики (поймано Playwright: backdrop exit_intent
   блокировал dismiss welcome). */
[data-widget-type][hidden] {
    display: none !important;
}

.afsw-btn {
    display: inline-block;
    padding: 10px 22px;
    border: none;
    border-radius: 10px;
    background: var(--accent, #00b8d4);
    color: #ffffff;
    font-family: var(--font-main, "Segoe UI", system-ui, sans-serif);
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: background 0.15s ease;
}
.afsw-btn:hover {
    background: var(--accent-hover, #009db5);
    color: #ffffff;
}
.afsw-btn--sm {
    padding: 7px 16px;
    font-size: 0.85rem;
}
/* Ghost — вторичное действие (cookie_bar «Подробнее»); dark — через afsw-токены */
.afsw-btn--ghost {
    background: transparent;
    color: var(--afsw-surface-text, var(--text-main));
    border: 1px solid var(--afsw-border);
}
.afsw-btn--ghost:hover {
    background: var(--afsw-border);
    color: var(--afsw-surface-text, var(--text-main));
}

.afsw-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    min-height: 28px;
    padding: 2px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--afsw-muted, var(--text-muted, #6a6a88));
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}
.afsw-close:hover {
    color: var(--afsw-surface-text, var(--text-main, #1a1a2e));
    background: var(--bg-secondary, rgba(0, 0, 0, 0.05));
}
.afsw-close svg {
    width: 16px;
    height: 16px;
}

.afsw-preview-badge {
    position: absolute;
    top: 6px;
    left: 8px;
    z-index: 2;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--danger, #dc3545);
    color: #ffffff;
    font-family: var(--font-main, "Segoe UI", system-ui, sans-serif);
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    pointer-events: none;
}

/* --- Bottom-стек (promo bottom + cta bottom_strip + cookie_bar) ---------- */

.afsw-bottom-stack {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 10020;
    display: flex;
    flex-direction: column;
}

/* --- Промо-баннер -------------------------------------------------------- */

.afsw-promo {
    --afsw-promo-bg: var(--bg-card, #f6f7fc);
    --afsw-promo-text: var(--text-main, #1a1a2e);
    position: relative;
    width: 100%;
    background: var(--afsw-promo-bg);
    color: var(--afsw-promo-text);
    border-bottom: 1px solid var(--afsw-border, var(--border, rgba(90, 82, 224, 0.12)));
    font-family: var(--font-main, "Segoe UI", system-ui, sans-serif);
}
.afsw-promo--bottom {
    border-bottom: none;
    border-top: 1px solid var(--afsw-border, var(--border, rgba(90, 82, 224, 0.12)));
}
.afsw-promo__inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 44px 10px 16px;
}
.afsw-promo__text {
    font-size: 0.9rem;
    font-weight: 600;
}
.afsw-promo__link {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent, #00b8d4);
    text-decoration: none;
    white-space: nowrap;
}
.afsw-promo__link:hover {
    text-decoration: underline;
}
.afsw-promo .afsw-close {
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
}

/* --- CTA-форма ----------------------------------------------------------- */

.afsw-cta {
    position: relative;
    width: 300px;
    padding: 18px 20px;
    border: 1px solid var(--afsw-border);
    border-radius: 14px;
    background: var(--afsw-surface);
    color: var(--afsw-surface-text);
    box-shadow: var(--shadow-lg, 0 12px 48px rgba(0, 0, 0, 0.10));
    font-family: var(--font-main, "Segoe UI", system-ui, sans-serif);
}
.afsw-cta--floating {
    position: fixed;
    bottom: 20px;
    z-index: 10020;
    animation: afsw-rise 0.25s ease-out;
}
.afsw-cta--dock-left { left: 20px; }
.afsw-cta--dock-right { right: 20px; }
.afsw-cta--bottom_strip {
    width: 100%;
    border: none;
    border-top: 1px solid var(--afsw-border);
    border-radius: 0;
    box-shadow: none;
    text-align: center;
}
.afsw-cta__close {
    position: absolute;
    top: 8px;
    right: 8px;
}
.afsw-cta__title {
    padding-right: 26px;
    font-size: 1rem;
    font-weight: 800;
}
.afsw-cta__text {
    margin-top: 6px;
    color: var(--afsw-muted);
    font-size: 0.86rem;
    line-height: 1.45;
}
.afsw-cta .afsw-btn {
    margin-top: 12px;
    width: 100%;
}
.afsw-cta--bottom_strip .afsw-btn {
    width: auto;
}

/* --- Модалки (welcome_modal / returning_promo modal / exit_intent) -------- */

.afsw-modal {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
/* Backdrop по умолчанию ПОД контентом: hidden-модалки (fixed inset:0, но
   pointer-events:none у [hidden]) иначе перекрывали бы клики всеми своими
   backdrop'ами; у открытой модалки JS ставит z-index ниже dialog (10040). */
.afsw-modal__backdrop {
    position: absolute;
    inset: 0;
    z-index: -1;
    background: var(--afsw-backdrop);
}
.afsw-modal[open] .afsw-modal__backdrop {
    z-index: 10040;
}
.afsw-modal__dialog {
    position: relative;
    z-index: 10050;
    width: 100%;
    max-width: 460px;
    padding: 28px;
    border: 1px solid var(--afsw-border);
    border-radius: 16px;
    background: var(--afsw-surface);
    color: var(--afsw-surface-text);
    box-shadow: var(--shadow-lg, 0 12px 48px rgba(0, 0, 0, 0.10));
    font-family: var(--font-main, "Segoe UI", system-ui, sans-serif);
    animation: afsw-pop 0.22s ease-out;
}
.afsw-modal__close {
    position: absolute;
    top: 10px;
    right: 10px;
}
.afsw-modal__title {
    padding-right: 30px;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1.3;
}
.afsw-modal__text {
    margin-top: 10px;
    color: var(--afsw-muted);
    font-size: 0.92rem;
    line-height: 1.5;
}
.afsw-modal__bullets {
    margin: 12px 0 0;
    padding-left: 20px;
    color: var(--afsw-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}
.afsw-modal .afsw-btn {
    margin-top: 18px;
    width: 100%;
}

/* --- Тост (returning_promo style=toast) и соцдоказательство --------------- */

.afsw-toast,
.afsw-social {
    position: fixed;
    right: 20px;
    bottom: 20px; /* JS поднимает над bottom-стеком / floating_calc FAB */
    z-index: 10035;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 340px;
    padding: 14px 16px;
    border: 1px solid var(--afsw-border);
    border-radius: 12px;
    background: var(--afsw-surface);
    color: var(--afsw-surface-text);
    box-shadow: var(--shadow-lg, 0 12px 48px rgba(0, 0, 0, 0.10));
    font-family: var(--font-main, "Segoe UI", system-ui, sans-serif);
    animation: afsw-rise 0.25s ease-out;
}
.afsw-toast__title {
    font-size: 0.95rem;
    font-weight: 800;
}
.afsw-toast__text {
    margin-top: 4px;
    color: var(--afsw-muted);
    font-size: 0.85rem;
    line-height: 1.45;
}
.afsw-toast .afsw-btn {
    margin-top: 10px;
}
.afsw-social__icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    margin-top: 2px;
    color: var(--accent, #00b8d4);
}
.afsw-social__text {
    font-size: 0.88rem;
    font-weight: 600;
    line-height: 1.4;
}
.afsw-social .afsw-close,
.afsw-toast .afsw-close {
    flex-shrink: 0;
}

/* --- Cookie-бар ----------------------------------------------------------- */

.afsw-cookie {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    width: 100%;
    padding: 12px 16px;
    border-top: 1px solid var(--afsw-border);
    background: var(--afsw-surface);
    color: var(--afsw-surface-text);
    font-family: var(--font-main, "Segoe UI", system-ui, sans-serif);
}
.afsw-cookie__text {
    font-size: 0.86rem;
    line-height: 1.45;
}
.afsw-cookie__btn {
    flex-shrink: 0;
}

/* --- Снег ----------------------------------------------------------------- */

.afsw-snow {
    position: fixed;
    inset: 0;
    z-index: 10030;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* --- Анимации -------------------------------------------------------------- */

@keyframes afsw-rise {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes afsw-pop {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

/* --- Мобильный (<768px) ---------------------------------------------------- */

@media (max-width: 768px) {
    .afsw-cta--floating {
        left: 12px;
        right: 12px;
        bottom: 12px;
        width: auto;
    }
    .afsw-cta--dock-right { right: 12px; }
    .afsw-toast,
    .afsw-social {
        right: 12px;
        left: 12px;
        max-width: none;
    }
    .afsw-modal__dialog {
        padding: 22px 18px;
    }
    .afsw-promo__inner {
        padding: 8px 40px 8px 12px;
        gap: 8px;
    }
    .afsw-promo__text {
        font-size: 0.82rem;
    }
    .afsw-cookie {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }
    .afsw-cookie__text {
        font-size: 0.8rem;
    }
}

/* --- Reduced motion: ни одной анимации; снег не показывается СОВСЕМ -------- */

@media (prefers-reduced-motion: reduce) {
    .afsw-cta--floating,
    .afsw-toast,
    .afsw-social,
    .afsw-modal__dialog {
        animation: none;
    }
    .afsw-snow {
        display: none !important;
    }
}

/* --- Печать: виджеты скрыты СВОИМ файлом (print.css НЕ трогаем — паттерн
       widget-calc.css); [data-widget-type] покрывает и top-промо вне .afsw-root -- */

@media print {
    [data-widget-type],
    .afsw-root {
        display: none !important;
    }
}
