:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --ink: #1a2233;
  --muted: #66718a;
  --line: #e2e7f0;
  --brand: #1f6feb;
  --brand-dark: #144a9e;
  --ap: #1f6feb;       /* Activities & Participation */
  --env: #0c8a6e;      /* Environmental factors */
  --icf: #6b3fb5;      /* ICF code chips */
  --hpo: #b5482a;      /* HPO / phenotype */
  /* frequency */
  --f-very: #b4232a; --f-freq: #d9772b; --f-occ: #c9a227; --f-unspec: #9aa3b5;
  /* severity */
  --s-complete: #7a1620; --s-severe: #b4232a; --s-moderate: #d9772b; --s-mild: #c9a227; --s-unspec: #9aa3b5;
  --shadow: 0 1px 3px rgba(20,30,60,.08), 0 6px 18px rgba(20,30,60,.05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(120deg, var(--brand-dark), var(--brand));
  color: #fff;
  padding: 14px 22px 0;
  box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
.org-logo {
  position: absolute; top: 18px; right: 22px;
  display: inline-flex; align-items: center;
  opacity: .94; transition: opacity .12s;
}
.org-logo img {
  display: block; height: 28px; width: auto; max-height: 28px;
}
.org-logo:hover { opacity: 1; }
.brand { display: flex; align-items: center; gap: 16px; }
.logo {
  font-weight: 800; font-size: 20px; letter-spacing: 1px;
  background: rgba(255,255,255,.16); padding: 8px 12px; border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25);
}
.brand-text h1 { font-size: 18px; margin: 0; font-weight: 700; }
.brand-text p { margin: 2px 0 0; font-size: 12.5px; opacity: .92; }
.brand-text b { font-weight: 700; }
.tabs { display: flex; gap: 4px; margin-top: 12px; }
.tab {
  background: transparent; border: none; color: #fff;
  padding: 10px 18px; cursor: pointer; font-size: 14px; font-weight: 600;
  border-radius: 8px 8px 0 0; opacity: .8;
}
.tab:hover { opacity: 1; background: rgba(255,255,255,.1); }
.tab.active { background: var(--bg); color: var(--brand-dark); opacity: 1; }

/* ---------- layout ---------- */
main { height: calc(100vh - 92px - 30px); }  /* header + footer */
.page-footer {
  height: 30px; box-sizing: border-box;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 0 16px; border-top: 1px solid var(--line);
  background: var(--panel); color: var(--muted);
  font-size: 11.5px;
}
.page-footer a { color: var(--brand); text-decoration: none; }
.page-footer a:hover { text-decoration: underline; }
.page-footer .sep { color: var(--line); }
.view { display: none; height: 100%; }
.view.active { display: flex; }
#view-about.view.active { display: block; overflow: auto; }

.sidebar {
  width: 340px; min-width: 300px; background: var(--panel);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
}
.content { flex: 1; overflow: auto; padding: 22px 26px; }

.search-wrap { padding: 14px; border-bottom: 1px solid var(--line); }
.search-wrap input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; outline: none;
}
.search-wrap input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,111,235,.12); }
.search-meta { font-size: 11.5px; color: var(--muted); margin-top: 8px; }

