/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    min-height: 100vh;
    color: #e0e0e0;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-bottom: 1px solid #333;
    margin-bottom: 30px;
}

header h1 {
    font-size: 1.8rem;
    color: #00d4ff;
}

nav {
    display: flex;
    gap: 15px;
}

nav a {
    color: #888;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 8px;
    transition: all 0.3s ease;
}

nav a:hover {
    background: #2a2a4a;
    color: #fff;
}

nav a.active {
    background: #00d4ff;
    color: #1a1a2e;
    font-weight: 600;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: all 0.3s ease;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: #00d4ff;
    color: #1a1a2e;
}

.btn-primary:hover:not(:disabled) {
    background: #00b8e6;
    transform: translateY(-2px);
}

.btn-secondary {
    background: #444;
    color: #fff;
}

.btn-secondary:hover:not(:disabled) {
    background: #555;
}

.btn-success {
    background: #00c853;
    color: #fff;
}

.btn-success:hover:not(:disabled) {
    background: #00b248;
}

.btn-danger {
    background: #ff4757;
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #ff3344;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Chat Container */
.chat-container {
    background: #1e1e3f;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.chat-settings {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #2a2a4a;
    border-radius: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.chat-settings label {
    font-weight: 500;
}

.chat-settings select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #444;
    background: #1a1a2e;
    color: #fff;
    font-size: 0.9rem;
    min-width: 200px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Chat Messages */
.chat-messages {
    height: 500px;
    overflow-y: auto;
    padding: 20px;
    background: #151530;
    border-radius: 12px;
    margin-bottom: 20px;
}

.message {
    margin-bottom: 20px;
    animation: fadeIn 0.3s ease;
}

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

.message.user {
    text-align: right;
}

.message.user .message-content {
    background: #00d4ff;
    color: #1a1a2e;
    display: inline-block;
    max-width: 70%;
    text-align: left;
}

.message.assistant .message-content {
    background: #2a2a4a;
    display: inline-block;
    max-width: 70%;
}

.message.system .message-content {
    background: #3a3a5a;
    color: #aaa;
    text-align: center;
    display: block;
    font-style: italic;
}

.message-content {
    padding: 15px 20px;
    border-radius: 16px;
    line-height: 1.6;
}

.rag-info {
    margin-top: 10px;
    max-width: 70%;
}

.rag-info details {
    background: #2a2a4a;
    border-radius: 8px;
    padding: 10px;
    font-size: 0.85rem;
}

.rag-info summary {
    cursor: pointer;
    color: #00d4ff;
    font-weight: 500;
}

.rag-info ul {
    margin-top: 10px;
    padding-left: 20px;
}

.rag-info li {
    margin-bottom: 8px;
    color: #aaa;
}

/* Chat Form */
.chat-form {
    display: flex;
    gap: 15px;
}

.chat-form textarea {
    flex: 1;
    padding: 15px;
    border-radius: 12px;
    border: 1px solid #444;
    background: #2a2a4a;
    color: #fff;
    font-size: 1rem;
    resize: none;
    font-family: inherit;
}

.chat-form textarea:focus {
    outline: none;
    border-color: #00d4ff;
}

.chat-form textarea::placeholder {
    color: #666;
}

/* Management Page */
.manage-container {
    display: flex;
    flex-direction: column;
    gap: 30px;
}

.settings-section,
.add-rag-section,
.rag-table-section {
    background: #1e1e3f;
    border-radius: 16px;
    padding: 25px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.settings-section h2,
.add-rag-section h2,
.rag-table-section h2 {
    margin-bottom: 20px;
    color: #00d4ff;
    font-size: 1.3rem;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.form-group select,
.form-group textarea {
    width: 100%;
    padding: 12px 15px;
    border-radius: 8px;
    border: 1px solid #444;
    background: #2a2a4a;
    color: #fff;
    font-size: 1rem;
    font-family: inherit;
}

.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #00d4ff;
}

.form-group textarea {
    resize: vertical;
    min-height: 120px;
}

.settings-form {
    display: flex;
    align-items: flex-end;
    gap: 15px;
    flex-wrap: wrap;
}

.settings-form .form-group {
    margin-bottom: 0;
    flex: 1;
    min-width: 250px;
}

.info-text {
    margin-top: 15px;
    color: #888;
    font-size: 0.9rem;
}

.status-message {
    font-size: 0.9rem;
    padding: 5px 10px;
}

.status-message.success {
    color: #00c853;
}

.status-message.error {
    color: #ff4757;
}

/* RAG Table */
.table-container {
    overflow-x: auto;
}

.rag-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.rag-table th,
.rag-table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #333;
}

.rag-table th {
    background: #2a2a4a;
    font-weight: 600;
    color: #00d4ff;
}

.rag-table tr:hover {
    background: #252545;
}

.rag-table .empty-row td {
    text-align: center;
    color: #666;
    font-style: italic;
}

.content-cell {
    max-width: 400px;
}

.content-preview {
    color: #ccc;
    font-size: 0.9rem;
    line-height: 1.5;
}

.content-cell details {
    margin-top: 10px;
}

.content-cell summary {
    cursor: pointer;
    color: #00d4ff;
    font-size: 0.85rem;
}

.full-content {
    margin-top: 10px;
    padding: 10px;
    background: #2a2a4a;
    border-radius: 8px;
    font-size: 0.85rem;
    line-height: 1.6;
    max-height: 200px;
    overflow-y: auto;
}

/* Scrollbar Styles */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #1a1a2e;
}

::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Responsive */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        gap: 15px;
    }
    
    .chat-settings {
        flex-direction: column;
        align-items: stretch;
    }
    
    .chat-form {
        flex-direction: column;
    }
    
    .message.user .message-content,
    .message.assistant .message-content,
    .rag-info {
        max-width: 90%;
    }
    
    .settings-form {
        flex-direction: column;
        align-items: stretch;
    }
    
    .rag-table {
        font-size: 0.85rem;
    }
    
    .rag-table th,
    .rag-table td {
        padding: 10px;
    }
}
/* RAG Context Styling */
.rag-info {
    margin-top: 10px;
    padding: 10px;
    background: #f8f9fa;
    border-left: 3px solid #007bff;
    border-radius: 4px;
    font-size: 0.9em;
}

.rag-info summary {
    cursor: pointer;
    font-weight: 600;
    color: #007bff;
    padding: 5px;
    user-select: none;
}

.rag-info summary:hover {
    background: #e9ecef;
    border-radius: 4px;
}

.rag-info ul {
    list-style: none;
    padding: 0;
    margin: 10px 0 0 0;
}

.rag-info li {
    padding: 10px;
    margin: 8px 0;
    background: white;
    border-radius: 4px;
    border: 1px solid #dee2e6;
}

.rag-info li strong {
    color: #28a745;
    font-size: 1.1em;
}

.similarity-badge {
    display: inline-block;
    padding: 2px 8px;
    background: #28a745;
    color: white;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
    margin-left: 5px;
}

.context-preview {
    margin-top: 8px;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
    color: #495057;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    line-height: 1.4;
}