:root {
  --fg: #111;
  --muted: #666;
  --line: #e5e5e5;
  --bg: #fff;
  --accent: #111;
  --accent-fg: #fff;
  --panel-w: 340px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px 0;
  border-bottom: 1px solid var(--line);
  gap: 24px;
  flex-wrap: wrap;
}

.title h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.title p {
  margin: 2px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

/* Tab nav */
nav.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: -1px; /* pull tabs into the bottom border */
}
.tab {
  background: transparent;
  border: 1px solid transparent;
  border-bottom: 0;
  padding: 8px 14px;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  border-radius: 6px 6px 0 0;
}
.tab:hover { color: var(--fg); }
.tab.active {
  color: var(--fg);
  background: var(--bg);
  border-color: var(--line);
  border-bottom-color: var(--bg);
  font-weight: 600;
}

/* Views */
main {
  position: relative;
  flex: 1;
  min-height: 0;
}
.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.view[hidden] { display: none !important; }

.view-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.view-body {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
}

#plot {
  flex: 1;
  position: relative;
  min-width: 0;
}

/* Clustermaps: two subviews (pert + gene) stacked, mode toggle at top */
.cmap-mode-row { flex: none; }
.cmap-subview {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.cmap-subview[hidden] { display: none; }

/* Clustermap: main + side-by-side panes */
.cmap-body { padding: 0; }
.cmap-pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.cmap-pane:first-of-type { flex: 2.2; border-right: 1px solid var(--line); }
.cmap-pane.cmap-pane-narrow { flex: 1; }
.cmap-title {
  padding: 8px 12px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  border-bottom: 1px solid var(--line);
  letter-spacing: 0.01em;
  flex: none;
}
.cmap-plot { flex: 1; min-height: 0; }
@media (max-width: 900px) {
  .cmap-body { flex-direction: column; }
  .cmap-pane:first-of-type, .cmap-pane.cmap-pane-narrow {
    height: 50%; flex: none;
  }
  .cmap-pane:first-of-type { border-right: 0; border-bottom: 1px solid var(--line); }
}

.hint {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  pointer-events: none;
  z-index: 5;
}

/* Inputs / buttons */
input[type="search"] {
  width: 240px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  outline: none;
}
input[type="search"]:focus { border-color: var(--fg); }

.toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.seg {
  background: transparent;
  border: 0;
  padding: 7px 12px;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.seg.active {
  background: var(--accent);
  color: var(--accent-fg);
}
.seg + .seg { border-left: 1px solid var(--line); }

#reset {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  color: var(--fg);
  cursor: pointer;
}
#reset:hover { border-color: var(--fg); }

/* Combo (search + suggestions) */
.combo {
  position: relative;
}
.suggest {
  position: absolute;
  top: 100%;
  left: 0;
  width: 100%;
  margin: 2px 0 0;
  padding: 4px 0;
  list-style: none;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.06);
  max-height: 280px;
  overflow: auto;
  z-index: 20;
}
.suggest li {
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg);
}
.suggest li.active,
.suggest li:hover { background: #f3f3f3; }
.suggest li mark {
  background: transparent;
  color: var(--fg);
  font-weight: 600;
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

/* Side panel */
.panel {
  width: 0;
  border-left: 0 solid var(--line);
  background: var(--bg);
  overflow: hidden;
  transition: width .18s ease-out, border-left-width 0s .18s;
  position: relative;
}
.panel.open {
  width: var(--panel-w);
  border-left-width: 1px;
  transition: width .22s ease-out, border-left-width 0s;
}
.panel-close {
  position: absolute;
  top: 6px; right: 6px;
  width: 28px; height: 28px;
  border: 0;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border-radius: 4px;
}
.panel-close:hover { background: #f3f3f3; color: var(--fg); }
.panel-body {
  padding: 18px 20px 24px;
  overflow: auto;
  height: 100%;
  width: var(--panel-w);
}
.panel-body h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.panel-body h3 {
  margin: 18px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kv {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 2px 10px;
  margin: 8px 0 2px;
  font-size: 13px;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; color: var(--fg); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.muted-tag {
  margin-left: 6px;
  font-weight: 400;
  font-size: 10px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

table.degs {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
table.degs td {
  padding: 2px 6px;
  border-bottom: 1px solid #f1f1f1;
}
table.degs td:first-child  { color: var(--fg); }
table.degs td:last-child   { color: var(--muted); text-align: right; }
table.degs tr:last-child td { border-bottom: 0; }

ol.neighbors {
  list-style: none;
  margin: 6px 0;
  padding: 0;
  font-size: 13px;
}
ol.neighbors li {
  padding: 3px 0;
  border-bottom: 1px solid #f1f1f1;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
ol.neighbors li:last-child { border-bottom: 0; }
ol.neighbors li .g {
  cursor: pointer;
  color: var(--fg);
}
ol.neighbors li .g:hover { text-decoration: underline; }
ol.neighbors li .d { color: var(--muted); font-variant-numeric: tabular-nums; }

button.mini {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 8px;
  font: inherit;
  font-size: 11px;
  color: var(--muted);
  text-transform: none;
  letter-spacing: normal;
  cursor: pointer;
}
button.mini:hover { border-color: var(--fg); color: var(--fg); }
button.mini.on    { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

.placeholder {
  margin: auto;
  max-width: 480px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  font-size: 14px;
}
.placeholder strong { color: var(--fg); }

/* Gene query layout */
.gq-body { display: block; padding: 18px 24px; overflow: auto; }
.gq-hist { width: 100%; height: 240px; margin-top: 14px; }
.gq-body h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.gq-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 16px;
}
@media (max-width: 720px) {
  .gq-cols { grid-template-columns: 1fr; }
}

/* Clusters layout */
.cl-body { display: flex; flex-direction: row; overflow: hidden; }
.cl-list {
  width: 280px;
  min-width: 240px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  background: #fafafa;
}
.cl-row {
  display: flex; align-items: baseline; gap: 6px;
  padding: 8px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer; font-size: 13px; line-height: 1.3;
}
.cl-row:hover { background: #f0f0f0; }
.cl-row.active { background: #e8f0fe; }
.cl-row .cid { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 28px; }
.cl-row .clbl { flex: 1; color: var(--fg); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.cl-row .cn { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.cl-main { flex: 1; padding: 18px 24px; overflow: auto; }
.cl-main h2 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.cl-members { margin-top: 22px; }
.cl-members h3 { margin: 0 0 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-block; padding: 3px 9px; border-radius: 10px;
  background: #f2f2f2; border: 1px solid var(--line);
  font-size: 12px; color: var(--fg);
  cursor: pointer; text-decoration: none;
  font-variant-numeric: tabular-nums;
}
.chip:hover { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
@media (max-width: 720px) {
  .cl-body { flex-direction: column; }
  .cl-list { width: 100%; max-height: 40vh; border-right: 0; border-bottom: 1px solid var(--line); }
}

/* Home / overview layout */
#view-home { overflow: auto; }
.home-body {
  padding: 28px 32px 48px;
  max-width: 860px;
  margin: 0 auto;
  width: 100%;
  line-height: 1.55;
}
.home-body h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.home-body .lede {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
}
.home-section { margin-top: 22px; }
.home-section h3 {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.home-section p {
  margin: 0 0 8px;
  font-size: 14px;
  text-align: justify;
}
.home-section p.cite { text-align: left; color: var(--muted); }
.home-section a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}
.home-section a:hover { text-decoration-color: var(--fg); }
.home-links { margin: 0; padding: 0 0 0 18px; font-size: 14px; }
.home-links li { margin: 4px 0; }
.home-links code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  padding: 1px 5px;
  background: #f3f3f3;
  border: 1px solid var(--line);
  border-radius: 4px;
}
.home-tabs {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 4px 14px;
  margin: 4px 0 0;
  font-size: 14px;
}
.home-tabs dt { font-weight: 600; }
.home-tabs dt a {
  color: var(--fg);
  text-decoration: none;
}
.home-tabs dt a:hover { text-decoration: underline; }
.home-tabs dd { margin: 0 0 10px; color: var(--fg); }
@media (max-width: 720px) {
  .home-tabs { grid-template-columns: 1fr; }
  .home-tabs dd { margin-bottom: 14px; }
  .home-body { padding: 20px 18px 32px; }
}

/* Gene panel layout */
.pn-body { display: flex; flex-direction: column; padding: 14px 24px 24px; overflow: auto; gap: 12px; }
.pn-pickers {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  align-items: start;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.pn-picker { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.pn-pick-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.pn-pick-label .muted-tag { margin-left: 4px; font-weight: 400; }
.pn-body .chip-row { flex-wrap: wrap; gap: 6px; min-height: 28px; }
.pn-body .chip { padding-right: 4px; }
.pn-body .chip .x {
  display: inline-block; margin-left: 6px; padding: 0 4px;
  color: var(--muted); cursor: pointer;
}
.pn-body .chip:hover .x { color: #d62728; }
.pn-plot { width: 100%; min-height: 260px; }
@media (max-width: 720px) {
  .pn-pickers { grid-template-columns: 1fr; }
}

footer {
  padding: 10px 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}
footer a {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 2px;
}
footer a:hover { color: var(--fg); }

@media (max-width: 900px) {
  .view-body { flex-direction: column; }
  .panel.open {
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 50vh;
  }
  .panel-body { width: 100%; }
}
@media (max-width: 600px) {
  header { padding: 10px 14px 0; }
  .view-controls { padding: 10px 14px; }
  input[type="search"] { width: 100%; }
}
