:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2430;
  --muted: #667085;
  --line: #d9dee7;
  --accent: #2457a6;
  --accent-soft: #e8f0ff;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: #111827;
  color: white;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 32px;
}
.topbar h1 {
  margin: 0;
  font-size: 24px;
}
.topbar p {
  margin: 6px 0 0;
  color: #cbd5e1;
}
.topbar .dek { color: #e2e8f0; }

.global-search {
  position: relative;
  display: flex;
  width: min(620px, 48vw);
}
.global-search input {
  flex: 1;
  min-width: 0;
  padding: 11px 13px;
  border: 1px solid #475569;
  border-radius: 7px 0 0 7px;
  font: inherit;
}
.global-search > button {
  border-radius: 0 7px 7px 0;
  border-color: #2457a6;
  background: #2457a6;
  color: white;
}
.suggestions {
  position: absolute;
  z-index: 20;
  top: calc(100% + 7px);
  right: 0;
  width: 100%;
  max-height: 70vh;
  overflow: auto;
  padding: 10px;
  color: var(--text);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgb(15 23 42 / 24%);
}
.suggestions section + section { margin-top: 10px; }
.suggestions h3 {
  margin: 4px 7px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}
.suggestion {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 5px;
  padding: 7px;
}
.suggestion:hover { background: var(--accent-soft); }
.suggestion span, .suggestion small { color: var(--muted); }
.suggestion small { grid-column: 1 / -1; }

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 82px);
}

.filters {
  padding: 18px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 14px;
}

input[type="search"], select {
  width: 100%;
  margin-top: 6px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  font: inherit;
}

.panel-intro {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.region-controls {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) repeat(3, minmax(130px, 170px)) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 12px;
}
.region-check {
  align-self: center;
  max-width: 190px;
  margin: 0;
}
.region-controls label { margin: 0; }
.region-controls button {
  height: 39px;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}
