/* Shared UI system styles */
:root {
  --app-bg: #f8f9fa;
  --app-card-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
  --app-border-radius: 12px;
}

body {
  background-color: var(--app-bg);
}

.app-page-title {
  font-weight: 600;
}

.app-card {
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  border: 1px solid #e9ecef;
}

.app-steps {
  gap: 0.5rem;
}

.app-steps .nav-link {
  border-radius: 999px;
  padding: 0.35rem 0.8rem;
  font-size: 0.85rem;
}

.app-steps .nav-link.active {
  background-color: #206bc4;
  color: #fff;
}

.app-auth-wrapper {
  min-height: 70vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-auth-card {
  max-width: 420px;
  width: 100%;
  padding: 2rem;
  background-color: #fff;
  margin: 0 auto;
}

.app-auth-logo {
  max-width: 60vw;
  width: 100%;
  margin: 0 auto 1rem;
  display: block;
}

.app-auth-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.app-login-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.app-logo-float {
  animation: app-logo-float 6s ease-in-out infinite;
}

.app-start-button {
  padding: 0.65rem 1.6rem;
  border-radius: 999px;
  box-shadow: 0 10px 24px rgba(32, 107, 196, 0.15);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.app-start-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(32, 107, 196, 0.22);
}

.app-login-card {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
}

.app-login-card.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.app-fade-out {
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

@keyframes app-logo-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.app-inline-help {
  color: #6c757d;
  font-size: 0.9rem;
}

.app-stepper {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.app-stepper .step {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: #e9ecef;
  font-size: 0.85rem;
}

.app-stepper .step.active {
  background: #206bc4;
  color: #fff;
}

.app-chart-container {
  background: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  padding: 1rem;
  border: 1px solid #e9ecef;
}

.app-map {
  width: 100%;
  height: 60vh;
  max-height: 720px;
  min-height: 320px;
  background-color: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
}

.app-sidebar {
  width: 100%;
  background: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  padding: 1rem;
}

.app-kpi-card {
  background: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  padding: 1rem;
}

.app-loading {
  display: none;
  align-items: center;
  gap: 0.5rem;
}

.app-loading.active {
  display: inline-flex;
}

.app-toast {
  margin-bottom: 1rem;
}

.cell-type-selector {
  background: #fff;
  padding: 1rem;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  margin-bottom: 1rem;
}

.cell-type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.cell-type-item {
  display: flex;
  align-items: center;
  padding: 8px;
  background: #f8f9fa;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s;
}

.cell-type-item:hover {
  background: #e9ecef;
}

.cell-type-color {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  margin-right: 8px;
  border: 1px solid #dee2e6;
}

.cell-type-label {
  flex: 1;
  font-size: 14px;
}

.cell-type-checkbox {
  margin-left: 8px;
}

.image-wrapper {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1050;
  display: none;
}

.background-layer {
  position: absolute;
  inset: 0;
  background-color: rgba(255, 255, 255, 0.7);
  border-radius: 8px;
}

#flashImage {
  position: relative;
  display: block;
  max-width: 100%;
  z-index: 1;
}

.fade-in-out {
  opacity: 0;
  transition: opacity 1s ease;
}

.app-floating-chat {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 1050;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

.app-chat-panel {
  width: 320px;
  max-height: 60vh;
  background: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  display: none;
  overflow: hidden;
  border: 1px solid #e9ecef;
}

.app-chat-panel.active {
  display: flex;
  flex-direction: column;
}

.app-chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid #e9ecef;
  font-weight: 600;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-chat-toolbar {
  padding: 8px 16px;
  border-bottom: 1px solid #e9ecef;
  display: flex;
  gap: 8px;
  align-items: center;
  background: #fff;
}

.app-chat-toolbar .form-select {
  flex: 1;
}

.app-chat-preview {
  padding: 8px 16px;
  border-bottom: 1px solid #e9ecef;
  background: #fff;
}

.app-chat-preview img {
  margin-top: 6px;
  max-width: 100%;
  border-radius: var(--app-border-radius);
  border: 1px solid #e9ecef;
}

.app-chat-body {
  padding: 12px 16px;
  flex: 1;
  overflow-y: auto;
  font-size: 0.9rem;
  color: #495057;
  background: #fdfdfd;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-chat-footer {
  padding: 12px 16px;
  border-top: 1px solid #e9ecef;
  display: flex;
  gap: 8px;
  background: #f8f9fa;
}

.app-chat-input {
  flex: 1;
}

.app-chat-fab {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: var(--app-card-shadow);
  position: relative;
}

.app-chat-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #fa5252;
  color: #fff;
  font-size: 0.7rem;
  line-height: 20px;
  text-align: center;
}

.app-chat-message {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  background: #eef2ff;
  color: #1f2d3d;
  line-height: 1.4;
}

.app-chat-message.user {
  align-self: flex-end;
  background: #206bc4;
  color: #fff;
}

.app-chat-message.system {
  align-self: flex-start;
  background: #f1f3f5;
  color: #495057;
}

.app-chat-message.bot {
  align-self: flex-start;
  background: #e7f5ff;
  color: #1c7ed6;
}

.app-chat-status {
  font-size: 0.75rem;
  color: #868e96;
}

.app-chat-typing {
  display: none;
  align-self: flex-start;
  font-size: 0.8rem;
  color: #868e96;
}

.app-chat-typing.active {
  display: inline-flex;
}

.app-preview {
  opacity: 0.7;
  border: 1px dashed #ced4da;
  padding: 0.5rem;
  border-radius: var(--app-border-radius);
  margin-top: 1rem;
}

.app-card .card-title::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #206bc4;
  margin-right: 8px;
  transform: translateY(-1px);
}
.app-chat-divider {
  height: 1px;
  width: 100%;
  background: #e9ecef;
  margin: 4px 0;
}

.app-report-tabs {
  padding-bottom: 1rem;
}

.app-report-tab-nav {
  border-bottom: 1px solid #e9ecef;
}

.app-report-tab-nav .nav-link {
  font-weight: 600;
}

.app-report-tab-nav .nav-link.active {
  color: #206bc4;
  border-color: #dee2e6 #dee2e6 #fff;
}

.app-report-tab-content {
  padding-top: 1rem;
}

.app-dashboard-card {
  background: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  border: 1px solid #e9ecef;
  height: 100%;
  padding: 1rem;
}

.app-dashboard-card-header {
  margin-bottom: 0.75rem;
}

.app-dashboard-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.app-dashboard-list-item .progress {
  height: 8px;
  margin-top: 0.35rem;
}

.app-dashboard-metric {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.app-dashboard-metric-value {
  font-size: 2rem;
  font-weight: 700;
  color: #1f2937;
}

.app-dashboard-top-list {
  padding-left: 1.1rem;
}

.app-dashboard-top-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.45rem;
}

.app-pipeline-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.app-pipeline-badge {
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  font-weight: 600;
}

.app-pipeline-badge.is-complete {
  background: #d3f9d8;
  color: #2b8a3e;
}

.app-pipeline-badge.is-running {
  background: #ffe3e3;
  color: #c92a2a;
}

.app-map-viewport {
  position: relative;
}

.app-map--tab {
  min-height: 78vh;
  max-height: none;
}

.app-map-viewport.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1100;
  padding: 1rem;
  background: rgba(10, 14, 20, 0.92);
}

