/* ============================================================
 * AI Chat — docked side panel + topbar launcher button
 * ------------------------------------------------------------
 * Префикс .ai-chat-*: при Features:AIChat:Enabled = false файл
 * не подгружается — ноль побочных зависимостей.
 * Переменные цвета/радиусов/теней — из основной темы (site.css),
 * поэтому dark-mode и ребрендинг работают автоматически.
 *
 * Архитектура:
 * - Кнопка-launcher (.ai-chat-launcher) — в AppTopBar справа.
 * - Панель (.ai-chat-panel) — внутри <aside.ai-chat-dock> в MainLayout,
 *   занимает третью колонку flex-row .page (отодвигает контент).
 * - Открытое состояние: на .page добавляется класс page--ai-open;
 *   на <aside> — ai-chat-dock--open.
 * ============================================================ */

/* ── Launcher-кнопка (анимированный owl_animated.svg) ──
   Используем <img>, чтобы CSS-анимация внутри SVG (пульсирующий
   Signal Orange правый глаз) работала. Mask не подходит — он отбрасывает цвета. */
.ai-chat-launcher-icon {
    display: block;
    width: 18px;
    height: 18px;
    object-fit: contain;
}
/* Mobile-вариант (внутри .nav-mobile-topbar-row): иконка крупнее (под стиль соседних 20-24px SVG)
   и центрируется над подписью «Ассистент». */
.ai-chat-launcher-icon--mobile {
    width: 22px;
    height: 22px;
    margin: 0 auto;
}

/* ── Dock-панель: третья колонка в .page flex-layout ── */
.ai-chat-dock {
    flex: 0 0 0;
    width: 0;
    overflow: hidden;
    transition: flex-basis .25s ease, width .25s ease;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-sizing: border-box;
    height: 100vh;
    position: sticky;
    top: 0;
    align-self: stretch;
}
.ai-chat-dock--open {
    flex: 0 0 420px;
    width: 420px;
}

/* ── Сама панель чата (заполняет dock полностью) ── */
.ai-chat-panel {
    width: 100%;
    height: 100%;
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: aiChatSlideIn .22s ease-out;
}

@keyframes aiChatSlideIn {
    from { opacity: 0; transform: translateX(12px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* Mobile: dock на весь экран как overlay поверх контента */
@media (max-width: 768px) {
    .ai-chat-dock--open {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 1042;
        flex-basis: auto;
        width: 100vw;
        max-width: 420px;
        box-shadow: var(--shadow-lg);
    }
}

/* ── Шапка панели ── */
.ai-chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: var(--color-primary);
    color: #fff;
    flex-shrink: 0;
}
.ai-chat-header-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.ai-chat-header-icon img {
    width: 22px;
    height: 22px;
    object-fit: contain;
    display: block;
}
.ai-chat-header-title {
    flex: 1;
    min-width: 0;
}
.ai-chat-header-title-main {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
}
.ai-chat-header-title-sub {
    font-size: 11px;
    opacity: .75;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ai-chat-header-actions {
    display: flex;
    gap: 4px;
}
.ai-chat-header-btn {
    background: transparent;
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    opacity: .75;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background .15s ease, opacity .15s ease;
}
.ai-chat-header-btn:hover {
    background: rgba(255,255,255,.12);
    opacity: 1;
}

/* ── Лента сообщений ── */
.ai-chat-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    background: var(--color-surface-2);
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}
.ai-chat-body::-webkit-scrollbar { width: 6px; }
.ai-chat-body::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

/* Сообщение */
.ai-chat-msg {
    max-width: 88%;
    padding: 9px 12px;
    border-radius: var(--radius-md, 8px);
    font-size: 12px;
    line-height: 1.45;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.ai-chat-msg.user {
    align-self: flex-end;
    background: var(--color-primary);
    color: #fff;
    border-bottom-right-radius: 2px;
}
.ai-chat-msg.assistant {
    align-self: flex-start;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-bottom-left-radius: 2px;
}
.ai-chat-msg.assistant code {
    background: var(--color-surface-offset);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--font-mono, monospace);
    font-size: 12.5px;
}
.ai-chat-msg.assistant pre {
    background: var(--color-surface-offset);
    padding: 8px 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-family: var(--font-mono, monospace);
    font-size: 12.5px;
    margin: 6px 0;
}
.ai-chat-msg.error {
    align-self: stretch;
    background: var(--color-error-bg);
    border: 1px solid var(--color-error-border);
    color: var(--color-error);
    font-size: 13px;
}

/* Тул-бейдж "выполняется запрос к данным" */
.ai-chat-tool-badge {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--color-text-muted);
    background: var(--color-primary-surface);
    border: 1px solid var(--color-primary-border);
    padding: 4px 9px;
    border-radius: 9999px;
}
.ai-chat-tool-badge .fa {
    animation: aiChatSpin 1s linear infinite;
}
.ai-chat-tool-badge.done .fa { animation: none; }
@keyframes aiChatSpin {
    to { transform: rotate(360deg); }
}

/* «Печатает…» индикатор */
.ai-chat-typing {
    align-self: flex-start;
    display: inline-flex;
    gap: 3px;
    padding: 6px 10px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 9999px;
}
.ai-chat-typing span {
    width: 6px;
    height: 6px;
    background: var(--color-text-muted);
    border-radius: 50%;
    animation: aiChatBlink 1.2s infinite;
}
.ai-chat-typing span:nth-child(2) { animation-delay: .2s; }
.ai-chat-typing span:nth-child(3) { animation-delay: .4s; }
.ai-chat-typing-label {
    width: auto !important;
    height: auto !important;
    background: transparent !important;
    border-radius: 0 !important;
    margin-left: 6px;
    color: var(--color-text-muted);
    font-size: 12px;
    animation: none !important;
    opacity: 1 !important;
    align-self: center;
    white-space: nowrap;
}
@keyframes aiChatBlink {
    0%, 60%, 100% { opacity: .25; }
    30%           { opacity: 1; }
}

/* Приветственный блок при пустом чате */
.ai-chat-greeting {
    text-align: center;
    padding: 28px 16px;
    color: var(--color-text-muted);
    font-size: 13px;
    line-height: 1.5;
}
.ai-chat-greeting-icon {
    font-size: 36px;
    color: var(--color-primary);
    margin-bottom: 8px;
}
.ai-chat-greeting-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 4px;
}
.ai-chat-suggestions {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 14px;
    padding: 0 8px;
}
.ai-chat-suggestion {
    text-align: left;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 8px);
    padding: 8px 10px;
    font-size: 12.5px;
    color: var(--color-text);
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}
.ai-chat-suggestion:hover {
    border-color: var(--color-primary);
    background: var(--color-primary-surface);
}

