/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

/* Container */
.container {
    max-width: 900px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: calc(100vh - 40px);
}

/* Header */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 24px 32px;
    text-align: center;
}

header h1 {
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Chat Container */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
    background: #f8f9fa;
}

.messages-area {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Welcome Message */
.welcome-message {
    text-align: center;
    padding: 40px 20px;
    color: #6c757d;
}

.welcome-message p {
    font-size: 16px;
}

/* Message Styles */
.message {
    padding: 16px 20px;
    border-radius: 8px;
    max-width: 85%;
    word-wrap: break-word;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    background: #667eea;
    color: white;
    align-self: flex-end;
    margin-left: auto;
}

.message.assistant {
    background: white;
    color: #333;
    border: 1px solid #e0e0e0;
    align-self: flex-start;
}

.message-content {
    line-height: 1.6;
}

.message-sources {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 13px;
    opacity: 0.8;
}

.message-sources strong {
    display: block;
    margin-bottom: 4px;
}

.loading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    max-width: 85%;
    color: #6c757d;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Input Area */
.input-area {
    padding: 24px 32px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.input-wrapper {
    display: flex;
    gap: 12px;
}

.question-input {
    flex: 1;
    padding: 14px 18px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.2s;
}

.question-input:focus {
    outline: none;
    border-color: #667eea;
}

.question-input::placeholder {
    color: #adb5bd;
}

.search-button {
    padding: 14px 32px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.search-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.search-button:active {
    transform: translateY(0);
}

.search-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Error Message */
.error-message {
    margin-top: 12px;
    padding: 12px 16px;
    border-radius: 6px;
    font-size: 14px;
    display: none;
    border-left: 4px solid;
    position: relative;
}

.error-message.show {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

/* Default error styling */
.error-message.error {
    background: #fee;
    color: #c33;
    border-left-color: #c33;
}

/* Network error styling */
.error-message.network-error {
    background: #fff3cd;
    color: #856404;
    border-left-color: #ffc107;
}

.error-message.network-error::before {
    content: "⚠️ ";
    margin-right: 4px;
}

/* Service/timeout error styling */
.error-message.service-error,
.error-message.timeout-error {
    background: #d1ecf1;
    color: #0c5460;
    border-left-color: #17a2b8;
}

.error-message.service-error::before,
.error-message.timeout-error::before {
    content: "ℹ️ ";
    margin-right: 4px;
}

/* Close button for persistent errors */
.error-message::after {
    content: "×";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 20px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.error-message::after:hover {
    opacity: 1;
}

/* Footer */
footer {
    padding: 16px 32px;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

.footer-text {
    font-size: 13px;
    color: #6c757d;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 0;
    }
    
    .container {
        height: 100vh;
        border-radius: 0;
    }
    
    header {
        padding: 20px 16px;
    }
    
    header h1 {
        font-size: 24px;
    }
    
    #chat-container {
        padding: 16px;
    }
    
    .input-area {
        padding: 16px;
    }
    
    .input-wrapper {
        flex-direction: column;
    }
    
    .search-button {
        width: 100%;
    }
    
    .message {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 20px;
    }
    
    .subtitle {
        font-size: 12px;
    }
    
    .question-input {
        font-size: 14px;
    }
}
