:root {
  --bg: #f4f6f2;
  --panel: #ffffff;
  --panel2: #eef2ed;
  --line: #cbd4cc;
  --line-strong: #9dac9f;
  --text: #17251f;
  --muted: #637069;
  --accent: #237052;
  --accent2: #174d3a;
  --burgundy: #8d3547;
  --gold: #c99735;
  --sky: #5f8496;
  --cds: #26815c;
  --utr5: #d29a2f;
  --utr3: #be5d42;
  --intron: #6f7c75;
  --promoter: #8e5b91;
  --downstream: #537d92;
  --exon: #438994;
  --intergenic: #929b95;
  --shadow: 0 12px 32px rgba(23, 48, 37, .09);
}

* { box-sizing: border-box; }

html, body {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font-family: Inter, Aptos, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid rgba(201, 151, 53, .34);
  outline-offset: 2px;
}

.masthead {
  min-height: 158px;
  position: relative;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  overflow: hidden;
  padding: 26px clamp(20px, 4vw, 64px) 24px;
  color: #fff;
  background-color: #173b31;
  background-image: url("/static/assets/sorghum-field-v2.webp");
  background-position: center 58%;
  background-size: cover;
}

.masthead-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(13, 37, 29, .94) 0%, rgba(13, 37, 29, .82) 33%, rgba(13, 37, 29, .20) 67%, rgba(13, 37, 29, .11) 100%);
}

