/* ================================================================
   AI-чат по статье (public/blog/ask-article.html)
   Палитра сайта: фон #0a0a0a, акцент #00ff88 -> #00ccff, "стеклянные" карточки rgba(255,255,255,.0x)
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; }

.ai-page {
    margin: 0;
    height: 100vh;
    height: 100dvh;           /* dvh учитывает адресную строку мобильного браузера */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    color: rgba(255, 255, 255, 0.9);
    background:
        radial-gradient(ellipse at 20% 0%, rgba(0, 255, 136, 0.07) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(0, 204, 255, 0.07) 0%, transparent 50%),
        #0a0a0a;
}

/* Высота navbar подставляется скриптом (--nav-h); 64px — запасное значение до его запуска */
.ai-chat {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 860px;
    margin: var(--nav-h, 64px) auto 0;
    display: flex;
    flex-direction: column;
}

/* ── Шапка ─────────────────────────────────────────────── */
.ai-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 12px 0;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
}

.ai-header__back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 50%;
    color: #00ff88;
    background: rgba(0, 255, 136, 0.08);
    border: 1px solid rgba(0, 255, 136, 0.2);
    text-decoration: none;
    transition: background 0.2s, transform 0.2s;
}

.ai-header__back:hover {
    background: rgba(0, 255, 136, 0.16);
    transform: translateX(-2px);
}

.ai-header__avatar,
.ai-msg__avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    color: #0a0a0a;
    background: linear-gradient(135deg, #00ff88, #00ccff);
}

.ai-header__avatar {
    width: 40px;
    height: 40px;
    font-size: 1rem;
    box-shadow: 0 0 18px rgba(0, 255, 136, 0.35);
}

.ai-header__info { flex: 1; min-width: 0; }

.ai-header__name {
    font-weight: 700;
    font-size: 1rem;
    background: linear-gradient(135deg, #ffffff, #00ff88);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.ai-header__article {
    margin-top: 2px;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.5);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-header__title { color: rgba(255, 255, 255, 0.8); }

/* ── Сообщения ─────────────────────────────────────────── */
.ai-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 255, 136, 0.25) transparent;
}

.ai-messages::-webkit-scrollbar { width: 6px; }
.ai-messages::-webkit-scrollbar-thumb { background: rgba(0, 255, 136, 0.25); border-radius: 6px; }

.ai-msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: ai-appear 0.25s ease-out;
}

.ai-msg--user { flex-direction: row-reverse; }

.ai-msg__avatar {
    width: 30px;
    height: 30px;
    font-size: 0.75rem;
    margin-top: 2px;
}

.ai-msg__bubble {
    min-width: 0;
    max-width: min(82%, 640px);
    padding: 11px 15px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.65;
    overflow-wrap: anywhere;   /* длинные ссылки и слова не распирают пузырь */
}

.ai-msg__bubble--ai {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top-left-radius: 6px;
}

.ai-msg__bubble--user {
    color: #ffffff;
    background: linear-gradient(135deg, rgba(0, 255, 136, 0.22), rgba(0, 204, 255, 0.22));
    border: 1px solid rgba(0, 255, 136, 0.28);
    border-top-right-radius: 6px;
    white-space: pre-wrap;     /* переносы строк из textarea */
}

.ai-msg__bubble--error {
    border-color: rgba(255, 107, 107, 0.35);
    background: rgba(255, 107, 107, 0.07);
}

