/* Demento AI Chat — виджет (Jivo-style). Префикс .daichat-* для изоляции. */

#daichat-root { all: initial; }

/* Пока показан cookie-баннер темы — виджет НЕ прячем (он доступен до принятия куки),
   а приподнимаем над баннером, чтобы не перекрывать его. Высоту подъёма
   (--daichat-cookie-lift) задаёт тема в syncBannerOffset() по фактической геометрии
   баннера; без баннера переменная = 0 → обычная позиция. У fixed-элемента с заданным
   bottom margin-bottom сдвигает его вверх — базовые bottom не дублируем. */
body:has(.cookie-banner.is-shown) #daichat-root .daichat-fab,
body:has(.cookie-banner.is-shown) #daichat-root .daichat-window,
body:has(.cookie-banner.is-shown) #daichat-root .daichat-tip {
    margin-bottom: var(--daichat-cookie-lift, 0px);
}
#daichat-root *, #daichat-root *::before, #daichat-root *::after {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ── FAB-кнопка + индикатор online + tooltip ─────────────────── */
.daichat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--daichat-color, #6c63ff);
    box-shadow: 0 8px 24px rgba(0,0,0,0.30), 0 2px 8px rgba(0,0,0,0.20);
    cursor: pointer;
    z-index: 2147483000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    padding: 0;
    border: 0;
    overflow: visible;
}
.daichat-fab:hover { transform: translateY(-2px) scale(1.04); box-shadow: 0 12px 32px rgba(0,0,0,0.35); }

.daichat-fab__icon {
    display: block;
    position: relative;
    z-index: 1;
}
/* Картинка-аватар (если задана через media uploader) */
.daichat-fab__icon--img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}
/* Текст-аватар (default <DV/>) — больше и чётче чем когда был SVG-img.
   flex-центрирование чтобы глиф был ровно по центру круга (без baseline-смещения). */
.daichat-fab__icon--text {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
    font-size: 17px;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.5px;
    line-height: 1;
}
.daichat-fab__close-icon { display: none; width: 24px; height: 24px; color: #fff; position: relative; z-index: 1; }
.daichat-fab.is-open .daichat-fab__icon { display: none; }
.daichat-fab.is-open .daichat-fab__close-icon { display: block; }

/* Пульсирующие волны вокруг FAB — два слоя со сдвигом по фазе */
.daichat-fab__ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--daichat-color, #6c63ff);
    opacity: 0.45;
    z-index: 0;
    animation: daichatRipple 1.8s ease-out infinite;
    pointer-events: none;
}
.daichat-fab__ring--delayed { animation-delay: 0.9s; }
@keyframes daichatRipple {
    0%   { transform: scale(1);   opacity: 0.45; }
    80%  { opacity: 0; }
    100% { transform: scale(2);   opacity: 0; }
}
/* Останавливаем волны когда окно чата открыто — не отвлекаем */
.daichat-fab.is-open .daichat-fab__ring { display: none; }
/* Если пользователь предпочитает уменьшенную анимацию — выключаем */
@media (prefers-reduced-motion: reduce) {
    .daichat-fab__ring { animation: none; opacity: 0; }
}

