/* ═══════════════════════════════════════════════════════
   Glitrex AI — Chat Area
   ═══════════════════════════════════════════════════════ */

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    height: var(--app-height);
    background: var(--bg-primary);
}

/* ── Header ────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    height: var(--header-height);
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(8, 8, 13, 0.8);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-info h2 {
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-model-badge {
    font-size: 0.72rem;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 100px;
    background: var(--gradient-subtle);
    color: var(--accent-purple);
    border: 1px solid rgba(139, 92, 246, 0.2);
    white-space: nowrap;
}

/* ── Messages Container ────────────────────────────── */
.messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 24px 0;
    overscroll-behavior: contain;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 24px;
    animation: fadeIn var(--duration-slow) ease;
}

.welcome-icon {
    margin-bottom: 20px;
}

.welcome-screen h2 {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 8px;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-screen p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    max-width: 380px;
}

/* ── Message Bubbles ───────────────────────────────── */
.message {
    display: flex;
    gap: 14px;
    padding: 8px 32px;
    animation: slideUp var(--duration-normal) var(--ease-out);
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.message+.message {
    margin-top: 4px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 700;
    margin-top: 4px;
}

.message.user .message-avatar {
    background: var(--gradient-primary);
    color: white;
}

.message.assistant .message-avatar {
    background: var(--surface-2);
    color: var(--accent-cyan);
}

.message-body {
    flex: 1;
    min-width: 0;
}

.message-content {
    font-size: 0.92rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.message.user .message-content {
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 18px;
}

.message.assistant .message-content {
    padding: 6px 0;
}

/* ── Thinking Block ──────────────────────────────────── */
.thinking-block {
    margin-bottom: 12px;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: var(--radius-md);
    background: rgba(139, 92, 246, 0.04);
    overflow: hidden;
    animation: slideUp var(--duration-normal) var(--ease-out);
}

.thinking-block summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--accent-purple);
    user-select: none;
    list-style: none;
    transition: background var(--duration-fast) ease;
}

.thinking-block summary::-webkit-details-marker {
    display: none;
}

.thinking-block summary:hover {
    background: rgba(139, 92, 246, 0.08);
}

.thinking-icon {
    font-size: 1rem;
    line-height: 1;
}

.thinking-label {
    flex: 1;
}

.thinking-chevron {
    transition: transform var(--duration-fast) ease;
    opacity: 0.6;
}

.thinking-block[open] .thinking-chevron {
    transform: rotate(180deg);
}

.thinking-content {
    padding: 8px 16px 14px;
    font-size: 0.82rem;
    line-height: 1.55;
    color: var(--text-tertiary);
    border-top: 1px solid rgba(139, 92, 246, 0.1);
    font-style: italic;
    max-height: 400px;
    overflow-y: auto;
}

.thinking-content p {
    margin-bottom: 6px;
}

.thinking-content p:last-child {
    margin-bottom: 0;
}

@keyframes thinkPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.thinking-block[open] .thinking-label {
    animation: thinkPulse 1.5s ease-in-out infinite;
}

/* ── Message images ────────────────────────────────── */
.message-image {
    max-width: 360px;
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    border: 1px solid var(--border-subtle);
    cursor: pointer;
    transition: transform var(--duration-fast) ease;
}

.message-image:hover {
    transform: scale(1.02);
}

/* ── Markdown inside messages ──────────────────────── */
.message-content p {
    margin-bottom: 10px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
    color: var(--text-secondary);
}

.message-content ul,
.message-content ol {
    padding-left: 24px;
    margin-bottom: 10px;
}

.message-content li {
    margin-bottom: 4px;
}

.message-content blockquote {
    border-left: 3px solid var(--accent-purple);
    padding-left: 16px;
    margin: 10px 0;
    color: var(--text-secondary);
}

.message-content a {
    color: var(--accent-cyan);
    text-decoration: underline;
    text-decoration-color: rgba(6, 182, 212, 0.3);
    text-underline-offset: 3px;
}

.message-content a:hover {
    text-decoration-color: var(--accent-cyan);
}

