/* Gosset Ontology Visualizer — visual language borrowed from the Gosset webapp
   (Inter, #7C3AED accent, generous whitespace) and the interaction model from
   disease-ontology.org: search-first, hierarchy on the left, detail on the
   right. Dark and light both supported because this gets opened next to other
   tools, not on its own. */

:root {
  --accent: #7c3aed;
  --accent-soft: #ede9fe;
  --accent-line: #c4b5fd;

  --bg: #ffffff;
  --bg-sunk: #f8fafc;
  --panel: #ffffff;
  --line: #e2e8f0;
  --line-soft: #eef2f6;

  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;

  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
  --radius: 12px;
  --topbar-h: 68px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #a78bfa;
    --accent-soft: #2e1065;
    --accent-line: #6d28d9;
    --bg: #0b1020;
    --bg-sunk: #070b16;
    --panel: #101729;
    --line: #1e293b;
    --line-soft: #172033;
    --text: #e2e8f0;
    --text-2: #94a3b8;
    --text-3: #64748b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

/* `hidden` must actually hide. Any rule setting `display` outranks the UA
   sheet's [hidden]{display:none}, so .empty (display:grid) stayed on screen
   above the detail panel even with the attribute set. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg-sunk);
  color: var(--text);
  font: 15px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }

/* The Gosset mark, same asset the webapp uses. It is drawn with
   fill="currentColor", so it takes the accent colour and flips correctly in
   dark mode without a second file. */
.brand .mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  color: var(--accent);
  flex: 0 0 auto;
}
.brand .mark svg { width: 100%; height: 100%; display: block; }

.brand h1 { margin: 0; font-size: 15.5px; font-weight: 700; letter-spacing: -.01em;
  white-space: nowrap; }
.sub { margin: 1px 0 0; font-size: 12px; color: var(--text-3); }

.search-wrap { position: relative; flex: 1 1 auto; max-width: 620px; }

#search {
  width: 100%;
  height: 40px;
  padding: 0 14px;
  font: inherit;
  color: var(--text);
  background: var(--bg-sunk);
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  transition: border-color .12s, box-shadow .12s, background .12s;
}
#search:focus {
  border-color: var(--accent-line);
  background: var(--panel);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
#search::placeholder { color: var(--text-3); }

.results {
  position: absolute;
  top: 46px; left: 0; right: 0;
  max-height: min(60vh, 460px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 50;
}

.result {
  display: flex; align-items: baseline; gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: none; background: none; width: 100%; text-align: left;
  font: inherit; color: var(--text);
}
.result:hover, .result.active { background: var(--accent-soft); }
.result .rid {
  font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-3); flex: 0 0 auto; padding-top: 2px;
}
.result mark { background: transparent; color: var(--accent); font-weight: 700; }
.result-empty { padding: 14px; color: var(--text-3); font-size: 13px; }

.src {
  font-size: 12px; color: var(--text-3); text-decoration: none;
  border: 1px solid var(--line); padding: 6px 10px; border-radius: 8px;
  flex: 0 0 auto;
}
.src:hover { color: var(--accent); border-color: var(--accent-line); }

/* ---------- layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - var(--topbar-h));
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-2); }

.ghost {
  font: 12px/1 inherit; color: var(--text-2);
  background: none; border: 1px solid var(--line);
  padding: 6px 9px; border-radius: 7px; cursor: pointer;
}
.ghost:hover { color: var(--accent); border-color: var(--accent-line); }

/* ---------- tree ---------- */

.tree { overflow-y: auto; padding: 8px 6px 24px; flex: 1 1 auto; }

.row {
  display: flex; align-items: center; gap: 4px;
  border-radius: 8px;
  padding: 3px 6px;
  cursor: pointer;
  color: var(--text);
}
.row:hover { background: var(--bg-sunk); }
.row.selected { background: var(--accent-soft); }
.row.selected .label { color: var(--accent); font-weight: 650; }

.twisty {
  width: 18px; height: 18px; flex: 0 0 auto;
  display: grid; place-items: center;
  border: none; background: none; cursor: pointer; padding: 0;
  color: var(--text-3);
}
.twisty svg { transition: transform .14s ease; }
.twisty.open svg { transform: rotate(90deg); }
.twisty.leaf { visibility: hidden; }

