/* ═══════════════════════════════════════════
   Shakarim AI Research Intelligence | v2.0
   Compact layout · Light color scheme
   ═══════════════════════════════════════════ */

:root {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;

    --bg: #F0F4F8; /* Softer, slightly cooler background */
    --surface: #ffffff;
    --surface-hover: #F8FAFC;
    --surface-active: #F1F5F9;
    --border: rgba(15, 23, 42, 0.04); /* Almost invisible borders */
    --border-strong: rgba(15, 23, 42, 0.08);

    --text: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    --accent: #1D4ED8;
    --accent-soft: #EFF6FF;
    --accent-strong: #1E40AF;
    --accent-glow: rgba(29, 78, 216, 0.15);
    --accent-main: var(--accent);
    --muted: var(--text-muted);

    --green: #10B981;
    --green-soft: #ECFDF5;
    --orange: #F59E0B;
    --orange-soft: #FFFBEB;
    --purple: #8B5CF6;
    --purple-soft: #F5F3FF;
    --red: #EF4444;
    --red-soft: #FEF2F2;
    --teal: #14B8A6;
    --teal-soft: #F0FDFA;

    --radius: 24px; /* Highly rounded cards */
    --radius-sm: 16px;
    --radius-xs: 12px;
    --radius-full: 9999px;

    --shadow: 0 4px 20px rgba(0, 0, 0, 0.03); /* Soft shadows */
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.08);

    --header-h: 72px; /* Taller header */
    --spacing: 24px;
    --spacing-sm: 16px;
    --spacing-xs: 8px;
}

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

html, body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { cursor: pointer; font: inherit; }
input, textarea, select { font: inherit; color: var(--text); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(15,23,42,0.12); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: rgba(15,23,42,0.2); }

/* ═══════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════ */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    padding: 0 var(--spacing);
    background: transparent;
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 12px;
    margin-bottom: 12px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.brand-logo {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    object-fit: contain;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.brand-name {
    font-size: 16px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.brand-name span {
    color: var(--text-muted);
    font-weight: 500;
}

/* ── Navigation ── */
.app-nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
    overflow-x: auto;
    padding: 0 8px;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.app-nav::-webkit-scrollbar { display: none; }

.app-nav .nav-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
    transition: all 0.2s ease;
}

.app-nav .nav-item i, .app-nav .nav-item svg {
    width: 16px;
    height: 16px;
    stroke-width: 2.5;
}

.app-nav .nav-item:hover {
    color: var(--text);
    background: rgba(0,0,0,0.03);
}

.app-nav .nav-item.active {
    color: #fff;
    background: var(--accent);
    box-shadow: 0 4px 12px var(--accent-glow);
}

/* ── Header Actions ── */
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 16px;
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    border: none;
    box-shadow: var(--shadow);
    transition: all 0.2s ease;
    white-space: nowrap;
}

.header-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    color: var(--text);
}

.header-btn.primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.header-btn.primary:hover {
    background: var(--accent-strong);
}

.header-btn i, .header-btn svg {
    width: 16px;
    height: 16px;
}

/* ═══════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════ */

.app-main {
    max-width: 1440px;
    margin: 0 auto;
    padding: var(--spacing);
    display: grid;
    gap: var(--spacing);
}

/* ── Section Header ── */
.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 0 24px 0;
    margin-bottom: 0;
}

.section-tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.section-head h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
    color: var(--text);
}

.section-head p {
    font-size: 14px;
    color: var(--text-muted);
    margin-top: 6px;
    font-weight: 500;
}

.section-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* ── Section content (animated) ── */
.app-section {
    display: none;
    animation: sectionIn 0.25s ease-out;
}

.app-section.active {
    display: block;
}

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