/* Зелёный online-индикатор в правом нижнем углу FAB */
.daichat-fab::after {
    content: '';
    position: absolute;
    right: 4px;
    bottom: 4px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #4ade80;
    border: 2px solid var(--daichat-color, #6c63ff);
    box-shadow: 0 0 0 1px rgba(255,255,255,0.25);
}
.daichat-fab.is-open::after { display: none; }

/* Жёлтый ярлычок-бейдж сверху-справа («AI · 24/7») */
.daichat-fab__badge {
    position: absolute;
    top: -12px;
    right: -26px;
    background: #ffd23b;
    color: #1f1f2c;
    font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, monospace;
    font-size: 11px;
    font-weight: 500;
    padding: 5px 10px;
    border-radius: 6px;
    line-height: 1;
    letter-spacing: 0.02em;
    box-shadow: 0 4px 10px rgba(0,0,0,0.18);
    white-space: nowrap;
    pointer-events: none;
    transform: rotate(8deg);
    z-index: 2;
}
.daichat-fab.is-open .daichat-fab__badge { display: none; }

/* Tooltip-облачко рядом с FAB (когда виджет свёрнут) */
.daichat-tip {
    position: fixed;
    right: 100px;
    bottom: 32px;
    max-width: 240px;
    background: #fff;
    color: #1f2937;
    padding: 12px 16px;
    border-radius: 14px;
    border-bottom-right-radius: 4px;
    box-shadow: 0 10px 28px rgba(0,0,0,0.18), 0 2px 6px rgba(0,0,0,0.08);
    font-size: 14px;
    line-height: 1.4;
    z-index: 2147482999;
    cursor: pointer;
    opacity: 0;
    transform: translateX(8px);
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
}
.daichat-tip.is-shown {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}
.daichat-tip__close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #f3f4f6;
    color: #6b7280;
    border: 0;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.10);
}
.daichat-tip__close:hover { background: #e5e7eb; }

/* ── Окно чата ─────────────────────────────────────────── */
.daichat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: 580px;
    max-height: calc(100vh - 130px);
    background: #fff;
    border-radius: 18px;
    box-shadow: 0 20px 56px rgba(0,0,0,0.25), 0 4px 12px rgba(0,0,0,0.10);
    z-index: 2147483000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    transform-origin: bottom right;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.daichat-window.is-open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }

.daichat-header {
    background: var(--daichat-color, #6c63ff);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}
.daichat-header__avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,0.22);
    flex: none;
}
.daichat-header__avatar--img { object-fit: cover; }
.daichat-header__avatar--text {
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: ui-monospace, "JetBrains Mono", Menlo, Consolas, "Courier New", monospace;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.3px;
    line-height: 1;
}
.daichat-header__body { flex: 1; min-width: 0; }
.daichat-header__title { font-size: 15px; font-weight: 700; line-height: 1.2; }
.daichat-header__subtitle {
    font-size: 12px;
    opacity: 0.90;
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.daichat-header__subtitle::before {
    content: '';
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74,222,128,0.7);
    flex: none;
}
.daichat-header__close {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 0;
    background: rgba(255,255,255,0.18);
    color: #fff;
    cursor: pointer;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}
.daichat-header__close:hover { background: rgba(255,255,255,0.30); }
.daichat-header__close svg { width: 14px; height: 14px; }