/* ---------- disease list ---------- */
.disease-list { list-style: none; margin: 0; padding: 6px; overflow: auto; flex: 1; }
.disease-list li {
  padding: 9px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.disease-list li:hover { background: #eef3fc; }
.disease-list li.active { background: #e0ebfd; }
.disease-list .dz-name { font-weight: 600; font-size: 13.5px; }
.disease-list .dz-meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; gap: 8px; }
.dz-meta .pill { background: #eef1f7; border-radius: 20px; padding: 1px 7px; }
.dz-meta .pill.hpo { color: var(--hpo); background: #fbeae5; }
.dz-meta .pill.func { color: var(--ap); background: #e7effd; }

/* ---------- placeholder ---------- */
.placeholder { height: 100%; display: flex; align-items: center; justify-content: center; }
.placeholder-card {
  max-width: 520px; background: var(--panel); padding: 30px 34px; border-radius: 14px;
  box-shadow: var(--shadow); text-align: center;
}
.placeholder-card h2 { margin-top: 0; }
.hint { color: var(--muted); font-size: 13px; }
.link-btn {
  background: none; border: none; color: var(--brand); cursor: pointer;
  font: inherit; text-decoration: underline; padding: 0;
}

/* ---------- disease profile ---------- */
.dz-header {
  background: var(--panel); border-radius: 14px; padding: 20px 24px;
  box-shadow: var(--shadow); margin-bottom: 18px;
}
.dz-header h2 { margin: 0 0 6px; font-size: 22px; }
.dz-header .chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px;
  padding: 4px 10px; border-radius: 20px; background: #eef1f7; color: var(--ink);
  text-decoration: none;
}
.chip.orpha { background: #e7effd; color: var(--brand-dark); font-weight: 600; }
.chip.orpha:hover { background: #d4e3fc; }
.chip.type { background: #f0ecf9; color: #5a3b9e; }
.chip.count-func { background: #e7effd; color: var(--ap); }
.chip.count-hpo { background: #fbeae5; color: var(--hpo); }

.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
@media (max-width: 1100px) { .profile-grid { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.panel-head {
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-head h3 { margin: 0; font-size: 15px; }
.panel-head .sub { font-size: 11.5px; color: var(--muted); }
.panel.func .panel-head { border-top: 3px solid var(--ap); }
.panel.hpo .panel-head { border-top: 3px solid var(--hpo); }
.panel-body { padding: 8px 14px 14px; }

/* group sections */
.group-sec { margin-top: 12px; }
.group-head {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); display: flex; align-items: center; gap: 8px; margin: 10px 4px 6px;
}
.group-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.group-head .dot.ap { background: var(--ap); }
.group-head .dot.env { background: var(--env); }
.group-head .gcount { margin-left: auto; font-weight: 600; color: var(--muted); }

/* functional consequence card */
.fc {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  background: #fcfdff;
}
.fc-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.fc-label { font-weight: 600; font-size: 13.5px; }
.fc-alt { font-size: 11.5px; color: var(--muted); font-weight: 400; }
.fc-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; align-items: center; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 6px; font-weight: 600; color: #fff;
}
.badge.outline { background: #fff; border: 1px solid var(--line); color: var(--muted); font-weight: 500; }
.badge.loss { background: #2b2f3a; }
.b-freq-very { background: var(--f-very); } .b-freq-frequent { background: var(--f-freq); }
.b-freq-occasional { background: var(--f-occ); } .b-freq-unspecified { background: var(--f-unspec); }
.b-sev-complete { background: var(--s-complete); } .b-sev-severe { background: var(--s-severe); }
.b-sev-moderate { background: var(--s-moderate); } .b-sev-mild { background: var(--s-mild); }
.b-sev-unspecified { background: var(--s-unspec); }

.icf-row { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.icf-chip {
  font-size: 10.5px; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  padding: 2px 7px; border-radius: 6px; background: #f1ecfa; color: var(--icf);
  text-decoration: none; border: 1px solid #e3d9f5; white-space: nowrap;
}
.icf-chip:hover { background: #e7dcf7; }
.icf-chip .m { opacity: .7; font-size: 9.5px; margin-left: 3px; }
.icf-none { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 6px; }

/* HPO list */
.hpo-item {
  display: flex; align-items: baseline; gap: 10px; padding: 7px 6px;
  border-bottom: 1px solid #f0f2f7;
}
.hpo-item:last-child { border-bottom: none; }
.hpo-term { flex: 1; font-size: 13px; }
.hpo-id {
  font-size: 10.5px; font-family: ui-monospace, Menlo, monospace; color: var(--hpo);
  text-decoration: none; background: #fbeae5; padding: 1px 6px; border-radius: 5px;
}
.hpo-id:hover { background: #f6d8cf; }
.hpo-freq { font-size: 10.5px; color: var(--muted); min-width: 120px; text-align: right; }
.freq-band { font-size: 11px; font-weight: 700; color: var(--muted); margin: 12px 4px 4px; text-transform: uppercase; letter-spacing: .3px; }
.no-hpo { padding: 24px; text-align: center; color: var(--muted); font-style: italic; }

/* ---------- thesaurus ---------- */
.concept-tree { overflow: auto; flex: 1; padding: 8px; }
.domain-block { margin-bottom: 6px; }
.domain-title {
  font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
  padding: 8px 10px 4px; display: flex; align-items: center; gap: 7px;
}
.domain-title .dot { width: 9px; height: 9px; border-radius: 50%; }
.grp { margin: 1px 0; }
.grp-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer;
  border-radius: 7px; font-weight: 600; font-size: 13px;
}
.grp-row:hover { background: #eef3fc; }
.grp-row .caret { font-size: 10px; color: var(--muted); width: 10px; transition: transform .12s; }
.grp-row.open .caret { transform: rotate(90deg); }
.grp-row .gcount { margin-left: auto; font-size: 11px; color: var(--muted); font-weight: 600; }
.grp-children { display: none; padding-left: 14px; }
.grp-children.open { display: block; }
.leaf {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer;
  border-radius: 7px; font-size: 12.5px;
}
.leaf:hover { background: #eef3fc; }
.leaf.active { background: #e0ebfd; }
.leaf .lcount { margin-left: auto; font-size: 10.5px; color: var(--muted); }
.leaf code { font-size: 10px; color: var(--icf); }

/* concept detail */
.concept-detail h2 { margin: 0 0 4px; }
.concept-detail .crumb { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.concept-detail .crumb b { color: var(--ink); }
.def-box { background: #f7f9fc; border-left: 3px solid var(--brand); padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.section-title { font-size: 13px; font-weight: 700; margin: 18px 0 8px; color: var(--ink); }
.icf-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.icf-table th, .icf-table td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.icf-table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.match-tag { font-size: 10.5px; padding: 1px 7px; border-radius: 20px; font-weight: 600; }
.match-exact { background: #e3f5ec; color: #0c8a6e; }
.match-bn { background: #fdf0e3; color: #b4660f; }
.match-nb { background: #eef0fb; color: #3b53b5; }

.dz-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.dz-chip {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px;
  cursor: pointer; font-size: 12.5px; display: flex; gap: 7px; align-items: center;
}
.dz-chip:hover { border-color: var(--brand); background: #f6f9ff; }
.dz-chip .oc { font-size: 10.5px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; }

/* ---------- disease network / navigator ---------- */
.nav-content { display: flex; flex-direction: column; padding: 0; }
.nav-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 11px 20px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.nav-crumbs { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; font-size: 12.5px; min-height: 22px; }
.crumb { cursor: pointer; color: var(--brand); padding: 2px 7px; border-radius: 6px; }
.crumb:hover { background: #eef3fc; }
.crumb.cur { color: var(--ink); font-weight: 700; cursor: default; }
.crumb.cur:hover { background: none; }
.crumb-sep, .crumb-ell { color: var(--muted); }
.nav-controls { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--muted); }
.nav-controls label { display: flex; align-items: center; gap: 4px; cursor: pointer; color: var(--ink); }
.ctrl-sep { width: 1px; height: 16px; background: var(--line); }
#navContent { flex: 1; overflow: auto; padding: 8px 16px 18px; display: flex; flex-direction: column; align-items: center; }
.net-svg { width: 100%; max-width: 1000px; height: auto; display: block; }
.net-node { cursor: pointer; }
.net-node circle { transition: filter .1s, stroke-width .1s; }
.net-node:hover circle { filter: brightness(1.06); stroke-width: 2.5; }
.net-num { font-size: 13px; font-weight: 700; }
.net-label { font-size: 12px; fill: #2a3346; }
.net-node:hover .net-label { font-weight: 700; fill: var(--brand-dark); }
.net-center { cursor: pointer; }
.net-center:hover circle { filter: brightness(1.07); }
.net-cnum { fill: #fff; font-size: 26px; font-weight: 800; }
.net-csub { fill: #dbe7fb; font-size: 11px; }
.net-cname { font-size: 16px; font-weight: 800; fill: var(--ink); }
.net-cmeta { font-size: 11.5px; fill: var(--muted); }
.net-legend {
  max-width: 780px; margin: 4px auto 0; display: flex; flex-direction: column; gap: 3px;
  font-size: 12px; color: var(--muted); text-align: center;
}
.net-empty { padding: 46px 30px; text-align: center; color: var(--muted); }
.net-empty h3 { color: var(--ink); margin-top: 0; }

/* ---------- SPARQL view ---------- */
.sparql-sidebar { display: flex; flex-direction: column; padding: 12px; gap: 12px; overflow-y: auto; }
.status-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.status-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
#storeStatus { font-size: 13px; color: var(--ink); }
#storeStatus.ready { color: #1f7a3f; font-weight: 600; }
#storeStatus.loading { color: var(--brand-dark); font-weight: 600; }
#storeStatus.err { color: #b3261e; }
.status-card button {
  padding: 8px 10px; border-radius: 6px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; font-size: 12.5px; color: var(--ink);
}
.status-card button.primary { background: var(--brand); color: #fff; border-color: var(--brand-dark); }
.status-card button:disabled { opacity: .45; cursor: not-allowed; }
.status-card button:not(:disabled):hover { filter: brightness(1.05); }
.status-hint { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.sidebar-h { margin: 4px 0 2px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.example-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.example-list li {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
  background: #fff; font-size: 12.5px; line-height: 1.35; color: var(--ink);
}
.example-list li:hover { border-color: var(--brand); background: #f6faff; }
.example-list li b { color: var(--brand-dark); display: block; font-size: 13px; margin-bottom: 2px; }

.sparql-content { display: flex; flex-direction: column; padding: 0; }
.sparql-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.sparql-hint { font-size: 12px; color: var(--muted); }
.sparql-hint kbd { font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 1px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; background: #fff; }
#runQuery {
  padding: 8px 16px; border-radius: 6px; border: 1px solid var(--brand-dark);
  background: var(--brand); color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
}
#runQuery:disabled { opacity: .45; cursor: not-allowed; }
#sparqlEditor {
  width: 100%; box-sizing: border-box; resize: vertical; min-height: 200px; height: 240px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; line-height: 1.45;
  padding: 12px 14px; border: none; border-bottom: 1px solid var(--line); outline: none;
  background: #fbfcfe; color: #0f172a;
}
.sparql-msg { padding: 6px 16px; font-size: 12.5px; color: var(--muted); min-height: 24px; }
.sparql-msg.err { color: #b3261e; }
.sparql-msg.ok { color: #1f7a3f; }
.sparql-results { flex: 1; overflow: auto; padding: 0 16px 16px; }
.sparql-results table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.sparql-results thead th {
  position: sticky; top: 0; background: var(--panel); text-align: left;
  padding: 8px 10px; border-bottom: 1px solid var(--line); font-weight: 700; color: var(--muted);
  text-transform: uppercase; font-size: 11px; letter-spacing: .04em;
}
.sparql-results tbody td {
  padding: 6px 10px; border-bottom: 1px solid #eef2f7; vertical-align: top;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: #1f2937;
  max-width: 480px; overflow-wrap: anywhere;
}
.sparql-results tbody tr:hover { background: #f6faff; }
.sparql-results .lit { color: #0f172a; font-family: inherit; }
.sparql-results .iri { color: var(--brand-dark); }
.sparql-results .bn  { color: var(--muted); }
.sparql-results .empty { padding: 20px; color: var(--muted); font-style: italic; }

/* ---------- about ---------- */
.about { max-width: 980px; margin: 0 auto; padding: 30px 26px 60px; }
.about h2 { font-size: 22px; }
.about p, .about li { font-size: 14px; color: #2a3346; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 20px 0 28px; }
@media (max-width: 760px) { .stat-grid { grid-template-columns: repeat(2,1fr); } }
.stat {
  background: var(--panel); border-radius: 12px; padding: 18px; box-shadow: var(--shadow); text-align: center;
}
.stat .num { font-size: 28px; font-weight: 800; color: var(--brand-dark); }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 4px; }
.card { background: var(--panel); border-radius: 12px; padding: 20px 24px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card h3 { margin-top: 0; }
.legend { display: flex; flex-wrap: wrap; gap: 18px; }
.legend .grp-leg { min-width: 200px; }
.legend .row { display: flex; align-items: center; gap: 8px; margin: 5px 0; font-size: 12.5px; }
.legend .sw { width: 14px; height: 14px; border-radius: 4px; }
.about a { color: var(--brand); }
.acro { font-weight: 700; color: var(--brand-dark); }
.about ul { line-height: 1.7; }
.about ul.maintainers { margin: 4px 0 8px; padding-left: 18px; }
.about ul.maintainers li { margin: 2px 0; }
.erdera-chip {
  display: inline-block; float: right; margin: 0 0 10px 16px;
  padding: 14px 18px; border-radius: 8px;
  background: linear-gradient(120deg, var(--brand-dark), var(--brand));
}
.erdera-chip img { display: block; height: 54px; }
.erdera-chip:hover { filter: brightness(1.06); }

/* Provenance & architecture tab */
.prov-table { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0 4px; }
.prov-table th, .prov-table td {
  text-align: left; vertical-align: top; padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.prov-table thead th {
  font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); background: #f7f9fc;
}
.prov-table td b { color: var(--ink); }
.prov-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.prov-table code, .prov-flow code, .prov-note code { font-size: 12px; }
.prov-note { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.prov-flow { padding-left: 22px; line-height: 1.55; }
.prov-flow li { margin: 8px 0; }
.prov-flow ul { margin: 4px 0 4px 0; padding-left: 20px; line-height: 1.55; }
.prov-code, .prov-arch {
  background: #0f172a; color: #d3e2f5; padding: 14px 16px; border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.5; overflow: auto;
  margin: 8px 0 4px;
}
.prov-code { white-space: pre; }
.mermaid-wrap {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 18px; margin: 8px 0 4px; overflow: auto; text-align: center;
}
.mermaid-wrap img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.mermaid-wrap .prov-note { text-align: center; margin: 12px 0 0; }
.about h4 { margin: 14px 0 6px; font-size: 14px; color: var(--brand-dark); }
