/* AI Chat — стили. Шрифты от темы. */

.iht-ai-wrap {
    --ai-bg:      #0d0d12;
    --ai-card:    #16161f;
    --ai-input:   #1e1e2a;
    --ai-border:  #2a2a38;
    --ai-text:    #f0f0f5;
    --ai-muted:   #8888a0;
    --ai-accent:  #6c63ff;
    --ai-accent2: #a78bfa;
    --ai-user:    #6c63ff;
    --ai-bot:     #1e1e2a;
    --ai-radius:  16px;
}

.iht-ai-wrap {
    background: var(--ai-bg);
    border-radius: 24px;
    max-width: 720px;
    margin: 32px auto;
    color: var(--ai-text);
    box-shadow: 0 0 0 1px var(--ai-border), 0 32px 80px rgba(0,0,0,0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* Декоративный блик */
.iht-ai-wrap::before {
    content: '';
    position: absolute;
    top: -80px; right: -80px;
    width: 260px; height: 260px;
    background: radial-gradient(circle, rgba(108,99,255,0.12) 0%, transparent 70%);
    pointer-events: none;
}

/* =============================================================================
   ШАПКА
   ============================================================================= */
.iht-ai-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 24px;
    border-bottom: 1px solid var(--ai-border);
    background: var(--ai-card);
    position: relative;
    z-index: 1;
}

.iht-ai-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent2));
    border-radius: 12px;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(108,99,255,0.35);
}

.iht-ai-icon i { color: #fff; }

.iht-ai-header-text { flex: 1; }

.iht-ai-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--ai-text);
}

.iht-ai-subtitle {
    font-size: 12px;
    color: var(--ai-muted);
    margin-top: 2px;
}

.iht-ai-clear {
    background: none;
    border: 1px solid var(--ai-border);
    border-radius: 8px;
    color: var(--ai-muted);
    padding: 7px 10px;
    cursor: pointer;
    font-size: 13px;
    transition: color 0.2s, border-color 0.2s;
}

.iht-ai-clear:hover {
    color: var(--ai-text);
    border-color: var(--ai-accent);
}

/* =============================================================================
   ОБЛАСТЬ СООБЩЕНИЙ
   ============================================================================= */
.iht-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 360px;
    max-height: 520px;
    scroll-behavior: smooth;
}

.iht-ai-messages::-webkit-scrollbar { width: 4px; }
.iht-ai-messages::-webkit-scrollbar-track { background: transparent; }
.iht-ai-messages::-webkit-scrollbar-thumb { background: var(--ai-border); border-radius: 4px; }

/* Сообщение — обёртка */
.iht-ai-msg {
    display: flex;
    gap: 10px;
    animation: iht-ai-fadein 0.25s ease;
}

@keyframes iht-ai-fadein {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Пользователь — справа */
.iht-ai-msg.user {
    flex-direction: row-reverse;
}

/* Пузырёк */
.iht-ai-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.iht-ai-msg.user .iht-ai-bubble {
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent2));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.iht-ai-msg.assistant .iht-ai-bubble {
    background: var(--ai-bot);
    color: var(--ai-text);
    border: 1px solid var(--ai-border);
    border-bottom-left-radius: 4px;
}

/* Аватар */
.iht-ai-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    margin-top: 2px;
}

.iht-ai-msg.assistant .iht-ai-avatar {
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent2));
    color: #fff;
}

.iht-ai-msg.user .iht-ai-avatar {
    background: var(--ai-input);
    color: var(--ai-muted);
    border: 1px solid var(--ai-border);
}

/* Индикатор набора (три точки) */
.iht-ai-typing .iht-ai-bubble {
    padding: 14px 20px;
}

.iht-ai-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

.iht-ai-dots span {
    width: 7px; height: 7px;
    background: var(--ai-muted);
    border-radius: 50%;
    animation: iht-ai-dot 1.2s ease-in-out infinite;
}

.iht-ai-dots span:nth-child(2) { animation-delay: 0.2s; }
.iht-ai-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes iht-ai-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%            { transform: translateY(-5px); opacity: 1; }
}

/* Markdown-подобное форматирование в ответах */
.iht-ai-bubble strong { font-weight: 700; }
.iht-ai-bubble em     { font-style: italic; }
.iht-ai-bubble code   { background: rgba(255,255,255,0.08); padding: 1px 6px; border-radius: 4px; font-size: 13px; font-family: monospace; }
.iht-ai-bubble pre    { background: rgba(0,0,0,0.3); padding: 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0 0; }
.iht-ai-bubble pre code { background: none; padding: 0; }
.iht-ai-bubble ul, .iht-ai-bubble ol { padding-left: 20px; margin: 6px 0; }
.iht-ai-bubble li     { margin: 3px 0; }
.iht-ai-bubble p      { margin: 6px 0 0; }
.iht-ai-bubble p:first-child { margin-top: 0; }

/* =============================================================================
   ПОЛЕ ВВОДА
   ============================================================================= */
.iht-ai-input-area {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--ai-border);
    background: var(--ai-card);
}

.iht-ai-input {
    flex: 1;
    background: var(--ai-input);
    border: 1px solid var(--ai-border);
    border-radius: 14px;
    padding: 12px 16px;
    font-size: 14px;
    color: var(--ai-text);
    resize: none;
    outline: none;
    max-height: 48px;
    overflow-y: hidden;
    line-height: 1.5;
    transition: border-color 0.2s;
    font-family: inherit;
}

.iht-ai-input::placeholder { color: var(--ai-muted); }
.iht-ai-input:focus { border-color: var(--ai-accent); }

.iht-ai-send {
    width: 44px; height: 44px;
    background: linear-gradient(135deg, var(--ai-accent), var(--ai-accent2));
    border: none;
    border-radius: 12px;
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.1s;
    box-shadow: 0 4px 12px rgba(108,99,255,0.35);
}

.iht-ai-send:hover  { opacity: 0.88; }
.iht-ai-send:active { transform: scale(0.93); }
.iht-ai-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Ошибка конфига */
.iht-ai-error {
    background: rgba(255,59,59,0.1);
    border: 1px solid rgba(255,59,59,0.3);
    border-radius: 8px;
    padding: 14px 18px;
    font-size: 14px;
    color: #ff8a80;
    margin: 16px 0;
}
.iht-ai-error a { color: inherit; }

/* Mobile */
@media (max-width: 480px) {
    .iht-ai-wrap   { border-radius: 16px; margin: 16px auto; }
    .iht-ai-messages { padding: 16px; min-height: 280px; max-height: 380px; }
    .iht-ai-bubble { max-width: 88%; }
    .iht-ai-input-area { padding: 12px 16px; }
    .iht-ai-header { padding: 16px; }
}