.app-map-viewport.is-fullscreen .app-map {
  height: calc(100vh - 2rem);
  min-height: calc(100vh - 2rem);
  border-radius: 8px;
}

.app-map-fullscreen-open {
  overflow: hidden;
}

.app-download-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1rem;
}

@media (max-width: 992px) {
  .app-map--tab {
    min-height: 68vh;
  }
}

@media (max-width: 768px) {
  .app-download-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Report Screen Design v2 ===== */

:root {
  --app-brand: #206bc4;
  --app-brand-green: #2f9e44;
  --app-brand-orange: #e67700;
  --app-card-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

/* --- KPI Cards --- */
.app-kpi-card {
  background: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  padding: 1.25rem 1.5rem;
  border: 1px solid #e9ecef;
  border-left: 4px solid var(--app-brand);
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.app-kpi-card--green { border-left-color: var(--app-brand-green); }
.app-kpi-card--orange { border-left-color: var(--app-brand-orange); }

.app-kpi-icon {
  font-size: 1.35rem;
  color: var(--app-brand);
  margin-bottom: 0.35rem;
  line-height: 1;
}
.app-kpi-card--green .app-kpi-icon { color: var(--app-brand-green); }
.app-kpi-card--orange .app-kpi-icon { color: var(--app-brand-orange); }

.app-kpi-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #868e96;
}

.app-kpi-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: #1f2937;
  line-height: 1.15;
  margin-top: 0.1rem;
}

/* --- Tab Navigation --- */
.app-report-tab-nav {
  border-bottom: 2px solid #e9ecef;
  gap: 0;
}

.app-report-tab-nav .nav-item {
  margin-bottom: -2px;
}

.app-report-tab-nav .nav-link {
  font-weight: 600;
  font-size: 0.875rem;
  color: #6c757d;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 0.65rem 1.1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: color 0.15s ease, border-color 0.15s ease;
  background: transparent;
}

.app-report-tab-nav .nav-link i {
  font-size: 1rem;
  opacity: 0.65;
  transition: opacity 0.15s ease;
}

.app-report-tab-nav .nav-link:hover {
  color: var(--app-brand);
  border-bottom-color: #aec8e8;
  background: none;
}

.app-report-tab-nav .nav-link.active {
  color: var(--app-brand);
  border-bottom: 2px solid var(--app-brand);
  background: none;
}

.app-report-tab-nav .nav-link.active i {
  opacity: 1;
}

/* --- Section Icon Utility --- */
.app-section-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #e7f0fb;
  color: var(--app-brand);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* --- Dashboard Card Header --- */
.app-dashboard-card-header {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #f1f3f5;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.app-dashboard-card-header h6 {
  font-weight: 700;
  color: #374151;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  margin-bottom: 0;
}

/* --- Chart Container Title --- */
.app-chart-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #f1f3f5;
  margin-bottom: 0.85rem;
}

