/* ============================================================
   AIxBio Explorer — dark scientific console
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&family=Inter:wght@400;450;500;600;700&display=swap');

:root {
  /* surfaces */
  --bg:        #070a0f;
  --bg-1:      #0b0f16;
  --panel:     #0e141d;
  --panel-2:   #121925;
  --raised:    #18212e;
  --line:      #1e2836;
  --line-2:    #2a3647;
  /* text */
  --ink:       #e8eef6;
  --ink-2:     #9fb0c3;
  --ink-3:     #61728a;
  --ink-4:     #44546a;
  /* accent */
  --teal:      #2dd4bf;
  --teal-dim:  #15917f;
  --teal-glow: rgba(45,212,191,.16);
  /* semantic flag colours (from legend) */
  --gold:      #f5c451;
  --red:       #ef4444;
  --green:     #4ade80;
  --amber:     #fbbf24;
  --violet:    #a78bfa;
  --blue:      #60a5fa;
  --pink:      #f472b6;

  --r-sm: 6px; --r: 10px; --r-lg: 14px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'Inter', system-ui, sans-serif;
  --display: 'Space Grotesk', var(--sans);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background:
    radial-gradient(1200px 700px at 78% -8%, rgba(45,212,191,.07), transparent 60%),
    radial-gradient(900px 600px at 0% 100%, rgba(96,165,250,.05), transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
#root { height: 100%; }

::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 6px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #38465a; background-clip: content-box; }

/* ---------- typography helpers ---------- */
.mono { font-family: var(--mono); }
.tnum { font-variant-numeric: tabular-nums; }
.eyebrow {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  letter-spacing: .18em; text-transform: uppercase; color: var(--ink-3);
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; letter-spacing: -.01em; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 0 22px; height: 58px; flex: none;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(18,25,37,.7), rgba(11,15,22,.5));
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: radial-gradient(120% 120% at 30% 20%, #1b3a37, #0b1714);
  border: 1px solid var(--teal-dim);
  display: grid; place-items: center;
  box-shadow: 0 0 0 1px rgba(45,212,191,.08), 0 0 18px var(--teal-glow);
}
.brand .name { font-family: var(--display); font-weight: 700; font-size: 15px; letter-spacing: -.01em; }
.brand .name b { color: var(--teal); font-weight: 700; }
.brand .sub { font-family: var(--mono); font-size: 10px; color: var(--ink-3); letter-spacing: .12em; text-transform: uppercase; }

.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  color: var(--ink-3); font-family: var(--mono); font-size: 12px; font-weight: 500;
  letter-spacing: .04em; padding: 8px 14px; border-radius: var(--r-sm);
  position: relative; transition: color .15s, background .15s;
  display: flex; align-items: center; gap: 8px;
}
.tab:hover { color: var(--ink-2); background: rgba(255,255,255,.025); }
.tab.active { color: var(--ink); background: var(--raised); }
.tab.active::after {
  content: ''; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px;
  background: var(--teal); border-radius: 2px; box-shadow: 0 0 10px var(--teal);
}
.tab .idx { font-size: 10px; color: var(--ink-4); }
.tab.active .idx { color: var(--teal); }

.topbar .spacer { flex: 1; }
.topbar .count-pill {
  font-family: var(--mono); font-size: 11px; color: var(--ink-2);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 5px 12px;
  display: flex; align-items: center; gap: 8px;
}
.topbar .count-pill b { color: var(--teal); }
.topbar .count-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 8px var(--teal); }

.view { flex: 1; min-height: 0; overflow: auto; }
.view-network { overflow: hidden; scrollbar-gutter: stable; }
.view-pad { padding: 22px; }