/* ── Подвал с textarea ── */
.ai-chat-footer {
    border-top: 1px solid var(--color-border);
    background: var(--color-surface);
    padding: 10px;
    flex-shrink: 0;
}
.ai-chat-input-wrap {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ai-chat-input {
    flex: 1;
    min-height: 38px;
    max-height: 120px;
    resize: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md, 8px);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    transition: border-color .15s ease;
    background: var(--color-surface);
    color: var(--color-text);
}
.ai-chat-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(var(--color-primary-rgb, 27 20 100), .12);
}
.ai-chat-send-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md, 8px);
    background: var(--color-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: background .15s ease, opacity .15s ease;
}
.ai-chat-send-btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
}
.ai-chat-send-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
}
.ai-chat-footer-hint {
    font-size: 11px;
    color: var(--color-text-faint);
    margin-top: 6px;
    text-align: right;
}

/* ── Feedback (👍/👎) ── */
.ai-chat-feedback {
    display: inline-flex;
    gap: 4px;
    margin-top: 4px;
}
.ai-chat-feedback-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text-faint);
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background .15s ease, transform .1s ease, opacity .15s ease;
    opacity: 0.55;
}
.ai-chat-feedback-emoji {
    font-size: 16px;
    line-height: 1;
    /* На Windows эмодзи рендерятся системным Segoe UI Emoji — принудительно указываем. */
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
    filter: grayscale(1);
    transition: filter .15s ease;
}
.ai-chat-feedback-btn:hover {
    background: var(--color-surface-offset);
    opacity: 1;
}
.ai-chat-feedback-btn:hover .ai-chat-feedback-emoji { filter: none; }
.ai-chat-feedback-btn.active-up,
.ai-chat-feedback-btn.active-down {
    opacity: 1;
}
.ai-chat-feedback-btn.active-up   .ai-chat-feedback-emoji { filter: none; }
.ai-chat-feedback-btn.active-down .ai-chat-feedback-emoji { filter: none; }
.ai-chat-feedback-btn.active-up   { background: rgba(40, 167, 69, 0.12); }
.ai-chat-feedback-btn.active-down { background: rgba(220, 53, 69, 0.12); }

/* ── Dark theme overrides ── */
:root[data-theme="dark"] .ai-chat-msg.assistant {
    background: var(--color-surface);
    border-color: var(--color-border);
}
:root[data-theme="dark"] .ai-chat-msg.assistant code,
:root[data-theme="dark"] .ai-chat-msg.assistant pre {
    background: rgba(255,255,255,.06);
}
:root[data-theme="dark"] .ai-chat-typing {
    background: var(--color-surface);
    border-color: var(--color-border);
}

/* ── AI markdown links — на токенах OWLS ── */
.ai-chat-link {
    color: var(--color-accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.ai-chat-link:hover { color: var(--color-accent-hover); }
.ai-chat-link.ai-chat-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 4px 0;
    padding: 6px 12px;
    background: var(--color-accent);
    color: #fff !important;
    border-radius: var(--radius-md);
    text-decoration: none;
    font-weight: 600;
    font-size:12px;
    transition: background .15s ease;
}
.ai-chat-link.ai-chat-download:hover { background: var(--color-accent-hover); }