/* ═══════════════════════════════════════════
   BUTTONS
   ═══════════════════════════════════════════ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border-radius: var(--radius-xs);
    font-size: 12.5px;
    font-weight: 600;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-secondary);
    transition: all 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
    color: var(--text);
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--accent);
    border-color: transparent;
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-strong);
    color: #fff;
}

.btn-ghost {
    border-color: transparent;
    background: transparent;
}

.btn-ghost:hover {
    background: var(--surface-hover);
}

.btn i, .btn svg {
    width: 14px;
    height: 14px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ═══════════════════════════════════════════
   STATS GRID
   ═══════════════════════════════════════════ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
}

.stat-card {
    background: var(--surface);
    border: none;
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    position: relative;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

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

.stat-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.stat-icon i {
    width: 20px;
    height: 20px;
    color: #fff;
}

.stat-icon.blue { background: var(--accent); }
.stat-icon.green { background: var(--green); }
.stat-icon.orange { background: var(--orange); }
.stat-icon.purple { background: var(--purple); }

.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.03em;
    line-height: 1;
    margin-bottom: 8px;
}

.stat-trend {
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-trend.up { color: var(--green); }
.stat-trend.down { color: var(--red); }
.stat-trend span { color: var(--text-muted); font-weight: 500; }

/* ═══════════════════════════════════════════
   PANELS
   ═══════════════════════════════════════════ */

.panels-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: 24px;
}

.panel {
    background: var(--surface);
    border: none;
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.panel-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

/* ── Timeline Chart ── */
.timeline-chart {
    min-height: 200px;
}

/* ═══════════════════════════════════════════
   DATABASE
   ═══════════════════════════════════════════ */

.db-controls {
    display: flex;
    gap: var(--spacing-xs);
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.db-tabs {
    display: flex;
    gap: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 3px;
}

.db-tab {
    padding: 6px 12px;
    border-radius: 5px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.db-tab:hover { color: var(--text-secondary); }
.db-tab.active {
    background: var(--surface);
    color: var(--accent-strong);
    box-shadow: var(--shadow);
}

.db-search {
    flex: 1;
    min-width: 200px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease;
}

.db-search:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

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

/* ── Table ── */
.db-table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: auto;
    box-shadow: var(--shadow);
}

.db-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.db-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
}

.db-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.db-table tr:last-child td { border-bottom: none; }
.db-table tbody tr { transition: background 0.1s ease; }
.db-table tbody tr:hover { background: var(--bg); }

.cell-title {
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 360px;
}

.cell-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 360px;
}

.cell-author {
    font-weight: 500;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 180px;
}

.cell-dept {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.type-badge.badge-purple { background: var(--purple-soft); color: var(--purple); }
.type-badge.badge-teal { background: var(--teal-soft); color: var(--teal); }
.type-badge.badge-green { background: var(--green-soft); color: var(--green); }
.type-badge.badge-orange { background: var(--orange-soft); color: var(--orange); }

/* ── Sync Source Buttons ── */
.sync-source {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 26px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    transition: all 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
}

.sync-source:hover {
    border-color: var(--border-strong);
    color: var(--text-secondary);
    background: var(--surface-hover);
}

/* ═══════════════════════════════════════════
   TRENDS
   ═══════════════════════════════════════════ */

.trends-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.trend-block {
    background: var(--surface);
    border: none;
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.trend-block h3 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 20px;
    letter-spacing: -0.01em;
}

.trend-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 12px;
}

.trend-list li {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.trend-list li:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(0,0,0,0.03);
    transform: translateX(4px);
}

.rank {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--orange);
    color: #fff;
    font-weight: 800;
    font-size: 14px;
    flex-shrink: 0;
}

.trend-list li:nth-child(n+4) .rank {
    background: var(--surface-active);
    color: var(--text-muted);
}

.trend-list li strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
}

.trend-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