/* ── Code blocks ───────────────────────────────────── */
.message-content code {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--surface-2);
    padding: 2px 7px;
    border-radius: 5px;
    color: var(--accent-cyan);
}

.message-content pre {
    position: relative;
    margin: 12px 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
}

.message-content pre code {
    display: block;
    padding: 16px 20px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    overflow-x: auto;
    font-size: 0.84rem;
    line-height: 1.6;
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.75rem;
    color: var(--text-tertiary);
}

.copy-code-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    padding: 3px 8px;
    border-radius: 4px;
    transition: all var(--duration-fast) ease;
}

.copy-code-btn:hover {
    background: var(--surface-2);
    color: var(--text-primary);
}

.copy-code-btn.copied {
    color: var(--accent-green);
}

/* ── Tables in messages ────────────────────────────── */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 0.87rem;
}

.message-content th,
.message-content td {
    padding: 10px 14px;
    text-align: left;
    border: 1px solid var(--border-subtle);
}

.message-content th {
    background: var(--surface-1);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.message-content td {
    background: transparent;
}

/* ── Input Area ────────────────────────────────────── */
.input-area {
    padding: 16px 24px calc(20px + var(--safe-area-bottom));
    border-top: 1px solid var(--border-subtle);
    background: var(--bg-primary);
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
}

.attachment-preview {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 12px;
    animation: slideUp var(--duration-normal) var(--ease-out);
    position: relative;
}

.attachment-preview-content {
    flex: 1;
    min-width: 0;
}

.upload-overlay {
    position: absolute;
    inset: 0;
    background: rgba(8, 8, 13, 0.8);
    backdrop-filter: blur(4px);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 5;
    animation: fadeIn var(--duration-fast) ease;
}

.upload-overlay span {
    font-size: 0.78rem;
    color: var(--accent-purple);
    font-weight: 500;
}

.upload-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(139, 92, 246, 0.2);
    border-top-color: var(--accent-purple);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.attachment-preview-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-medium);
}

.attachment-card {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 12px 14px;
    background: var(--surface-1);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    text-decoration: none;
    transition: all var(--duration-fast) ease;
}

.attachment-card:hover {
    background: var(--surface-2);
    border-color: rgba(139, 92, 246, 0.35);
}

.attachment-card-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    background: rgba(139, 92, 246, 0.12);
    color: var(--accent-purple);
}

.attachment-card-info {
    flex: 1;
    min-width: 0;
}

.attachment-card-name {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-card-meta {
    margin-top: 2px;
    font-size: 0.76rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-card-action {
    flex-shrink: 0;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--accent-cyan);
}

.message-attachment {
    max-width: 420px;
    margin-bottom: 10px;
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-medium);
    border-radius: var(--radius-lg);
    padding: 8px 12px;
    transition: border-color var(--duration-fast) ease;
}

.input-row:focus-within {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1);
}

.input-row textarea {
    flex: 1;
    resize: none;
    padding: 8px 4px;
    max-height: 160px;
    line-height: 1.5;
    font-size: 0.92rem;
    color: var(--text-primary);
    background: transparent;
}

.input-row textarea::placeholder {
    color: var(--text-tertiary);
}

.attach-btn {
    cursor: pointer;
}

.send-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--gradient-primary);
    color: white;
    transition: all var(--duration-fast) ease;
    flex-shrink: 0;
}

.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 2px 12px rgba(139, 92, 246, 0.4);
}

.stop-btn {
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    background: var(--accent-red);
    color: white;
    flex-shrink: 0;
    transition: all var(--duration-fast) ease;
}

.stop-btn:hover {
    background: #dc2626;
    transform: scale(1.05);
}

/* ── Error message ─────────────────────────────────── */
.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--accent-red);
    font-size: 0.87rem;
    margin: 8px 32px;
    max-width: 900px;
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
    .message {
        padding: 8px 16px;
    }

    .input-area {
        padding: 12px 16px calc(16px + var(--safe-area-bottom));
    }

    .chat-header {
        padding: 0 16px;
    }

    .message-attachment {
        max-width: 100%;
    }
}
