:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #66718a;
  --accent: #2d6cdf;
  --border: #e2e6ee;
  --warn-bg: #fff6e0;
  --warn-border: #f0c969;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
}

header, main, footer { max-width: 1100px; margin: 0 auto; padding: 0 20px; }

header { padding-top: 24px; }
h1 { margin: 0; font-size: 28px; display: flex; align-items: center; gap: 10px; }
.site-logo { width: 34px; height: 34px; border-radius: 7px; flex-shrink: 0; }
.tagline { margin: 4px 0 12px; color: var(--muted); }

.banner {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 14px;
  margin-bottom: 12px;
}

.hidden { display: none; }
.muted { color: var(--muted); font-size: 14px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin: 16px 0;
}

label, .ctl-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--muted);
}

textarea, select, input[type="number"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

textarea { resize: vertical; }

/* Inline checkbox control (e.g. Include IEA). */
.check-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 14px; font-weight: 400; color: var(--ink); margin-bottom: 0; cursor: pointer;
}
.check-label input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }
.control.disabled { opacity: 0.5; }
.control.disabled .check-label { cursor: not-allowed; }

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.toggle button {
  border: none;
  background: #fff;
  padding: 8px 16px;
  cursor: pointer;
  font-size: 14px;
}
.toggle button.active { background: var(--accent); color: #fff; }

/* Action rows: consistent gap and alignment (setup row + run/export row). */
.actions, .input-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.input-actions { margin: 10px 0 2px; }
.actions { margin-top: 12px; }

/* Secondary button is the default; .primary (Run) is the one accent button. */
button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 8px 15px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
}
button:not(.primary):not(:disabled):hover { border-color: var(--accent); color: var(--accent); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:not(:disabled):hover { background: #1b4fae; border-color: #1b4fae; }

.report { margin-top: 14px; font-size: 14px; }
.report .ok { color: #1c7a3d; }
.report .warn { color: #b9651b; }

.results-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  margin-bottom: 12px;
}
.rc-group { display: flex; align-items: center; gap: 6px; }
.rc-group label { margin-bottom: 0; }
.rc-group input[type="number"] { width: 72px; }
.rc-group select { width: auto; }
.rc-group .dash { color: var(--muted); }
.help { border-bottom: 1px dotted var(--muted); cursor: help; }

/* "?" helper badge next to control labels. */
.helpq {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; margin-left: 5px; border-radius: 50%;
  border: 1px solid var(--border); color: var(--muted);
  font-size: 10px; font-weight: 600; line-height: 1; cursor: help; vertical-align: middle;
}
.helpq { cursor: pointer; }
.helpq:hover { color: var(--accent); border-color: var(--accent); }
.helpq:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Tap/keyboard popover for the "?" helper badges (hover title is kept too). */
.help-pop {
  position: absolute; z-index: 1000; max-width: 280px;
  background: #1c2330; color: #fff; font-size: 12.5px; line-height: 1.45;
  padding: 9px 11px; border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}
.help-pop.hidden { display: none; }

/* Active-filter chips + clear control. */
.active-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.chip {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  background: #eef2fb; color: #33415c; font-size: 12px; border: 1px solid var(--border);
}
.link-btn {
  border: none; background: none; color: var(--accent); padding: 2px 4px;
  font-size: 13px; cursor: pointer; text-decoration: underline;
}
.link-btn:hover { color: #1b4fae; }

/* Horizontal scroll only inside the table, never the page. */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; font-size: 13px; min-width: 600px; width: 100%; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { cursor: pointer; user-select: none; white-space: nowrap; background: #fafbfd; position: relative; }
th[data-sort]:hover { color: var(--accent); }
td.num, th[data-sort="K"], th[data-sort="k"], th[data-sort="fold"],
th[data-sort="p"], th[data-sort="fdr"], th[data-sort="bonferroni"] { white-space: nowrap; }
td.ns { white-space: nowrap; }
/* Long text columns truncate with a tooltip instead of widening the table.
   Click the Term cell to expand/wrap the full name (hover title kept too). */
td.term { max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
td.term.expanded { white-space: normal; overflow: visible; }
td.term:hover { color: var(--accent); }
td.ns { max-width: 130px; overflow: hidden; text-overflow: ellipsis; }
/* Genes cell shows a short preview + "+N more"; full list is hidden until
   expanded (and is always in the title tooltip). Export keeps the full list. */
td.genes {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  max-width: 260px; white-space: nowrap;
}
td.genes .gene-full { display: none; }
td.genes.expanded { white-space: normal; }
td.genes.expanded .gene-preview { display: none; }
td.genes.expanded .gene-full { display: inline; }
td.genes .more {
  border: none; background: none; color: var(--accent); cursor: pointer;
  font-size: 11px; padding: 0 0 0 2px; white-space: nowrap;
}
td.genes .more:hover { text-decoration: underline; }
/* Redundancy collapse: a representative row carries a "+N similar" toggle in
   its Term cell; collapsed member rows are hidden until expanded. */
td.term .sim {
  border: none; background: none; color: var(--accent); cursor: pointer;
  font-size: 11px; padding: 0 0 0 6px; white-space: nowrap;
}
td.term .sim:hover { text-decoration: underline; }
tr.member-row.hidden { display: none; }
tr.member-row td { background: #f7f9fc; }
td.term.member { padding-left: 22px; color: var(--muted); }
tbody tr:hover { background: #f4f7fe; }

/* Sort direction indicator drawn as a small triangle (no glyph). */
th.sort-asc::after, th.sort-desc::after {
  content: ""; display: inline-block; margin-left: 6px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
}
th.sort-asc::after { border-bottom: 5px solid currentColor; }
th.sort-desc::after { border-top: 5px solid currentColor; }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }

/* Visualization panel. */
.viz-controls { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; margin-bottom: 10px; }
.viz-controls .toggle button { padding: 6px 14px; }
.viz-dl { margin-left: auto; }
.chart-wrap { width: 100%; overflow-x: auto; }
/* The chart is rendered at the panel width (clamped) in JS, so it fills wide
   screens; on narrow screens it keeps a minimum width and scrolls here. */
.chart-wrap svg { display: block; }
.empty-chart { color: var(--muted); padding: 16px 4px; }

.rc-search input[type="search"] { width: 150px; }

/* Auto-generated, copy-pasteable figure legend + methods text. */
.fig-text { margin-top: 16px; display: grid; gap: 12px; }
.fig-text.hidden { display: none; }
.fig-block { border: 1px solid var(--border); border-radius: 8px; background: #fafbfd; }
.fig-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 12px; border-bottom: 1px solid var(--border);
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.fig-body { margin: 0; padding: 11px 12px; font-size: 13px; line-height: 1.5; }

footer { padding: 18px 20px 40px; color: var(--muted); font-size: 13px; }
footer a { color: var(--accent); }

@media (max-width: 640px) {
  td.term { max-width: 200px; }
  td.genes { max-width: 160px; }
}