/* ── AI Trends form ── */
.ai-form {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.ai-form input {
    flex: 1;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease;
}

.ai-form input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* ── Topic Evolution ── */
.topic-evolution { min-height: 200px; }
.topic-evolution-card {
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
}
.topic-evolution-card h4 { margin: 0 0 8px; font-size: 13px; font-weight: 600; }
.topic-bar-row {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 8px;
    align-items: center;
    padding: 4px 0;
    font-size: 12px;
}
.topic-bar-track {
    display: grid;
    align-items: center;
    background: var(--accent-soft);
    border-radius: 999px;
    height: 10px;
    position: relative;
}
.topic-bar { height: 100%; background: var(--accent); border-radius: 999px; }
.topic-bar-track strong { font-size: 10px; color: var(--text-muted); position: absolute; right: 6px; }

/* ── Heatmap ── */
#topic-heatmap { min-height: 200px; }
.heatmap-row {
    display: grid;
    gap: 4px;
    align-items: center;
    margin-bottom: 4px;
    font-size: 12px;
}
.heatmap-header { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.heatmap-cell { min-height: 28px; border-radius: var(--radius-xs); display: grid; place-items: center; font-size: 11px; font-weight: 600; color: #fff; padding: 0 4px; }
.heatmap-header-cell { background: transparent; color: var(--text-muted); font-weight: 500; }

/* ── Profiles & Matches ── */
.profile-grid, .match-grid { display: grid; gap: 8px; }
.profile-card, .match-card {
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: grid;
    gap: 6px;
}
.profile-card h4, .match-card h4 { margin: 0; font-size: 13px; }
.profile-meta { font-size: 11px; color: var(--text-muted); }
.kw-list { display: flex; flex-wrap: wrap; gap: 4px; }
.kw-list span {
    background: var(--accent-soft);
    color: var(--accent-strong);
    padding: 3px 8px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 500;
}
.suggestions { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ═══════════════════════════════════════════
   GRAPH
   ═══════════════════════════════════════════ */

.graph-shell {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    min-height: 400px;
    margin-top: var(--spacing-sm);
    box-shadow: var(--shadow);
}

.graph-shell svg {
    width: 100%;
    height: 100%;
    min-height: 400px;
    display: block;
}

.graph-empty {
    position: absolute;
    inset: 0;
    display: none;
    place-items: center;
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
}

.graph-tooltip {
    position: fixed;
    pointer-events: none;
    background: var(--text);
    border: 1px solid var(--border-strong);
    color: #fff;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    display: none;
    z-index: 200;
    line-height: 1.4;
    max-width: 280px;
}

/* ── Citation Legend ── */
.citation-legend {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-muted);
    flex-wrap: wrap;
    padding: 8px 0;
}

.citation-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ═══════════════════════════════════════════
   CLUSTERS
   ═══════════════════════════════════════════ */

.cluster-shell {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.clusters-chart { min-height: 350px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
#clusters-svg { width: 100%; height: 100%; }

.cluster-list {
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-y: auto;
    max-height: 450px;
    box-shadow: var(--shadow);
}

.cluster-card {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 4px;
}

.cluster-card:last-child { border-bottom: none; }
.cluster-card h4 { margin: 0; font-size: 13px; }
.cluster-kws { color: var(--text-muted); font-size: 11px; }
.cluster-count { font-size: 11px; color: var(--accent-strong); font-weight: 600; }

.loader-bar {
    display: none;
    text-align: center;
    padding: 16px;
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 500;
}

/* ═══════════════════════════════════════════
   RESEARCHERS
   ═══════════════════════════════════════════ */

.researchers-layout {
    display: grid;
    grid-template-columns: 1.4fr 0.8fr;
    gap: var(--spacing-sm);
    align-items: start;
    margin-top: var(--spacing-sm);
}

.researchers-grid { display: grid; gap: 8px; }

.researcher-card {
    padding: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    display: grid;
    gap: 4px;
    box-shadow: var(--shadow);
}

.researcher-card:hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.researcher-avatar {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: var(--accent-soft);
    color: var(--accent-strong);
    border-radius: var(--radius-xs);
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 2px;
}

.researcher-card h4 { margin: 0; font-size: 13px; }
.researcher-badge { font-size: 11px; color: var(--text-muted); }

.researcher-detail {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: grid;
    gap: 12px;
    position: sticky;
    top: calc(var(--header-h) + var(--spacing));
    box-shadow: var(--shadow);
}

.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.detail-stat {
    background: var(--bg);
    border-radius: var(--radius-sm);
    padding: 10px;
    text-align: center;
}
.detail-stat h4 { margin: 0; font-size: 18px; color: var(--accent-strong); }
.detail-stat p { margin: 0; font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.detail-kws { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-kws span { padding: 4px 8px; background: var(--accent-soft); border-radius: var(--radius-full); font-size: 11px; font-weight: 500; color: var(--accent-strong); }
.detail-papers { display: grid; gap: 6px; }
.detail-papers h4 { margin: 0; font-size: 12px; color: var(--text-muted); }
.detail-paper-item { padding: 4px 0; font-size: 12px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.detail-paper-item:last-child { border-bottom: none; }

/* ═══════════════════════════════════════════
   FUNDING
   ═══════════════════════════════════════════ */

.funding-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.funding-card {
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: grid;
    gap: 8px;
    transition: border-color 0.15s ease, background 0.15s ease;
    box-shadow: var(--shadow);
}

.funding-card:hover {
    border-color: var(--border-strong);
    background: var(--surface-hover);
}

.funding-card h4 { margin: 0; font-size: 13px; font-weight: 600; }

.funding-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    width: fit-content;
}

.funding-badge.nsf { background: var(--accent-soft); color: var(--accent-strong); }
.funding-badge.cordis { background: var(--purple-soft); color: var(--purple); }

.funding-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 11px;
    color: var(--text-muted);
}

.funding-meta span {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

/* ═══════════════════════════════════════════
   GAP ANALYSIS
   ═══════════════════════════════════════════ */

.gap-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-sm);
    margin-top: var(--spacing-sm);
}

.gap-grid h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.gap-list {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    min-height: 180px;
    box-shadow: var(--shadow);
}

.gap-list > div {
    padding: 6px 8px;
    margin-bottom: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    transition: border-color 0.15s ease;
}

.gap-list > div:hover { border-color: var(--border-strong); }

.gap-kw-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.gap-item {
    border-left: 2px solid var(--accent);
}

.gap-report {
    margin-top: var(--spacing-sm);
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* ═══════════════════════════════════════════
   MODAL
   ═══════════════════════════════════════════ */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 300;
    backdrop-filter: blur(4px);
}

.modal.show { display: flex; }

.modal-content {
    width: min(500px, 100%);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 24px;
    position: relative;
    box-shadow: var(--shadow-lg);
}

.modal-content h3 { margin: 0 0 4px; font-size: 16px; }
.modal-content form { display: grid; gap: 12px; margin-top: 12px; }
.modal-close {
    position: absolute;
    right: 16px;
    top: 16px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: color 0.15s ease;
}

.modal-close:hover { color: var(--text); }

.upload-drop {
    display: grid;
    gap: 8px;
    padding: 20px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    text-align: center;
    cursor: pointer;
    background: var(--bg);
    min-height: 100px;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    color: var(--text-muted);
    transition: border-color 0.15s ease, background 0.15s ease;
}

.upload-drop:hover { border-color: var(--accent); background: var(--accent-soft); }

.modal-content input[type="text"] {
    width: 100%;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
}

.modal-content input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

/* ═══════════════════════════════════════════
   TOAST
   ═══════════════════════════════════════════ */

#toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: var(--text);
    border: 1px solid var(--border-strong);
    color: #fff;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    z-index: 400;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: none;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}

#toast.toast-success { border-left: 3px solid var(--green); }
#toast.toast-error { border-left: 3px solid var(--red); }
#toast.toast-warning { border-left: 3px solid var(--orange); }
#toast.toast-sync, #toast.toast-graph, #toast.toast-pdf { border-left: 3px solid var(--accent); }

/* ═══════════════════════════════════════════
   ANIMATIONS
   ═══════════════════════════════════════════ */

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

.spinning {
    animation: spin 0.8s linear infinite;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--accent-soft);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ═══════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════ */

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .trends-grid { grid-template-columns: 1fr; }
    .funding-grid { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
    .panels-grid { grid-template-columns: 1fr; }
    .cluster-shell { grid-template-columns: 1fr; }
    .researchers-layout { grid-template-columns: 1fr; }
    .gap-grid { grid-template-columns: 1fr; }
    .app-header { padding: 0 var(--spacing-sm); }
    .brand-name { display: none; }
    .app-nav { justify-content: flex-start; }
    .header-btn .btn-label { display: none; }
}

@media (max-width: 720px) {
    .app-main { padding: var(--spacing-sm); }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: var(--spacing-xs); }
    .stat-card { padding: 12px; }
    .stat-value { font-size: 22px; }
    .db-controls { flex-direction: column; align-items: stretch; }
    .db-search { min-width: 0; }
    .section-head { flex-direction: column; align-items: flex-start; }
    .section-head-actions { width: 100%; }
    .section-head-actions .btn { flex: 1; }
    .researcher-detail { position: static; }
    .detail-grid { grid-template-columns: 1fr; }
    .graph-shell { min-height: 300px; }
    .graph-shell svg { min-height: 300px; }
}

/* ═══════════════════════════════════════════
   RAG CHAT (Conversation UI)
   ═══════════════════════════════════════════ */

.chat-shell {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: 400px;
    max-height: 600px;
}

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

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 14px;
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-actions button {
    background: none;
    border: none;
    padding: 6px;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 12px;
}

.chat-header-actions button:hover {
    background: var(--surface);
    color: var(--text);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-welcome {
    display: grid;
    place-items: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.chat-welcome h3 {
    margin: 0 0 8px;
    font-size: 16px;
    color: var(--text);
}

.chat-welcome p {
    font-size: 13px;
    max-width: 360px;
    line-height: 1.6;
}

.chat-message {
    display: flex;
    gap: 10px;
    animation: msgIn 0.2s ease-out;
}

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

.chat-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-xs);
    display: grid;
    place-items: center;
    font-size: 16px;
    flex-shrink: 0;
    background: var(--bg);
}

.chat-user .chat-avatar {
    background: var(--accent-soft);
}

.chat-bubble {
    flex: 1;
    min-width: 0;
}

.chat-content {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text);
}

.chat-content p {
    margin: 0 0 8px;
}

.chat-content p:last-child {
    margin-bottom: 0;
}

.chat-content h3, .chat-content h4 {
    margin: 12px 0 6px;
    font-size: 14px;
}

.chat-content ul {
    margin: 6px 0;
    padding-left: 20px;
}

.chat-content li {
    margin-bottom: 4px;
}

.chat-user .chat-content {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-assistant .chat-content {
    background: var(--bg);
    border-bottom-left-radius: 4px;
}

.chat-content.streaming {
    border-right: 2px solid var(--accent);
}

.stream-cursor {
    display: inline-block;
    animation: blink 0.8s step-end infinite;
    color: var(--accent);
    font-weight: 300;
    margin-left: 2px;
}

@keyframes blink {
    50% { opacity: 0; }
}

.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}

#stream-input {
    flex: 1;
    height: 40px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s ease;
}

#stream-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-soft);
}

#stream-input::placeholder {
    color: var(--text-muted);
}