.label { font-size: 13.5px; line-height: 1.35; }
.badge {
  font: 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-3);
  background: var(--bg-sunk);
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  padding: 2px 6px;
  margin-left: auto;
  flex: 0 0 auto;
}
.kids { margin-left: 13px; border-left: 1px solid var(--line-soft); padding-left: 4px; }

/* ---------- detail ---------- */

.detail-panel { overflow-y: auto; }
#detail-body { padding: 20px 24px 40px; }

.empty {
  height: 100%; display: grid; place-content: center; justify-items: center;
  text-align: center; gap: 6px; padding: 40px; color: var(--text-2);
}
.empty h2 { margin: 4px 0 0; font-size: 17px; color: var(--text); }
.empty p { margin: 0; max-width: 44ch; font-size: 13.5px; }
.empty-mark {
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--accent-soft); border: 1px solid var(--accent-line);
}

.crumbs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  font-size: 12px; color: var(--text-3); margin-bottom: 10px; }
.crumbs a { color: var(--text-2); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.crumbs .sep { color: var(--text-3); }

#node-label { margin: 0 0 8px; font-size: 22px; line-height: 1.25; letter-spacing: -.01em; }

.meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.chip {
  font: 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 5px 9px; border-radius: 999px;
  background: var(--bg-sunk); border: 1px solid var(--line); color: var(--text-2);
}
.chip.accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

.graph-wrap {
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  background: var(--bg-sunk); margin-bottom: 20px; overflow-x: auto;
}
#graph { display: block; width: 100%; min-height: 180px; }
.gnode { cursor: pointer; }
.gnode rect { fill: var(--panel); stroke: var(--line); stroke-width: 1.2; rx: 8; }
.gnode.center rect { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1.6; }
.gnode text { font-size: 11.5px; fill: var(--text); }
.gnode.center text { fill: var(--accent); font-weight: 650; }
.gnode:hover rect { stroke: var(--accent-line); }
.glink { stroke: var(--accent-line); stroke-width: 1.4; fill: none; opacity: .75; }
.glabel { font-size: 10px; fill: var(--text-3); text-transform: uppercase; letter-spacing: .07em; }

.relations { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 22px; }
@media (max-width: 900px) { .relations { grid-template-columns: 1fr; } }

.relations h3, .paths h3 {
  margin: 0 0 8px; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--text-2);
}
.count { color: var(--text-3); font-weight: 500; }

.rel-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.rel-list li { }
.rel-list button {
  width: 100%; text-align: left; font: inherit; font-size: 13.5px;
  color: var(--text); background: none; border: 1px solid transparent;
  border-radius: 8px; padding: 7px 9px; cursor: pointer;
  display: flex; gap: 8px; align-items: baseline;
}
.rel-list button:hover { background: var(--bg-sunk); border-color: var(--line); }
.rel-list .rid { font: 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text-3); }
.rel-none { color: var(--text-3); font-size: 13px; padding: 6px 2px; }

.path-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 5px;
  padding: 9px 10px; border: 1px solid var(--line-soft);
  border-radius: 9px; margin-bottom: 7px; background: var(--bg-sunk);
  font-size: 12.5px;
}
.path-row button {
  font: inherit; background: none; border: none; cursor: pointer;
  color: var(--text-2); padding: 1px 3px; border-radius: 5px;
}
.path-row button:hover { color: var(--accent); background: var(--accent-soft); }
.path-row .term { color: var(--accent); font-weight: 650; }

/* ---------- loader ---------- */

.loader {
  position: fixed; inset: 0; display: grid; place-content: center; justify-items: center;
  gap: 14px; background: var(--bg-sunk); z-index: 100; color: var(--text-2); font-size: 13px;
}
.loader.hidden { display: none; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 2.5px solid var(--line); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loader.error .spinner { display: none; }
.loader.error p { color: #dc2626; max-width: 52ch; text-align: center; }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .panel { height: auto; max-height: 70vh; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 10px; }
  .search-wrap { order: 3; flex-basis: 100%; max-width: none; }
}
