/* ═══════════════════════════════════════════════════════
   Brain Archive — Design System
   Dark mode, glassmorphism, premium aesthetics
   ═══════════════════════════════════════════════════════ */

/* ── CSS Custom Properties ────────────────────────────── */
:root {
    --bg-deep: #0a0a1a;
    --bg-surface: rgba(255, 255, 255, 0.04);
    --bg-surface-hover: rgba(255, 255, 255, 0.08);
    --bg-glass: rgba(255, 255, 255, 0.06);

    --primary: #7c3aed;
    --primary-light: #a78bfa;
    --primary-glow: rgba(124, 58, 237, 0.4);
    --secondary: #06b6d4;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.15);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px var(--primary-glow);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset & Base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    background: var(--bg-deep);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Gradient background overlay */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 0%, rgba(124, 58, 237, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(6, 182, 212, 0.06) 0%, transparent 60%);
    pointer-events: none;
    z-index: 0;
}

/* Custom scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(124, 58, 237, 0.3);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(124, 58, 237, 0.5); }

/* ── Navigation ───────────────────────────────────────── */
.nav-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(10, 10, 26, 0.8);
    backdrop-filter: blur(24px);
    border-bottom: 1px solid var(--border);
}

.nav-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.nav-logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.nav-tabs { display: flex; gap: 4px; }

.nav-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all var(--transition);
    position: relative;
}

.nav-tab:hover {
    color: var(--text-primary);
    background: var(--bg-surface-hover);
}

.nav-tab.active {
    color: var(--primary-light);
    background: rgba(124, 58, 237, 0.1);
}

.nav-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 16px;
    right: 16px;
    height: 2px;
    background: var(--primary);
    border-radius: 1px;
    box-shadow: 0 0 8px var(--primary-glow);
}

.nav-icon { font-size: 1rem; }

/* ── Container ────────────────────────────────────────── */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px;
    position: relative;
    z-index: 1;
}

/* ── Views ─────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.4s ease; }

.view-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text-primary);
}

/* ── Search Hero ──────────────────────────────────────── */
.search-hero {
    text-align: center;
    padding: 48px 0 40px;
}

.search-title {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--primary-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.search-subtitle {
    color: var(--text-secondary);
    font-size: 1rem;
    margin-bottom: 32px;
}

.search-box {
    position: relative;
    max-width: 640px;
    margin: 0 auto;
}

.search-icon {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.2rem;
    z-index: 2;
}

.search-input {
    width: 100%;
    padding: 18px 24px 18px 52px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    color: var(--text-primary);
    font-size: 1.05rem;
    font-family: var(--font);
    outline: none;
    transition: all var(--transition);
    backdrop-filter: blur(12px);
}

.search-input::placeholder { color: var(--text-muted); }

.search-input:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-glow);
    background: rgba(255, 255, 255, 0.08);
}

/* ── Cards ─────────────────────────────────────────────── */
.card {
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition);
    cursor: pointer;
}

