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

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    background: #eef1f5;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 860px;
    margin: 0 auto;
    width: 100%;
    background: #fff;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
}

/* Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    flex-shrink: 0;
}

.header h1 {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.product-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.product-selector label {
    font-size: 0.8125rem;
    opacity: 0.7;
    font-weight: 400;
}

.product-selector select {
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 0.8125rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

.product-selector select:focus {
    outline: none;
    border-color: #7c74ff;
}

.product-selector select option {
    color: #333;
    background: #fff;
}

/* Messages */
.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: #f7f8fa;
}

.messages {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.message {
    display: flex;
    max-width: 88%;
    animation: fadeIn 0.2s ease-out;
}

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

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

.message.assistant {
    align-self: flex-start;
}

.message-content {
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.65;
    word-wrap: break-word;
}

.message.user .message-content {
    background: #4f46e5;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: #fff;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    border: 1px solid #e8eaed;
}

/* Markdown formatting in assistant messages */
.message.assistant .message-content h3,
.message.assistant .message-content h4 {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #0f172a;
    margin: 12px 0 4px;
}

.message.assistant .message-content h3:first-child,
.message.assistant .message-content h4:first-child {
    margin-top: 0;
}

.message.assistant .message-content strong {
    font-weight: 700;
    color: #0f172a;
}

.message.assistant .message-content em {
    font-style: italic;
}

.message.assistant .message-content code {
    background: #f1f3f5;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.8125rem;
    font-family: 'Cascadia Code', 'Consolas', monospace;
    color: #c2255c;
    border: 1px solid #e9ecef;
}

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

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

.message.assistant .message-content li::marker {
    color: #4f46e5;
    font-weight: 600;
}

.message.assistant .message-content p {
    margin: 6px 0;
}

.message.assistant .message-content p:first-child {
    margin-top: 0;
}

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

/* Inline citation badges */
.citation-ref {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5625rem;
    font-weight: 700;
    background: #4f46e5;
    color: #fff;
    min-width: 15px;
    height: 15px;
    border-radius: 7px;
    padding: 0 3px;
    margin: 0 1px;
    vertical-align: super;
    line-height: 1;
    cursor: default;
}

/* Sources */
.sources-container {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

.sources-label {
    font-size: 0.6875rem;
    color: #94a3b8;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}

.sources-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.source-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px 4px 4px;
    background: #f0eeff;
    border: 1px solid #e0ddf7;
    border-radius: 20px;
    font-size: 0.6875rem;
    color: #4338ca;
    cursor: default;
    transition: all 0.15s ease;
    font-weight: 500;
}

.source-chip:hover {
    background: #e4e1fb;
    border-color: #c7c2f0;
}

.source-chip .citation-num {
    font-weight: 700;
    font-size: 0.5625rem;
    background: #4f46e5;
    color: #fff;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.source-chip .source-icon {
    font-size: 0.625rem;
    opacity: 0.5;
}

/* Input area */
.input-area {
    padding: 14px 24px;
    background: #fff;
    border-top: 1px solid #e8eaed;
    flex-shrink: 0;
}

#chat-form {
    display: flex;
    gap: 8px;
}

#chat-input {
    flex: 1;
    padding: 10px 16px;
    border: 1.5px solid #d1d5db;
    border-radius: 22px;
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

#chat-input:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#chat-input:disabled {
    background: #f9fafb;
    cursor: not-allowed;
    color: #9ca3af;
}

#send-btn {
    padding: 10px 20px;
    background: #4f46e5;
    color: #fff;
    border: none;
    border-radius: 22px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

#send-btn:hover:not(:disabled) {
    background: #4338ca;
}

#send-btn:disabled {
    background: #c7d2fe;
    cursor: not-allowed;
}

/* Loading indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 8px 4px;
}

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: #a5b4fc;
    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; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }

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

/* Scrollbar */
.chat-container::-webkit-scrollbar {
    width: 5px;
}

.chat-container::-webkit-scrollbar-track {
    background: transparent;
}

.chat-container::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}
