:root {
  color-scheme: dark;
  --bg: #0b0a10;
  --surface: #14131b;
  --surface-2: #1a1722;
  --surface-glass: rgba(20, 19, 27, 0.82);
  --well: #100f16;
  --ink: #f4f1e9;
  --subtle: #b7b3a9;
  --brand: #f1eee6;
  --brand-fg: #090a09;
  --link: #8db4ff;
  --sage: #91b897;
  --slate: #a6b2c4;
  --graphite: #bbb7ad;
  --violet: #9d86ff;
  --rose: #d896a7;
  --amber: #d7b16d;
  --danger: #ef8f85;
  --hair: rgba(255, 255, 255, 0.14);
  --hair-strong: rgba(255, 255, 255, 0.22);
  --accent-weak: rgba(255, 255, 255, 0.055);
  --link-weak: rgba(141, 180, 255, 0.12);
  --sage-weak: rgba(145, 184, 151, 0.12);
  --danger-weak: rgba(239, 143, 133, 0.1);
  --font-sans: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "Faculty Glyphic", var(--font-sans);
  --font-mono: "Geist Mono", "SFMono-Regular", Consolas, monospace;
  --sidebar: 224px;
  --chat: 350px;
  --radius: 12px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html,
body { margin: 0; min-height: 100%; }

html { background: var(--bg); }

body {
  min-width: 320px;
  overflow: hidden;
  background:
    radial-gradient(ellipse 70% 60% at 18% -8%, rgba(104, 75, 170, 0.19), transparent 67%),
    radial-gradient(ellipse 55% 72% at 96% 46%, rgba(62, 101, 94, 0.12), transparent 72%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body::before {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(rgba(244, 241, 233, 0.055) 0.7px, transparent 0.7px);
  background-size: 25px 25px;
  -webkit-mask-image: radial-gradient(ellipse 70% 70% at 50% 45%, #000 12%, transparent 78%);
  mask-image: radial-gradient(ellipse 70% 70% at 50% 45%, #000 12%, transparent 78%);
  content: "";
}

button,
input { font: inherit; }

button,
a { -webkit-tap-highlight-color: transparent; }

button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}

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

::selection { background: rgba(141, 180, 255, 0.25); color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 999px; background: rgba(255, 255, 255, 0.18); background-clip: padding-box; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  transform: translateY(-160%);
  border-radius: 8px;
  background: var(--brand);
  color: var(--brand-fg);
  padding: 9px 13px;
  text-decoration: none;
  transition: transform 180ms ease;
}

.skip-link:focus { transform: translateY(0); }

.ambient {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 50% 8%, rgba(124, 92, 255, 0.08), transparent 34%),
    linear-gradient(to bottom, transparent 70%, rgba(0, 0, 0, 0.22));
}

.glass-panel {
  background: var(--surface-glass);
  border-color: var(--hair);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.055);
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--chat);
  height: 100vh;
  height: 100svh;
  min-height: 100svh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  flex-direction: column;
  border-right: 1px solid var(--hair);
  padding: 24px 16px 18px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark { flex: 0 0 auto; color: var(--graphite); transform: translateY(1px); }
.brand-outflow { stroke: var(--link); }
.brand-core { fill: var(--link); }

.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 17px; font-weight: 600; letter-spacing: -0.03em; }
.brand-copy small { color: var(--subtle); font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; }

.primary-nav { display: flex; flex-direction: column; gap: 3px; margin-top: 42px; }
.nav-label,
.eyebrow {
  margin: 0 0 10px;
  color: var(--subtle);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--subtle);
  padding: 10px 11px;
  cursor: pointer;
  text-align: left;
  transition: color 180ms ease, background 180ms ease, border-color 180ms ease;
}

.nav-item span { width: 20px; color: rgba(183, 179, 169, 0.58); font-family: var(--font-mono); font-size: 10px; }
.nav-item:hover { color: var(--ink); background: var(--accent-weak); }
.nav-item.active { border-color: var(--hair); background: rgba(255, 255, 255, 0.07); color: var(--ink); }
.nav-item.active span { color: var(--link); }

