/* ═══════════════════════════════════════════════════════════════════
   WashU eg3 Browser — Modern UI
   Design tokens, collapsible sections, custom checkboxes, toast
   ═══════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ─────────────────────────────────────────────── */
:root {
  --color-bg:        #f0f2f7;
  --color-surface:   #ffffff;
  --color-surface2:  #f8f9fd;
  --color-border:    #e2e6f0;
  --color-border2:   #d4d9e6;
  --color-text:      #1a1f2e;
  --color-text2:     #5c6378;
  --color-text3:     #8b90a0;
  --color-primary:   #3b6cf4;
  --color-primary2:  #2b54d4;
  --color-accent:    #10b964;
  --color-accent2:   #0d944e;
  --color-warn:      #f59e0b;
  --color-danger:    #ef4444;
  --color-header-bg: linear-gradient(135deg, #1e3a6e 0%, #2c5aa0 40%, #3b6cf4 100%);
  --color-shadow:    0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --color-shadow-lg: 0 4px 16px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --radius-sm: 6px;
  --radius:   10px;
  --radius-lg: 14px;
  --radius-full: 999px;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --font-ui:   'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ── Reset & Base ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  font-family: var(--font-ui);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select { font: inherit; }

/* ── Custom Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c5cad6; border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: #a4aab8; }
* { scrollbar-width: thin; scrollbar-color: #c5cad6 transparent; }

/* ── App Shell ─────────────────────────────────────────────────── */
.app-shell { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* ── Header ────────────────────────────────────────────────────── */
.header {
  flex-shrink: 0;
  background: var(--color-header-bg);
  color: white;
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 2px solid rgba(255,255,255,0.1);
  position: relative;
  overflow: hidden;
}
.header::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255,255,255,0.06) 0%, transparent 60%);
  pointer-events: none;
}
.header-title-group {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.header-title-group h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.preprint-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: rgba(255,255,255,0.82);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  transition: color var(--transition);
  width: fit-content;
}
.preprint-link:hover {
  color: white;
  text-decoration: underline;
}
.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Header stat badges */
.stat-badges {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.stat-badge {
  background: rgba(255,255,255,0.14);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: var(--radius-full);
  padding: 3px 12px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(255,255,255,0.92);
  white-space: nowrap;
  transition: background var(--transition);
}
.stat-badge:hover { background: rgba(255,255,255,0.22); }

/* Copy link button */
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  border-radius: var(--radius);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  backdrop-filter: blur(4px);
  white-space: nowrap;
}
.btn-icon:hover {
  background: rgba(255,255,255,0.22);
  border-color: rgba(255,255,255,0.35);
}
.btn-icon svg { width: 14px; height: 14px; opacity: 0.85; }

/* ── Workspace ─────────────────────────────────────────────────── */
.workspace {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(250px, 310px) minmax(0, 1fr);
  gap: 0;
  overflow: hidden;
}

/* ── Filter Panel ──────────────────────────────────────────────── */
.filter-panel {
  background: var(--color-surface);
  padding: 8px 10px;
  border-right: 1px solid var(--color-border);
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  align-items: stretch;
}

/* ── Filter Group (collapsible) ────────────────────────────────── */
.filter-group {
  background: var(--color-surface2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.filter-group:hover {
  border-color: var(--color-border2);
}
.filter-group.is-collapsed .filter-group-body { display: none; }
.filter-group.is-collapsed { border-color: var(--color-border); }

.filter-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.filter-group-header:hover { background: rgba(59,108,244,0.04); }
.filter-group-header > label {
  font-weight: 700;
  color: var(--color-text);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  cursor: pointer;
  flex: 1;
}
.collapse-arrow {
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text3);
  transition: transform var(--transition);
  font-size: 12px;
  flex-shrink: 0;
}
.is-collapsed .collapse-arrow { transform: rotate(-90deg); }
.filter-group-body { padding: 0 10px 8px; display: flex; flex-direction: column; gap: 6px; }

.filter-help {
  color: var(--color-text2);
  font-size: 11px;
  line-height: 1.3;
  font-weight: 600;
  padding: 0 2px;
}

/* ── Checkbox Group ────────────────────────────────────────────── */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: auto;
}

/* ── Custom Checkbox ───────────────────────────────────────────── */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  line-height: 1.3;
  min-height: 24px;
  color: var(--color-text);
  cursor: pointer;
  padding: 1px 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}
.checkbox-label:hover { background: rgba(59,108,244,0.05); }

/* Hide native checkbox */
.checkbox-label input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin: 0;
  flex-shrink: 0;
  border: 2px solid var(--color-border2);
  border-radius: 4px;
  background: white;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.checkbox-label input[type="checkbox"]:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}
.checkbox-label input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3.8px; top: 1px;
  width: 5px; height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.checkbox-label input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* Age color dots */
.checkbox-label .age-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: -2px;
}

/* ── Subtype chips ─────────────────────────────────────────────── */
.selected-subtypes {
  display: none;
  gap: 6px;
  align-items: flex-start;
  flex-wrap: wrap;
  padding: 7px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.selected-subtypes.has-items { display: flex; }
.selected-subtypes-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--color-primary);
  padding-top: 4px;
  text-transform: uppercase;
}
.selected-subtypes-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex: 1;
}
.subtype-chip {
  border: 1px solid var(--color-border2);
  background: white;
  color: var(--color-text);
  border-radius: var(--radius-full);
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  transition: all var(--transition);
}
.subtype-chip:hover {
  border-color: var(--color-danger);
  color: var(--color-danger);
  background: #fef2f2;
}

