/* run.css — the Runs list, the run view (progress and log, summary, figures, tables, spatial viewer, configuration)
   and the help pages. Builds on the tokens and components of app.css. */

:root {
  /* figures are drawn on white paper (as printed) in both themes */
  --fg-paper: #ffffff;
}


/* ---------------------------------------------------------------- runs list */
.runs-filters { border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
.runs-filters .select { width: auto; min-width: 190px; }
.runs-table td { vertical-align: middle; }
.runs-name { min-width: 190px; }
.runs-name a { font-weight: 600; }
.runs-name .mono { white-space: nowrap; }
.runs-table td:nth-child(3) { min-width: 140px; }
.runs-progress-cell { min-width: 190px; max-width: 340px; }
.runs-progress { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.runs-progress .progress { height: 5px; }
.runs-step { font-size: 13px; color: var(--text-muted); max-width: 320px; }
.runs-error { display: inline-block; max-width: 320px; vertical-align: bottom; color: var(--danger); font-size: 13.5px; }
/* last column: Cancel on an active run, then the row's "Run actions" menu (revealed on hover or focus) */
.runs-actions-cell { width: 1%; white-space: nowrap; }
.runs-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }

/* ---------------------------------------------------------------- run header and layout */
.run-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.run-title h1 { overflow-wrap: anywhere; }
.run-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; }
.run-header .actions { flex-wrap: nowrap; }
@media (max-width: 560px) { .run-header .actions { flex-wrap: wrap; } }
.run-body { min-height: 240px; }
.run-toast { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------------------------------------------------------------- progress tab */
.run-headline { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.run-progress { height: 10px; border-radius: 5px; }
.run-progress.is-succeeded > .bar { background: var(--success); }
.run-progress.is-failed > .bar, .run-progress.is-interrupted > .bar { background: var(--danger); }
.run-progress.is-cancelled > .bar { background: var(--warning); }
.run-times { display: flex; flex-wrap: wrap; gap: 4px 18px; font-variant-numeric: tabular-nums; }

.run-steps { list-style: none; margin: 0; padding: 0; }
.run-step { display: flex; align-items: flex-start; gap: 10px; padding: 8px 18px; border-bottom: 1px solid var(--border); }
.run-step:last-child { border-bottom: 0; }
.run-step.is-running { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }
.run-step-icon {
  width: 20px; height: 20px; flex: 0 0 20px; margin-top: 1px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text-faint);
}
.run-step.is-done .run-step-icon { color: var(--success); background: var(--success-soft); }
.run-step.is-failed .run-step-icon { color: var(--danger); background: var(--danger-soft); }
.run-step.is-running .run-step-icon { color: var(--accent); }
.run-step-icon .spinner { width: 15px; height: 15px; border-width: 2px; }
.run-ring { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--border-strong); }
.run-dash { width: 10px; height: 2px; border-radius: 1px; background: var(--text-faint); }
.run-step-main { flex: 1 1 auto; min-width: 0; }
.run-step-label { overflow-wrap: anywhere; }
.run-step.is-running .run-step-label { font-weight: 600; }
.run-step.is-pending .run-step-label, .run-step.is-skipped .run-step-label { color: var(--text-muted); }
.run-step-reason { font-size: 13px; color: var(--text-faint); overflow-wrap: anywhere; }
.run-step.is-failed .run-step-reason { color: var(--danger); }
.run-step-time { flex: 0 0 auto; font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.run-failure .banner-body > * + * { margin-top: 8px; }
.run-pre {
  margin: 0; padding: 8px 10px; max-height: 340px; overflow: auto;
  background: var(--log-bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: 12px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word;
}
.run-error { color: var(--danger); }
.run-traceback > summary { cursor: pointer; font-weight: 600; }
.run-traceback-body { position: relative; margin-top: 6px; }
.run-traceback-body > .btn { position: absolute; top: 6px; right: 18px; z-index: 1; }
.run-warning-list { margin: 0; padding-left: 18px; font-size: 14px; }
.run-warning-list li { margin: 3px 0; overflow-wrap: anywhere; }
.run-warnings details > summary { cursor: pointer; color: var(--accent-text); margin-top: 6px; font-size: 14px; }

/* log */
.lv-body { position: relative; }
.lv .lv-log { min-height: 260px; max-height: 560px; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.lv-empty { position: absolute; left: 16px; bottom: 14px; color: var(--text-faint); font: 12px var(--mono); pointer-events: none; }
.lv-trim {
  display: flex; align-items: center; gap: 6px; padding: 6px 14px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); color: var(--text-muted); font-size: 13px;
}
.lv-jump { position: absolute; right: 18px; bottom: 14px; box-shadow: var(--shadow); }
.lv-meta { font-variant-numeric: tabular-nums; }
.lv.lv-live .lv-meta::before {
  content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%;
  background: var(--success); vertical-align: 1px; animation: pulse 1.4s ease-in-out infinite;
}
.lv-error { color: var(--warning); font-size: 13px; }

/* ---------------------------------------------------------------- summary tab */
.sum-sections { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.sum-section {
  display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 14px;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2);
}
.sum-section-head { display: flex; align-items: center; gap: 8px; min-height: 24px; }
.sum-section-head h3 { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.sum-funnel { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.sum-funnel-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.sum-funnel-bar { height: 6px; margin-top: 3px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.sum-funnel-bar > span { display: block; height: 100%; border-radius: 3px; }
.sum-section-kv { padding-top: 8px; border-top: 1px solid var(--border); font-size: 13.5px; }
.sum-section-kv dd { text-align: right; font-variant-numeric: tabular-nums; }
.sum-section-metrics { margin-top: 16px; }
.sum-groups { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 440px), 1fr)); align-items: start; }
.sum-group.wide { grid-column: 1 / -1; }
.sum-extra { align-items: start; }
.sum-metrics { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.sum-metrics .metric { background: var(--surface-2); border-color: transparent; }
.sum-metrics .metric-value { overflow-wrap: anywhere; }
.sum-timings .sum-bar-cell { width: 38%; min-width: 110px; vertical-align: middle; }
.sum-bar { height: 8px; border-radius: 4px; background: var(--surface-3); overflow: hidden; }
.sum-bar > span { display: block; height: 100%; border-radius: 4px; background: var(--accent); }
.sum-env { grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr); }
/* "N warnings" in the Overview card: a quiet pointer to the warnings card, in the warning color */
.btn.ghost.sum-warn-link, .btn.ghost.sum-warn-link:hover:not(:disabled) { color: var(--warning); }
@media (max-width: 700px) { .sum-env { grid-template-columns: max-content minmax(0, 1fr); } }

/* ---------------------------------------------------------------- configuration tab */
.run-json {
  margin: 0; padding: 14px 18px; max-height: 70vh; overflow: auto;
  background: var(--log-bg); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  font: 12px/1.55 var(--mono); white-space: pre;
}
.run-json .j-key { color: var(--accent-text); }
.run-json .j-str { color: var(--success); }
.run-json .j-num { color: var(--info); }
.run-json .j-lit { color: var(--warning); font-weight: 600; }

/* ---------------------------------------------------------------- figures */
.fg { display: flex; flex-direction: column; gap: 24px; }
/* top line: how many figures and how to get them, with "Download all" at the right */
.fg-bar { display: flex; align-items: center; gap: 8px 16px; flex-wrap: wrap; margin-bottom: -8px; }
.fg-bar-text { flex: 1 1 320px; margin: 0; font-size: 14px; color: var(--text-muted); }
.fg-bar-actions { display: flex; align-items: center; gap: 8px; }
.fg-group-title { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.fg-group-count {
  padding: 0 7px; border-radius: 9px; background: var(--surface-3); color: var(--text-muted);
  font-size: 12px; font-weight: 700; line-height: 18px;
}
.fg-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.fg-card {
  display: flex; flex-direction: column; min-width: 0; overflow: hidden; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  transition: border-color 0.12s, background 0.12s;
}
/* the whole card opens the figure */
.fg-card:hover { border-color: var(--border-hover); background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.fg-card.has-error { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.fg-card.has-error:hover { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
.fg-thumb {
  position: relative; display: flex; align-items: center; justify-content: center; height: 210px; padding: 10px;
  border: 0; border-bottom: 1px solid var(--border); background: var(--fg-paper); cursor: zoom-in; overflow: hidden;
}
.fg-thumb:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: none; }
.fg-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; opacity: 0; transition: opacity 0.2s; }
.fg-thumb.loaded img { opacity: 1; }
.fg-thumb.is-loading::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--surface-3) 70%, transparent), transparent);
  animation: fg-shimmer 1.2s ease-in-out infinite;
}
@keyframes fg-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.fg-thumb.is-broken { background: var(--surface-2); cursor: pointer; }
.fg-broken { display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--text-faint); font-size: 13.5px; text-align: center; }
.fg-broken.bad { color: var(--danger); }
.fg-info { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; padding: 10px 12px 12px; }
.fg-title { font-weight: 600; font-size: 14.5px; overflow-wrap: anywhere; }
.fg-caption {
  font-size: 13px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.fg-error { font-size: 13px; color: var(--danger); overflow-wrap: anywhere; }
.fg-modal { display: flex; flex-direction: column; gap: 10px; height: 100%; min-height: 0; }
.fg-modal-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; flex: 0 0 auto; }
.fg-counter { min-width: 64px; text-align: center; font-size: 13.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
/* the viewer's downloads of the figure shown: "Download [PNG] [PDF]", set apart from the zoom button */
.fg-downloads { display: inline-flex; align-items: center; gap: 6px; margin-left: 8px; padding-left: 14px; border-left: 1px solid var(--border); }
.fg-downloads:empty { display: none; }
.fg-downloads-label { font-size: 13.5px; color: var(--text-muted); }
.fg-stage { flex: 1 1 0; min-height: 0; overflow: auto; background: var(--fg-paper); border: 1px solid var(--border); border-radius: var(--radius); }
.fg-stage.fit { display: flex; align-items: center; justify-content: center; overflow: hidden; }
.fg-zoom { display: block; padding: 0; border: 0; background: none; cursor: zoom-in; }
.fg-stage.fit .fg-zoom { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; padding: 8px; }
.fg-stage.fit .fg-zoom img { max-width: 100%; max-height: 100%; object-fit: contain; }
.fg-stage.actual .fg-zoom { cursor: zoom-out; }
.fg-stage.actual .fg-zoom img { display: block; max-width: none; }
.fg-stage-msg { width: 100%; padding: 16px; background: var(--surface); align-self: stretch; }
.fg-modal-caption { flex: 0 0 auto; max-height: 18vh; overflow: auto; font-size: 14px; color: var(--text-muted); }

/* ---------------------------------------------------------------- tables */
.tv-layout { display: grid; grid-template-columns: minmax(230px, 300px) minmax(0, 1fr); gap: 16px; align-items: start; }
.tv-layout.no-tables { grid-template-columns: minmax(0, 1fr); }
.tv-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow: auto; }
.tv-layout.no-tables .tv-side { position: static; max-height: none; }
.tv-main { min-width: 0; }
.tv-filter-box { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.tv-list { display: flex; flex-direction: column; }
.tv-item {
  display: flex; flex-direction: column; gap: 1px; width: 100%; padding: 9px 14px 9px 11px;
  border: 0; border-bottom: 1px solid var(--border); border-left: 3px solid transparent;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.tv-item:last-child { border-bottom: 0; }
.tv-item:hover { background: var(--surface-2); }
.tv-item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.tv-item-title { font-size: 14px; font-weight: 600; overflow-wrap: anywhere; }
.tv-item-file { font: 11.5px var(--mono); color: var(--text-muted); overflow-wrap: anywhere; }
.tv-item-meta { font-size: 12.5px; color: var(--text-faint); }
.tv-item-desc {
  font-size: 13px; color: var(--text-muted);
  display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.tv-none { padding: 14px; font-size: 14px; }
.tv-files { list-style: none; margin: 0; padding: 0; }
.tv-files li { padding: 3px 0; border-bottom: 1px solid var(--border); }
.tv-files li:last-child { border-bottom: 0; }
/* a file of the list is one download link (no button per file); the icon at the right says what a click does */
.tv-file {
  display: flex; align-items: center; gap: 10px; margin: 0 -8px; padding: 6px 8px;
  border-radius: var(--radius-sm); color: var(--text); text-decoration: none; transition: background 0.12s;
}
.tv-file:hover { background: var(--surface-2); text-decoration: none; }
.tv-file-main { display: flex; flex-direction: column; gap: 1px; flex: 1 1 auto; min-width: 0; }
.tv-file-icon { flex: 0 0 auto; color: var(--text-faint); transition: color 0.12s; }
.tv-file:hover .tv-file-icon, .tv-file:focus-visible .tv-file-icon { color: var(--accent-text); }
.tv-other > summary { padding: 12px 18px; cursor: pointer; font-weight: 600; }
.tv-other .tv-files { padding: 0 18px 8px; }
.tv-desc { margin: 0; font-size: 14px; }
.tv-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tv-search-box { position: relative; display: flex; align-items: center; flex: 1 1 240px; max-width: 420px; }
.tv-search-box > .icon { position: absolute; left: 10px; color: var(--text-faint); pointer-events: none; }
.tv-search-box .input { padding-left: 32px; }
.tv-spinner { width: 16px; height: 16px; border-width: 2px; color: var(--accent); }
.tv-count { font-size: 13.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tv-pager { display: inline-flex; gap: 4px; }
.tv-double .icon + .icon { margin-left: -10px; }
.tv-wrap { max-height: 62vh; min-height: 120px; transition: opacity 0.15s; }
.tv-wrap.is-loading { opacity: 0.55; }
.tv-table th { padding: 0; }
.tv-table th.tv-rownum { padding: 6px 10px; }
.tv-sort {
  display: flex; align-items: center; gap: 4px; width: 100%; padding: 6px 10px;
  border: 0; background: none; color: inherit; font: inherit; text-align: inherit; white-space: nowrap; cursor: pointer;
}
.tv-table th.num .tv-sort { justify-content: flex-end; }
.tv-sort-icon { opacity: 0; transition: opacity 0.1s; }
.tv-table th:hover .tv-sort-icon, .tv-sort:focus-visible .tv-sort-icon, .tv-sort-icon.on { opacity: 1; }
.tv-sort-icon.on { color: var(--accent-text); }
.tv-table th.tv-sorted { color: var(--text); }
.tv-table td { white-space: nowrap; }
.tv-table td.tv-long { min-width: 260px; max-width: 520px; white-space: normal; overflow-wrap: anywhere; }
.tv-rownum { width: 1%; color: var(--text-faint); }
.tv-null { color: var(--text-faint); }
.tv-bool { text-align: center; }
.tv-true { color: var(--success); font-weight: 700; }
.tv-false { color: var(--text-faint); }
.tv-norows { padding: 24px !important; text-align: center; color: var(--text-muted); }
.tv-error { padding: 12px; }
@media (max-width: 960px) {
  .tv-layout { grid-template-columns: minmax(0, 1fr); }
  .tv-side { position: static; max-height: none; }
}

/* ---------------------------------------------------------------- spatial viewer (components/spatial-viewer.js) */
/* map height: the window less what must be seen with the maps; --sv-lead (space above the first maps) and --sv-row
   (what a second row of panels adds above its maps) are measured by the viewer */
.sv {
  display: flex; flex-direction: column; gap: 12px;
  --sv-stage-h: clamp(420px, calc(100vh - var(--sv-lead, 380px) - 20px), 900px);
}
.sv[data-rows="1"]:not([data-layout="1"]) { --sv-stage-h: clamp(360px, calc(100vh - var(--sv-lead, 440px) - 20px), 760px); }
.sv[data-rows="2"] { --sv-stage-h: clamp(200px, calc((100vh - var(--sv-lead, 340px) - var(--sv-row, 180px) - 20px) / 2), 560px); }
.sv-toolbar {
  display: flex; align-items: flex-end; gap: 12px 18px; flex-wrap: wrap; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.sv-control { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.sv-control-auto { min-width: 0; }
.sv-control > label, .sv-control-label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.sv-range-row, .sv-switch-row { display: flex; align-items: center; gap: 10px; height: 32px; }
.sv-range { width: 120px; accent-color: var(--accent); }
.sv-range:disabled { opacity: 0.45; }
.sv-size-out { min-width: 38px; font-size: 13.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sv-layout { height: 32px; align-items: center; }
.sv-layout .btn { min-width: 34px; font-variant-numeric: tabular-nums; }
/* Save PNG: a small ghost button, centred on the 32 px rows of the controls beside it */
.sv-toolbar .sv-save { margin-bottom: 2px; }
.sv-note { margin: 0; font-size: 12.5px; color: var(--text-faint); }

/* panels: 1 up to the number of sections; 2 and 3 side by side, 4 in 2 x 2, 5 and 6 in 3 x 2 (--sv-cols columns);
   one column in narrow windows */
.sv-panels { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.sv:not([data-layout="1"]) .sv-panels { grid-template-columns: repeat(var(--sv-cols, 2), minmax(0, 1fr)); }
.sv-panel { display: flex; flex-direction: column; min-width: 0; }
.sv-panel-head { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 9px 14px; border-bottom: 1px solid var(--border); }
.sv-panel-title { flex: 1 1 auto; min-width: 0; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-panel-controls { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.sv-panel-controls .sv-control { flex: 1 1 150px; min-width: 0; max-width: 320px; }
.sv-panel-controls .sv-control-wide { flex: 2 1 240px; max-width: none; }
/* two or four panels: section, coloring and overlays on one line */
.sv:not([data-layout="1"]) .sv-panel-controls { align-content: flex-start; gap: 8px 10px; padding: 8px 12px; }
.sv:not([data-layout="1"]) .sv-panel-controls .sv-control { flex-basis: 110px; }
.sv:not([data-layout="1"]) .sv-panel-controls .sv-control-wide { flex-basis: 200px; }
.sv-ovl-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 14px; border-bottom: 1px solid var(--border); }
.sv-ovl-chips { flex: 1 1 auto; }
.sv-chip { font-family: var(--font); }
/* "+ Add gene" (where the overlays are chosen) and its popover: a gene box, then the yes/no fields not shown yet */
.sv-panel-controls .sv-control-auto { flex: 0 0 auto; }
.sv-add { align-self: flex-start; white-space: nowrap; }
.sv-add[aria-expanded="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); }
.sv-add-pop { display: flex; flex-direction: column; gap: 12px; }
.sv-add-section { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sv-add-section + .sv-add-section { padding-top: 11px; border-top: 1px solid var(--border); }
.sv-add-label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.sv-add-hint { margin: 0; font-size: 12.5px; line-height: 1.45; color: var(--text-muted); }
.sv-add-list { list-style: none; margin: 0 -6px; padding: 0; max-height: 200px; overflow: auto; display: flex; flex-direction: column; gap: 1px; }
.sv-add-item {
  display: block; width: 100%; padding: 6px 8px; border: 0; border-radius: 5px; background: none; color: var(--text);
  font: 500 12.5px/1.35 var(--font); text-align: left; cursor: pointer;
}
.sv-add-item:hover, .sv-add-item:focus { background: var(--surface-3); outline: none; }
.sv-add-item:focus-visible { box-shadow: inset 0 0 0 2px rgba(61, 124, 245, 0.55); }
@media (max-height: 720px) { .sv-add-list { max-height: 132px; } }
.sv-dim { font-size: 13.5px; color: var(--text-muted); }
.sv-panel-body { display: grid; grid-template-columns: minmax(0, 1fr); }
.sv[data-layout="1"] .sv-panel-body { grid-template-columns: minmax(0, 1fr) 260px; }

/* "Color by genes": one gene box per line, its color swatch before it and its remove button after it */
.sv-lines { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.sv-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.sv-line > .sv-gene-box { flex: 1 1 auto; }
.sv-line-swatch { flex: 0 0 auto; width: 12px; height: 12px; border-radius: 3px; }
.sv-line.warn .sv-line-swatch { outline: 2px solid var(--warning); outline-offset: 1px; }
.sv-add-line { align-self: flex-start; }
.sv-shape-swatch { flex: 0 0 auto; display: inline-block; vertical-align: middle; }
/* "Correlated genes": a button per overlap combination (legend), and the dialog's thresholds and table */
.sv-corr-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.sv-corr-list li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sv-corr-list .sv-item-label { flex: 1 1 auto; min-width: 0; font-size: 13.5px; overflow-wrap: anywhere; }
.sv-corr-thresholds { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; }
.sv-corr-field { display: flex; flex-direction: column; gap: 4px; min-width: 150px; }
.sv-corr-field label { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.sv-corr-field .input { width: 130px; }
.sv-corr-table { max-height: 46vh; }
.sv-outline-swatch {
  flex: 0 0 auto; width: 13px; height: 13px; box-sizing: border-box;
  border: 2px solid #ffffff; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.85), inset 0 0 0 1px rgba(0, 0, 0, 0.85);
}
.sv-lines-note { margin: 0; }

/* gene box with suggestions */
.sv-gene-box { display: flex; align-items: center; gap: 6px; min-width: 0; }
.sv-gene-field { position: relative; flex: 1 1 auto; min-width: 0; }
.sv-suggest {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20; max-height: 280px; overflow: auto;
  margin: 0; padding: 4px; list-style: none;
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.sv-suggest li {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px;
  padding: 5px 8px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13.5px;
}
.sv-suggest li:hover, .sv-suggest li.active { background: var(--accent-soft); }
.sv-suggest-gene { font-family: var(--mono); font-size: 13px; color: var(--text); overflow-wrap: anywhere; }
.sv-suggest-meta { color: var(--text-muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.sv-suggest li.sv-suggest-more { cursor: default; color: var(--text-muted); font-size: 12.5px; }
.sv-suggest li.sv-suggest-more:hover { background: none; }

/* map */
.sv-stage { position: relative; height: var(--sv-stage-h); overflow: hidden; background: var(--plot-bg); }
.sv[data-layout="1"] .sv-stage { border-bottom-left-radius: calc(var(--radius-lg) - 1px); }
.sv-canvas { position: absolute; inset: 0; display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
.sv-stage.dragging .sv-canvas { cursor: grabbing; }
.sv-canvas:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; box-shadow: none; border-radius: 0; }
/* zoom in, zoom out and fit: one compact floating group of icon-only ghost buttons */
.sv-zoom {
  position: absolute; top: 10px; right: 10px; z-index: 2; display: flex; flex-direction: column; gap: 2px; padding: 3px;
  background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.sv-zoom .btn.ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
/* tooltip: placed in the window next to the pointer (the viewer keeps it off the pointer), never cut by a panel's edge */
.sv-tip {
  position: fixed; left: 0; top: 0; z-index: 40; max-width: min(330px, calc(100vw - 16px)); max-height: calc(100vh - 16px);
  overflow: hidden; padding: 8px 10px; pointer-events: none;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); font-size: 13px; line-height: 1.45;
}
.sv-tip-head { margin-bottom: 4px; font-weight: 650; font-variant-numeric: tabular-nums; }
.sv-tip-grid { display: grid; grid-template-columns: auto auto; gap: 0 14px; margin: 0; }
.sv-tip-grid dt { color: var(--text-muted); }
.sv-tip-grid dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.sv-tip-grid dd.mono { font-size: 12px; }
.sv-tip-grid .on { color: var(--text); font-weight: 700; }
.sv-tip-grid dd.sv-tip-calls { text-align: left; }
/* the genes of the bin under the pointer: a wider tooltip, the genes in columns by UMIs */
.sv-tip.sv-tip-wide { width: min(620px, calc(100vw - 16px)); max-width: none; }
.sv-tip-genes { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.sv-tip-genes-head { font-weight: 650; margin-bottom: 2px; }
.sv-tip-genes-head .muted, .sv-tip-genes > .muted { font-weight: 400; color: var(--text-muted); }
.sv-tip-gene-list {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 0 12px;
  margin: 2px 0 4px; padding: 0; list-style: none; font-size: 12px; line-height: 1.4;
}
.sv-tip-gene-list li { display: flex; justify-content: space-between; gap: 6px; min-width: 0; }
.sv-tip-gene-list .sv-g { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-tip-gene-list .sv-n { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sv-bin-genes { max-height: min(60vh, 520px); overflow: auto; }
.sv-msg {
  position: absolute; inset: 0; z-index: 4; display: flex; align-items: center; justify-content: center; overflow: auto;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
}
.sv-msg-body { width: calc(100% - 32px); max-width: 540px; }
.sv-msg-body > .banner { margin-bottom: 0; }

/* legend: beside the map with one panel; with two or four, beside it in a narrow column when the panel is wide enough
   (see the end of this section), else under it */
.sv-legend-body { display: flex; flex-direction: column; gap: 10px; min-width: 0; padding: 12px 14px; overflow: auto; }
.sv[data-layout="1"] .sv-legend-body { max-height: var(--sv-stage-h); border-left: 1px solid var(--border); }
.sv:not([data-layout="1"]) .sv-legend-body { max-height: 220px; border-top: 1px solid var(--border); }
.sv-legend-body:empty { display: none; }
.sv-legend-title { font-size: 15px; overflow-wrap: anywhere; }
.sv-legend { display: flex; flex-direction: column; gap: 1px; }
.sv:not([data-layout="1"]) .sv-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 1px 8px; }
.sv-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 6px;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text);
  font: 12.5px var(--font); text-align: left; cursor: pointer;
}
.sv-item:hover { background: var(--surface-2); }
.sv-item.off { opacity: 0.45; }
.sv-item.off .sv-item-label { text-decoration: line-through; }
.sv-item-label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.sv-item-count { color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sv-colorbar { display: block; width: 100%; height: 12px; border-radius: 3px; }
.sv-colorbar-labels { display: flex; justify-content: space-between; gap: 6px; font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sv-legend-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 8px;
  border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted);
}
.sv-legend-section { display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 1px solid var(--border); }
.sv-ovl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.sv-ovl { display: flex; align-items: center; gap: 8px; padding: 3px 6px; font-size: 13.5px; }
/* bins in two or more overlays: light on the map, dark over the H&E image; the rim keeps the dark one visible here */
.sv-swatch-ink { border-color: var(--text-faint); }
.sv-facts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--text-muted); }
.sv-warn { color: var(--warning); }
.sv-hint { margin: 0; font-size: 13px; color: var(--text-faint); }
.sv-error { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; font-size: 13px; color: var(--danger); }
.sv-error > span { flex: 1 1 140px; min-width: 0; overflow-wrap: anywhere; }
.sv-busy { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.sv-busy .spinner { width: 14px; height: 14px; border-width: 2px; }

@media (max-width: 960px) {
  .sv[data-layout="1"] .sv-panel-body { grid-template-columns: minmax(0, 1fr); }
  .sv[data-layout="1"] .sv-stage { border-bottom-left-radius: 0; }
  .sv[data-layout="1"] .sv-legend-body { max-height: none; border-left: 0; border-top: 1px solid var(--border); }
}
@media (max-width: 760px) {
  .sv:not([data-layout="1"]) .sv-panels { grid-template-columns: minmax(0, 1fr); }
  .sv:not([data-layout="1"]) { --sv-stage-h: clamp(300px, 62vh, 560px); }
  .sv:not([data-layout="1"]) .sv-legend-body { max-height: none; }
  .sv-range { width: 100px; }
}
/* side by side, the maps of a row line up whatever each panel shows above them (gene box, overlays): every panel spans
   the same four rows of the grid (head, controls, overlays, map and legend) */
@media (min-width: 761px) {
  @supports (grid-template-rows: subgrid) {
    .sv:not([data-layout="1"]) .sv-panels { row-gap: 0; grid-template-rows: repeat(4, auto); align-items: stretch; }
    .sv[data-rows="2"] .sv-panels { grid-template-rows: repeat(4, auto) 16px repeat(4, auto); }
    .sv:not([data-layout="1"]) .sv-panel { display: grid; grid-template-rows: subgrid; grid-row: 1 / span 4; }
    .sv[data-rows="2"][data-cols="2"] .sv-panel:nth-child(n + 3),
    .sv[data-rows="2"][data-cols="3"] .sv-panel:nth-child(n + 4) { grid-row: 6 / span 4; }
    .sv:not([data-layout="1"]) .sv-panel-head { grid-row: 1; }
    .sv:not([data-layout="1"]) .sv-panel-controls { grid-row: 2; }
    .sv:not([data-layout="1"]) .sv-ovl-row { grid-row: 3; }
    .sv:not([data-layout="1"]) .sv-panel-body { grid-row: 4; }
  }
}
/* two or four panels: the legend in a narrow column beside the map when the panel is wide enough (sv-wide: set by the
   viewer from the panel's width, 500 px with four panels, 700 px with two) */
.sv:not([data-layout="1"]) .sv-panel.sv-wide .sv-panel-body { grid-template-columns: minmax(0, 1fr) 180px; }
.sv:not([data-layout="1"]) .sv-panel.sv-wide .sv-legend-body {
  max-height: var(--sv-stage-h); padding: 10px 12px; border-top: 0; border-left: 1px solid var(--border);
}
.sv:not([data-layout="1"]) .sv-panel.sv-wide .sv-legend { display: flex; flex-direction: column; }
/* in that column an entry's count goes under its label, which keeps the width of the column (words not cut) */
.sv:not([data-layout="1"]) .sv-panel.sv-wide .sv-item,
.sv:not([data-layout="1"]) .sv-panel.sv-wide .sv-ovl {
  display: grid; grid-template-columns: 12px minmax(0, 1fr); align-items: center; gap: 0 8px;
}
.sv:not([data-layout="1"]) .sv-panel.sv-wide .sv-item-count { grid-column: 2; font-size: 12.5px; }

/* ---------------------------------------------------------------- help */
.help-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 24px; align-items: start; }
.help-side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 16px; }
.help-nav { display: flex; flex-direction: column; gap: 2px; padding: 6px; }
.help-nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-muted); font-weight: 500; }
.help-nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.help-nav-item.active { background: var(--accent-soft); color: var(--accent-text); }
.help-toc { font-size: 13.5px; }
.help-toc-title { margin: 0 0 6px 12px; font-size: 12.5px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-faint); }
.help-toc ul { list-style: none; margin: 0; padding: 0; border-left: 2px solid var(--border); max-height: calc(100vh - 300px); overflow: auto; }
.help-toc li a { display: block; padding: 3px 10px; color: var(--text-muted); }
.help-toc li.sub a { padding-left: 22px; font-size: 13px; }
.help-toc li a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.help-content { min-width: 0; }
.help-content > .prose { max-width: none; padding: 24px 32px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.help-content > .prose > :first-child { margin-top: 0; }
.help-lead { font-size: 16px; color: var(--text-muted); }
.help-actions { margin: 12px 0 4px; }
.help-steps { list-style: none; padding: 0 !important; counter-reset: help-step; }
.help-steps > li { position: relative; margin: 0 0 16px; padding-left: 44px; counter-increment: help-step; }
.help-steps > li::before {
  content: counter(help-step); position: absolute; left: 0; top: 0; width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent-text); font-size: 14px; font-weight: 700;
}
.help-steps h3 { margin: 4px 0 4px; }
.help-steps p { margin: 0; }
.help-glossary { display: grid; grid-template-columns: minmax(150px, max-content) minmax(0, 1fr); gap: 10px 20px; margin: 0; }
.help-glossary dt { font-weight: 650; }
.help-glossary dd { margin: 0; color: var(--text-muted); }
@media (max-width: 860px) {
  .help-layout { grid-template-columns: minmax(0, 1fr); }
  .help-side { position: static; }
  .help-glossary { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .help-glossary dd { margin-bottom: 8px; }
  .help-content > .prose { padding: 18px; }
}

/* Markdown documents (components/markdown.js) */
.md-table-wrap { margin: 10px 0; overflow-x: auto; }
.md-table-wrap > table { margin: 0; }
.prose li.md-task { list-style: none; margin-left: -18px; }
.md-task > input { margin: 0 6px 0 0; vertical-align: -2px; }
.md-link-text { text-decoration: underline dotted var(--text-faint); text-underline-offset: 3px; }
.md-image { font-style: italic; }
.prose code { overflow-wrap: anywhere; }

/* the Cell types tab: Regenerate stays in view while the cell types below are edited */
.retype-bar { position: sticky; top: 8px; z-index: 6; box-shadow: var(--shadow); }
