/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.hidden { display: none !important; }

:root {
  --bg: #1a1a1a;
  --surface: #242424;
  --surface2: #2e2e2e;
  --border: #3a3a3a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #4a9eff;
  --toolbar-h: 44px;
  --gene-tree-w: 120px;
  --array-tree-h: 100px;
  --label-w: 160px;
  --label-h: 80px;
  --viewer-gap: 14px;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 13px;
}

/* ===== Toolbar ===== */
#toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--toolbar-h);
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

.toolbar-brand {
  flex-shrink: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.toolbar-section {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-section + .toolbar-section {
  border-left: 1px solid var(--border);
  padding-left: 12px;
}

.ctrl-label {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.ctrl-label select,
.ctrl-label input[type="range"] {
  margin: 0;
}

#contrast-display {
  width: 28px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.zoom-buttons {
  display: flex;
  gap: 3px;
}

.btn {
  padding: 4px 10px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.btn:hover { background: #3a3a3a; }
.btn:active { background: #444; }

.btn-sm {
  padding: 3px 7px;
  font-size: 11px;
}

select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  padding: 3px 6px;
  font-size: 12px;
}

input[type="range"] {
  width: 90px;
  accent-color: var(--accent);
}

#status-bar {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ===== Main viewer area ===== */
#viewer-container {
  position: relative;
  width: 100%;
  height: calc(100vh - var(--toolbar-h));
  overflow: hidden;
}

.viewer-workspace {
  display: grid;
  gap: var(--viewer-gap);
  width: 100%;
  height: 100%;
  padding: 12px;
  /* Default: only the main heatmap */
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
  grid-template-areas: "main";
}

/* Selection open, no protein */
.viewer-workspace.show-detail {
  grid-template-columns: 2fr 2fr 1fr;
  grid-template-areas: "main detail annotation";
}

/* Protein visible, no selection */
.viewer-workspace.has-protein {
  grid-template-columns: 2fr 2fr 1fr;
  grid-template-areas: "main protein protein";
}

/* Protein visible + selection open */
.viewer-workspace.has-protein.show-detail {
  grid-template-columns: 2fr 2fr 1fr;
  grid-template-rows: 1fr 1fr;
  grid-template-areas:
    "main protein  protein"
    "main detail   annotation";
}

.viewer-pane-primary { grid-area: main; }
#protein-pane        { grid-area: protein; }
#detail-pane         { grid-area: detail; }
#annotation-pane     { grid-area: annotation; }

.viewer-pane {
  min-width: 0;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
}

.viewer-pane-primary {
  overflow: hidden;
}

.detail-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.detail-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0));
}

.detail-pane-kicker {
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-pane-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.detail-grid {
  min-height: 0;
}

.annotation-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.protein-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.protein-pane-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.protein-message {
  max-width: 220px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.5;
  text-align: right;
}

.protein-viewport {
  position: relative;
  min-height: 0;
}

.protein-viewport .msp-plugin {
  inset: 0;
}

.annotation-pane-header {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0));
}

.annotation-list {
  overflow: auto;
  padding: 8px;
}

.annotation-item {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  cursor: pointer;
  transition: background 120ms ease;
}

.annotation-item:hover {
  background: rgba(255,255,255,0.04);
}

.annotation-item:last-child {
  border-bottom: 0;
}

.annotation-item.is-active {
  background: rgba(255, 200, 0, 0.12);
  box-shadow: inset 2px 0 0 rgba(255, 200, 0, 0.7);
}

.annotation-item.has-mod-color {
  border-left: 4px solid var(--annotation-mod-color, transparent);
  padding-left: 8px;
}

.annotation-gene {
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
}

.annotation-name {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.4;
  margin-top: 2px;
}

.annotation-meta,
.annotation-sequence {
  color: var(--text-muted);
  font-size: 10px;
  line-height: 1.4;
  margin-top: 4px;
}

.annotation-mod {
  font-size: 11px;
  font-weight: 600;
  color: var(--annotation-mod-color, var(--text));
}

.detail-selection-band {
  background: rgba(255, 200, 0, 0.22);
}

