/* ─────────────────────────────────────────────────────────────────────
   AI Chat Widget — превью для magistcalc.ru
   Floating FAB → выезжающее чат-окно с моком intelligence.
   Брендинг: orange #EA580C + purple #7C3AED (AI accent).
   Видим только клиенту (.client-show), скрыт в embed-режиме.
   ───────────────────────────────────────────────────────────────────── */

/* === FAB (плавающая кнопка) === */
#ai-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, #EA580C 0%, #7C3AED 100%);
    border: 0;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(234, 88, 12, 0.35), 0 4px 12px rgba(124, 58, 237, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    z-index: 9998;
    transition: transform .2s ease-out, box-shadow .2s;
    -webkit-tap-highlight-color: transparent;
}
#ai-chat-fab:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 12px 32px rgba(234, 88, 12, 0.45), 0 6px 16px rgba(124, 58, 237, 0.35); }
#ai-chat-fab:active { transform: scale(0.96); }
#ai-chat-fab:focus-visible { outline: 3px solid #7C3AED; outline-offset: 3px; }
#ai-chat-fab svg { width: 28px; height: 28px; }
#ai-chat-fab .ai-fab-pulse {
    position: absolute; inset: 0; border-radius: 50%;
    border: 2px solid rgba(234, 88, 12, 0.55);
    animation: aiFabPulse 2s ease-out infinite;
    pointer-events: none;
}
@keyframes aiFabPulse {
    0%   { transform: scale(1);   opacity: 0.8; }
    100% { transform: scale(1.7); opacity: 0;   }
}
#ai-chat-fab .ai-fab-badge {
    position: absolute;
    top: -4px; right: -4px;
    background: #16A34A;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 3px 6px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(22, 163, 74, 0.4);
    pointer-events: none;
}

/* === Окно чата === */
#ai-chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    height: min(620px, calc(100vh - 130px));
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 16px 48px rgba(15, 23, 42, 0.18), 0 4px 16px rgba(15, 23, 42, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity .2s ease-out, transform .25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
#ai-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* === Header === */
.ai-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    background: linear-gradient(135deg, #EA580C 0%, #7C3AED 100%);
    color: #fff;
}
.ai-chat-avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ai-chat-avatar svg { width: 22px; height: 22px; }
.ai-chat-titles { flex: 1; min-width: 0; }
.ai-chat-title { font-size: 15px; font-weight: 600; line-height: 1.2; }
.ai-chat-subtitle {
    font-size: 12px;
    opacity: 0.92;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.ai-chat-subtitle::before {
    content: '';
    width: 7px; height: 7px;
    background: #4ADE80;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
    animation: aiDotPulse 2s infinite;
}
@keyframes aiDotPulse {
    0%   { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7); }
    70%  { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
    100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0); }
}
.ai-chat-close {
    width: 32px; height: 32px;
    border: 0;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
}
.ai-chat-close:hover { background: rgba(255, 255, 255, 0.28); }
.ai-chat-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* === Тело чата === */
.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #FAFAF9;
}
.ai-chat-body::-webkit-scrollbar { width: 6px; }
.ai-chat-body::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }

/* === Сообщения === */
.ai-msg {
    display: flex;
    gap: 8px;
    animation: aiMsgIn .25s ease-out;
    max-width: 100%;
}
.ai-msg.ai-msg-user { justify-content: flex-end; }
.ai-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 80%;
    word-wrap: break-word;
}
.ai-msg-ai .ai-msg-bubble {
    background: #fff;
    color: #0F172A;
    border: 1px solid #E2E8F0;
    border-bottom-left-radius: 4px;
}
.ai-msg-user .ai-msg-bubble {
    background: #EA580C;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-msg-mini-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #EA580C, #7C3AED);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 13px;
    align-self: flex-start;
}
.ai-msg-mini-avatar svg { width: 14px; height: 14px; }
@keyframes aiMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* === Typing-индикатор === */
.ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}
.ai-typing span {
    width: 6px; height: 6px;
    background: #94A3B8;
    border-radius: 50%;
    animation: aiTypingJump 1.2s infinite ease-in-out;
}
.ai-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes aiTypingJump {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* === Quick-reply chips === */
.ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 4px 36px; /* отступ под mini-avatar */
}
.ai-chip {
    padding: 8px 14px;
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 20px;
    font-size: 13px;
    color: #475569;
    cursor: pointer;
    transition: all .15s;
    line-height: 1.2;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}