.app-chart-title h6 {
  font-weight: 700;
  color: #374151;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.055em;
  margin-bottom: 0;
}

/* --- Region Stats Grid --- */
.app-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.app-stat-item {
  background: #f8f9fa;
  border-radius: 7px;
  padding: 0.55rem 0.8rem;
  border: 1px solid #e9ecef;
}

.app-stat-item-label {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #868e96;
  margin-bottom: 0.15rem;
}

.app-stat-item-value {
  font-size: 1rem;
  font-weight: 700;
  color: #1f2937;
}

/* --- Analysis Pipeline --- */
.app-pipeline-list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0;
}

.app-pipeline-arrow {
  color: #adb5bd;
  margin: 0 0.4rem;
  font-size: 1rem;
  line-height: 1;
}

/* --- Dashboard Metric (Tumor Ratio) --- */
.app-dashboard-metric-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--app-brand);
  line-height: 1;
  letter-spacing: -0.02em;
}

/* --- Card title accent dot override --- */
.app-card .card-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: #374151;
}

/* --- Phenotype distribution rows --- */
.app-phenotype-dist-header {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #868e96;
  margin-bottom: 0.6rem;
  padding-top: 0.75rem;
  border-top: 1px solid #f1f3f5;
}

/* --- Report Sidebar Layout --- */
.app-report-layout {
  display: flex;
  align-items: flex-start;
  padding-top: 1rem;
  gap: 0;
}

.app-report-main {
  flex: 1;
  min-width: 0;
  padding-right: 0.5rem;
}

.app-report-layout .app-report-tab-content {
  padding-top: 0;
}

/* --- Sidebar Wrapper (toggle btn + aside) --- */
.app-report-sidebar-wrapper {
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
  position: sticky;
  top: 1rem;
}

/* --- Toggle Button --- */
.app-sidebar-toggle {
  position: sticky;
  top: 1rem;
  align-self: flex-start;
  width: 22px;
  height: 44px;
  padding: 0;
  background: #fff;
  border: 1px solid #e9ecef;
  border-right: none;
  border-radius: 6px 0 0 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #868e96;
  transition: background 0.15s ease, color 0.15s ease;
  box-shadow: -2px 2px 6px rgba(0,0,0,0.05);
  flex-shrink: 0;
}

.app-sidebar-toggle:hover {
  background: #f1f3f5;
  color: var(--app-brand);
}

