* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --secondary-color: #6366F1;
    --background: #0F172A;
    --surface: #1E293B;
    --surface-light: #334155;
    --text-primary: #F1F5F9;
    --text-secondary: #CBD5E1;
    --bot-message-bg: #1E293B;
    --user-message-bg: #4F46E5;
    --border-color: #334155;
    --success-color: #10B981;
    --error-color: #EF4444;
    --warning-color: #F59E0B;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.chat-container {
    width: 100%;
    max-width: 900px;
    height: 90vh;
    max-height: 800px;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.chat-header {
    padding: 20px 24px;
    background: var(--surface-light);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
    animation: pulse 2s infinite;
}

.status-dot.connecting {
    background: var(--warning-color);
}

.status-dot.error {
    background: var(--error-color);
    animation: none;
}

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

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
    align-items: flex-start;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: var(--surface);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--surface-light);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: var(--border-color);
}

.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease-in;
    max-width: 85%;
    margin-bottom: 0;
    position: relative;
    flex-shrink: 0;
}

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

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    background: var(--surface-light);
}

.user-message .message-avatar {
    background: var(--primary-color);
}

.message-content {
    padding: 12px 16px;
    border-radius: 12px;
    line-height: 1.6;
    word-wrap: break-word;
    overflow-wrap: break-word;
    position: relative;
    width: 100%;
}

.bot-message .message-content {
    background: var(--bot-message-bg);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.user-message .message-content {
    background: var(--user-message-bg);
    color: white;
}

.message-content p {
    margin: 0;
    white-space: pre-wrap;
    min-height: 1em; /* Ensure paragraph has height even when empty */
}

.streaming-message .message-content {
    min-height: 50px; /* Ensure streaming messages are visible */
}

.streaming-text {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.message-content pre {
    background: rgba(0, 0, 0, 0.3);
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

.message-content code {
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
}

/* Citations/Sources styling (like Cloudflare AI Search) */
.citations {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.citations-header {
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-secondary);
}

.citations-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.citation-item {
    padding: 10px 12px;
    background: rgba(79, 70, 229, 0.1);
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: 8px;
    font-size: 13px;
    transition: all 0.2s;
}

.citation-item:hover {
    background: rgba(79, 70, 229, 0.15);
    border-color: rgba(79, 70, 229, 0.3);
}

.citation-content {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.citation-number {
    font-weight: 600;
    color: var(--primary-color);
    min-width: 24px;
}

.citation-link {
    color: var(--primary-color);
    text-decoration: none;
    transition: color 0.2s;
    word-break: break-word;
}

.citation-link:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

.citation-text {
    color: var(--text-primary);
    word-break: break-word;
}

.citation-score {
    font-size: 11px;
    color: var(--text-secondary);
    margin-left: auto;
}

.citation-snippet {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(79, 70, 229, 0.1);
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    font-style: italic;
}

/* Streaming text styles */
.streaming-message .streaming-text {
    position: relative;
}

.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--primary-color);
    margin-left: 2px;
    animation: blink 1s infinite;
    vertical-align: baseline;
}

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

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

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.7;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

.chat-input-container {
    padding: 20px 24px;
    background: var(--surface-light);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    transition: border-color 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
}

.input-wrapper textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 150px;
    overflow-y: auto;
    outline: none;
}

.input-wrapper textarea::placeholder {
    color: var(--text-secondary);
}

.send-button {
    background: var(--primary-color);
    border: none;
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-button:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: scale(1.05);
}

.send-button:active:not(:disabled) {
    transform: scale(0.95);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.char-count {
    font-size: 12px;
}

.clear-button {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

.clear-button:hover {
    background: var(--surface);
    border-color: var(--error-color);
    color: var(--error-color);
}

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--error-color);
    color: var(--error-color);
    padding: 12px 16px;
    border-radius: 8px;
    margin: 8px 0;
}

@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .message {
        max-width: 95%;
    }
    
    .chat-header h1 {
        font-size: 20px;
    }
}