/* ---------- panels ---------- */
.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-1));
  border: 1px solid var(--line); border-radius: var(--r-lg);
}
.panel-h { display: flex; align-items: center; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.panel-h h3 { font-size: 13px; font-weight: 600; }
.panel-h .eyebrow { margin-left: auto; }

/* ============================================================
   PRIMITIVES
   ============================================================ */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px;
  border-radius: 999px; font-family: var(--mono); font-size: 11px; font-weight: 500;
  border: 1px solid var(--line-2); color: var(--ink-2); white-space: nowrap;
}
.chip .swatch { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip.flag { color: var(--gold); border-color: rgba(245,196,81,.4); background: rgba(245,196,81,.07); }
.chip.standout { color: var(--teal); border-color: rgba(45,212,191,.35); background: rgba(45,212,191,.07); }

.btn {
  appearance: none; cursor: pointer; font-family: var(--mono); font-size: 12px; font-weight: 500;
  border: 1px solid var(--line-2); background: var(--raised); color: var(--ink-2);
  border-radius: var(--r-sm); padding: 7px 12px; transition: all .14s; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { color: var(--ink); border-color: #3a4a5e; background: #1d2734; }
.btn.on { color: #04110f; background: var(--teal); border-color: var(--teal); box-shadow: 0 0 14px var(--teal-glow); }
.btn.ghost { background: transparent; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: var(--r-sm); overflow: hidden; }
.seg button {
  appearance: none; border: 0; cursor: pointer; background: transparent; color: var(--ink-3);
  font-family: var(--mono); font-size: 11.5px; font-weight: 500; padding: 7px 13px; transition: all .13s;
}
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button:hover { color: var(--ink-2); }
.seg button.on { background: var(--teal); color: #04110f; }

input[type="range"] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 4px; background: var(--line-2); outline: none; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: var(--teal); cursor: pointer; border: 2px solid #04110f; box-shadow: 0 0 8px var(--teal-glow); }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--teal); cursor: pointer; border: 2px solid #04110f; }

.search {
  display: flex; align-items: center; gap: 8px; background: var(--bg-1); border: 1px solid var(--line-2);
  border-radius: var(--r-sm); padding: 8px 11px; color: var(--ink-3);
}
.search:focus-within { border-color: var(--teal-dim); }
.search input { background: transparent; border: 0; outline: 0; color: var(--ink); font-family: var(--sans); font-size: 13px; width: 100%; }

/* ---------- stat cards ---------- */
.statgrid { display: grid; gap: 12px; }
.stat {
  background: linear-gradient(180deg, var(--panel-2), var(--panel)); border: 1px solid var(--line);
  border-radius: var(--r); padding: 14px 15px; position: relative; overflow: hidden;
}
.stat .k { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.stat .v { font-family: var(--display); font-size: 30px; font-weight: 600; line-height: 1; margin-top: 8px; letter-spacing: -.02em; }
.stat .v small { font-size: 14px; color: var(--ink-3); font-weight: 500; }
.stat .sparkbar { display: flex; gap: 2px; align-items: flex-end; height: 22px; margin-top: 11px; }
.stat .sparkbar span { flex: 1; background: var(--teal-dim); border-radius: 1px; opacity: .55; }

/* ---------- tooltip ---------- */
.tip {
  position: fixed; z-index: 9999; pointer-events: none; max-width: 320px;
  background: rgba(7,11,16,.97); border: 1px solid var(--line-2); border-radius: var(--r-sm);
  padding: 9px 11px; font-size: 12px; color: var(--ink); box-shadow: 0 12px 40px rgba(0,0,0,.6);
  backdrop-filter: blur(6px);
}
.tip .t-title { font-family: var(--display); font-weight: 600; font-size: 12.5px; margin-bottom: 4px; }
.tip .t-row { display: flex; justify-content: space-between; gap: 14px; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.tip .t-row b { color: var(--ink); }

/* ============================================================
   EXPLORE
   ============================================================ */
.explore { display: grid; grid-template-columns: 248px 1fr; gap: 0; height: 100%; }
.facets { border-right: 1px solid var(--line); overflow: auto; padding: 16px; background: var(--bg-1); }
.facets .fgroup { margin-bottom: 18px; }
.facets .fgroup > .eyebrow { display: block; margin-bottom: 9px; }
.facet-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 7px; border-radius: var(--r-sm);
  cursor: pointer; font-size: 12.5px; color: var(--ink-2); transition: background .12s;
}
.facet-row:hover { background: rgba(255,255,255,.03); }
.facet-row.on { color: var(--ink); }
.facet-row .box { width: 14px; height: 14px; border-radius: 4px; border: 1.5px solid var(--line-2); flex: none; display: grid; place-items: center; }
.facet-row.on .box { background: var(--teal); border-color: var(--teal); }
.facet-row .n { margin-left: auto; font-family: var(--mono); font-size: 10.5px; color: var(--ink-4); }
.facet-row .swatch { width: 9px; height: 9px; border-radius: 2px; flex: none; }

.explore-main { overflow: auto; min-width: 0; }
.explore-toolbar { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 3; }

table.papers { width: 100%; border-collapse: collapse; }
table.papers th {
  position: sticky; top: 0; text-align: left; font-family: var(--mono); font-size: 10px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3); font-weight: 500; padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: var(--bg-1); cursor: pointer; white-space: nowrap; user-select: none;
}
table.papers th:hover { color: var(--ink-2); }
table.papers th .arr { color: var(--teal); margin-left: 4px; }
table.papers td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 13px; }
table.papers tr.row { cursor: pointer; transition: background .1s; }
table.papers tr.row:hover { background: rgba(45,212,191,.04); }
table.papers tr.flagged td:first-child { box-shadow: inset 2px 0 0 var(--gold); }
.cell-title { font-weight: 500; color: var(--ink); max-width: 460px; }
.cell-title .meta { font-size: 11px; color: var(--ink-3); margin-top: 2px; }

.scorebar { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 12px; }
.scorebar .track { width: 46px; height: 5px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.scorebar .fill { height: 100%; border-radius: 3px; }

/* ============================================================
   DETAIL DRAWER
   ============================================================ */
.drawer-scrim { position: fixed; inset: 0; background: rgba(3,6,10,.6); backdrop-filter: blur(2px); z-index: 50; opacity: 0; animation: fade .2s forwards; }
@keyframes fade { to { opacity: 1; } }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 92vw); z-index: 51;
  background: linear-gradient(180deg, var(--panel), var(--bg-1)); border-left: 1px solid var(--line-2);
  box-shadow: -30px 0 80px rgba(0,0,0,.5); overflow: auto; transform: translateX(100%); animation: slidein .26s cubic-bezier(.22,1,.36,1) forwards;
}
@keyframes slidein { to { transform: translateX(0); } }
.drawer-h { position: sticky; top: 0; background: linear-gradient(180deg, var(--panel-2), rgba(14,20,29,.96)); border-bottom: 1px solid var(--line); padding: 18px 22px; backdrop-filter: blur(8px); z-index: 2; }
.drawer-body { padding: 6px 22px 60px; }
.drawer .sec { padding: 16px 0; border-bottom: 1px solid var(--line); }
.drawer .sec:last-child { border: 0; }
.drawer .sec .eyebrow { display: block; margin-bottom: 7px; }
.drawer .sec p { margin: 0; color: var(--ink-2); font-size: 13.5px; line-height: 1.62; }
.drawer .closex { position: absolute; top: 16px; right: 18px; }

.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.kv { background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 9px 11px; }
.kv .k { font-family: var(--mono); font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.kv .v { font-family: var(--display); font-size: 19px; font-weight: 600; margin-top: 3px; }

/* ============================================================
   CHARTS / CANVAS
   ============================================================ */
.chart-grid { display: grid; gap: 14px; }
svg text { font-family: var(--mono); }
.axis-label { fill: var(--ink-3); font-size: 10px; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.net-canvas { display: block; width: 100%; cursor: grab; }
.net-canvas:active { cursor: grabbing; }

.net-layout { display: flex; height: 100%; min-height: 0; min-width: 0; overflow: hidden; }
.net-sidebar {
  width: 320px; flex-shrink: 0; border-right: 1px solid var(--line);
  overflow-x: hidden; overflow-y: auto; background: var(--bg-1);
  padding: 14px 14px 30px; display: flex; flex-direction: column; gap: 18px;
  scrollbar-gutter: stable;
}
.net-busy {
  position: absolute; top: 10px; right: 10px; z-index: 10; pointer-events: none;
  font-family: var(--mono); font-size: 11px; color: var(--teal);
  background: rgba(7,10,15,.88); border: 1px solid var(--line-2);
  border-radius: 999px; padding: 4px 10px;
}
.net-heatmap { flex-shrink: 0; border-top: 1px solid var(--line); background: var(--bg-1); max-height: 300px; overflow-y: auto; scrollbar-gutter: stable; }
.net-sidebar .seg { display: flex; width: 100%; }
.net-sidebar .seg button { flex: 1; min-width: 0; padding: 7px 8px; font-size: 11px; }
.net-sidebar .ctrl-row label { min-width: 108px; flex-shrink: 0; }
.net-sidebar .ctrl-row input[type=range] { flex: 1; min-width: 0; }
.net-reset-btn { width: 100%; justify-content: center; margin-top: 4px; font-size: 11px; }
.net-reset-btn:disabled { opacity: 0.45; cursor: default; }
.net-main { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.legend-row { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.legend-item .sw { width: 10px; height: 10px; border-radius: 3px; }

.ctrl-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.ctrl-row label { font-family: var(--mono); font-size: 11px; color: var(--ink-3); min-width: 96px; }
.ctrl-row .val { font-family: var(--mono); font-size: 11px; color: var(--teal); min-width: 34px; text-align: right; }
.ctrl-row input[type=range] { flex: 1; }

.help { font-size: 12px; color: var(--ink-3); line-height: 1.55; }
.help b { color: var(--ink-2); font-weight: 600; }

.empty { color: var(--ink-3); font-family: var(--mono); font-size: 12px; padding: 40px; text-align: center; }
