/* ============================================
   ChatGenzAI - Chat Styles
   File: css/chat.css
   ============================================ */

.chat-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
}

.messages-container {
    flex: 1;
    max-width: 820px;
    width: 100%;
    margin: 0 auto;
    padding: 24px 20px 40px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ============================================
   Message Bubble
   ============================================ */
.message {
    display: flex;
    gap: 12px;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 14px;
}

.message.user .message-avatar {
    background: var(--accent-gradient);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    border: 1px solid var(--border-color);
}

.message-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.message-role {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.message.user .message-role {
    color: var(--text-primary);
}

.message-body {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ============================================
   Markdown Elements (in message body)
   ============================================ */
.message-body p {
    margin-bottom: 12px;
}

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

.message-body h1, .message-body h2, .message-body h3,
.message-body h4, .message-body h5, .message-body h6 {
    margin-top: 20px;
    margin-bottom: 12px;
    font-weight: 600;
    line-height: 1.3;
}

.message-body h1 { font-size: 1.6em; }
.message-body h2 { font-size: 1.4em; }
.message-body h3 { font-size: 1.2em; }
.message-body h4 { font-size: 1.1em; }
.message-body h5 { font-size: 1.0em; }
.message-body h6 { font-size: 0.9em; color: var(--text-tertiary); }

.message-body ul, .message-body ol {
    margin: 8px 0 12px;
    padding-left: 24px;
}

.message-body ul { list-style: disc; }
.message-body ol { list-style: decimal; }

.message-body li {
    margin-bottom: 4px;
}

.message-body li > ul, .message-body li > ol {
    margin-top: 4px;
    margin-bottom: 0;
}

.message-body a {
    color: var(--accent-primary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.15s;
}

.message-body a:hover {
    border-bottom-color: var(--accent-primary);
}

.message-body blockquote {
    margin: 12px 0;
    padding: 8px 16px;
    border-left: 4px solid var(--accent-primary);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 0 8px 8px 0;
}

.message-body blockquote p {
    margin: 0;
}

.message-body code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    background: var(--bg-tertiary);
    color: var(--accent-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
}

.message-body pre {
    margin: 12px 0;
    background: var(--code-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.message-body pre code {
    display: block;
    padding: 16px;
    background: transparent;
    color: var(--code-text);
    font-size: 13px;
    line-height: 1.5;
    overflow-x: auto;
    border-radius: 0;
}

/* Code block header (copy button) */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
    background: var(--code-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
}

.code-block-lang {
    text-transform: uppercase;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.btn-copy-code {
    padding: 4px 10px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s, color 0.15s;
}

.btn-copy-code:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.btn-copy-code.copied {
    color: var(--success);
}

.code-block-wrapper pre {
    margin: 0;
    background: transparent;
    border: none;
    border-radius: 0;
}

.code-block-wrapper pre code {
    padding: 16px;
    border-radius: 0;
    font-size: 13px;
    background: transparent;
}

/* Tables */
.message-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 14px;
    overflow-x: auto;
    display: block;
}

.message-body th, .message-body td {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    text-align: left;
}

.message-body th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.message-body tr:nth-child(even) {
    background: var(--bg-tertiary);
}

/* Horizontal rule */
.message-body hr {
    margin: 20px 0;
    border: none;
    border-top: 1px solid var(--border-color);
}

/* Images */
.message-body img {
    max-width: 100%;
    border-radius: 8px;
    margin: 8px 0;
}

/* ============================================
   Message Actions (copy, regenerate, etc)
   ============================================ */
.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}

.message:hover .message-actions {
    opacity: 1;
}

.msg-action-btn {
    padding: 6px 8px;
    border-radius: 6px;
    color: var(--text-muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background 0.15s, color 0.15s;
}

.msg-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.msg-action-btn.active {
    color: var(--accent-primary);
}

/* ============================================
   Typing Indicator
   ============================================ */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

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

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

/* ============================================
   Cursor Blink (when streaming)
   ============================================ */
.streaming-cursor {
    display: inline-block;
    width: 8px;
    height: 16px;
    background: var(--accent-primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 1s infinite;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* ============================================
   Error Message
   ============================================ */
.message-error {
    background: var(--error-light);
    color: var(--error);
    padding: 12px 16px;
    border-radius: 8px;
    border-left: 4px solid var(--error);
    font-size: 14px;
}

.message-error .error-title {
    font-weight: 600;
    margin-bottom: 4px;
}

/* ============================================
   Empty conversation
   ============================================ */
.empty-conversations {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================
   Date separator in conversation list
   ============================================ */
.conv-date-label {
    padding: 12px 12px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@media (max-width: 768px) {
    .messages-container {
        padding: 16px 14px 30px;
    }
    
    .message {
        gap: 8px;
    }
    
    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
    }
    
    .message-body {
        font-size: 14px;
    }
    
    .message-actions {
        opacity: 1;
    }
    
    .msg-action-btn {
        padding: 8px 10px;
    }
}
