/**
 * True Heart - Chat Interface
 * FULL CONSOLIDATED FILE
 * Integration: Fixed Input Well + Bottom Nav Compatibility
 */

/* ============================================
   1. CHAT WRAPPER
   ============================================ */
.chat-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
    background: transparent;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

/* ============================================
   2. CHAT HEADER
   ============================================ */
.chat-header {
    background: var(--th-bg-primary);
    border-bottom: 1px solid var(--th-border);
    padding: 16px 20px;
    position: relative;
    z-index: 100;
}

.chat-header-content {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-title h1 {
    font-size: 18px;
    font-weight: 500;
    color: var(--th-text-primary);
}

.chat-status {
    font-size: 12px;
    color: var(--th-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--th-primary);
    border-radius: 50%;
    box-shadow: 0 0 8px var(--th-primary);
}

/* ============================================
   3. CHAT MESSAGES AREA
   ============================================ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    /* Massive padding-bottom to clear BOTH the input (~85px) and nav (~70px) */
    padding-bottom: 180px; 
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.message-group {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
}

/* ============================================
   4. MESSAGE BUBBLES
   ============================================ */
.message-bubble {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 20px;
    margin-bottom: 8px;
    line-height: 1.5;
    font-size: 15px;
    position: relative;
    overflow: hidden;
}

/* Lumi / AI Bubble */
.message-ai {
    background: var(--th-gradient-lumi);
    color: var(--th-text-primary);
    align-self: flex-start;
    border: 1px solid rgba(62, 207, 207, 0.2);
    border-bottom-left-radius: 4px;
    line-height: 1.5;
    letter-spacing: 0.01em;
    white-space: pre-line; /* Keeps the spacing Lumi generates */
}

/* User Bubble */
.message-user {
    background: var(--th-gradient-user);
    color: white;
    align-self: flex-end;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom-right-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--th-text-light);
    margin-top: 4px;
}

.message-ai + .message-time { align-self: flex-start; margin-left: 4px; }
.message-user + .message-time { align-self: flex-end; margin-right: 4px; }

/* ============================================
   5. TYPING INDICATOR
   ============================================ */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    background: var(--th-gradient-lumi);
    border-radius: 20px;
    width: fit-content;
    margin-bottom: 12px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--th-primary-light);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

    /* ── Streaming bubble: background appears quickly; text reveals after 150ms via JS ── */
    .message-bubble.th-streaming {
        animation: th-bubble-appear 0.2s ease both;
    }
    @keyframes th-bubble-appear {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

    /* ── Per-chunk word reveal: soft fade-in as each token arrives ── */
    .th-word-reveal {
        display: inline;
        animation: th-word-fade-in 0.25s ease both;
    }
    @keyframes th-word-fade-in {
        from { opacity: 0; }
        to   { opacity: 1; }
    }

/* ============================================
   6. FIXED INPUT AREA (Stacked Above Nav)
   ============================================ */
.chat-input-wrapper {
    position: fixed;
    /* Sits above the nav bar; nav bar bottom padding grows by safe-bottom so this must too */
    bottom: calc(66px + var(--th-safe-bottom));
    left: 0;
    right: 0;
    background: #141c26; 
    border-top: 1px solid rgba(245,245,240,0.1);
    padding: 15px 20px;
    z-index: 999; 
    box-shadow: 0 -4px 12px rgba(0,0,0,0.4);
}

/* Bleeds the wrapper background down to cover any sub-pixel gap above the nav */
.chat-input-wrapper::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 0;
    right: 0;
    height: 8px;
    background: #141c26;
}

.chat-input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-input {
    flex: 1;
    height: 48px;
    max-height: 150px;
    padding: 10px 20px;
    background: #0d1117 !important; 
    border: 2px solid var(--th-primary) !important;
    border-radius: 24px;
    color: #FFFFFF !important;
    font-size: 16px;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    transition: all 0.2s ease;
    display: block;
}

.chat-input:focus {
    outline: none;
    border-color: var(--th-primary-light) !important;
    box-shadow: 0 0 10px rgba(62, 207, 207, 0.3);
}

.chat-input::placeholder {
    color: rgba(245,245,240,0.3);
}

/* ============================================
   7. SEND BUTTON
   ============================================ */
.send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--th-primary);
    border: none;
    color: #0d1117;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s ease;
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    background: var(--th-primary-light);
}

.send-btn:disabled {
    background: #1e2a38;
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   8. WELCOME CARD
   ============================================ */
.welcome-card {
    background: var(--th-gradient-lumi);
    padding: 32px;
    border-radius: 24px;
    text-align: center;
    color: white;
    margin-bottom: 24px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.welcome-card h3 {
    font-size: clamp(13px, 4vw, 20px);
    margin-bottom: 12px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
}

.welcome-card p {
    font-size: 14px;
    opacity: 0.9;
    line-height: 1.6;
}