.app-sidebar-toggle i {
  font-size: 0.85rem;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Sidebar --- */
.app-report-sidebar {
  width: 280px;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: #dee2e6 transparent;
  border-left: 1px solid #e9ecef;
  padding-left: 1rem;
  /* Slide animation */
  transition: width 0.32s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease,
              padding-left 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-report-sidebar::-webkit-scrollbar { width: 4px; }
.app-report-sidebar::-webkit-scrollbar-track { background: transparent; }
.app-report-sidebar::-webkit-scrollbar-thumb { background: #dee2e6; border-radius: 4px; }

/* Collapsed state */
.app-report-sidebar.is-collapsed {
  width: 0;
  opacity: 0;
  padding-left: 0;
  border-left-color: transparent;
  pointer-events: none;
}

/* Content inside sidebar — prevent width transition from clipping text ugly */
.app-report-sidebar > * {
  min-width: 260px;
}

/* Toggle icon flips when collapsed */
.app-sidebar-toggle.is-open i {
  transform: rotate(180deg);
}

/* --- Sidebar Cards --- */
.app-sidebar-region-card {
  background: #fff;
  border-radius: var(--app-border-radius);
  box-shadow: var(--app-card-shadow);
  border: 1px solid #e9ecef;
  padding: 1rem;
}

.app-sidebar-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6c757d;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.app-sidebar-section-title i {
  color: var(--app-brand);
  font-size: 0.95rem;
}

/* Single column stat-grid inside sidebar */
.app-report-sidebar .app-stat-grid {
  grid-template-columns: 1fr;
}

@media (max-width: 768px) {
  .app-report-layout {
    flex-direction: column;
  }
  .app-report-sidebar-wrapper {
    position: static;
    width: 100%;
    flex-direction: column;
  }
  .app-sidebar-toggle {
    width: 100%;
    height: 32px;
    border-radius: 6px;
    border-right: 1px solid #e9ecef;
    border-bottom: none;
  }
  .app-report-sidebar {
    width: 100% !important;
    max-height: none;
    border-left: none;
    border-top: 1px solid #e9ecef;
    padding-left: 0;
    padding-top: 1rem;
  }
  .app-report-sidebar.is-collapsed {
    width: 0 !important;
    padding-top: 0;
  }
  .app-report-sidebar > * {
    min-width: unset;
  }
  .app-stat-grid {
    grid-template-columns: 1fr;
  }
  .app-kpi-value {
    font-size: 1.4rem;
  }
}

/* ==========================================================================
   Floating map controls (Phase 4)
   ========================================================================== */
.app-floating-controls {
  position: absolute;
  top: 12px;
  right: 12px;
  width: min(360px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: var(--app-border-radius);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  z-index: 600;
  overflow: hidden;
  transition: transform 220ms ease, opacity 220ms ease;
}

.app-floating-controls.is-collapsed {
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
}

.app-floating-controls__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 0.75rem;
  border-bottom: 1px solid #e9ecef;
  background: #f8fafc;
}

.app-floating-controls__tabs {
  display: flex;
  flex: 1;
  gap: 0.25rem;
  overflow-x: auto;
}

.app-floating-controls__tab {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.6rem;
  border: none;
  background: transparent;
  border-radius: 999px;
  color: #4b5563;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease, color 120ms ease;
}

.app-floating-controls__tab i {
  font-size: 0.95rem;
}

.app-floating-controls__tab:hover {
  background: #e7eef9;
  color: #1f2937;
}

.app-floating-controls__tab.is-active {
  background: var(--app-brand, #206bc4);
  color: #fff;
}

.app-floating-controls__tab:focus-visible,
.app-floating-controls__collapse:focus-visible,
.app-floating-controls__handle:focus-visible {
  outline: 2px solid #206bc4;
  outline-offset: 2px;
}

.app-floating-controls__collapse {
  border: none;
  background: transparent;
  color: #4b5563;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease;
}

.app-floating-controls__collapse:hover {
  background: #e7eef9;
}

.app-floating-controls__pane {
  display: none;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.85rem 0.85rem 1rem;
  overflow-y: auto;
  scrollbar-width: thin;
}

.app-floating-controls__pane.is-active {
  display: flex;
}

.app-floating-controls__pane::-webkit-scrollbar {
  width: 6px;
}

.app-floating-controls__pane::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.app-floating-controls__divider {
  height: 1px;
  background: #e5e7eb;
  margin: 0.25rem 0;
}

.app-floating-controls__handle {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: #fff;
  color: #1f2937;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 600;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.18);
  transition: transform 120ms ease, background 120ms ease;
}

.app-floating-controls__handle:hover {
  background: #f3f4f6;
  transform: translateX(-2px);
}

/* ==========================================================================
   Cell-type toggle list (Phase 2)
   ========================================================================== */
.app-cell-toggle-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.app-cell-toggle-search {
  position: relative;
}

.app-cell-toggle-search i {
  position: absolute;
  top: 50%;
  left: 0.55rem;
  transform: translateY(-50%);
  color: #9ca3af;
  font-size: 0.95rem;
  pointer-events: none;
}

.app-cell-toggle-search input {
  padding-left: 1.85rem;
}

.app-cell-toggle-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
}

.app-cell-toggle-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 38vh;
  overflow-y: auto;
  padding-right: 0.15rem;
  scrollbar-width: thin;
}

.app-cell-toggle-list::-webkit-scrollbar {
  width: 6px;
}

.app-cell-toggle-list::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.app-cell-toggle-empty {
  padding: 0.75rem;
  text-align: center;
  color: #6b7280;
  font-size: 0.85rem;
  background: #f9fafb;
  border-radius: 6px;
}

.app-cell-toggle-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.55rem;
  padding: 0.5rem 0.65rem;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  transition: border-color 120ms ease, background 120ms ease, opacity 120ms ease;
  user-select: none;
}

.app-cell-toggle-item:hover {
  border-color: #c7d2fe;
  background: #f8fafc;
}

.app-cell-toggle-item.is-disabled {
  opacity: 0.55;
  filter: grayscale(0.45);
}

.app-cell-toggle-item.is-disabled .app-cell-toggle-item__swatch {
  background: transparent;
  box-shadow: inset 0 0 0 2px var(--swatch-color, #9ca3af);
}

.app-cell-toggle-item__swatch {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--swatch-color, #9ca3af);
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.app-cell-toggle-item__body {
  min-width: 0;
}

.app-cell-toggle-item__name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-cell-toggle-item__stats {
  display: flex;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: #6b7280;
}

.app-cell-toggle-item__count::before {
  content: 'n=';
  opacity: 0.7;
  margin-right: 1px;
}

.app-cell-toggle-item__roles {
  display: flex;
  gap: 0.25rem;
}

.app-cell-toggle-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 22px;
  padding: 0 0.35rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: #6b7280;
  background: #f3f4f6;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.app-cell-toggle-chip input {
  position: absolute;
  opacity: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.app-cell-toggle-chip:has(input:checked) {
  background: #1f2937;
  color: #fff;
  border-color: #1f2937;
}

.app-cell-toggle-chip--heatmap:has(input:checked) {
  background: #b45309;
  border-color: #b45309;
}

.app-cell-toggle-chip:has(input:focus-visible) {
  outline: 2px solid #206bc4;
  outline-offset: 1px;
}

.app-cell-toggle-chip.is-disabled,
.app-cell-toggle-chip:has(input:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.app-cell-toggle-groups {
  font-size: 0.82rem;
}

.app-cell-toggle-groups summary {
  cursor: pointer;
  color: #4b5563;
  margin-bottom: 0.4rem;
}

.app-cell-toggle-groups__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.5rem;
}

.app-cell-toggle-groups__form {
  display: flex;
  gap: 0.3rem;
}

.app-cell-toggle-group-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.app-cell-toggle-group-chip:hover {
  background: #e0e7ff;
}

.app-cell-toggle-group-chip__remove {
  border: none;
  background: transparent;
  color: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  opacity: 0.6;
}

.app-cell-toggle-group-chip__remove:hover {
  opacity: 1;
}

/* ==========================================================================
   Nearest Neighbor controls (Phase 3)
   ========================================================================== */
.app-nn-form__title {
  font-size: 0.8rem;
  font-weight: 700;
  color: #1f2937;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}

.app-nn-form .form-label-sm {
  font-size: 0.75rem;
  font-weight: 600;
  color: #4b5563;
  margin-bottom: 0.2rem;
}

#nnFavoriteToggle.is-favorited {
  color: #b45309;
  border-color: #f59e0b;
  background: #fffbeb;
}

.app-nn-section {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.app-nn-section__head {
  font-size: 0.72rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.app-nn-favorites__list,
.app-nn-recommend__list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.app-nn-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.55rem;
  background: #f3f4f6;
  color: #1f2937;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease;
}

.app-nn-chip:hover {
  background: #e5e7eb;
  border-color: #d1d5db;
}

.app-nn-chip__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.app-nn-chip__meta {
  font-size: 0.68rem;
  color: #6b7280;
}

.app-nn-chip--recommend {
  background: #fff7ed;
  color: #9a3412;
}

.app-nn-pair-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.app-nn-pair-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 38vh;
  overflow-y: auto;
  padding-right: 0.15rem;
}

.app-nn-pair-list::-webkit-scrollbar {
  width: 6px;
}

.app-nn-pair-list::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 4px;
}

.app-nn-pair-empty {
  padding: 0.6rem 0.75rem;
  font-size: 0.78rem;
  text-align: center;
  color: #6b7280;
  background: #f9fafb;
  border-radius: 6px;
}

.app-nn-pair-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  transition: opacity 120ms ease, background 120ms ease;
}

.app-nn-pair-row.is-hidden {
  opacity: 0.6;
  background: #f9fafb;
}

.app-nn-pair-row:hover {
  background: #f8fafc;
}

.app-nn-pair-row__color {
  position: relative;
  width: 22px;
  height: 22px;
  cursor: pointer;
}

.app-nn-pair-row__color input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
}

