:root {
    --primary: #2563eb;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --bg-input: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border: #475569;
}

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

html, body {
    width: 100%;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-primary);
}

.dashboard-container {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    gap: 0;
}

/* ──────────────────────── SIDEBAR ──────────────────────── */
.sidebar {
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow-y: auto;
}

.sidebar-header {
    margin-bottom: 32px;
    text-align: center;
}

.sidebar-logo {
    width: 160px;
    height: auto;
    display: block;
    margin: 0 auto 8px;
    filter: drop-shadow(0 0 12px rgba(0, 200, 255, 0.35));
}

.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-left: 3px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-size: 14px;
    font-weight: 500;
}

.nav-item:hover {
    background: rgba(37, 99, 235, 0.1);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(37, 99, 235, 0.15);
    border-left-color: var(--primary);
    color: var(--text-primary);
}

.nav-item .icon {
    font-size: 18px;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 16px;
    text-align: center;
}

.version {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.api-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 12px;
    color: var(--success);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--secondary);
}

.status-dot.online {
    background: var(--success);
    animation: pulse 2s infinite;
}

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

/* ──────────────────────── MAIN CONTENT ──────────────────────── */
.main-content {
    display: flex;
    flex-direction: column;
    padding: 32px;
    overflow-y: auto;
    background: linear-gradient(135deg, rgba(15, 23, 42, 1) 0%, rgba(30, 41, 59, 0.5) 100%);
    gap: 32px;
    width: 100%;
}

.content-section {
    display: none;
}

.content-section.active {
    display: block;
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.section-header {
    margin-bottom: 32px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.section-header h2 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.section-header p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ──────────────────────── UPLOAD AREA ──────────────────────── */
.upload-area {
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: 8px;
    padding: 48px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 24px;
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.05);
}

.upload-area.dragover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
}

.upload-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.upload-area h3 {
    font-size: 18px;
    margin-bottom: 8px;
}

.upload-area p {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ──────────────────────── UPLOAD QUEUE ──────────────────────── */
.upload-queue {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.upload-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.upload-item-name {
    flex: 1;
}

.upload-item-name strong {
    display: block;
    margin-bottom: 4px;
}

.upload-item-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.upload-item.success .upload-item-status {
    color: var(--success);
}

.upload-item.error .upload-item-status {
    color: var(--danger);
}

/* ──────────────────────── FORMS ──────────────────────── */
.query-form {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    margin-bottom: 24px;
}

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

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.1);
}

textarea.form-input {
    resize: vertical;
}

/* ──────────────────────── BUTTONS ──────────────────────── */
.btn-primary,
.btn-secondary,
.btn-close {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
    justify-content: center;
}

.btn-primary:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background: var(--secondary);
    color: white;
}

.btn-secondary:hover {
    background: #475569;
}

.btn-close {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px;
}

.btn-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* ──────────────────────── PROGRESS & LOADING ──────────────────────── */
.ingest-progress,
.query-progress {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    text-align: center;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 12px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), #7c3aed);
    width: 0%;
    animation: progress 2s ease-in-out infinite;
}

@keyframes progress {
    0% { width: 0%; }
    50% { width: 100%; }
    100% { width: 100%; }
}

.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ──────────────────────── DOCUMENTS LIST ──────────────────────── */
.documents-list {
    display: grid;
    gap: 16px;
}

.document-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
    transition: all 0.2s;
}

.document-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.document-card-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    margin-bottom: 12px;
}

.document-card-title {
    font-size: 16px;
    font-weight: 600;
}

.document-card-id {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: monospace;
}

.document-card-meta {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
    margin: 12px 0;
}

.document-card-meta span::before {
    content: "• ";
    margin-right: 4px;
}

.document-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.badge {
    display: inline-block;
    padding: 4px 8px;
    background: rgba(37, 99, 235, 0.2);
    border: 1px solid var(--primary);
    border-radius: 4px;
    font-size: 12px;
    color: var(--primary);
}

/* ──────────────────────── HEALTH STATUS ──────────────────────── */
.health-status {
    display: grid;
    gap: 12px;
}

.health-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.health-item-name {
    font-weight: 600;
}

.health-item-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.health-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--secondary);
}

.health-dot.ok {
    background: var(--success);
}

.health-dot.error {
    background: var(--danger);
}

.health-dot.warning {
    background: var(--warning);
}

.health-group-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted, #888);
    padding: 0.75rem 0 0.25rem;
    border-bottom: 1px solid var(--border, #333);
    margin-bottom: 0.25rem;
}
.health-group-label:first-child { padding-top: 0; }

/* ──────────────────────── RESPONSE PANEL ──────────────────────── */
.response-panel {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 350px;
    max-height: 600px;
    width: 100%;
}

.response-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.response-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.response-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    font-size: 12px;
    font-family: 'Monaco', 'Courier New', monospace;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.response-block {
    background: rgba(0, 0, 0, 0.25);
    padding: 12px;
    border-radius: 6px;
    border: 1px solid var(--border);
    max-width: 100%;
    word-break: break-word;
}

.response-block.success {
    border-color: rgba(16, 185, 129, 0.4);
}

.response-block.error {
    border-color: rgba(239, 68, 68, 0.4);
}

.response-header-text {
    font-weight: 700;
    margin-bottom: 10px;
}

.response-body {
    overflow-x: auto;
}

.response-text {
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.response-json {
    display: grid;
    gap: 8px;
}

.kv {
    display: grid;
    grid-template-columns: minmax(120px, 200px) 1fr;
    gap: 10px;
    align-items: start;
    padding: 6px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

.key {
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: none;
}

.value {
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

.value-scalar {
    color: var(--text-primary);
}

.response-list {
    display: grid;
    gap: 8px;
}

.response-list-item {
    padding: 8px;
    border: 1px dashed rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    overflow-wrap: anywhere;
}

.response-list-index {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.response-empty {
    color: var(--text-secondary);
    font-style: italic;
}

.placeholder {
    color: var(--text-secondary);
    text-align: center;
    padding: 24px;
}

.loading {
    color: var(--text-secondary);
}

.error-text {
    color: var(--danger);
}

.success-text {
    color: var(--success);
}

/* ──────────────────────── RESPONSIVE ──────────────────────── */
@media (max-width: 1400px) {
    .dashboard-container {
        grid-template-columns: 280px 1fr;
    }
}

@media (max-width: 1024px) {
    .dashboard-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
    }

    .response-panel {
        display: none;
    }

    .main-content {
        padding: 16px;
    }
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--secondary);
}
