/* chat.css */
#ai-chat {
    background: var(--bg-dashboard);
    height: calc(100% - max(var(--homeza-nav-height, 56px), var(--coach-keyboard-inset, 0px)));
    min-height: 0;
    font-family: var(--font-family);
}

.chat-header { margin-bottom: 0; }

.chat-container {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px var(--homeza-screen-gutter, 16px) 12px;
    scroll-behavior: smooth;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */
}

.chat-messages::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.message {
    display: flex;
    margin-bottom: 12px;
    animation: messageSlide 0.3s ease-out;
}

.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    display: none;
}

.message-content {
    min-width: 0;
    max-width: 88%;
    background: var(--surface);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 14px 16px;
    border-radius: 12px;
    font: 400 1rem/1.5 var(--font-family);
    overflow-wrap: anywhere;
}

.user-message .message-content {
    background: var(--surface-secondary);
}

.message-content p {
    margin: 0;
}

.message-content :is(h1, h2, h3) {
    margin: 8px 0 4px;
    font-size: 1.125rem;
    line-height: 1.5rem;
    font-weight: 500;
}

.message-content strong {
    font-weight: 600;
}

.message-content li {
    margin: 2px 0;
}

.message-content img {
    max-width: 100%;
    height: auto;
}

.message-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
}

.message-content p + p {
    margin-top: 8px;
}

/* Markdown в AI-сообщениях */
.ai-message .message-content ul,
.ai-message .message-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.ai-message .message-content p:first-child,
.ai-message .message-content h1:first-child,
.ai-message .message-content h2:first-child,
.ai-message .message-content h3:first-child {
    margin-top: 0;
}

.ai-message .message-content p:last-child {
    margin-bottom: 0;
}

.ai-message .message-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 4px;
    font-size: 13px;
}

.ai-message .message-content pre {
    background: rgba(0, 0, 0, 0.06);
    padding: 8px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
}

.ai-message .message-content pre code {
    background: none;
    padding: 0;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    align-self: flex-end;
}

/* Быстрые действия */
.chat-quick-actions {
    position: fixed;
    bottom: 115px; /* Над полем ввода */
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 388px;
    padding: 16px 20px;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto; /* Прокрутка если кнопки не помещаются */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* Internet Explorer 10+ */
    background: transparent;
    z-index: 999;
}

/* Скрываем скроллбар в WebKit браузерах (Chrome, Safari) */
.chat-quick-actions::-webkit-scrollbar {
    display: none;
}

.quick-action {
    background: var(--primary);
    border: 1px solid var(--primary);
    padding: 8px 12px;
    border-radius: 20px;
    font-size: 12px;
    color: white;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    white-space: nowrap;
    display: flex;
    align-items: center;
}

.quick-action svg {
    color: inherit;
}

/* Поле ввода */
.chat-input-container {
    flex: 0 0 auto;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 8px var(--homeza-screen-gutter, 16px);
    z-index: 1000;
}

.chat-input-wrapper {
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 2px;
}

.chat-input-wrapper:focus-within {
    outline: 2px solid var(--success, #526B58);
    outline-offset: -1px;
}

#chatInput {
    flex: 1;
    min-width: 0;
    min-height: 44px;
    border: none;
    background: none;
    padding: 8px;
    font: 400 1rem/1.5 var(--font-family);
    color: var(--text-primary);
    outline: none;
    text-overflow: ellipsis;
}

#chatInput::placeholder {
    color: var(--text-secondary);
    opacity: 1;
}

#ai-chat :is(.voice-btn, .send-btn) .homeza-icon {
    width: 20px;
    height: 20px;
    stroke-width: 1.75;
    color: inherit;
}

#ai-chat :is(.voice-btn, .send-btn):focus-visible {
    outline: 2px solid var(--success, #526B58);
    outline-offset: -1px;
}

/* Голосовой ввод */
.voice-btn {
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-primary);
    transition: var(--transition-fast);
    flex-shrink: 0;
    padding: 0;
}

.voice-btn:active {
    transform: scale(0.9);
}

.voice-btn.recording {
    color: #e53e3e;
    animation: voicePulse 1s ease-in-out infinite;
}

@keyframes voicePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

.send-btn {
    width: 44px;
    height: 44px;
    background: var(--accent-fill);
    color: #fff;
    border: none;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    flex-shrink: 0;
    padding: 0;
}

.send-btn:disabled {
    background: var(--surface-secondary);
    color: var(--text-secondary);
    cursor: not-allowed;
}

.send-icon {
    color: white;
    font-size: 16px;
}

/* Индикатор печатания */
.typing-indicator {
    display: flex;
    align-items: center;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 12px;
}

.typing-dots {
    display: flex;
    align-items: center;
    margin-right: 8px;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    background: var(--text-secondary);
    border-radius: 50%;
    margin: 0 1px;
    animation: typingDot 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

/* Typing indicator в чате (три точки) */
.chat-typing-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 20px !important;
    min-height: auto;
}
.chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-secondary, #8c8279);
    opacity: 0.4;
    animation: chatTypingBounce 1.4s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

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


/* Keep the test overlay above the composer when the keyboard is closed. */
body:has(#ai-chat.active) > #testEnvBanner {
    --test-badge-bottom: calc(var(--homeza-nav-height, 56px) + 78px);
}

/* The test overlay stays out of the composer while the keyboard is open. */
body:has(#ai-chat.active.coach-keyboard-open) > #testEnvBanner {
    visibility: hidden;
}