.card:hover {
    transform: translateY(-4px);
    border-color: var(--border-hover);
    box-shadow: var(--shadow-md);
    background: var(--bg-surface-hover);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.card-type-icon { font-size: 1.4rem; }

.card-meta {
    flex: 1;
    min-width: 0;
}

.card-source {
    font-size: 0.8rem;
    color: var(--secondary);
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    max-width: 400px;
}

.card-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.card-body { margin-bottom: 12px; }

.card-content {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-summary {
    font-size: 0.85rem;
    color: var(--text-primary);
    background: rgba(124, 58, 237, 0.06);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--primary);
    margin-top: 8px;
}

.card-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ── Card List & Grid ─────────────────────────────────── */
.card-list { display: flex; flex-direction: column; gap: 12px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

/* ── Badges ────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.badge-completed {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.25);
}

.badge-failed {
    background: rgba(239, 68, 68, 0.15);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.25);
}

.badge-pending {
    background: rgba(6, 182, 212, 0.15);
    color: var(--secondary);
    border: 1px solid rgba(6, 182, 212, 0.25);
}

.badge-topic {
    background: transparent;
    color: var(--primary-light);
    border: 1px solid rgba(124, 58, 237, 0.3);
    cursor: pointer;
    transition: all var(--transition);
}

.badge-topic:hover {
    background: rgba(124, 58, 237, 0.15);
    border-color: var(--primary);
}

.fallback-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 500;
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

/* ── Chunk cards ──────────────────────────────────────── */
.chunk-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.chunk-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ── Detail View ──────────────────────────────────────── */
.detail-header {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 24px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.detail-icon { font-size: 2rem; }

.detail-title {
    font-size: 1.4rem;
    font-weight: 600;
    word-break: break-word;
}

.detail-badges {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.detail-section {
    margin-bottom: 24px;
}

.detail-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.detail-raw-content {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    font-size: 0.9rem;
    line-height: 1.8;
    color: var(--text-secondary);
    max-height: 300px;
    overflow: hidden;
    position: relative;
    white-space: pre-wrap;
    word-break: break-word;
    transition: max-height 0.4s ease;
}

.detail-raw-content.expanded { max-height: none; }

.detail-raw-content .show-more-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 80px;
    background: linear-gradient(transparent, var(--bg-deep));
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 8px;
}

.warning-banner {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: var(--radius-md);
    padding: 14px 18px;
    font-size: 0.85rem;
    color: var(--warning);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.claim-item {
    padding: 12px 16px;
    background: var(--bg-surface);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-primary);
    border-left: 3px solid var(--secondary);
}

/* ── Buttons ──────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
}

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

.btn-ghost:hover { color: var(--text-primary); }

.btn-small {
    padding: 4px 12px;
    font-size: 0.8rem;
}

/* ── Skeletons ────────────────────────────────────────── */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-surface) 25%,
        rgba(255, 255, 255, 0.08) 50%,
        var(--bg-surface) 75%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
    width: 80%;
}

.skeleton-text:nth-child(2) { width: 60%; }
.skeleton-text:nth-child(3) { width: 40%; }

/* ── Empty States ─────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state-text {
    font-size: 1rem;
    color: var(--text-secondary);
}

/* ── Loader ───────────────────────────────────────────── */
.loader-container {
    text-align: center;
    padding: 24px;
}

/* ── Animations ───────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 0 20px rgba(124, 58, 237, 0.2); }
    50%      { box-shadow: 0 0 40px rgba(124, 58, 237, 0.4); }
}

.fade-in {
    animation: fadeIn 0.5s ease forwards;
    opacity: 0;
}

/* Staggered delays */
.fade-in:nth-child(1)  { animation-delay: 0.00s; }
.fade-in:nth-child(2)  { animation-delay: 0.05s; }
.fade-in:nth-child(3)  { animation-delay: 0.10s; }
.fade-in:nth-child(4)  { animation-delay: 0.15s; }
.fade-in:nth-child(5)  { animation-delay: 0.20s; }
.fade-in:nth-child(6)  { animation-delay: 0.25s; }
.fade-in:nth-child(7)  { animation-delay: 0.30s; }
.fade-in:nth-child(8)  { animation-delay: 0.35s; }
.fade-in:nth-child(9)  { animation-delay: 0.40s; }
.fade-in:nth-child(10) { animation-delay: 0.45s; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 768px) {
    .nav-inner { padding: 0 16px; }
    .nav-logo { font-size: 1rem; }
    .nav-tab span:not(.nav-icon) { display: none; }
    .nav-tab { padding: 8px 12px; }

    .container { padding: 16px; }

    .search-hero { padding: 32px 0 24px; }
    .search-title { font-size: 1.5rem; }
    .search-input { padding: 14px 20px 14px 44px; font-size: 0.95rem; }

    .card-grid { grid-template-columns: 1fr; }
    .card { padding: 16px; }

    .detail-header { flex-direction: column; gap: 12px; }
}

@media (max-width: 480px) {
    .nav-tabs { gap: 2px; }
    .search-title { font-size: 1.3rem; }
    .search-subtitle { font-size: 0.85rem; }
}
