:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9dee6;
  --text: #1c2430;
  --muted: #667385;
  --accent: #2f6fed;
  --active: #1f7a66;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 220px;
  cursor: default;
}
.logo {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(47, 111, 237, 0.22);
}
.logo-mark { width: 46px; height: 46px; display: block; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: -0.02em; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.brand p sup, .legend-item sup {
  font-size: 0.68em;
  line-height: 0;
  font-weight: 600;
}
.brand-tooltip {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  width: min(440px, calc(100vw - 40px));
  padding: 12px 14px;
  background: #1c2430;
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(28, 36, 48, 0.22);
  opacity: 0;
  visibility: hidden;
  transform: translateY(4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s;
  z-index: 40;
  pointer-events: none;
}
.brand-tooltip::before {
  content: "";
  position: absolute;
  top: -6px;
  left: 18px;
  border: 6px solid transparent;
  border-top: 0;
  border-bottom-color: #1c2430;
}
.brand-tooltip strong {
  display: block;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
}
.brand-tooltip span {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.45;
  color: #c9d2de;
  font-weight: 400;
}
.brand:hover .brand-tooltip,
.brand:focus-within .brand-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.stats { color: var(--muted); font-size: 13px; white-space: nowrap; }

.tabs { display: flex; gap: 8px; }
.tabs button, .mode-toggle button, .sidebar button, .sidebar select, .sidebar input {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}
.tabs button.active, .mode-toggle button.active {
  background: var(--active);
  color: #fff;
  border-color: var(--active);
  font-weight: 700;
}
.tabs button { cursor: pointer; }

.layout { display: grid; grid-template-columns: 280px 1fr; height: calc(100% - 70px); }
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 16px 16px 12px;
  overflow: auto;
}
.copyright {
  position: sticky;
  bottom: 0;
  margin: auto 0 0;
  padding: 10px 0 2px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0), #fff 10px);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}
.sidebar h2 {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 14px 0 8px;
}
.sidebar h2:first-child { margin-top: 0; }
.sidebar section { margin-bottom: 8px; }
.sidebar select, .sidebar input, .sidebar button { width: 100%; }
.sidebar label { display: block; font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#gene-go {
  margin-top: 8px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.legend-wrap { max-height: 280px; overflow: auto; margin-top: 12px; }
#legend { display: grid; gap: 6px; font-size: 13px; }
.legend-item { display: flex; gap: 8px; align-items: center; }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 12px; }

.canvas-wrap { min-width: 0; min-height: 0; height: 100%; overflow: hidden; background: var(--bg); }
.view { height: 100%; }
.view[hidden] { display: none !important; }
.view.stack { display: grid; grid-template-rows: 1.15fr 0.95fr; }
.plot-fill, .plot-top, .plot-bottom { width: 100%; height: 100%; min-height: 240px; }
.split-row { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr); min-height: 0; }
.split-row.equal { grid-template-columns: 1fr 1fr; }
.split-row:has(#plot-clinical-fc[hidden]) { grid-template-columns: 1fr; }
#plot-clinical-fc, #plot-expr-subset, #plot-gsea-subset { background: #fff; border-left: 1px solid var(--line); }
#pathway-go {
  margin-top: 8px;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { flex-wrap: wrap; }
  .view.stack { grid-template-rows: 420px 360px; }
}
