/* Scientific visualization surfaces. These are first-class page regions rather
   than generic cards, but still use the homepage typography, rules and palette. */

.research-toolbar {
  position: sticky;
  z-index: 45;
  top: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 5px var(--page-gutter);
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border-bottom: 1px solid var(--line-strong);
  backdrop-filter: blur(18px);
}
.research-toolbar-group { display: flex; align-items: center; gap: 6px; min-width: 0; }
.research-toolbar-title { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-editorial); font-size: 15px; font-weight: 600; }
.research-toolbar .icon-button { width: 34px; height: 34px; background: transparent; }
.research-toolbar .button-small { min-height: 34px; }
.toolbar-divider { width: 1px; height: 24px; margin: 0 4px; background: var(--line); }

.visualization-stage {
  position: relative;
  min-height: 580px;
  overflow: hidden;
  color: var(--ink-soft);
  background:
    linear-gradient(rgba(117, 83, 147, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(117, 83, 147, .04) 1px, transparent 1px),
    var(--surface-raised);
  background-size: 36px 36px;
  border-bottom: 1px solid var(--line-strong);
}
html[data-theme="dark"] .visualization-stage {
  background:
    linear-gradient(rgba(198, 169, 226, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(198, 169, 226, .03) 1px, transparent 1px),
    #0c0a15;
  background-size: 36px 36px;
}
.visualization-empty { min-height: 440px; display: grid; place-items: center; padding: 34px; text-align: center; }
.visualization-empty > div { max-width: 650px; }
.visualization-empty svg { width: 56px; height: 56px; margin: 0 auto 14px; color: var(--status-metadata); }
.visualization-empty h2 { margin: 0 0 8px; font-family: var(--font-editorial); font-size: 30px; font-weight: 500; }
.visualization-empty p { margin: 0; color: var(--muted); }

/* Circular genome map */
.genome-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 650px; }
.genome-main { min-width: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); }
.genome-canvas { min-height: 590px; display: grid; place-items: center; padding: 24px; overflow: auto; }
.genome-map {
  position: relative;
  width: min(560px, 77vh, 82vw);
  aspect-ratio: 1;
  transform: scale(var(--viewer-scale, 1));
  transform-origin: center;
  transition: transform 160ms ease;
}
.genome-map svg { width: 100%; height: 100%; overflow: visible; }
.genome-map .ring-muted { stroke: var(--lavender-300); }
.genome-map .ring-primary { stroke: var(--lavender-700); }
.genome-map .ring-gold { stroke: var(--gold-600); }
.genome-map .feature { cursor: pointer; transition: opacity 120ms ease, stroke-width 120ms ease; }
.genome-map .feature:hover { opacity: 1; stroke-width: 10; }
.genome-map .feature.is-selected { stroke: var(--focus); stroke-width: 12; filter: drop-shadow(0 0 4px color-mix(in srgb, var(--focus) 52%, transparent)); }
.genome-map text { fill: var(--ink-soft); font-family: var(--font-mono); font-size: 9px; }
.genome-map .center-title { fill: var(--ink); font-family: var(--font-editorial); font-size: 13px; font-weight: 600; }
.genome-map .center-subtitle { fill: var(--muted); font-family: var(--font-ui); font-size: 8px; }
.genome-inspector { padding: 18px; background: color-mix(in srgb, var(--surface) 94%, transparent); border-left: 1px solid var(--line-strong); }
.genome-inspector h2 { margin: 0 0 4px; font-family: var(--font-editorial); font-size: 20px; }
.inspector-section { padding: 15px 0; border-top: 1px solid var(--line); }
.inspector-section:first-of-type { margin-top: 12px; }
.inspector-section h3 { margin: 0 0 9px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.inspector-grid { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 7px 12px; font-size: 13px; }
.inspector-grid dt { color: var(--muted); }
.inspector-grid dd { margin: 0; color: var(--ink-soft); overflow-wrap: anywhere; }
.legend-list { display: grid; gap: 8px; }
.legend-item { display: flex; align-items: center; gap: 9px; color: var(--ink-soft); font-size: 12px; }
.legend-swatch { width: 26px; height: 8px; background: var(--lavender-700); border: 1px solid color-mix(in srgb, currentColor 35%, transparent); }
.legend-swatch.is-gold { background: var(--gold-600); }
.legend-swatch.is-moss { background: #71806a; }
.legend-swatch.is-blue { background: #5f8794; }

.linear-genome-section { padding: 24px 0 0; }
.linear-genome-scroll { overflow-x: auto; background: var(--surface-raised); border: 1px solid var(--line); }
.linear-genome {
  position: relative;
  width: 1400px;
  min-height: 330px;
  padding: 36px 36px 26px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.genome-ruler { position: relative; height: 42px; border-top: 1px solid var(--line-strong); }
.genome-ruler-tick { position: absolute; top: -5px; width: 1px; height: 12px; background: var(--line-strong); }
.genome-ruler-tick span { position: absolute; top: 14px; transform: translateX(-50%); color: var(--muted); }
.feature-track { position: relative; height: 54px; border-top: 1px solid var(--line); }
.feature-track-label { position: absolute; left: 0; top: 7px; color: var(--muted); font-family: var(--font-ui); font-size: 12px; }
.feature-arrow {
  position: absolute;
  top: 22px;
  height: 16px;
  min-width: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 7px;
  color: #fff;
  background: var(--lavender-700);
  font-size: 9px;
  clip-path: polygon(0 0, calc(100% - 7px) 0, 100% 50%, calc(100% - 7px) 100%, 0 100%);
}
.feature-arrow.reverse { clip-path: polygon(7px 0, 100% 0, 100% 100%, 7px 100%, 0 50%); background: var(--gold-700); }
.feature-arrow.is-selected { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Heatmap */
.heatmap-shell { overflow: auto; border: 1px solid var(--line); background: var(--surface-raised); }
.heatmap {
  min-width: 760px;
  display: grid;
  grid-template-columns: 180px repeat(5, minmax(84px, 1fr));
  font-size: 12px;
}
.heatmap-cell {
  min-height: 47px;
  display: grid;
  place-items: center;
  padding: 6px;
  color: var(--ink-soft);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.heatmap-cell.is-header { position: sticky; top: 0; z-index: 3; min-height: 42px; background: var(--surface-soft); font-weight: 700; }
.heatmap-cell.is-label { position: sticky; left: 0; z-index: 2; justify-items: start; background: var(--surface-raised); font-family: var(--font-mono); font-weight: 500; }
.heatmap-cell.heat-0 { background: #f7fafa; color: #29373b; }
.heatmap-cell.heat-1 { background: #e3eef0; color: #29373b; }
.heatmap-cell.heat-2 { background: #c6dce1; color: #26383d; }
.heatmap-cell.heat-3 { background: #9fc2ca; color: #203238; }
.heatmap-cell.heat-4 { background: #76a3ae; color: #12262b; }
.heatmap-cell.heat-5 { background: #527e89; color: #fff; }
.heatmap-cell.heat-6 { background: #354f59; color: #fff; }
.heatmap-cell.is-nd {
  color: var(--status-nd);
  background-color: #f4f0ec;
  background-image: repeating-linear-gradient(135deg, transparent 0 4px, rgba(107, 90, 79, .34) 4px 5px);
  font-weight: 700;
}
html[data-theme="dark"] .heatmap-cell.heat-0 { background: #1a2325; color: #e7f1f2; }
html[data-theme="dark"] .heatmap-cell.heat-1 { background: #243438; color: #e7f1f2; }
html[data-theme="dark"] .heatmap-cell.heat-2 { background: #31505a; color: #fff; }
html[data-theme="dark"] .heatmap-cell.is-nd { background-color: #28231f; }
.heatmap-legend { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; padding: 12px 0; color: var(--muted); font-size: 12px; }
.legend-gradient { width: 220px; height: 10px; background: linear-gradient(90deg, #f7fafa, #c6dce1, #76a3ae, #354f59); border: 1px solid var(--line-strong); }
.nd-legend { width: 22px; height: 16px; background-color: #f4f0ec; background-image: repeating-linear-gradient(135deg, transparent 0 4px, rgba(107, 90, 79, .34) 4px 5px); border: 1px solid #cfc4bb; }

/* Sequence viewer */
.sequence-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 18px; padding: 18px 0; border-bottom: 1px solid var(--line-strong); }
.sequence-header h1 { margin: 0; font-family: var(--font-mono); font-size: 26px; font-weight: 500; overflow-wrap: anywhere; }
.sequence-header p { margin: 6px 0 0; color: var(--muted); }
.sequence-viewer {
  height: min(640px, calc(100vh - 245px));
  overflow: auto;
  background: #111019;
  border: 1px solid var(--line-strong);
  color: #eee7f5;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.65;
  scrollbar-color: var(--lavender-500) #111019;
}
.sequence-line { min-width: 860px; display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 20px; padding: 0 18px; }
.sequence-line:nth-child(5n) { border-bottom: 1px solid rgba(255,255,255,.055); }
.sequence-coordinate { color: #b9a7c8; text-align: right; user-select: none; }
.sequence-bases { letter-spacing: .06em; white-space: pre; }
.sequence-bases mark { color: #17131d; background: var(--gold-300); }
.sequence-metadata { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--line); border-top: 0; }
.sequence-metadata div { padding: 12px 15px; border-right: 1px solid var(--line); }
.sequence-metadata div:last-child { border-right: 0; }
.sequence-metadata span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; }
.sequence-metadata strong { display: block; margin-top: 3px; color: var(--ink); font-size: 13px; }

/* Phylogenetic tree */
.tree-stage { min-height: calc(100vh - 108px); display: grid; grid-template-columns: minmax(0, 1fr) 300px; }
.tree-canvas { min-height: 690px; overflow: auto; padding: 30px; }
.tree-svg { width: 1050px; height: 660px; transform: scale(var(--viewer-scale, 1)); transform-origin: left top; transition: transform 160ms ease; }
.tree-svg .branch { fill: none; stroke: var(--ink-soft); stroke-width: 1.35; }
.tree-svg .branch-soft { stroke: var(--muted-faint); }
.tree-svg .taxon-label { fill: var(--ink); font-family: var(--font-editorial); font-size: 14px; font-style: italic; }
.tree-svg .clade-label { fill: var(--gold-700); font-family: var(--font-ui); font-size: 12px; font-weight: 700; }
.tree-svg .terminal { fill: var(--surface-raised); stroke: var(--lavender-700); stroke-width: 1.5; }
.tree-svg .selected-branch { stroke: var(--focus); stroke-width: 3; }
.tree-svg .selected-terminal { fill: var(--focus); stroke: var(--surface-raised); stroke-width: 2; }
.tree-svg .selected-label { fill: var(--focus); font-weight: 700; }
.tree-inspector { padding: 18px; background: var(--surface); border-left: 1px solid var(--line-strong); }
.tree-scale { width: 120px; display: flex; align-items: flex-end; gap: 7px; color: var(--muted); font-family: var(--font-mono); font-size: 10px; }
.tree-scale::before { content: ""; width: 70px; height: 8px; border-left: 1px solid currentColor; border-right: 1px solid currentColor; border-bottom: 1px solid currentColor; }

/* Alignment */
.alignment-stage { min-height: calc(100vh - 108px); background: #111019; color: #eee7f5; overflow: auto; }
.alignment-grid { min-width: 1180px; display: grid; grid-template-columns: 190px minmax(920px, 1fr); font-family: var(--font-mono); font-size: 13px; }
.alignment-id,
.alignment-sequence { min-height: 46px; display: flex; align-items: center; border-bottom: 1px solid rgba(255,255,255,.075); }
.alignment-id { position: sticky; left: 0; z-index: 2; padding: 0 15px; color: #d9cfe1; background: #16131f; border-right: 1px solid rgba(255,255,255,.11); }
.alignment-sequence { padding: 0 18px; letter-spacing: .07em; white-space: pre; }
.alignment-sequence .match { color: #f2d785; }
.alignment-sequence .variant { color: #a7d1dc; }
.alignment-ruler { color: #9d91a8; background: #0d0c13; }
.alignment-consensus { color: var(--gold-300); background: #17131f; }

/* BLAST */
.blast-results-layout { display: grid; grid-template-rows: auto minmax(260px, 40vh) minmax(330px, 1fr); min-height: calc(100vh - 108px); }
.blast-hit-table { overflow: auto; border-bottom: 1px solid var(--line-strong); }
.blast-alignment { overflow: auto; padding: 22px; color: #eee7f5; background: #111019; font-family: var(--font-mono); font-size: 13px; line-height: 1.6; }
.alignment-block { min-width: 880px; margin-bottom: 18px; }
.alignment-row { display: grid; grid-template-columns: 72px 82px minmax(0, 1fr) 82px; gap: 12px; }
.alignment-row .label { color: #b7a9c2; }
.alignment-row .coord { color: #d4c9db; text-align: right; }
.alignment-row .seq { letter-spacing: .04em; white-space: pre; }
.alignment-row .bars { color: var(--gold-300); }

@media (max-width: 1100px) {
  .genome-layout { grid-template-columns: 1fr; }
  .genome-inspector { border-left: 0; border-top: 1px solid var(--line-strong); }
  .tree-stage { grid-template-columns: 1fr; }
  .tree-inspector { border-left: 0; border-top: 1px solid var(--line-strong); }
}

@media (max-width: 760px) {
  .research-toolbar { padding-inline: 8px; overflow-x: auto; justify-content: flex-start; }
  .research-toolbar-title { max-width: 210px; }
  .research-toolbar .button span { display: none; }
  .visualization-stage { min-height: 430px; }
  .genome-canvas { min-height: 410px; padding: 8px; }
  .genome-map { width: 358px; max-width: none; }
  .linear-genome { width: 1050px; }
  .genome-inspector { padding: 14px; }
  .heatmap { grid-template-columns: 140px repeat(5, 64px); }
  .heatmap-cell { min-height: 42px; }
  .sequence-header { grid-template-columns: 1fr; }
  .sequence-viewer { height: 450px; font-size: 12px; }
  .sequence-metadata { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sequence-metadata div:nth-child(2) { border-right: 0; }
  .sequence-metadata div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .tree-canvas { min-height: 610px; padding: 16px; }
  .tree-svg { width: 980px; height: 640px; }
  .alignment-grid { grid-template-columns: 130px 900px; font-size: 12px; }
  .blast-results-layout { grid-template-rows: auto 330px minmax(360px, 1fr); }
}