/* Содержимое ответа AI */
.ai-msg__bubble--ai > :first-child { margin-top: 0; }
.ai-msg__bubble--ai > :last-child { margin-bottom: 0; }
.ai-msg__bubble--ai p { margin: 0 0 0.7em; }
.ai-msg__bubble--ai ul,
.ai-msg__bubble--ai ol { margin: 0.4em 0 0.8em; padding-left: 1.3em; }
.ai-msg__bubble--ai li { margin-bottom: 0.3em; }
.ai-msg__bubble--ai strong { color: #ffffff; font-weight: 600; }

.ai-msg__bubble--ai a {
    color: #00ff88;
    text-decoration: none;
    border-bottom: 1px solid rgba(0, 255, 136, 0.35);
    transition: color 0.2s, border-color 0.2s;
}

.ai-msg__bubble--ai a:hover { color: #00ccff; border-bottom-color: #00ccff; }

.ai-msg__bubble--ai code {
    padding: 0.15em 0.4em;
    border-radius: 6px;
    font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
    font-size: 0.88em;
    color: #00ff88;
    background: rgba(255, 255, 255, 0.1);
}

.ai-msg__bubble--ai pre {
    margin: 0.6em 0 0.9em;
    padding: 12px 14px;
    overflow-x: auto;          /* код прокручивается внутри блока, а не выталкивает страницу */
    border-radius: 12px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ai-msg__bubble--ai pre code {
    padding: 0;
    background: none;
    color: rgba(255, 255, 255, 0.9);
    white-space: pre;
    overflow-wrap: normal;
}

.ai-retry {
    margin-top: 10px;
    padding: 7px 14px;
    font: inherit;
    font-size: 0.85rem;
    color: #00ff88;
    cursor: pointer;
    background: rgba(0, 255, 136, 0.08);
    border: 1px solid rgba(0, 255, 136, 0.3);
    border-radius: 20px;
    transition: background 0.2s;
}

.ai-retry:hover { background: rgba(0, 255, 136, 0.16); }

/* Быстрые вопросы */
.ai-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 40px;        /* под аватаркой */
}

.ai-chip {
    padding: 8px 14px;
    font: inherit;
    font-size: 0.85rem;
    text-align: left;
    color: #00ff88;
    cursor: pointer;
    background: rgba(0, 255, 136, 0.07);
    border: 1px solid rgba(0, 255, 136, 0.25);
    border-radius: 20px;
    transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.ai-chip:hover {
    background: rgba(0, 255, 136, 0.15);
    border-color: rgba(0, 255, 136, 0.45);
    transform: translateY(-1px);
}

/* Индикатор "печатает" и курсор */
.ai-spinner { display: flex; gap: 5px; padding: 6px 2px; }

.ai-spinner-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #00ff88;
    animation: ai-bounce 1.2s infinite ease-in-out;
}

.ai-spinner-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-spinner-dot:nth-child(3) { animation-delay: 0.4s; }

.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: #00ff88;
    animation: ai-blink 0.8s infinite;
}

@keyframes ai-appear { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes ai-bounce { 0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
@keyframes ai-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* ── Поле ввода ────────────────────────────────────────── */
.ai-composer-wrap {
    flex-shrink: 0;
    padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
}

.ai-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 6px 6px 18px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 26px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-composer:focus-within {
    border-color: rgba(0, 255, 136, 0.45);
    box-shadow: 0 0 0 3px rgba(0, 255, 136, 0.08);
}

.ai-composer__input {
    flex: 1;
    min-width: 0;
    max-height: 140px;
    padding: 9px 0;
    font: inherit;
    font-size: 16px;           /* меньше 16px — iOS Safari приближает страницу при фокусе */
    line-height: 1.4;
    color: #ffffff;
    background: transparent;
    border: 0;
    outline: none;
    resize: none;
}

.ai-composer__input::placeholder { color: rgba(255, 255, 255, 0.4); }

.ai-composer__btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s;
}

.ai-composer__btn[hidden] { display: none; }

.ai-composer__btn--send {
    color: #0a0a0a;
    background: linear-gradient(135deg, #00ff88, #00ccff);
    box-shadow: 0 4px 14px rgba(0, 255, 136, 0.3);
}

.ai-composer__btn--stop {
    color: #ff6b6b;
    background: rgba(255, 68, 68, 0.15);
    border: 1px solid rgba(255, 68, 68, 0.35);
}

.ai-composer__btn:hover { opacity: 0.88; transform: scale(1.05); }
.ai-composer__btn:focus-visible,
.ai-chip:focus-visible,
.ai-retry:focus-visible,
.ai-header__back:focus-visible { outline: 2px solid #00ccff; outline-offset: 2px; }

.ai-hint {
    margin: 8px 0 0;
    text-align: center;
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.4);
}

/* Honeypot против ботов */
.ai-hp {
    position: absolute;
    left: -9999px;
    width: 0;
    height: 0;
    opacity: 0;
    pointer-events: none;
}

/* ── Адаптив ───────────────────────────────────────────── */
@media (max-width: 768px) {
    .ai-header { margin: 8px 8px 0; padding: 10px 12px; border-radius: 16px; }
    .ai-messages { padding: 16px 12px 6px; }
    .ai-msg__bubble { max-width: 88%; }
    .ai-composer-wrap { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
}

@media (max-width: 480px) {
    .ai-header__avatar { width: 34px; height: 34px; }
    .ai-header__back { width: 34px; height: 34px; }
    .ai-msg__avatar { width: 26px; height: 26px; font-size: 0.65rem; }
    .ai-msg__bubble { max-width: 90%; font-size: 0.92rem; padding: 10px 13px; }
    .ai-chips { padding-left: 0; }
    .ai-chip { flex: 1 1 100%; }
    .ai-hint { font-size: 0.68rem; }
}

/* Низкий экран (телефон в альбомной ориентации): прячем подсказку, чтобы осталось место под переписку */
@media (max-height: 480px) {
    .ai-hint { display: none; }
    .ai-header { padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .ai-msg, .ai-spinner-dot, .typing-cursor { animation: none; }
}
