/* ==========================================================================
   CHAT PAGE - ChatGPT-inspired layout
   ========================================================================== */

.chat-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 92px);
    background: radial-gradient(circle at top, #f8fafc 0%, #f1f5f9 48%, #eef2ff 100%);
    position: relative;
}

.syllabus-bar {
    margin: 12px 16px 0;
    padding: 10px 14px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid #e2e8f0;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    gap: 10px;
    position: sticky;
    top: 0;
    z-index: 12;
}

.syllabus-item {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.syllabus-item i {
    color: #4f46e5;
}

.syllabus-item select {
    border: none;
    background: transparent;
    font-weight: 600;
    color: #334155;
    outline: none;
    max-width: 210px;
    text-overflow: ellipsis;
}

.divider {
    width: 1px;
    height: 18px;
    background: #dbeafe;
}

.chat-messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 26px 22px 180px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

/* Keep chat content centered like ChatGPT-style reading column */
.chat-messages-container > .date-divider,
.chat-messages-container > .ai-message-wrapper,
.chat-messages-container > .user-message-wrapper,
.chat-messages-container > .typing-bubble,
.chat-messages-container > .typing-indicator {
    width: min(960px, 100%);
    margin-left: auto;
    margin-right: auto;
}

.date-divider {
    align-self: center;
    font-size: 12px;
    color: #64748b;
    background: rgba(255, 255, 255, 0.86);
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    padding: 4px 12px;
}

.ai-message-wrapper,
.user-message-wrapper {
    width: 100%;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.user-message-wrapper {
    justify-content: flex-end;
}

.ai-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #dbeafe;
    background: #ffffff;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.08);
    flex-shrink: 0;
}

.ai-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ai-message,
.user-message {
    max-width: min(820px, calc(100% - 56px));
    border-radius: 16px;
    padding: 14px 16px;
    line-height: 1.6;
    font-size: 15px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.06);
    word-break: break-word;
}

.ai-message {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    color: #0f172a;
}

.user-message {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    color: #ffffff;
    border: 1px solid #4338ca;
}

.message-time {
    margin-top: 8px;
    font-size: 11px;
    opacity: 0.7;
}

.typing-bubble {
    margin-left: 46px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

/* Fallback style used by ai-engine when legacy typing node is injected */
.typing-indicator {
    margin-left: 46px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6366f1;
    animation: chatDotPulse 1.4s ease-in-out infinite;
}

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

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

.chat-page .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6366f1;
    animation: chatDotPulse 1.4s ease-in-out infinite;
}

.chat-page .dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-page .dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatDotPulse {
    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

.chat-actions-bar {
    position: sticky;
    bottom: 94px;
    z-index: 11;
    margin: 0 auto;
    width: min(880px, calc(100% - 24px));
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
    padding: 10px 8px 0;
}

.action-token {
    border: 1px solid #cbd5e1;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    padding: 7px 12px;
    cursor: pointer;
    transition: all 0.18s ease;
}

.action-token:hover {
    border-color: #6366f1;
    color: #4338ca;
    transform: translateY(-1px);
}

.clear-btn {
    color: #b91c1c;
}

.chat-input-bar {
    position: sticky;
    bottom: 0;
    z-index: 12;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px;
    margin: 10px auto 14px;
    width: min(880px, calc(100% - 24px));
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #dbeafe;
    border-radius: 20px;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.12);
}

.input-container {
    position: relative;
    flex: 1;
}

#userInput {
    width: 100%;
    min-height: 24px;
    max-height: 170px;
    resize: none;
    border: none;
    outline: none;
    background: transparent;
    color: #0f172a;
    font-size: 15px;
    line-height: 1.5;
    padding: 8px 10px;
}

#userInput::placeholder {
    color: #94a3b8;
}

#userInput.is-listening {
    color: #334155;
    background: linear-gradient(90deg, rgba(79, 70, 229, 0.05), rgba(56, 189, 248, 0.03));
    border-radius: 10px;
}

#userInput.transcribing {
    box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.25);
}

.voice-wave-container {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    display: none;
    align-items: center;
    gap: 3px;
}

/* AI Message Wave Animation */
.ai-voice-wave {
    display: none;
    align-items: center;
    gap: 3px;
    margin-top: 10px;
    padding: 10px;
    background: rgba(79, 70, 229, 0.05);
    border-radius: 8px;
    width: fit-content;
}

.ai-voice-wave.active {
    display: flex;
}

.wave-bar {
    width: 3px;
    border-radius: 8px;
    background: #4f46e5;
    height: 16px;
}

/* Only animate when active */
.ai-voice-wave.active .wave-bar,
.voice-wave-container.active .wave-bar {
    animation: voiceWave 1s ease-in-out infinite;
}

.wave-bar:nth-child(2) { animation-delay: 0.1s; height: 12px; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; height: 18px; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; height: 11px; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; height: 15px; }

@keyframes voiceWave {
    0%, 100% { transform: scaleY(0.6); opacity: 0.6; }
    50% { transform: scaleY(1); opacity: 1; }
}

#voiceToggle,
#sendBtn {
    width: 44px;
    height: 44px;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    background: #ffffff;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.16s ease;
}

#sendBtn {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    border-color: #4338ca;
    color: #ffffff;
}

#voiceToggle:hover,
#sendBtn:hover {
    transform: translateY(-1px);
}

#sendBtn.stopping {
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    border-color: #b91c1c;
    animation: stopPulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes stopPulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }
}

.chat-input-bar .mic-btn.listening {
    background: linear-gradient(135deg, #f59e0b, #ea580c) !important;
    border-color: #ea580c !important;
    color: #fff !important;
}

@media (max-width: 900px) {
    .chat-page {
        height: calc(100vh - 78px);
    }

    .chat-messages-container {
        padding: 18px 12px 170px;
        gap: 16px;
    }

    .chat-messages-container > .date-divider,
    .chat-messages-container > .ai-message-wrapper,
    .chat-messages-container > .user-message-wrapper,
    .chat-messages-container > .typing-bubble,
    .chat-messages-container > .typing-indicator {
        width: 100%;
    }

    .ai-message,
    .user-message {
        max-width: calc(100% - 42px);
        font-size: 14px;
        padding: 12px 13px;
    }

    .chat-actions-bar {
        bottom: 92px;
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 3px;
    }

    .action-token {
        flex: 0 0 auto;
    }

    .chat-input-bar {
        padding: 8px;
        border-radius: 16px;
        width: calc(100% - 16px);
        margin-left: 8px;
        margin-right: 8px;
    }
}