.brand, .status { position: relative; z-index: 1; }
.brand { min-width: 0; }
.brand-kicker {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
  color: #f2d58d;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.brand-kicker span { width: 18px; height: 1px; background: rgba(255,255,255,.44); }
.brand-kicker a { color: inherit; text-decoration: none; }
.brand-kicker a:hover { color: #fff; }
h1 { margin: 0; font-size: 38px; line-height: 1; font-weight: 660; }
h1, h2, th { letter-spacing: 0; }
.sub { margin-top: 10px; color: rgba(255,255,255,.82); font-size: 12px; }

.status {
  max-width: 520px;
  padding-bottom: 2px;
  color: rgba(255,255,255,.86);
  font-size: 11px;
  text-align: right;
  white-space: nowrap;
}
.status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #91d5a8;
  box-shadow: 0 0 0 3px rgba(145,213,168,.18);
}
.status .ok { color: #d7f0df; }
.status .bad { color: #ffd3c8; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  gap: 0;
  min-height: 52px;
  padding: 0 clamp(12px, 3.4vw, 54px);
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  box-shadow: 0 4px 14px rgba(23, 48, 37, .05);
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  min-height: 52px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 17px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.tab svg { width: 16px; height: 16px; flex: none; }
.tab:hover { color: var(--text); background: #f7f9f6; }
.tab.active { color: var(--accent2); border-bottom-color: var(--burgundy); }

.workspace {
  width: min(100%, 1680px);
  margin: 0 auto;
}
.tabpane { display: none; padding: 26px clamp(18px, 3.4vw, 54px) 48px; }
.tabpane.active { display: block; }

.searchbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 20px;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--line);
}
.primary-search {
  min-width: 320px;
  flex: 1;
  position: relative;
}
.primary-search > svg {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 18px;
  height: 18px;
  color: var(--burgundy);
  transform: translateY(-50%);
  pointer-events: none;
}
.searchbar input[type=text] {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px 10px 43px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  box-shadow: inset 0 1px 2px rgba(23,37,31,.04);
  font-size: 14px;
}
.searchbar input[type=text]::placeholder { color: #849088; }
.searchbar input[type=number] {
  width: 104px;
  min-height: 38px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}
.searchbar button, #geneSearchBtn, .genebtn, .snpbar button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--accent2);
  border-radius: 6px;
  background: var(--accent2);
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
}
#geneSearchBtn { min-height: 44px; padding-inline: 20px; }
.searchbar button svg, .genebtn svg, .snpbar button svg { width: 16px; height: 16px; }
.searchbar button:hover, #geneSearchBtn:hover, .genebtn:hover, .snpbar button:hover {
  border-color: var(--burgundy);
  background: var(--burgundy);
}
.searchbar button.secondary {
  border-color: var(--line-strong);
  background: transparent;
  color: var(--text);
}
.searchbar button.secondary:hover { border-color: var(--burgundy); color: var(--burgundy); background: #fff; }
.searchbar button:disabled { opacity: .42; cursor: not-allowed; }
.searchbar button:disabled:hover { border-color: var(--line-strong); background: transparent; color: var(--text); }
.flank {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: lowercase;
}
select {
  min-height: 38px;
  padding: 7px 32px 7px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

.results {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 390px), 1fr));
  gap: 8px;
  margin-bottom: 22px;
}
.gene-hit {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.gene-hit:hover { border-color: var(--burgundy); box-shadow: var(--shadow); transform: translateY(-1px); }
.gene-hit .gid { min-width: 0; overflow-wrap: anywhere; font-weight: 700; }
.gene-hit .loc { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.gene-hit .defline { flex-basis: 100%; color: var(--muted); font-size: 12px; line-height: 1.45; }
.sym {
  display: inline-block;
  padding: 2px 7px;
  border: 1px solid rgba(141,53,71,.28);
  border-radius: 999px;
  background: #f8edf0;
  color: var(--burgundy);
  font-size: 11px;
  font-weight: 700;
}

.hidden { display: none !important; }
.genehead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 20px;
  align-items: center;
  margin: 8px 0 10px;
  padding: 0 0 16px;
  border-bottom: 1px solid var(--line);
}
#geneTitle { min-width: 0; margin: 0; overflow-wrap: anywhere; font-size: 19px; line-height: 1.35; }
#geneTitle .sym { margin-left: 8px; vertical-align: 2px; }
.genefunc { grid-column: 1 / -1; color: var(--text); font-size: 12px; line-height: 1.5; }
.genemeta { grid-column: 1 / -1; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.genebtn { grid-row: 1; grid-column: 2; }
.warning {
  margin: 10px 0;
  padding: 9px 12px;
  border-left: 3px solid var(--gold);
  background: #fff8e8;
  color: #624b13;
  font-size: 12px;
}

.counts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin: 14px 0;
  color: var(--muted);
}
.countchip { display: flex; align-items: center; gap: 7px; padding: 2px 0; font-size: 11px; }
.countchip .dot { width: 8px; height: 8px; border-radius: 50%; }
.countchip b { color: var(--text); font-size: 12px; font-variant-numeric: tabular-nums; }

.track-wrap, .region-track {
  margin-bottom: 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: 0 5px 18px rgba(23,48,37,.045);
}
.track-wrap { padding: 12px; }
.region-track { margin: 8px 0 14px; padding: 10px; }
#geneTrack svg, .regtrack-svg { display: block; }
.lolli { cursor: pointer; }
.lolli:hover circle { stroke: var(--text); stroke-width: 1.5; }

.snptable-wrap {
  max-width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}
.snptable { width: 100%; border-collapse: collapse; font-size: 12px; }
.snptable th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 11px;
  border-bottom: 1px solid var(--line-strong);
  background: #e9eee9;
  color: #314139;
  cursor: pointer;
  font-size: 10px;
  font-weight: 750;
  text-align: left;
  text-transform: uppercase;
  user-select: none;
  white-space: nowrap;
}
.snptable th:hover { color: var(--burgundy); }
.snptable td { padding: 8px 11px; border-bottom: 1px solid #e1e6e1; font-variant-numeric: tabular-nums; }
.snptable tbody tr { cursor: pointer; }
.snptable tbody tr:nth-child(even) { background: #fafbfa; }
.snptable tbody tr:hover { background: #f3eee8; }
.rpill { display: inline-block; padding: 2px 7px; border-radius: 999px; color: #101713; font-size: 10px; font-weight: 700; }

.muted { margin: 7px 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.help { max-width: 900px; line-height: 1.7; }
.help h2 { margin: 24px 0 8px; padding-bottom: 7px; border-bottom: 1px solid var(--line); font-size: 15px; }
.help code { padding: 1px 5px; border-radius: 3px; background: #e8ece8; }
.help li { margin: 5px 0; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(12, 25, 19, .72);
  backdrop-filter: blur(3px);
}
.modal-box {
  position: relative;
  width: min(940px, 96vw);
  max-height: 90vh;
  overflow: auto;
  padding: 26px;
  border: 1px solid rgba(255,255,255,.34);
  border-radius: 7px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0,0,0,.28);
}
.modal-close {
  position: absolute;
  top: 11px;
  right: 11px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.modal-close:hover { background: var(--panel2); color: var(--text); }
.modal-close svg { width: 19px; height: 19px; }
.kv { display: grid; grid-template-columns: 140px minmax(0,1fr); gap: 5px 14px; margin: 12px 0; font-size: 12px; }
.kv .k { color: var(--muted); }
.gtbars { margin: 16px 0; }
.gtbar { display: flex; align-items: center; gap: 9px; margin: 4px 0; font-size: 11px; }
.gtbar .lab { width: 120px; color: var(--muted); }
.gtbar .bar { height: 13px; border-radius: 2px; background: var(--accent2); }
.grouptbl { width: 100%; margin-top: 7px; border-collapse: collapse; font-size: 11px; }
.grouptbl th, .grouptbl td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.spin { padding: 15px 0; color: var(--muted); }

.reg-genes { margin: 5px 0 16px; }
.reg-genes-head { margin-bottom: 8px; color: var(--text); font-size: 12px; }
.reg-genes-list { display: flex; flex-wrap: wrap; gap: 7px; }
.gene-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
  cursor: pointer;
  font-size: 11px;
}
.gene-chip:hover { border-color: var(--burgundy); color: var(--burgundy); }
.gene-chip .gid { font-weight: 700; }
.gene-chip .muted { margin: 0; }
.rt-gene { cursor: pointer; }
.rt-gene polygon { transition: fill .12s ease; }
.rt-gene:hover polygon { fill: var(--burgundy); }
.rt-gene .rt-lab { pointer-events: none; }
.snpbar { display: flex; align-items: center; gap: 12px; margin: 9px 0; flex-wrap: wrap; }
.snpbar button { min-height: 36px; padding: 7px 13px; border-color: var(--line-strong); background: transparent; color: var(--text); }
.snpbar button:hover { color: #fff; }
.snpbar button:disabled { opacity: .46; cursor: default; }

.bigmap, .snpmap {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel2);
  box-shadow: 0 5px 18px rgba(23,48,37,.045);
}
.bigmap { height: min(66vh, 650px); min-height: 480px; margin: 8px 0; }
.snpmap { height: 350px; margin: 4px 0 6px; }
.maplegend { display: flex; flex-wrap: wrap; gap: 9px 16px; margin: 10px 0; color: var(--muted); font-size: 11px; }
.maplegend .lgi { display: inline-flex; align-items: center; gap: 6px; }
.maplegend .dot { width: 10px; height: 10px; display: inline-block; border: 1px solid rgba(23,37,31,.45); border-radius: 50%; }
.leaflet-popup-content { font-size: 11px; line-height: 1.5; }

.genebtn { margin: 0; border-color: var(--line-strong); background: transparent; color: var(--text); }
.genebtn:hover { color: #fff; }
.snp-group-pies { margin: 16px 0; overflow-x: auto; }
.pielegend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 7px 0 3px; color: var(--muted); font-size: 11px; }
.pielegend .sw { width: 10px; height: 10px; display: inline-block; margin-right: 4px; border-radius: 2px; vertical-align: -1px; }
.gtinsight { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 3px 0 5px; color: var(--text); font-size: 11px; line-height: 1.5; }
.gtinsight .dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--burgundy); }
.gtmcap { margin: 7px 0 5px; color: var(--muted); font-size: 10px; }
.gtmatrix { margin: 5px 0; border-collapse: collapse; }
.gtmatrix th { padding: 5px 8px; color: var(--text); font-size: 11px; font-weight: 650; text-align: center; }
.gtmatrix th.rowlab { text-align: right; }
.gtmatrix th.margh, .gtmatrix tr.totrow th.rowlab { color: var(--muted); }
.gtmatrix td { width: 76px; height: 76px; padding: 2px; border: 1px solid var(--line); text-align: center; vertical-align: middle; }
.gtmatrix .gpie { display: flex; align-items: center; justify-content: center; transition: transform .12s ease; }
.gtmatrix td:hover .gpie { transform: scale(1.1); }
.gtmatrix .cn { margin-top: 1px; color: var(--muted); font-size: 10px; line-height: 1; }
.gtmatrix td .z { color: var(--muted); opacity: .35; }
.gtmatrix td.marg { background: #eef2ee; }
.gtmatrix td.corner { background: #e4e0d6; }
.gtmatrix tr:hover td { background: #f7f3ed; }
.gtmatrix tr:hover td.corner { background: #ddd6c7; }
.gtmatrix tr.totrow td { border-top: 2px solid var(--burgundy); }

.regiondist { width: 100%; margin: 8px 0 3px; border-collapse: collapse; font-size: 11px; }
.regiondist th, .regiondist td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.regiondist thead th { position: sticky; top: 0; z-index: 1; background: var(--panel2); white-space: nowrap; }
.regiondist th.rowlab { max-width: 240px; font-weight: 650; }
.regiondist td.countrypie { width: 46px; padding-block: 2px; }
.regiondist .countrycounts { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.regiondist tr.totrow th, .regiondist tr.totrow td { border-top: 2px solid var(--burgundy); font-weight: 650; }

@media (max-width: 800px) {
  .masthead { min-height: 170px; align-items: flex-start; flex-direction: column; justify-content: flex-end; gap: 14px; padding: 24px 18px 20px; background-position: 62% center; }
  .masthead-shade { background: linear-gradient(90deg, rgba(13,37,29,.94), rgba(13,37,29,.58)); }
  .brand-kicker { flex-wrap: wrap; }
  h1 { font-size: 30px; }
  .sub { max-width: 320px; line-height: 1.45; }
  .status { max-width: 100%; padding: 0; text-align: left; white-space: normal; line-height: 1.5; }
  .tabs { padding: 0 6px; }
  .tab { min-height: 50px; padding: 0 12px; }
  .tabpane { padding: 20px 14px 38px; }
  .primary-search { min-width: 100%; width: 100%; }
  .searchbar { align-items: center; }
  #geneSearchBtn { flex: 1; }
  .genehead { grid-template-columns: minmax(0,1fr); }
  .genebtn { grid-row: auto; grid-column: 1; justify-self: start; }
  .modal { padding: 8px; }
  .modal-box { width: 100%; padding: 22px 13px; }
  .kv { grid-template-columns: 110px minmax(0,1fr); }
  .bigmap { height: 58vh; min-height: 430px; }
  .snpmap { height: 360px; }
  .regiondist th, .regiondist td { padding: 5px 6px; }
}

@media (max-width: 460px) {
  .tab span { display: none; }
  .tab { width: 48px; justify-content: center; padding: 0; }
  .tab svg { width: 18px; height: 18px; }
  .tabs { justify-content: space-around; overflow: visible; }
  .searchbar button, #geneSearchBtn { min-height: 42px; }
  .flank { width: 100%; justify-content: space-between; }
  .flank input, .flank select { flex: 1; }
  .results { grid-template-columns: minmax(0,1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
