:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --background: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --radius: 0.75rem;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: 0.95rem;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 24px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Screen Management */
.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.screen.hidden {
    display: none;
}

/* Login Card */
.login-card {
    max-width: 420px;
    margin: auto;
    background: var(--surface);
    padding: 40px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
    border: 1px solid var(--border);
}

.login-card h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-main);
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

.login-fields {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.login-fields input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: all 0.2s;
}

.login-fields input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Navigation & Layout */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 32px;
    border: 1px solid var(--border);
}

.brand {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--primary);
    letter-spacing: -0.02em;
}

.page-nav {
    display: flex;
    gap: 8px;
    background: var(--background);
    padding: 4px;
    border-radius: 99px;
}

.nav-link {
    text-decoration: none;
    color: var(--text-muted);
    padding: 8px 20px;
    border-radius: 99px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.nav-link:hover {
    color: var(--text-main);
}

.nav-link.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    font-weight: 600;
}

/* Sections */
section {
    background: var(--surface);
    padding: 32px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    flex: 1;
}

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

h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

/* Buttons */
button {
    cursor: pointer;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    transition: all 0.2s;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button.primary {
    background: var(--primary);
    color: white;
}

button.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

button.secondary {
    background: var(--background);
    color: var(--text-main);
    border: 1px solid var(--border);
}

button.secondary:hover {
    background: #f1f5f9;
}

button.danger {
    background: #fee2e2;
    color: var(--danger);
}

button.danger:hover {
    background: #fecaca;
}

button.ghost {
    background: transparent;
    color: var(--text-muted);
}

button.ghost:hover {
    background: var(--background);
    color: var(--text-main);
}

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

/* Query Section */
.query-controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

textarea {
    width: 100%;
    min-height: 140px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    resize: vertical;
    font-size: 1rem;
    line-height: 1.6;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

#query-result {
    margin-top: 32px;
    padding: 0;
}

#query-result .answer {
    padding: 24px;
    background: #f8fafc;
    border-radius: 12px;
    line-height: 1.8;
    color: var(--text-main);
    border: 1px solid var(--border);
    white-space: pre-wrap;
}

.citations {
    margin-top: 16px;
    padding: 16px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--border);
    font-size: 0.9rem;
}

.citations strong {
    display: block;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.citations ul {
    list-style: none;
    padding: 0;
}

.citations li {
    padding: 4px 0;
    color: var(--primary);
}

/* File Management */
.upload-area {
    background: #f8fafc;
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 32px;
    text-align: center;
    margin-bottom: 32px;
}

.upload-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
}

input[type="file"] {
    background: white;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
}

/* Table */
.files-table {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.files-header {
    display: grid;
    grid-template-columns: 60px 2fr 1fr 1fr 140px;
    padding: 14px 20px;
    background: #f1f5f9;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.files-body {
    background: white;
}

.file-row {
    display: grid;
    grid-template-columns: 60px 2fr 1fr 1fr 140px;
    padding: 16px 20px;
    align-items: center;
    border-top: 1px solid var(--border);
    transition: background 0.1s;
}

.file-row:hover {
    background: #f8fafc;
}

.col-select { display: flex; justify-content: center; }
.col-select input { width: 18px; height: 18px; cursor: pointer; }

.col-name { font-weight: 500; color: var(--text-main); }
.col-date { color: var(--text-muted); font-size: 0.9rem; }

/* Status Badges */
.status-badge {
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-ready { background: #dcfce7; color: #166534; }
.status-indexing { background: #fef3c7; color: #92400e; }
.status-uploaded { background: #f1f5f9; color: #475569; }
.status-failed { background: #fee2e2; color: #991b1b; }
.status-disabled { background: #f1f5f9; color: #94a3b8; text-decoration: line-through; }

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid #e2e8f0;
    border-top-color: var(--primary);
    border-radius: 50%;
    display: inline-block;
    animation: spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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

/* Mobile */
@media (max-width: 768px) {
    .container { padding: 16px; }
    .topbar { flex-direction: column; gap: 16px; align-items: stretch; text-align: center; }
    .page-nav { justify-content: center; }
    .files-header { display: none; }
    .file-row {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 20px;
    }
    .col-select { justify-content: flex-start; margin-bottom: 8px; }
    .col-actions { justify-content: flex-start; margin-top: 12px; }
}