#stream-send-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-xs);
    border: none;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

#stream-send-btn:hover {
    background: var(--accent-strong);
}

#stream-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#stream-status {
    padding: 6px 16px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: none;
}

/* ── RAG Indicator ── */
.rag-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-full);
    font-size: 11px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.rag-indicator.rag-active {
    background: var(--green-soft);
    color: var(--green);
}

.rag-indicator.rag-inactive {
    background: var(--orange-soft);
    color: var(--orange);
}

.rag-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    display: inline-block;
}

.rag-dot.active {
    background: var(--green);
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
}

/* ── Chat Toggle Button ── */
#chat-toggle-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    box-shadow: 0 4px 20px var(--accent-glow);
    cursor: pointer;
    display: grid;
    place-items: center;
    z-index: 200;
    transition: all 0.2s ease;
}

#chat-toggle-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 24px var(--accent-glow);
}

#chat-toggle-btn svg {
    width: 24px;
    height: 24px;
}

/* ── Chat Floating Panel ── */
.floating-chat {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 420px;
    max-width: calc(100vw - 48px);
    max-height: 600px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    display: none;
    overflow: hidden;
    flex-direction: column;
}

.floating-chat.open {
    display: flex;
    animation: slideUp 0.2s ease-out;
}

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

.floating-chat .chat-shell {
    border: none;
    box-shadow: none;
    border-radius: 0;
    min-height: 400px;
    max-height: 550px;
}

/* ── Empty / Error states ── */
.empty-state {
    display: grid;
    place-items: center;
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
}

.empty-state i {
    width: 36px;
    height: 36px;
    margin-bottom: 8px;
    opacity: 0.3;
}

.empty-state strong {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state p {
    font-size: 12px;
    max-width: 280px;
}

/* ── Responsive Chat ── */
@media (max-width: 600px) {
    .floating-chat {
        right: 8px;
        bottom: 80px;
        width: calc(100vw - 16px);
        max-height: 70vh;
    }
}
