/* Chat Page Styles */

.chat-page {
    margin: 0;
    padding: 0;
    background: #f5f7fa;
    min-height: 100vh;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex-shrink: 0;
}

.chat-header-left {
    flex: 1;
}

.chat-header-center {
    flex: 2;
    text-align: center;
}

.chat-header-center h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.chat-subtitle {
    font-size: 12px;
    opacity: 0.85;
}

.chat-header-right {
    flex: 1;
    display: flex;
    justify-content: flex-end;
}

.back-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: white;
    text-decoration: none;
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background 0.2s;
}

.back-button:hover {
    background: rgba(255, 255, 255, 0.15);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #fbbf24;
    animation: pulse 2s infinite;
}

.status-indicator.online .status-dot {
    background: #34d399;
    animation: none;
}

.status-indicator.offline .status-dot {
    background: #f87171;
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    max-width: 600px;
    margin: 0 auto;
}

.welcome-icon {
    color: #667eea;
    margin-bottom: 16px;
}

.welcome-message h2 {
    margin: 0 0 8px 0;
    font-size: 24px;
    color: #1f2937;
}

.welcome-message p {
    margin: 0 0 24px 0;
    color: #6b7280;
}

.example-categories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    text-align: left;
}

.example-category {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 16px;
}

.example-category h3 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.example-question {
    display: block;
    padding: 8px 12px;
    margin: 4px 0;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    color: #4b5563;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    width: 100%;
}

.example-question:hover {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* Chat Messages */
.message {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #374151;
}

.message-content {
    background: #f3f4f6;
    padding: 12px 16px;
    border-radius: 16px;
    border-top-left-radius: 4px;
}

.message.user .message-content {
    background: #667eea;
    color: white;
    border-radius: 16px;
    border-top-right-radius: 4px;
}

.message-content p {
    margin: 0;
    line-height: 1.5;
}

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

/* Markdown content styling */
.message-content h1,
.message-content h2,
.message-content h3 {
    margin: 16px 0 8px 0;
    font-weight: 600;
}

.message-content h1 { font-size: 18px; }
.message-content h2 { font-size: 16px; }
.message-content h3 { font-size: 14px; }

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

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

.message-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 13px;
}

.message.user .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.message-content pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

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

.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

.message-content th,
.message-content td {
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    text-align: left;
}

.message-content th {
    background: #f9fafb;
    font-weight: 600;
}

.message-content blockquote {
    border-left: 3px solid #667eea;
    margin: 12px 0;
    padding-left: 16px;
    color: #6b7280;
}

/* Query Info */
.query-info {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 11px;
    color: #9ca3af;
}

.query-info details {
    cursor: pointer;
}

.query-info summary {
    outline: none;
}

.query-info pre {
    font-size: 11px;
    padding: 8px;
    margin-top: 8px;
}

/* Thinking Steps */
.thinking-steps {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.steps-header {
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.steps-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.7);
    border-radius: 6px;
    border-left: 3px solid #667eea;
}

.step-item.success {
    border-left-color: #10b981;
}

.step-item.error {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.08);
}

.step-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.step-description {
    flex: 1;
    color: #374151;
    word-break: break-word;
}

.step-result {
    font-size: 11px;
    color: #6b7280;
    white-space: nowrap;
}

.step-item.success .step-result {
    color: #10b981;
}

.step-item.error .step-result {
    color: #ef4444;
}

.response-content {
    /* Wrapper for the actual response */
}

/* Input Area */
.chat-input-area {
    padding: 16px 24px 24px;
    background: white;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.chat-input-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    border-radius: 16px;
    padding: 12px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-container:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    outline: none;
    line-height: 1.5;
}

#message-input::placeholder {
    color: #9ca3af;
}

.send-button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: #667eea;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: #5a6fd6;
    transform: scale(1.05);
}

.send-button:disabled {
    background: #d1d5db;
    cursor: not-allowed;
}

.chat-input-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 12px;
    color: #9ca3af;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: white;
    font-size: 16px;
    z-index: 1000;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #9ca3af;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.typing-hint {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 6px;
}

/* Error State */
.message.error .message-content {
    background: #fee2e2;
    color: #991b1b;
}

/* System Message (cancelled, etc) */
.message.system {
    max-width: 100%;
    justify-content: center;
}

.message.system .message-avatar {
    display: none;
}

.message.system .message-content {
    background: #f3f4f6;
    color: #6b7280;
    font-size: 13px;
    font-style: italic;
    padding: 8px 16px;
    border-radius: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-header {
        padding: 12px 16px;
    }

    .chat-header-center h1 {
        font-size: 16px;
    }

    .chat-subtitle {
        display: none;
    }

    .back-button span {
        display: none;
    }

    .messages-container {
        padding: 16px;
    }

    .message {
        max-width: 95%;
    }

    .example-categories {
        grid-template-columns: 1fr;
    }

    .chat-input-area {
        padding: 12px 16px 16px;
    }
}