.app-nn-pair-row__color-dot {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 0 0 2px #fff;
}

.app-nn-pair-row__body {
  min-width: 0;
}

.app-nn-pair-row__title {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-nn-pair-row__title i {
  color: #6b7280;
}

.app-nn-pair-row__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  font-size: 0.7rem;
  color: #6b7280;
}

.app-nn-pair-row__meta i {
  margin-right: 0.15rem;
  font-size: 0.78rem;
}

.app-nn-pair-row__topk {
  background: #eef2ff;
  color: #3730a3;
  border-radius: 999px;
  padding: 0 0.4rem;
  font-weight: 600;
}

.app-nn-pair-row__actions {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
}

.app-nn-pair-row__actions button {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Inline error state for NN selects */
#NNfrom.is-invalid,
#NNto.is-invalid {
  border-color: #dc2626;
}

#NNfromError,
#NNtoError {
  display: block;
  font-size: 0.72rem;
  color: #dc2626;
  min-height: 1em;
  margin-top: 0.2rem;
}

#NNfromError:empty,
#NNtoError:empty {
  display: none;
}

/* Mobile (offcanvas-like behavior) */
@media (max-width: 768px) {
  .app-floating-controls {
    width: calc(100% - 24px);
    max-height: 65%;
  }
  .app-cell-toggle-list,
  .app-nn-pair-list {
    max-height: 30vh;
  }
}