/* ===== Drop overlay ===== */
.drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(74, 158, 255, 0.15);
  border: 3px dashed var(--accent);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.drop-message {
  font-size: 20px;
  font-weight: 600;
  color: var(--accent);
}

/* ===== Empty state ===== */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  pointer-events: none;
}

.empty-icon {
  font-size: 48px;
  opacity: 0.3;
}

.empty-state h2 {
  font-size: 22px;
  color: var(--text);
  font-weight: 600;
}

.empty-state p {
  font-size: 14px;
  text-align: center;
  line-height: 1.5;
}

.empty-state .hint {
  font-size: 12px;
  color: var(--text-muted);
}

/* ===== Viewer grid =====
   Columns: gene-labels (left) | gene-tree | heatmap
   Rows:    sample-labels (top) | array-tree | heatmap-row
*/
.viewer-grid {
  display: grid;
  width: 100%;
  height: 100%;
  grid-template-columns: var(--label-w) var(--gene-tree-w) 1fr;
  grid-template-rows: var(--label-h) var(--array-tree-h) 1fr;
  grid-template-areas:
    "corner        corner2      sample-labels"
    "corner3       corner4      array-tree"
    "gene-labels   gene-tree    heatmap";
}

/* .hidden is defined globally at the top of this file */

.cell-corner        { grid-area: corner; }
.cell-corner-tr     { grid-area: corner2; }
.cell-corner2       { grid-area: corner3; }
.cell-corner-tr2    { grid-area: corner4; }
.cell-array-tree    { grid-area: array-tree; overflow: hidden; }
.cell-gene-tree     { grid-area: gene-tree; overflow: hidden; }
.cell-heatmap       { grid-area: heatmap; overflow: hidden; position: relative; }
.cell-gene-labels   { grid-area: gene-labels; overflow: hidden; position: relative; }
.cell-sample-labels { grid-area: sample-labels; overflow: hidden; position: relative; }

@media (max-width: 1100px) {
  .viewer-workspace,
  .viewer-workspace.show-detail,
  .viewer-workspace.has-protein,
  .viewer-workspace.has-protein.show-detail {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 1fr) minmax(260px, 0.8fr) minmax(260px, 0.8fr) minmax(180px, 0.6fr);
    grid-template-areas:
      "main"
      "protein"
      "detail"
      "annotation";
  }

  .protein-pane-header {
    flex-direction: column;
  }

  .protein-message {
    max-width: none;
    text-align: left;
  }
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ===== Labels ===== */
.gene-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.gene-label, .sample-label {
  position: absolute;
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
  pointer-events: auto;
  cursor: default;
}

.gene-label {
  left: 4px;
  right: 4px;
  transform: translateY(-50%);
  font-weight: 600;
}

.sample-label {
  /* Anchor at the bottom of the label cell (closest to heatmap), rotate upward */
  bottom: 2px;
  transform-origin: left bottom;
  transform: rotate(-65deg);
  max-width: 160px;
}

.sample-labels {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ===== Tooltip ===== */
.tooltip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  z-index: 1000;
  max-width: 280px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* .tooltip visibility handled by global .hidden class */

.tooltip-gene { font-weight: 600; color: var(--text); }
.tooltip-sample { color: var(--text-muted); }
.tooltip-value { font-variant-numeric: tabular-nums; }
.tooltip-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}

/* ===== Selection highlight ===== */
.selection-band {
  position: absolute;
  pointer-events: none;
  background: rgba(255, 200, 0, 0.15);
}
.selection-band[data-axis="gene"] {
  left: 0; right: 0;
  border-top: 1px solid rgba(255, 200, 0, 0.6);
  border-bottom: 1px solid rgba(255, 200, 0, 0.6);
}
.selection-band[data-axis="sample"] {
  top: 0; bottom: 0;
  border-left: 1px solid rgba(255, 200, 0, 0.6);
  border-right: 1px solid rgba(255, 200, 0, 0.6);
}

/* Drag-to-select cursors on label panels */
.cell-gene-labels { cursor: ns-resize; }
.cell-sample-labels { cursor: ew-resize; }

/* ===== Scrollbar style ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