.track-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  margin: 8px 0 12px;
  color: var(--muted);
  font-size: 12px;
}
.swatch {
  display: inline-block;
  width: 14px;
  height: 10px;
  margin-right: 5px;
  border-radius: 2px;
}
.swatch.grb { background: #d7dde8; }
.swatch.selected-gene { background: #f0a202; }
.swatch.qualifying-gene { background: #24856d; }
.swatch.context-gene { background: #aeb7c5; }
.swatch.ldblock { background: #d5a23b; }
.swatch.selected-ldblock { background: #a15c00; }
.swatch.enhancer { background: #3676b9; }
.swatch.selected-enhancer { background: #7c3aed; }
.swatch.tier1 { background: #c83c3c; }
.genome-view {
  min-height: 310px;
  overflow-x: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
}
.genome-view svg { width: 100%; min-width: 850px; height: auto; }
.track-title { font-weight: 700; font-size: 14px; fill: var(--text); }
.track-label { font-weight: 650; font-size: 12px; fill: #475467; }
.axis-label { font-size: 10px; fill: #667085; }
.axis-line { stroke: #98a2b3; stroke-width: 1; }
.track-baseline { stroke: #d9dee7; stroke-width: 1; }
.track-feature { cursor: pointer; stroke: white; stroke-width: 1; }
.track-feature:hover, .track-feature:focus { stroke: #111827; stroke-width: 2; outline: none; }
.gene-label { font-size: 10px; font-weight: 650; fill: #344054; }
.feature-detail {
  margin-top: 12px;
  padding: 12px 14px;
  border-left: 4px solid var(--accent);
  background: #f8fafc;
}
.feature-detail h3 { margin: 0 0 8px; font-size: 14px; }
.feature-detail h3 span { font-weight: 500; }
.feature-detail dl {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 5px 12px;
  margin: 0;
  font-size: 13px;
}
.feature-detail dt { color: var(--muted); font-weight: 650; }
.feature-detail dd { margin: 0; }
.error { color: #b42318; }

.partner-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.partner-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}
.partner-header h3 { margin: 0; }
.partner-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.partner-controls {
  display: flex;
  gap: 10px;
}
.partner-controls label {
  min-width: 145px;
  margin: 0;
}
.partner-count {
  margin: 12px 0 7px;
  color: var(--muted);
  font-size: 12px;
}
.partner-table-wrap { max-height: 360px; }
.partner-table { background: white; }

.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-weight: 500;
}

.definition {
  margin: 4px 0 14px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}
.definition summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 700;
}
.definition p { margin: 8px 0 0; }
.glossary { margin: 8px 0 0; }
.glossary dt {
  margin-top: 8px;
  color: var(--text);
  font-weight: 700;
}
.glossary dd { margin: 2px 0 0; }
.glossary-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.glossary-card {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}
.glossary-card h3 {
  margin: 0 0 10px;
  color: var(--accent);
  font-size: 16px;
}
.glossary-card .glossary {
  display: grid;
  grid-template-columns: minmax(145px, 0.35fr) 1fr;
  gap: 9px 16px;
}
.glossary-card .glossary dt,
.glossary-card .glossary dd { margin: 0; }

button {
  border: 1px solid var(--line);
  background: white;
  color: var(--text);
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 650;
}

#apply {
  width: 100%;
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.content {
  padding: 18px;
  min-width: 0;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.tab.active {
  background: var(--accent-soft);
  border-color: #9db7e8;
  color: var(--accent);
}

.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}
.panel.active { display: block; }

.panel-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.panel-header h2 {
  margin: 0;
  font-size: 18px;
}
.panel-header span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 190px);
  border: 1px solid var(--line);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

/* Long trait labels must not determine the intrinsic width of the table.
   Fixed layout lets the header resize handle make a column narrower than its
   contents; clipped labels remain available through their title tooltip. */
#traitsTable {
  table-layout: fixed;
  min-width: 980px;
}
#traitsTable th:first-child {
  width: 300px;
}
#traitsTable th:not(:first-child) {
  width: 120px;
}
#traitsTable td {
  overflow: hidden;
  text-overflow: ellipsis;
}
#traitsTable td:first-child .entity-link {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

th, td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  z-index: 1;
  min-width: 78px;
  overflow: hidden;
  resize: horizontal;
  cursor: pointer;
  user-select: none;
}
th[aria-sort="ascending"]::after { content: " ▲"; color: var(--accent); }
th[aria-sort="descending"]::after { content: " ▼"; color: var(--accent); }

tbody tr {
  cursor: pointer;
}
tbody tr:hover, tbody tr.selected {
  background: var(--accent-soft);
}

.entity-link {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 650;
  text-decoration: underline;
  text-decoration-color: #a8bee5;
  text-underline-offset: 2px;
}
.entity-link:hover {
  color: #173f7e;
  text-decoration-color: currentColor;
}

.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 999px;
  background: #eef2f7;
  color: #344054;
  font-size: 12px;
}

.plots {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 16px;
}

.plot-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfe;
}
.plot-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}
.plot-card img {
  width: 100%;
  height: auto;
  display: block;
  border: 1px solid var(--line);
  background: white;
}

.functional-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
}
.functional-controls label {
  min-width: 360px;
}
.functional-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.functional-summary > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8fafc;
}
.functional-summary strong { font-size: 15px; }
.functional-summary span { color: var(--muted); font-size: 12px; }
.functional-grid {
  display: grid;
  grid-template-columns: 0.8fr 1.35fr 1.15fr;
  gap: 14px;
}
.functional-grid h3, .functional-enhancers h3 {
  margin: 0 0 8px;
  font-size: 15px;
}
.compact-table { max-height: 330px; }
.functional-enhancers { margin-top: 18px; }

@media (max-width: 900px) {
  .topbar { align-items: stretch; flex-direction: column; }
  .global-search { width: 100%; }
  .layout { grid-template-columns: 1fr; }
  .filters { border-right: 0; border-bottom: 1px solid var(--line); }
  .region-controls { grid-template-columns: 1fr; }
  .glossary-layout { grid-template-columns: 1fr; }
  .glossary-card .glossary { grid-template-columns: 1fr; gap: 3px; }
  .glossary-card .glossary dd + dt { margin-top: 9px; }
  .partner-header, .partner-controls { align-items: stretch; flex-direction: column; }
  .functional-summary, .functional-grid { grid-template-columns: 1fr; }
  .functional-controls { align-items: stretch; flex-direction: column; }
  .functional-controls label { min-width: 0; }
}

@media (max-width: 1450px) and (min-width: 901px) {
  .region-controls { grid-template-columns: minmax(280px, 1fr) repeat(2, minmax(130px, 170px)); }
}
