* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft JhengHei', sans-serif;
    background: #f5f5f5;
    height: 100vh;
    overflow: hidden;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.1);
}

/* Header */
.chat-header {
    background: #2c3e50;
    color: white;
    padding: 20px 30px;
    border-bottom: 1px solid #34495e;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h1 {
    font-size: 1.5em;
    font-weight: 500;
}

.header-stats {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9em;
    opacity: 0.9;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #27ae60;
}

.status-dot.status-error {
    background: #e74c3c;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    background: #fafafa;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: #7f8c8d;
}

.welcome-message p {
    font-size: 1.3em;
    margin-bottom: 10px;
}

.welcome-subtitle {
    font-size: 0.95em !important;
    opacity: 0.8;
}

/* Message Bubbles */
.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-label {
    font-size: 0.85em;
    color: #7f8c8d;
    margin-bottom: 5px;
    font-weight: 500;
}

.message-user {
    display: flex;
    justify-content: flex-end;
}

.message-user .message-bubble {
    background: #3498db;
    color: white;
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 18px 18px 4px 18px;
    word-wrap: break-word;
}

.message-assistant {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message-assistant .message-bubble {
    background: white;
    color: #2c3e50;
    max-width: 85%;
    padding: 18px 22px;
    border-radius: 18px 18px 18px 4px;
    border: 1px solid #e0e0e0;
    white-space: pre-wrap;
    line-height: 1.6;
}

/* Sources */
.sources-container {
    margin-top: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 3px solid #3498db;
}

.sources-title {
    font-size: 0.9em;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 10px;
}

.source-item {
    padding: 10px;
    margin-bottom: 8px;
    background: white;
    border-radius: 6px;
    font-size: 0.9em;
    border: 1px solid #e0e0e0;
}

.source-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.source-name {
    font-weight: 500;
    color: #2c3e50;
}

.source-score {
    color: #3498db;
    font-size: 0.85em;
}

.source-meta {
    font-size: 0.85em;
    color: #7f8c8d;
    margin-top: 5px;
}

.source-link {
    display: inline-block;
    margin-top: 8px;
    color: #3498db;
    text-decoration: none;
    font-size: 0.85em;
}

.source-link:hover {
    text-decoration: underline;
}

/* Loading Indicator */
.message-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #7f8c8d;
    font-size: 0.9em;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #7f8c8d;
    animation: pulse 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes pulse {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: scale(0.8);
    }
    40% {
        opacity: 1;
        transform: scale(1);
    }
}

/* Input Container */
.chat-input-container {
    border-top: 1px solid #e0e0e0;
    background: white;
    padding: 20px 30px;
}

/* Filters Panel */
.filters-panel {
    display: none;
    margin-bottom: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 8px;
}

.filters-panel.active {
    display: block;
}

.filter-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.filter-select {
    flex: 1;
    min-width: 150px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9em;
    background: white;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: #3498db;
}

.mode-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
}

.mode-toggle input[type="checkbox"] {
    cursor: pointer;
}

.toggle-filters-btn {
    background: #ecf0f1;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9em;
    color: #2c3e50;
    margin-bottom: 10px;
    transition: background 0.2s;
}

.toggle-filters-btn:hover {
    background: #d5dbdb;
}

.toggle-filters-btn.active {
    background: #3498db;
    color: white;
}

/* Input Form */
.input-form {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

#question-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 0.95em;
    font-family: inherit;
    resize: none;
    transition: border-color 0.2s;
}

#question-input:focus {
    outline: none;
    border-color: #3498db;
}

.send-btn {
    padding: 12px 30px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.send-btn:hover {
    background: #2980b9;
}

.send-btn:disabled {
    background: #bdc3c7;
    cursor: not-allowed;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #bdc3c7;
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #95a5a6;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-header {
        padding: 15px 20px;
    }
    
    .header-content {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .chat-messages {
        padding: 20px 15px;
    }
    
    .chat-input-container {
        padding: 15px;
    }
    
    .filter-row {
        flex-direction: column;
    }
    
    .filter-select {
        min-width: 100%;
    }
    
    .input-form {
        flex-direction: column;
        gap: 10px;
    }
    
    .send-btn {
        width: 100%;
    }
    
    .message-user .message-bubble,
    .message-assistant .message-bubble {
        max-width: 85%;
    }
}