/* Nicheverse spatial viewer. All classes scoped under .nvv so nothing leaks into site chrome.
   Follows site tokens (--nv-paper/--nv-ink/--nv-mut/--nv-line/--nv-accent) and Inter (via --nv-sans).
   The map is the hero; every control is a hairline. */

:root { --nvv-panel: #0a0b0d; --nvv-panelW: 320px; --nvv-headH: 44px; --nvv-hair: 1px solid var(--nv-line); }

.nvv { position: fixed; inset: var(--nvv-top, 60px) 0 0 0; background: var(--nv-paper); color: var(--nv-ink);
       font-family: var(--nv-sans); font-size: 13px; line-height: 1.45; display: flex; flex-direction: column;
       font-feature-settings: "tnum" 1, "ss01" 1; z-index: 1; }
.nvv * { box-sizing: border-box; }

/* Header */
.nvv-head { height: var(--nvv-headH); flex: 0 0 auto; display: flex; align-items: center; gap: 10px;
            padding: 0 12px; border-bottom: var(--nvv-hair); background: var(--nv-paper); }
.nvv-sw { display: flex; align-items: center; gap: 6px; min-width: 0; }
.nvv-sw label { color: var(--nv-mut); font-size: 11px; letter-spacing: 0.02em; text-transform: none; }
.nvv-select { appearance: none; -webkit-appearance: none; background: transparent; color: var(--nv-ink);
              border: var(--nvv-hair); border-radius: 2px; padding: 4px 22px 4px 8px; font: inherit;
              max-width: 44ch; text-overflow: ellipsis; cursor: pointer;
              background-image: linear-gradient(45deg, transparent 50%, var(--nv-mut) 50%),
                                linear-gradient(-45deg, transparent 50%, var(--nv-mut) 50%);
              background-position: calc(100% - 12px) 55%, calc(100% - 8px) 55%;
              background-size: 4px 4px, 4px 4px; background-repeat: no-repeat; }
.nvv-select:focus { outline: 1px solid var(--nv-accent); outline-offset: 1px; }
.nvv-head-r { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.nvv-ibtn { background: transparent; color: var(--nv-mut); border: var(--nvv-hair); border-radius: 2px;
            padding: 3px 8px; font: inherit; cursor: pointer; letter-spacing: 0.01em; }
.nvv-ibtn:hover { color: var(--nv-ink); border-color: var(--nv-mut); }
.nvv-ibtn kbd { color: var(--nv-mut); font-size: 10px; padding: 0 4px; margin-left: 6px;
                border: 1px solid var(--nv-line); border-radius: 2px; font-family: var(--nv-mono); }
.nvv-meta { color: var(--nv-mut); font-size: 11px; padding: 0 6px; border-left: var(--nvv-hair); height: 22px;
            display: flex; align-items: center; margin-left: 4px; }
.nvv-meta b { color: var(--nv-ink); font-weight: 500; margin-right: 4px; }

/* Body: panel + canvas */
.nvv-body { flex: 1 1 auto; display: flex; min-height: 0; }
.nvv-panel { width: var(--nvv-panelW); flex: 0 0 auto; border-right: var(--nvv-hair);
             overflow: hidden; display: flex; flex-direction: column; background: var(--nv-paper); }
.nvv-stage { flex: 1 1 auto; position: relative; min-width: 0; overflow: hidden; background: #000; }
.nvv-canvas { position: absolute; inset: 0; }
.nvv-canvas canvas { display: block !important; }

/* Panel sections */
.nvv-sec { padding: 10px 12px; border-bottom: var(--nvv-hair); flex: 0 0 auto; }
.nvv-sec.grow { flex: 1 1 auto; overflow: auto; padding-top: 6px; padding-bottom: 8px; }
.nvv-lbl { color: var(--nv-mut); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
           margin: 0 0 6px 0; }
.nvv-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.nvv-pill { background: transparent; color: var(--nv-mut); border: var(--nvv-hair); border-radius: 2px;
            padding: 3px 8px; font: inherit; cursor: pointer; }
.nvv-pill:hover { color: var(--nv-ink); }
.nvv-pill.is-on { color: var(--nv-paper); background: var(--nv-accent); border-color: var(--nv-accent); }
.nvv-input { width: 100%; background: transparent; color: var(--nv-ink); border: var(--nvv-hair);
             border-radius: 2px; padding: 5px 8px; font: inherit; }
.nvv-input:focus { outline: none; border-color: var(--nv-accent); }
.nvv-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.nvv-row label { color: var(--nv-mut); font-size: 11px; min-width: 44px; }
.nvv-slider { flex: 1 1 auto; appearance: none; height: 3px; background: var(--nv-line); border-radius: 2px; }
.nvv-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; background: var(--nv-ink);
                                    border-radius: 50%; border: none; cursor: pointer; }
.nvv-slider::-moz-range-thumb { width: 12px; height: 12px; background: var(--nv-ink); border: none;
                                border-radius: 50%; cursor: pointer; }
.nvv-num { color: var(--nv-mut); font-size: 11px; min-width: 36px; text-align: right; font-variant-numeric: tabular-nums; }

/* Legend */
.nvv-legend-hd { display: flex; align-items: center; justify-content: space-between; gap: 6px;
                 padding: 8px 12px 4px; }
.nvv-legend-hd .nvv-lbl { margin: 0; }
.nvv-legend-hd .nvv-mini { font-size: 10px; color: var(--nv-mut); background: none; border: none;
                           padding: 0; cursor: pointer; letter-spacing: 0.02em; }
.nvv-legend-hd .nvv-mini:hover { color: var(--nv-ink); }
.nvv-legend-hd .nvv-mini + .nvv-mini { border-left: var(--nvv-hair); padding-left: 6px; margin-left: 2px; }
.nvv-legend-filter { padding: 0 12px 6px; }
.nvv-legend-filter input { width: 100%; background: transparent; color: var(--nv-ink); border: none;
                           border-bottom: var(--nvv-hair); padding: 3px 0; font: inherit; font-size: 12px; }
.nvv-legend-filter input:focus { outline: none; border-bottom-color: var(--nv-ink); }
.nvv-legend { padding: 0 12px 12px; }
.nvv-lrow { display: grid; grid-template-columns: 12px 1fr auto auto; gap: 8px; align-items: center;
            padding: 3px 0; cursor: pointer; color: var(--nv-ink); user-select: none; }
.nvv-lrow:hover { color: var(--nv-accent-dk); }
.nvv-lrow.is-off { color: var(--nv-mut); opacity: 0.55; }
.nvv-lrow.is-solo { color: var(--nv-accent); }
.nvv-lsw { width: 12px; height: 12px; border-radius: 2px; border: 1px solid rgba(255,255,255,0.06); flex: 0 0 auto; }
.nvv-lrow.is-off .nvv-lsw { background: transparent !important; border-color: var(--nv-line); }
.nvv-lname { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.nvv-lct { font-size: 11px; color: var(--nv-mut); font-variant-numeric: tabular-nums; }
.nvv-lpct { font-size: 11px; color: var(--nv-mut); font-variant-numeric: tabular-nums; min-width: 36px; text-align: right; }
/* API mode: per-row marker query */
.nvv-legend.has-mk .nvv-lrow { grid-template-columns: 12px 1fr auto auto auto; }
.nvv-lmk { font: inherit; font-size: 10px; line-height: 16px; color: var(--nv-mut); background: none;
           border: var(--nvv-hair); border-radius: 2px; padding: 0 5px; cursor: pointer; opacity: 0; }
.nvv-lrow:hover .nvv-lmk, .nvv-lmk:focus { opacity: 1; }
.nvv-lmk:hover { color: var(--nv-ink); border-color: var(--nv-mut); }
@media (hover: none) { .nvv-lmk { opacity: 1; } }
.nvv-radin { width: 62px; flex: 0 0 auto; padding: 3px 6px; font-size: 11px; -moz-appearance: textfield; }
.nvv-radin::-webkit-outer-spin-button, .nvv-radin::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Colorbar (gene mode) */
.nvv-cbar { padding: 4px 12px 10px; }
.nvv-cbar-bar { height: 8px; border-radius: 2px; margin: 4px 0; }
.nvv-cbar-lab { display: flex; justify-content: space-between; font-size: 10px; color: var(--nv-mut);
                font-variant-numeric: tabular-nums; }
.nvv-gmeta { font-size: 11px; color: var(--nv-mut); }
.nvv-gmeta b { color: var(--nv-ink); font-weight: 500; }

/* Gene autocomplete */
.nvv-ac { position: relative; }
.nvv-ac-list { position: absolute; left: 0; right: 0; top: 100%; background: var(--nvv-panel);
               border: var(--nvv-hair); border-top: none; max-height: 220px; overflow: auto; z-index: 10; }
.nvv-ac-item { padding: 4px 8px; cursor: pointer; font-size: 12px; }
.nvv-ac-item.is-on, .nvv-ac-item:hover { background: rgba(224,166,58,0.12); color: var(--nv-ink); }
.nvv-ac-item .nvv-ac-meta { color: var(--nv-mut); font-size: 10px; margin-left: 6px; }

/* Selection composition drawer */
.nvv-sel { position: absolute; left: 12px; bottom: 12px; background: rgba(0,0,0,0.86); color: var(--nv-ink);
           border: var(--nvv-hair); border-radius: 2px; padding: 10px 12px; min-width: 260px;
           max-width: 46ch; max-height: 46vh; overflow: auto; backdrop-filter: blur(4px); z-index: 3;
           font-size: 12px; }
.nvv-sel-hd { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.nvv-sel-hd b { font-weight: 600; }
.nvv-sel-close { background: none; border: none; color: var(--nv-mut); cursor: pointer; font-size: 14px; }
.nvv-sel-actions { display: flex; gap: 6px; margin-bottom: 8px; }
.nvv-sel-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.nvv-sel-table td { padding: 2px 4px; }
.nvv-sel-table td:first-child { width: 12px; }
.nvv-sel-table td:nth-child(2) { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nvv-sel-table td:nth-child(3), .nvv-sel-table td:nth-child(4) { text-align: right; color: var(--nv-mut); }
.nvv-sel-table .nvv-lsw { display: inline-block; vertical-align: -2px; }
.nvv-sel-deg { margin: 0 0 8px; padding-bottom: 8px; border-bottom: var(--nvv-hair); }
.nvv-sel-note { color: var(--nv-mut); font-size: 11px; margin: 0 0 6px; }
.nvv-sel-err { color: var(--nv-accent); font-size: 11px; margin: 0; }
.nvv-deg-hd { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.nvv-deg-wrap { overflow-x: auto; }
.nvv-deg-table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
.nvv-deg-table th { text-align: right; color: var(--nv-mut); font-weight: 400; font-size: 10px; letter-spacing: 0.04em;
                    text-transform: uppercase; padding: 2px 4px; border-bottom: var(--nvv-hair); white-space: nowrap; }
.nvv-deg-table td { text-align: right; color: var(--nv-mut); padding: 2px 4px; white-space: nowrap; }
.nvv-deg-table th:first-child, .nvv-deg-table td:first-child { text-align: left; }
.nvv-deg-table td:first-child { color: var(--nv-ink); font-weight: 500; }

/* Scale bar */
.nvv-scale { position: absolute; right: 14px; bottom: 14px; color: var(--nv-ink); font-size: 11px;
             letter-spacing: 0.02em; z-index: 2; text-shadow: 0 1px 2px rgba(0,0,0,0.8);
             font-variant-numeric: tabular-nums; pointer-events: none; }
.nvv-scale-bar { height: 2px; background: var(--nv-ink); margin-bottom: 3px; box-shadow: 0 1px 2px rgba(0,0,0,0.8); }

/* Tooltip */
.nvv-tt { position: absolute; background: rgba(0,0,0,0.9); color: var(--nv-ink); border: var(--nvv-hair);
          padding: 6px 8px; font-size: 11px; pointer-events: none; z-index: 4; max-width: 32ch;
          border-radius: 2px; }
.nvv-tt-row { display: flex; gap: 8px; }
.nvv-tt-row span:first-child { color: var(--nv-mut); }
.nvv-tt-row b { font-weight: 500; }

/* Loading + error */
.nvv-load { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
            color: var(--nv-mut); z-index: 6; background: #000; }
.nvv-load-in { text-align: center; }
.nvv-load b { display: block; color: var(--nv-ink); font-weight: 500; margin-bottom: 4px; font-size: 14px; }
.nvv-load i { display: inline-block; width: 90px; height: 2px; background: var(--nv-line); position: relative;
              overflow: hidden; margin-top: 8px; }
.nvv-load i::after { content: ""; position: absolute; inset: 0; background: var(--nv-accent); width: 30%;
                     animation: nvvSlide 1.2s ease-in-out infinite; }
@keyframes nvvSlide { 0% { transform: translateX(-100%); } 100% { transform: translateX(333%); } }
.nvv-err { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
           padding: 24px; text-align: center; color: var(--nv-ink); z-index: 6; background: #000; }
.nvv-err b { display: block; color: var(--nv-accent); margin-bottom: 6px; }
.nvv-err span { color: var(--nv-mut); font-size: 12px; max-width: 44ch; display: block; }

/* Help overlay */
.nvv-help { position: absolute; inset: 0; background: rgba(0,0,0,0.86); z-index: 20;
            display: flex; align-items: center; justify-content: center; padding: 24px; }
.nvv-help-card { background: var(--nvv-panel); border: var(--nvv-hair); padding: 20px 24px;
                 max-width: 460px; width: 100%; }
.nvv-help-card h3 { margin: 0 0 12px 0; font-size: 14px; font-weight: 600; letter-spacing: 0.02em; }
.nvv-help-card table { width: 100%; border-collapse: collapse; }
.nvv-help-card td { padding: 4px 0; font-size: 12px; color: var(--nv-mut); }
.nvv-help-card td:first-child { color: var(--nv-ink); width: 40%; }
.nvv-help-card td kbd { border: var(--nvv-hair); padding: 1px 5px; border-radius: 2px; font-family: var(--nv-mono);
                        font-size: 10px; margin-right: 4px; color: var(--nv-ink); }
.nvv-help-note { margin: 10px 0 0; font-size: 11px; color: var(--nv-mut); }

/* Mobile: panel becomes a bottom drawer */
@media (max-width: 900px) {
  .nvv-body { flex-direction: column; }
  .nvv-panel { width: 100%; max-height: 46vh; border-right: none; border-top: var(--nvv-hair); order: 2; }
  .nvv-stage { order: 1; min-height: 54vh; }
  .nvv-head { flex-wrap: wrap; height: auto; padding: 6px 10px; }
  .nvv-meta { display: none; }
  .nvv-sel { left: 8px; right: 8px; bottom: 8px; min-width: 0; max-width: none; max-height: 44vh; }
  .nvv-lmk { opacity: 1; }
}

/* Gallery integration: "Explore" badge on cards known to the viewer */
.bb-frame .bb-explore { position: absolute; right: 8px; bottom: 8px; z-index: 3;
                         background: rgba(0,0,0,0.72); color: var(--nv-ink); border: var(--nvv-hair);
                         padding: 3px 8px; font-size: 11px; letter-spacing: 0.02em;
                         text-decoration: none; border-radius: 2px; opacity: 0; transition: opacity 120ms; }
.bb-tile:hover .bb-explore { opacity: 1; }
.bb-frame .bb-explore:hover { color: var(--nv-accent); border-color: var(--nv-accent); }
.gx-lb-explore { display: inline-block; margin-left: 12px; padding: 4px 10px; border: var(--nvv-hair);
                 color: var(--nv-ink); text-decoration: none; font-size: 12px; border-radius: 2px; }
.gx-lb-explore:hover { color: var(--nv-accent); border-color: var(--nv-accent); }