.ai-chip:hover {
    border-color: #EA580C;
    color: #EA580C;
    background: rgba(234, 88, 12, 0.04);
    transform: translateY(-1px);
}
.ai-chip:focus-visible { outline: 2px solid #7C3AED; outline-offset: 2px; }
.ai-chip:active { transform: scale(0.96); }

/* === Inline CTA cards (после расчёта) === */
.ai-calc-card {
    margin: 6px 0 0 36px;
    padding: 14px;
    background: #fff;
    border: 1px solid #E2E8F0;
    border-radius: 14px;
}
.ai-calc-card__header {
    font-size: 12px;
    color: #64748B;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
    margin-bottom: 6px;
}
.ai-calc-card__title { font-size: 14px; color: #0F172A; font-weight: 600; margin-bottom: 4px; }
.ai-calc-card__price {
    font-size: 24px;
    font-weight: 700;
    color: #0F172A;
    font-family: 'JetBrains Mono', monospace;
    margin: 6px 0 4px;
}
.ai-calc-card__hint { font-size: 12px; color: #94A3B8; margin-bottom: 12px; }
.ai-calc-card__actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-cta {
    padding: 10px 14px;
    border-radius: 10px;
    border: 0;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    min-height: 40px;
    text-decoration: none;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.ai-cta-primary {
    background: #16A34A;
    color: #fff;
}
.ai-cta-primary:hover { background: #15803D; }
.ai-cta-secondary {
    background: #F1F5F9;
    color: #0F172A;
    border: 1px solid #E2E8F0;
}
.ai-cta-secondary:hover { background: #E2E8F0; }
.ai-cta:focus-visible { outline: 2px solid #7C3AED; outline-offset: 2px; }
.ai-cta:active { transform: scale(0.98); }

/* === Footer (input) === */
.ai-chat-footer {
    border-top: 1px solid #E2E8F0;
    padding: 12px 14px;
    background: #fff;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.ai-chat-input {
    flex: 1;
    border: 1px solid #E2E8F0;
    border-radius: 12px;
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    outline: 0;
    transition: border-color .15s, box-shadow .15s;
}
.ai-chat-input:focus { border-color: #EA580C; box-shadow: 0 0 0 3px rgba(234, 88, 12, 0.12); }
.ai-chat-send {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, #EA580C, #7C3AED);
    color: #fff;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform .15s, opacity .15s;
}
.ai-chat-send:hover { transform: translateY(-1px); }
.ai-chat-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.ai-chat-send:focus-visible { outline: 2px solid #fff; outline-offset: 2px; box-shadow: 0 0 0 4px #7C3AED; }
.ai-chat-send svg { width: 18px; height: 18px; }

.ai-chat-disclaimer {
    text-align: center;
    font-size: 10px;
    color: #94A3B8;
    padding: 6px 14px 10px;
    background: #fff;
    line-height: 1.4;
}

/* === Mobile (< 640px) === */
@media (max-width: 640px) {
    #ai-chat-fab {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    #ai-chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        transform: translateY(40px);
    }
    #ai-chat-window.open { transform: translateY(0); }
    .ai-chat-header { padding: max(16px, env(safe-area-inset-top)) 18px 16px; }
}

/* === Reduced motion === */
@media (prefers-reduced-motion: reduce) {
    #ai-chat-fab .ai-fab-pulse,
    .ai-chat-subtitle::before,
    .ai-typing span,
    .ai-msg { animation: none !important; }
    #ai-chat-window { transition: opacity .15s; transform: none; }
    #ai-chat-window.open { transform: none; }
}

/* === Скрыть для агента и менеджера (виден только клиенту) === */
body.manager-mode #ai-chat-fab,
body.manager-mode #ai-chat-window,
body.agent-mode #ai-chat-fab,
body.agent-mode #ai-chat-window { display: none !important; }

/* === Embed-mode — скрыть виджет в виджете на сторонних сайтах === */
body.embed-mode #ai-chat-fab,
body.embed-mode #ai-chat-window { display: none !important; }
