/* ═══════════════════════════════════════════════════════════
   AI-ЧАТ — Стили
   Плавающий виджет с полным чат-интерфейсом
   ═══════════════════════════════════════════════════════════ */

.ai-chat {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: var(--z-chat);
    font-family: var(--font-sans);
    overflow: visible;
    pointer-events: none;
}

.ai-chat__toggle,
.ai-chat.is-open .ai-chat__window {
    pointer-events: auto;
}

/* ═══════════════════════════════════════════════════════════
   КНОПКА ОТКРЫТИЯ
   ═══════════════════════════════════════════════════════════ */
.ai-chat__toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    display: grid;
    place-items: center;
    box-shadow: 
        0 12px 32px var(--accent-glow),
        0 4px 12px rgba(0, 0, 0, 0.3);
    transition: all 0.4s var(--ease-out);
    animation: chat-pulse 3s ease-in-out infinite;
}

.ai-chat__toggle:hover {
    box-shadow: 
        0 16px 48px var(--accent-glow),
        0 8px 24px rgba(0, 0, 0, 0.4);
}

.ai-chat.is-open .ai-chat__toggle {
    animation: none;
    transform: scale(0.9);
}

@keyframes chat-pulse {
    0%, 100% {
        box-shadow: 
            0 12px 32px var(--accent-glow),
            0 4px 12px rgba(0, 0, 0, 0.3),
            0 0 0 0 var(--accent-glow);
    }
    50% {
        box-shadow: 
            0 12px 32px var(--accent-glow),
            0 4px 12px rgba(0, 0, 0, 0.3),
            0 0 0 12px transparent;
    }
}

.ai-chat__toggle-icon {
    position: relative;
    width: 24px;
    height: 24px;
}

.ai-chat__toggle-open,
.ai-chat__toggle-close {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: all 0.4s var(--ease-elastic);
}

.ai-chat__toggle-close {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(-90deg) scale(0);
}

.ai-chat.is-open .ai-chat__toggle-open {
    opacity: 0;
    transform: translate(-50%, -50%) rotate(90deg) scale(0);
}

.ai-chat.is-open .ai-chat__toggle-close {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0) scale(1);
}

/* Бейдж с числом непрочитанных */
.ai-chat__toggle-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: grid;
    place-items: center;
    border: 2px solid var(--bg);
    transform: scale(1);
    transition: transform 0.3s var(--ease-elastic);
}

.ai-chat.is-open .ai-chat__toggle-badge,
.ai-chat.is-read .ai-chat__toggle-badge {
    transform: scale(0);
}

/* ═══════════════════════════════════════════════════════════
   ОКНО ЧАТА
   ═══════════════════════════════════════════════════════════ */
.ai-chat__window {
    position: fixed;
    right: 24px;
    bottom: 100px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-lg);
    box-shadow: 
        0 24px 80px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out), visibility 0s linear 0.4s;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    pointer-events: none;
}

.ai-chat.is-open .ai-chat__window {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out), visibility 0s;
}

/* ═══════════════════════════════════════════════════════════
   ХЕДЕР ЧАТА
   ═══════════════════════════════════════════════════════════ */
.ai-chat__header {
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--bg-2), var(--bg-3));
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ai-chat__header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat__avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #a3d900);
    color: var(--bg);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.02em;
    box-shadow: 0 4px 12px var(--accent-glow);
    flex-shrink: 0;
}

.ai-chat__avatar-status {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--surface);
    box-shadow: 0 0 8px rgba(0, 217, 126, 0.6);
    animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.ai-chat__name {
    font-size: 14px;
    font-weight: 600;
    color: var(--fg);
    margin-bottom: 2px;
    letter-spacing: -0.01em;
}

.ai-chat__status {
    font-size: 11px;
    color: var(--fg-3);
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-chat__status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 6px rgba(0, 217, 126, 0.6);
}

.ai-chat__minimize {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--fg-3);
    display: grid;
    place-items: center;
    transition: all 0.3s;
    flex-shrink: 0;
}

.ai-chat__minimize:hover {
    background: var(--surface-2);
    color: var(--fg);
}

/* ═══════════════════════════════════════════════════════════
   СООБЩЕНИЯ
   ═══════════════════════════════════════════════════════════ */
.ai-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.ai-chat__messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat__messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat__messages::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: var(--radius-full);
}

.ai-chat__messages::-webkit-scrollbar-thumb:hover {
    background: var(--border-3);
}

/* ─── Сообщение (общая структура) ──────────── */
.ai-chat__message {
    max-width: 85%;
    animation: message-in 0.4s var(--ease-out);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

@keyframes message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-chat__message-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    letter-spacing: -0.01em;
}

.ai-chat__message-bubble p {
    margin-bottom: 8px;
}

.ai-chat__message-bubble p:last-child {
    margin-bottom: 0;
}

.ai-chat__message-bubble strong {
    font-weight: 600;
    color: inherit;
}