/* ── Лента сообщений ───────────────────────────────── */
.daichat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f7f8fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.daichat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.daichat-msg--user {
    align-self: flex-end;
    background: var(--daichat-color, #6c63ff);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.daichat-msg--assistant {
    align-self: flex-start;
    background: #fff;
    color: #1f2937;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    white-space: normal; /* markdown сам управляет переносами */
}
.daichat-msg--assistant strong { font-weight: 700; }
.daichat-msg--assistant a {
    color: var(--daichat-color, #6c63ff);
    font-weight: 600;
    text-decoration: underline;
}
.daichat-msg--assistant a:hover { opacity: 0.85; }

/* ── Quick-replies pills под welcome-сообщением ───── */
.daichat-quick {
    align-self: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-width: 100%;
    margin-top: -2px;
}
.daichat-quick__btn {
    background: #fff;
    border: 1.5px solid var(--daichat-color, #6c63ff);
    color: var(--daichat-color, #6c63ff);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.1s;
    line-height: 1.2;
}
.daichat-quick__btn:hover {
    background: var(--daichat-color, #6c63ff);
    color: #fff;
}
.daichat-quick__btn:active { transform: scale(0.97); }

/* Typing-indicator (3 точки) */
.daichat-typing {
    align-self: flex-start;
    background: #fff;
    padding: 12px 16px;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    display: flex;
    gap: 4px;
    align-items: center;
}
.daichat-typing__dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: daichatBlink 1.2s infinite;
}
.daichat-typing__dot:nth-child(2) { animation-delay: 0.2s; }
.daichat-typing__dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes daichatBlink { 0%, 60%, 100% { opacity: 0.3; } 30% { opacity: 1; } }

.daichat-error {
    align-self: stretch;
    background: #fee2e2;
    color: #b91c1c;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

/* ── Input area ─────────────────────────────────── */
.daichat-input {
    border-top: 1px solid #eef0f3;
    background: #fff;
    padding: 10px 14px 6px;
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.daichat-input__textarea {
    flex: 1;
    resize: none;
    border: 0;
    background: transparent;
    padding: 9px 6px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
    max-height: 120px;
    outline: none;
    color: #1f2937;
}
.daichat-input__textarea::placeholder { color: #9ca3af; }

.daichat-input__send {
    width: 38px; height: 38px;
    flex: none;
    border-radius: 50%;
    background: #f3f4f6;
    color: #6b7280;
    border: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s, transform 0.1s;
}
.daichat-input__send:hover:not(:disabled) { background: #e5e7eb; color: #1f2937; }
.daichat-input__send:not(:disabled).is-ready {
    background: var(--daichat-color, #6c63ff);
    color: #fff;
}
.daichat-input__send:disabled { opacity: 0.45; cursor: not-allowed; }
.daichat-input__send svg { width: 16px; height: 16px; }

/* ── Footer brand ──────────────────────────────────────── */
.daichat-footer {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    padding: 0 12px 10px;
    background: #fff;
    line-height: 1.4;
}
.daichat-footer a { color: #6b7280; text-decoration: underline; }
.daichat-footer a:hover { color: var(--daichat-color, #6c63ff); }

/* ── Инлайн-инстанс (встроенный в поток страницы — демо-блок) ──────────
   Переиспользует всю внутрянку .daichat-* (header/messages/input/quick/typing),
   меняет только позиционирование окна: из fixed-плавающего в in-flow. */
.daichat-embed { box-sizing: border-box; }
.daichat-embed *, .daichat-embed *::before, .daichat-embed *::after {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
.daichat-embed .daichat-window {
    position: static;
    right: auto; bottom: auto;
    width: 100%;
    height: clamp(480px, 62vh, 560px);
    max-height: none;
    opacity: 1;
    transform: none;
    pointer-events: auto;
    border: 1px solid rgba(0,0,0,0.08);
    box-shadow: 0 20px 56px rgba(0,0,0,0.16);
}
.daichat-embed .daichat-header__close { display: none; }
@media (max-width: 600px) {
    .daichat-embed .daichat-window { height: 70vh; }
}

/* ── Mobile ───────────────────────────────────── */
@media (max-width: 600px) {
    .daichat-fab { width: 56px; height: 56px; bottom: 16px; right: 16px; }
    .daichat-fab__icon--img { width: 38px; height: 38px; }
    /* Текст-аватар: меньше шрифт, меньше внутренний бокс — иначе глиф упирается в края круга */
    .daichat-fab__icon--text { width: 38px; height: 38px; font-size: 14px; }
    .daichat-header__avatar { width: 36px; height: 36px; }
    .daichat-header__avatar--text { font-size: 11px; }
    .daichat-fab__badge { top: -8px; right: -10px; font-size: 10px; padding: 3px 7px; }
    .daichat-tip { right: 80px; bottom: 24px; max-width: 200px; font-size: 13px; padding: 10px 14px; }
    .daichat-window {
        right: 8px; left: 8px; bottom: 84px;
        width: auto;
        max-height: calc(100vh - 110px);
    }
}

/* demento.dev: the text avatar sits on a dark tint (white text on the light tint was 3:1, WCAG needs 4.5:1) */
.daichat-header__avatar--text { background: rgba(0, 0, 0, 0.2); }