.sidebar-status {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 0 8px;
  margin-top: auto;
  border-top: 1px solid var(--hair);
  padding: 18px 7px 0;
  color: var(--ink);
  font-size: 12px;
}

.sidebar-status small { grid-column: 2; color: var(--subtle); font-size: 11px; }

.live-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--sage);
  box-shadow: 0 0 0 4px var(--sage-weak);
}

main {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 42px clamp(24px, 4vw, 64px) 80px;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.view-head { margin-bottom: 30px; }
.view-head .eyebrow { margin-bottom: 11px; color: var(--link); }
.view-head-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

h1,
h2,
h3,
p { margin-top: 0; }

.view-head h1 {
  max-width: 820px;
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3.8rem);
  font-weight: 400;
  line-height: 1.03;
  letter-spacing: -0.035em;
}

.view-head p:last-child { max-width: 680px; margin: 14px 0 0; color: var(--subtle); font-size: 15px; }

.section-label { margin: 0 0 12px; color: var(--slate); font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.11em; text-transform: uppercase; }

.card {
  margin-bottom: 16px;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  background: rgba(20, 19, 27, 0.92);
  padding: 20px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.card:last-child { margin-bottom: 0; }
.card-accent { background: radial-gradient(ellipse 80% 140% at 0% 50%, rgba(124, 92, 255, 0.12), transparent 72%), rgba(20, 19, 27, 0.94); }

.well {
  border: 1px solid var(--hair);
  border-radius: 9px;
  background: var(--well);
  padding: 14px;
}

pre.well {
  max-height: 62vh;
  overflow: auto;
  color: var(--subtle);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.funnel { overflow: hidden; padding: clamp(24px, 4vw, 40px); }
.funnel-copy { margin: 0; color: var(--ink); font-family: var(--font-display); font-size: clamp(1.6rem, 3vw, 2.75rem); line-height: 1.25; letter-spacing: -0.025em; }
.funnel-copy b { color: var(--link); font-family: var(--font-mono); font-size: 1.04em; font-weight: 500; }

.metric-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.metric { min-height: 112px; }
.metric-value { margin: 16px 0 2px; font-family: var(--font-mono); font-size: 30px; color: var(--ink); }

.row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--hair);
  padding: 12px 0;
}

.row:first-child { padding-top: 0; }
.row:last-child { border-bottom: 0; padding-bottom: 0; }
.row > :last-child { flex: 0 0 auto; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.small { font-size: 12px; }
.subtle,
.muted { color: var(--subtle); }
.sage { color: var(--sage); }
.danger { color: var(--danger); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(141, 180, 255, 0.3);
  border-radius: 999px;
  background: var(--link-weak);
  color: var(--link);
  padding: 3px 9px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.4;
}

.badge.warn { border-color: rgba(239, 143, 133, 0.35); background: var(--danger-weak); color: var(--danger); }
.badge.good { border-color: rgba(145, 184, 151, 0.32); background: var(--sage-weak); color: var(--sage); }

input {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--hair);
  border-radius: 9px;
  background: rgba(10, 9, 15, 0.72);
  color: var(--ink);
  padding: 10px 12px;
  transition: border-color 180ms ease, background 180ms ease;
}

input::placeholder { color: rgba(183, 179, 169, 0.62); }
input:hover { border-color: var(--hair-strong); }
input:focus { border-color: rgba(141, 180, 255, 0.6); background: var(--well); outline: none; }

.button,
.toolbar button,
.chat-compose button {
  display: inline-flex;
  min-height: 39px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--brand);
  color: var(--brand-fg);
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 500;
  transition: filter 180ms ease, transform 120ms ease;
}