.ai-chat__message-bubble a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.ai-chat__message-bubble ul,
.ai-chat__message-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.ai-chat__message-bubble li {
    margin-bottom: 4px;
    list-style: disc;
}

.ai-chat__message-time {
    font-size: 10px;
    color: var(--fg-4);
    letter-spacing: 0.02em;
    padding: 0 8px;
}

/* ─── Сообщение бота ────────────────────────── */
.ai-chat__message--bot {
    align-self: flex-start;
}

.ai-chat__message--bot .ai-chat__message-bubble {
    background: var(--surface-2);
    color: var(--fg);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

/* ─── Сообщение пользователя ────────────────── */
.ai-chat__message--user {
    align-self: flex-end;
}

.ai-chat__message--user .ai-chat__message-bubble {
    background: var(--accent);
    color: var(--bg);
    border-bottom-right-radius: 4px;
    font-weight: 500;
}

.ai-chat__message--user .ai-chat__message-time {
    text-align: right;
}

/* ─── Системное сообщение (эскалация в TG) ────── */
.ai-chat__message--system {
    align-self: center;
    max-width: 90%;
    text-align: center;
}

.ai-chat__message--system .ai-chat__message-bubble {
    background: transparent;
    border: 1px dashed var(--border-2);
    color: var(--fg-3);
    font-size: 12px;
    padding: 8px 14px;
    border-radius: var(--radius-md);
}

.ai-chat__message--system a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.ai-chat__message--system a:hover {
    text-decoration: underline;
}

/* ═══════════════════════════════════════════════════════════
   БЫСТРЫЕ ОТВЕТЫ
   ═══════════════════════════════════════════════════════════ */
.ai-chat__quick {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
}

.ai-chat__quick-btn {
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--fg);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    text-align: left;
    transition: all 0.3s var(--ease-out);
    letter-spacing: -0.01em;
}

.ai-chat__quick-btn:hover {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateX(2px);
}

.ai-chat__quick.is-hidden {
    display: none;
}

/* ═══════════════════════════════════════════════════════════
   ИНДИКАТОР НАБОРА
   ═══════════════════════════════════════════════════════════ */
.ai-chat__typing {
    padding: 8px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--fg-3);
    animation: typing-in 0.3s var(--ease-out);
}

@keyframes typing-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ai-chat__typing-dots {
    display: flex;
    gap: 3px;
}

.ai-chat__typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.ai-chat__typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.ai-chat__typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.5;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ═══════════════════════════════════════════════════════════
   ФОРМА ВВОДА
   ═══════════════════════════════════════════════════════════ */
.ai-chat__form {
    padding: 14px 16px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat__input {
    flex: 1;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    color: var(--fg);
    font-size: 14px;
    letter-spacing: -0.01em;
    transition: all 0.3s;
}

.ai-chat__input::placeholder {
    color: var(--fg-4);
}

.ai-chat__input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--surface-2);
}

.ai-chat__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--bg);
    display: grid;
    place-items: center;
    transition: all 0.3s var(--ease-out);
    flex-shrink: 0;
}

.ai-chat__send:hover:not(:disabled) {
    transform: scale(1.05) rotate(-8deg);
    box-shadow: 0 4px 16px var(--accent-glow);
}

.ai-chat__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ai-chat__send svg {
    transition: transform 0.3s;
}

/* ═══════════════════════════════════════════════════════════
   ФУТЕР
   ═══════════════════════════════════════════════════════════ */
.ai-chat__footer {
    padding: 8px 20px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 10px;
    color: var(--fg-4);
    font-family: var(--font-mono);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.ai-chat__footer strong {
    color: var(--accent);
    font-weight: 500;
    margin-left: 4px;
}

/* ═══════════════════════════════════════════════════════════
   ПОДСКАЗКА (BUBBLE) при первом заходе
   ═══════════════════════════════════════════════════════════ */
.ai-chat__hint {
    position: absolute;
    bottom: calc(100% + 12px);
    right: 8px;
    background: var(--fg);
    color: var(--bg);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    animation: hint-bounce 2s ease-in-out infinite;
    letter-spacing: -0.01em;
}

.ai-chat__hint::after {
    content: '';
    position: absolute;
    top: 100%;
    right: 22px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-top: 8px solid var(--fg);
}

@keyframes hint-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

.ai-chat.is-open .ai-chat__hint,
.ai-chat.is-interacted .ai-chat__hint {
    display: none;
}

/* ═══════════════════════════════════════════════════════════
   МОБИЛЬНАЯ АДАПТАЦИЯ
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .ai-chat {
        bottom: 16px;
        right: 16px;
    }
    
    .ai-chat__toggle {
        width: 56px;
        height: 56px;
    }
    
    .ai-chat__window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }
    
    .ai-chat__header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
    }
    
    .ai-chat__form {
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }
    
    .ai-chat__hint {
        display: none;
    }
}

/* Скрываем ai-chat кнопку когда открыта scroll-top на маленьких экранах */
@media (max-width: 480px) {
    .scroll-top {
        bottom: 84px;
    }
}