.empty-subtype-message {
  color: var(--color-text3);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 4px;
}

/* ── Major / Subtype scroll areas ──────────────────────────────── */
.major-checkboxes {
  max-height: 150px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  background: var(--color-surface);
}
.celltype-scrollable {
  max-height: 190px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 6px;
  background: var(--color-surface);
}

/* Subtype filter states */
.subtype-filters.is-waiting .celltype-scrollable {
  background: var(--color-surface2);
  border-style: dashed;
}
.subtype-filters.is-waiting .filter-actions button { opacity: 0.5; }
.subtype-filters.is-ready {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 2px rgba(59,108,244,0.1);
}
.subtype-filters.is-ready .filter-help { color: var(--color-primary); }
.subtype-filters.step-flash {
  box-shadow: 0 0 0 4px rgba(59,108,244,0.2), 0 4px 20px rgba(59,108,244,0.12) !important;
  transition: box-shadow 300ms ease;
}

/* ── Filter Actions ────────────────────────────────────────────── */
.filter-actions {
  margin-top: 0;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.filter-actions button, .toolbar button {
  border: 1px solid var(--color-border2);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all var(--transition);
}
.filter-actions button:hover, .toolbar button:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
  background: rgba(59,108,244,0.04);
}
.filter-actions button:active, .toolbar button:active {
  transform: scale(0.97);
}
.filter-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  border-color: var(--color-border);
  color: var(--color-text3);
}

/* ── Region Input ──────────────────────────────────────────────── */
.region-box input {
  width: 100%;
  box-sizing: border-box;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  background: white;
  font-family: var(--font-mono);
  font-size: 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.region-box input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,108,244,0.1);
}

/* ── Toolbar ───────────────────────────────────────────────────── */
.toolbar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
  padding: 10px 4px 6px;
  font-size: 12px;
  color: var(--color-text2);
  background: linear-gradient(to top, var(--color-surface) 70%, rgba(255,255,255,0));
}
.toolbar button.primary {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: white;
  font-weight: 700;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(16,185,100,0.25);
  transition: all var(--transition);
}
.toolbar button.primary:hover {
  background: var(--color-accent2);
  border-color: var(--color-accent2);
  box-shadow: 0 4px 14px rgba(16,185,100,0.35);
  transform: translateY(-1px);
}
.toolbar button.primary:active { transform: translateY(0) scale(0.98); }
.toolbar button.primary:disabled {
  background: #b0c4b8;
  border-color: #b0c4b8;
  color: #e8efe9;
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

.kb-shortcut-hint {
  font-size: 11px;
  color: var(--color-text3);
  text-align: center;
  padding: 2px 0 0;
}

/* ── Viewer ────────────────────────────────────────────────────── */
.viewer-wrap {
  min-width: 0; min-height: 0; height: 100%;
  background: white;
  position: relative;
}
#viewer-root { height: 100%; }


#viewer-root .TrackLegend-label,
#viewer-root .TrackLegend-wrap text {
  font-size: 12px !important;
  font-weight: 700 !important;
  white-space: pre-line !important;
}

/* Empty data banner */
.viewer-empty-banner {
  position: absolute;
  top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 10;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(6px);
  border: 1px solid var(--color-border2);
  border-radius: var(--radius);
  padding: 8px 22px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-primary);
  box-shadow: var(--color-shadow-lg);
  pointer-events: none;
  animation: fadeInDown 0.3s ease;
}
@keyframes fadeInDown {
  from { opacity: 0; transform: translateX(-50%) translateY(-8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Loading Overlay ───────────────────────────────────────────── */
.loading-overlay {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(240,242,247,0.78);
  backdrop-filter: blur(3px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}
.loading-overlay.is-visible { display: flex; }

.loading-spinner {
  width: 38px; height: 38px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text2);
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.45; }
}

/* ── Toast Notifications ───────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-text);
  color: white;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.18);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.5s forwards;
  max-width: 360px;
}
.toast.success { border-left: 3px solid var(--color-accent); }
.toast.error   { border-left: 3px solid var(--color-danger); }
.toast.info    { border-left: 3px solid var(--color-primary); }
.toast-icon { flex-shrink: 0; font-size: 15px; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateY(0) scale(1); }
  to   { opacity: 0; transform: translateY(-8px) scale(0.96); }
}

/* ── Focus Visible ─────────────────────────────────────────────── */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ── Responsive ────────────────────────────────────────────────── */
@media (max-width: 1300px) {
  .workspace { grid-template-columns: 250px minmax(0, 1fr); }
  .header h1 { font-size: 17px; }
}
@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; }
  .filter-panel { border-right: 0; border-bottom: 1px solid var(--color-border); max-height: 50vh; }
}
@media (max-width: 760px) {
  .header { padding: 10px 16px; }
  .header h1 { font-size: 15px; }
  .stat-badges { display: none; }
}