.button:hover,
.toolbar button:hover,
.chat-compose button:hover { filter: brightness(1.08); }
.button:active,
.toolbar button:active,
.chat-compose button:active { transform: translateY(1px); }
.button.secondary,
.toolbar button.secondary { border-color: var(--hair); background: transparent; color: var(--ink); }
.button.secondary:hover,
.toolbar button.secondary:hover { background: var(--accent-weak); filter: none; }

.toolbar { display: flex; align-items: center; gap: 9px; }
.toolbar input { flex: 1 1 260px; }

a.link,
button.link,
.cite {
  border: 0;
  background: none;
  color: var(--link);
  padding: 0;
  cursor: pointer;
  text-decoration: none;
}

a.link:hover,
button.link:hover,
.cite:hover { text-decoration: underline; text-underline-offset: 3px; }

.cite { font-family: var(--font-mono); font-size: 11px; }

.legend { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 14px; color: var(--subtle); font-size: 12px; }
.legend > span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }

.slider { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
input[type="range"] { flex: 1; accent-color: var(--link); padding: 0; }

#net {
  position: relative;
  width: 100%;
  height: min(58vh, 560px);
  min-height: 420px;
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  background:
    radial-gradient(ellipse 70% 80% at 50% 50%, rgba(124, 92, 255, 0.07), transparent 72%),
    var(--well);
}

#net svg { width: 100%; height: 100%; }
#net .vis-tooltip { border: 1px solid var(--hair-strong) !important; border-radius: 8px !important; background: rgba(20, 19, 27, 0.96) !important; color: var(--ink) !important; padding: 8px 10px !important; font-family: var(--font-sans) !important; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.34) !important; }

.bartrack { width: 100%; min-width: 110px; height: 7px; overflow: hidden; border-radius: 999px; background: var(--accent-weak); }
.bar { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--violet), var(--link)); }

.table-scroll { overflow-x: auto; overscroll-behavior-inline: contain; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th,
td { border-bottom: 1px solid var(--hair); padding: 11px 9px; text-align: left; }
th { color: var(--subtle); font-family: var(--font-mono); font-size: 10px; font-weight: 500; letter-spacing: 0.09em; text-transform: uppercase; }
tr:last-child td { border-bottom: 0; }

.answer { font-size: 15px; white-space: pre-wrap; }
.answer-meta { margin-top: 12px; }
.citation-list { margin-top: 16px; }
.conflicts { margin-top: 16px; border-left: 3px solid var(--amber); }
.conflicts .row { display: block; }

.empty-state,
.error-state,
.loading-state {
  display: flex;
  min-height: 200px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1px dashed var(--hair);
  border-radius: var(--radius);
  color: var(--subtle);
  text-align: center;
}

.loading-mark { width: 8px; height: 8px; border-radius: 50%; background: var(--link); animation: breathe 1.6s ease-in-out infinite; }

.chat-panel {
  position: relative;
  z-index: 25;
  display: flex;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  flex-direction: column;
  border-left: 1px solid var(--hair);
}

.chat-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--hair); padding: 24px 20px 18px; }
.chat-header .eyebrow { margin-bottom: 5px; }
.chat-header h2 { margin: 0; font-family: var(--font-display); font-size: 21px; font-weight: 400; letter-spacing: -0.02em; }
.chat-header-actions { display: flex; align-items: center; gap: 8px; }
.live-state { display: inline-flex; align-items: center; gap: 7px; color: var(--sage); font-family: var(--font-mono); font-size: 11px; }

.icon-button {
  display: inline-grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 1px solid var(--hair);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  cursor: pointer;
}

.icon-button:hover { background: rgba(255, 255, 255, 0.1); }
.chat-close { display: none; }