/* Fullscreen viewport — keep panel readable on dark backdrop */
.app-map-viewport.is-fullscreen .app-floating-controls {
  background: rgba(255, 255, 255, 0.94);
}

.app-map-viewport.is-fullscreen .app-floating-controls__handle {
  background: rgba(255, 255, 255, 0.94);
}

/* =========================================================================
   AnyPath Design System — brand override layer
   Loaded last; remaps the legacy --app-* palette and Bootstrap/Tabler
   primitives onto the design tokens (colors_and_type.css). This brands
   report.html / select_columns.html (incl. JS-generated markup) with the
   navy/cyan system without rewriting their structure.
   ========================================================================= */
:root {
  --app-bg: var(--bg);
  --app-brand: var(--cyan-500);
  --app-brand-green: var(--success-500);
  --app-brand-orange: var(--warning-500);
  --app-border-radius: var(--r-md);
  --app-card-shadow: var(--shadow-1);
}

/* ----- Buttons ----- */
.btn-primary {
  background-color: var(--cyan-400); border-color: var(--cyan-400); color: #fff;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active,
.btn-primary:focus-visible, .btn-check:checked + .btn-primary {
  background-color: var(--cyan-500); border-color: var(--cyan-500); color: #fff;
}
.btn-success { background-color: var(--success-500); border-color: var(--success-500); color: #fff; }
.btn-success:hover, .btn-success:focus, .btn-success:active { filter: brightness(.94); color: #fff; }
.btn-secondary { background-color: #fff; border-color: var(--border-strong); color: var(--navy-700); }
.btn-secondary:hover, .btn-secondary:focus, .btn-secondary:active { background-color: var(--ink-50); color: var(--navy-700); border-color: var(--border-strong); }
.btn-outline-primary { color: var(--cyan-600); border-color: var(--cyan-400); }
.btn-outline-primary:hover, .btn-outline-primary:focus, .btn-outline-primary:active { background-color: var(--cyan-50); border-color: var(--cyan-500); color: var(--cyan-700); }
.btn-outline-secondary { color: var(--ink-700); border-color: var(--border-strong); }
.btn-outline-secondary:hover, .btn-outline-secondary:focus, .btn-outline-secondary:active { background-color: var(--ink-50); border-color: var(--border-strong); color: var(--ink-900); }
.btn-outline-danger { color: var(--danger-500); border-color: #F1C7CF; }
.btn-outline-danger:hover, .btn-outline-danger:focus, .btn-outline-danger:active { background-color: var(--danger-50); border-color: var(--danger-500); color: var(--danger-500); }
.btn:focus-visible, .btn:focus { box-shadow: var(--glow-cyan-sm); }

/* ----- Form controls ----- */
.form-control, .form-select {
  border-color: var(--border-strong);
  border-radius: var(--r-sm);
}
.form-control:focus, .form-select:focus {
  border-color: var(--cyan-400);
  box-shadow: var(--glow-cyan-sm);
}
.form-check-input:checked { background-color: var(--cyan-400); border-color: var(--cyan-400); }
.form-check-input:focus { border-color: var(--cyan-400); box-shadow: var(--glow-cyan-sm); }

/* ----- Nav pills (legacy) ----- */
.nav-pills .nav-link.active { background-color: var(--cyan-500); }

/* ----- Cards / alerts radius ----- */
.app-card, .card { border-radius: var(--r-md); }
a { color: var(--cyan-500); }
a:hover { color: var(--cyan-600); }

/* ----- Mapping stepper ----- */
.app-stepper .step {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--ink-500); font-weight: 600;
}
.app-stepper .step.active { background: var(--navy-50); color: var(--navy-700); border-color: var(--navy-100); }

/* ----- Report KPI cards: remove left-stripe, use brand gradients ----- */
.app-kpi-card {
  border: 0; border-radius: var(--r-lg); color: #fff;
  background: linear-gradient(135deg, #0098DA, #007BB8);
  box-shadow: var(--shadow-1);
}
.app-kpi-card--blue   { background: linear-gradient(135deg, #0098DA, #007BB8); }
.app-kpi-card--green  { background: linear-gradient(135deg, #0E9F6E, #0B7E58); }
.app-kpi-card--orange { background: linear-gradient(135deg, #E08900, #C06E00); }
.app-kpi-icon,
.app-kpi-card--green .app-kpi-icon,
.app-kpi-card--orange .app-kpi-icon { color: rgba(255, 255, 255, .55); }
.app-kpi-label { color: rgba(255, 255, 255, .85); }
.app-kpi-value { color: #fff; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ----- Report tabs ----- */
.app-report-tab-nav .nav-link:hover { color: var(--navy-700); border-bottom-color: var(--cyan-200); }
.app-report-tab-nav .nav-link.active { color: var(--navy-700); border-bottom-color: var(--cyan-400); }

/* ----- Section icon ----- */
.app-section-icon { background: var(--cyan-50); color: var(--cyan-500); }

/* ----- Dashboard metric ----- */
.app-dashboard-metric-value { color: var(--cyan-600); font-family: var(--font-mono); }

/* ----- Pipeline badges ----- */
.app-pipeline-badge.is-complete { background: var(--success-50); color: #0E7C56; }
.app-pipeline-badge.is-running  { background: var(--cyan-50); color: var(--cyan-600); }
