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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(135deg, #f0f4f8 0%, #e2e8f0 100%);
    color: #1e293b;
    min-height: 100vh;
}

.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

/* Login */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e293b 0%, #334155 50%, #1e293b 100%);
}

.login-box {
    background: #fff;
    padding: 3rem;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 420px;
}

.login-logo {
    display: block;
    margin: 0 auto 2rem;
    max-width: 200px;
    height: auto;
}

.login-box h1 {
    margin-bottom: 1.75rem;
    font-size: 1.4rem;
    text-align: center;
    color: #475569;
    font-weight: 500;
}

.login-box input {
    width: 100%;
    padding: 0.9rem 1.1rem;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    font-size: 1rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f8fafc;
}

.login-box input:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    background: #fff;
}

.login-box button {
    width: 100%;
    padding: 0.9rem;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.login-box button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.4);
}

.login-box button:active {
    transform: translateY(0);
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-logo {
    height: 40px;
    width: auto;
}

header h1 {
    font-size: 1.4rem;
    color: #1e293b;
    font-weight: 600;
}

header .nav-links a {
    margin-left: 1rem;
    color: #3b82f6;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: color 0.2s;
}

header .nav-links a:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.logout-btn {
    background: #fff;
    border: 1px solid #e2e8f0;
    padding: 0.5rem 1rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.logout-btn:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #475569;
}

/* Search */
.search-section {
    margin-bottom: 2rem;
}

.search-hint {
    font-size: 0.78rem;
    color: #94a3b8;
    margin-top: 0.5rem;
    text-align: left;
}

.search-bar {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

.search-bar textarea {
    flex: 1;
    padding: 1rem 1.2rem;
    border: 2px solid #e2e8f0;
    border-radius: 16px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: vertical;
    min-height: 80px;
    line-height: 1.5;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.search-bar textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12), 0 2px 8px rgba(0, 0, 0, 0.04);
}

.search-bar textarea::placeholder {
    color: #94a3b8;
}

.search-bar button {
    padding: 1rem 2rem;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: none;
    border-radius: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
    min-height: 52px;
}

.search-bar button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}

.search-bar button:active {
    transform: translateY(0);
}

.search-bar button:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Answer */
.answer-section {
    background: #fff;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    display: none;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.answer-section.visible {
    display: block;
    animation: fadeIn 0.3s ease-out;
}

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

.answer-section h2 {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.answer-text {
    line-height: 1.8;
    white-space: pre-wrap;
    margin-bottom: 1.5rem;
    color: #334155;
    font-size: 1.05rem;
}

.md-h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: #1e293b;
    display: block;
}

.md-h2 {
    font-size: 1.2rem;
    font-weight: 700;
    color: #1e293b;
    display: block;
}

.md-h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: #334155;
    display: block;
}

.inline-source {
    font-size: 0.75rem;
    color: #94a3b8;
    font-style: italic;
    font-weight: 400;
}

.sources {
    border-top: 1px solid #f1f5f9;
    padding-top: 1.25rem;
}

.sources h3 {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-bottom: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.source-tag {
    display: inline-block;
    background: none;
    color: #94a3b8;
    padding: 0.15rem 0;
    border-radius: 0;
    font-size: 0.75rem;
    margin: 0.15rem 0.5rem 0.15rem 0;
    font-weight: 400;
    font-style: italic;
    border: none;
}

.loading {
    text-align: center;
    padding: 2.5rem;
    color: #64748b;
    font-size: 1rem;
}

.spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 3px solid #e2e8f0;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 0.6rem;
    vertical-align: middle;
}

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

.error-msg {
    color: #dc2626;
    background: #fef2f2;
    padding: 0.85rem 1.1rem;
    border-radius: 12px;
    margin-top: 1rem;
    border: 1px solid rgba(220, 38, 38, 0.1);
    font-size: 0.95rem;
}

.time-info {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 0.75rem;
}

/* Admin */
.upload-section {
    background: #fff;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    margin-bottom: 2rem;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.upload-section h2 {
    margin-bottom: 1.25rem;
    font-size: 1.1rem;
    color: #1e293b;
    font-weight: 600;
}

.upload-form {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.upload-form input[type="file"] {
    flex: 1;
    min-width: 200px;
    font-size: 0.9rem;
}

.upload-form button {
    padding: 0.7rem 1.4rem;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 3px 10px rgba(37, 99, 235, 0.25);
}

.upload-form button:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 16px rgba(37, 99, 235, 0.35);
}

.upload-form button:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.doc-list {
    background: #fff;
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.doc-list h2 {
    margin-bottom: 1.25rem;
    font-size: 1.1rem;
    color: #1e293b;
    font-weight: 600;
}

.doc-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid #f1f5f9;
}

.doc-item:last-child {
    border-bottom: none;
}

.doc-info .doc-name {
    font-weight: 600;
    color: #1e293b;
}

.doc-info .doc-meta {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 0.3rem;
}

.delete-btn {
    background: #fff;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 0.4rem 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s;
}

.delete-btn:hover {
    background: #fef2f2;
    border-color: #fca5a5;
}

.status-msg {
    margin-top: 1rem;
    padding: 0.6rem 0.9rem;
    border-radius: 10px;
    font-size: 0.9rem;
}

.status-msg.success {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid rgba(22, 163, 74, 0.1);
}

.status-msg.error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid rgba(220, 38, 38, 0.1);
}

.empty-state {
    text-align: center;
    color: #94a3b8;
    padding: 2.5rem;
    font-size: 0.95rem;
}

/* Responsive */
@media (max-width: 640px) {
    .container {
        padding: 1.25rem 1rem;
    }

    .login-box {
        padding: 2rem 1.5rem;
        margin: 0 1rem;
    }

    .search-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-bar button {
        width: 100%;
    }

    .answer-section, .upload-section, .doc-list {
        padding: 1.5rem;
        border-radius: 16px;
    }

    header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }
}