.chat-log { display: flex; min-height: 0; flex: 1; flex-direction: column; gap: 13px; overflow: auto; padding: 18px; }
.chat-intro { margin: auto 0; padding: 32px 12px; color: var(--subtle); text-align: center; }
.chat-intro p { margin: 10px 0 0; }
.chat-spark { display: inline-grid; width: 42px; height: 42px; place-items: center; border: 1px solid rgba(141, 180, 255, 0.3); border-radius: 50%; background: var(--link-weak); color: var(--link); font-size: 18px; }
.chat-message { max-width: 94%; border: 1px solid var(--hair); border-radius: 11px; padding: 11px 12px; }
.chat-message.user { align-self: flex-end; background: var(--brand); color: var(--brand-fg); }
.chat-message.assistant { align-self: flex-start; background: rgba(255, 255, 255, 0.045); }
.chat-message p:last-child { margin-bottom: 0; }

.chat-compose { display: flex; gap: 8px; border-top: 1px solid var(--hair); padding: 14px 14px 8px; }
.chat-compose input { flex: 1; }
.chat-compose button { width: 40px; flex: 0 0 40px; padding: 0; font-size: 18px; }
.model-note { margin: 0; padding: 0 16px 14px; color: rgba(183, 179, 169, 0.62); font-family: var(--font-mono); font-size: 10px; text-align: center; }

.mobile-bar,
.mobile-backdrop { display: none; }

@keyframes breathe {
  0%, 100% { transform: scale(0.78); opacity: 0.55; }
  50% { transform: scale(1); opacity: 1; }
}

@media (max-width: 1180px) {
  :root { --sidebar: 210px; }
  .app-shell { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
  .chat-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(390px, 92vw);
    transform: translateX(104%);
    transition: transform 260ms var(--ease);
  }
  body.chat-open .chat-panel { transform: translateX(0); }
  .chat-close { display: inline-grid; }
  .mobile-bar { display: flex; position: fixed; z-index: 18; top: 14px; right: 18px; pointer-events: none; }
  .mobile-bar > * { pointer-events: auto; }
  .mobile-bar .brand,
  .mobile-bar #navToggle { display: none; }
  .mobile-backdrop { position: fixed; z-index: 22; inset: 0; background: rgba(5, 5, 8, 0.62); backdrop-filter: blur(4px); }
  body.chat-open .mobile-backdrop { display: block; }
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .app-shell { display: block; height: auto; min-height: 100svh; overflow: visible; padding-top: 65px; }
  .mobile-bar {
    display: flex;
    position: fixed;
    z-index: 30;
    inset: 0 0 auto;
    height: 65px;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--hair);
    background: rgba(11, 10, 16, 0.82);
    padding: 0 14px;
    pointer-events: auto;
    backdrop-filter: blur(18px) saturate(1.3);
  }
  .mobile-bar .brand,
  .mobile-bar #navToggle { display: inline-flex; }
  .brand-mobile { font-size: 17px; font-weight: 600; letter-spacing: -0.03em; }
  .brand-mobile .brand-mark { width: 25px; }
  .sidebar {
    position: fixed;
    z-index: 35;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(290px, 88vw);
    overflow-y: auto;
    transform: translateX(-104%);
    transition: transform 260ms var(--ease);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .mobile-backdrop,
  body.chat-open .mobile-backdrop { display: block; z-index: 32; }
  .chat-panel { z-index: 35; width: 100%; }
  main { min-height: calc(100svh - 65px); overflow: visible; padding: 32px 18px 64px; }
  .view-head { margin-bottom: 24px; }
  .view-head h1 { font-size: clamp(2rem, 11vw, 3rem); }
  .metric-grid { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .toolbar input { flex-basis: 100%; }
  .toolbar button { flex: 1; }
  .row { flex-direction: column; gap: 7px; }
  .row > :last-child { flex: auto; }
  .slider { flex-wrap: wrap; }
  .slider input[type="range"] { flex-basis: 100%; order: 3; }
  #net { min-height: 390px; height: 54vh; }
  .funnel { padding: 24px 20px; }
  .table-scroll { margin: 0 -4px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@supports not (backdrop-filter: blur(10px)) {
  .glass-panel,
  .mobile-bar { background: rgba(11, 10, 16, 0.96); }
}
