* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
  background: #f5f5f5;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

.header {
  background: #2c3e50;
  color: white;
  padding: 5px 45px 5px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  flex-wrap: nowrap;
  min-height: 60px;
  position: relative;
  transition: all 0.3s ease;
  gap: 12px;
}

.header.collapsed {
  min-height: 0;
  max-height: 8px;
  overflow: visible;
  padding: 0;
}

.header.collapsed .header-brand,
.header.collapsed .controls {
  opacity: 0;
  visibility: hidden;
  height: 0;
  overflow: hidden;
}

.header-toggle-btn {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, #34495e 0%, #2c3e50 100%);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  color: white;
  width: 32px;
  height: 32px;
  cursor: pointer;
  font-size: 14px;
  z-index: 1001;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-toggle-btn:hover {
  background: linear-gradient(135deg, #3d566e 0%, #34495e 100%);
  border-color: rgba(255, 255, 255, 0.4);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  transform: translateY(-50%) scale(1.08);
}

.header-toggle-btn .toggle-icon {
  display: inline-block;
  transition: transform 0.3s ease;
  font-size: 12px;
  font-weight: bold;
}

.header.collapsed .header-toggle-btn {
  top: 4px;
  transform: translateY(0);
  background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 0 3px 10px rgba(25, 118, 210, 0.4);
}

.header.collapsed .header-toggle-btn:hover {
  background: linear-gradient(135deg, #2196f3 0%, #1976d2 100%);
  box-shadow: 0 4px 14px rgba(25, 118, 210, 0.5);
  transform: translateY(0) scale(1.08);
}

.header.collapsed .header-toggle-btn .toggle-icon {
  transform: rotate(180deg);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header .logo {
  height: 55px;
  width: auto;
  object-fit: contain;
  filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.1));
  transition: transform 0.2s ease, filter 0.2s ease;
}

.header .logo:hover {
  transform: scale(1.05);
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.15));
}

.header h1 {
  font-size: 20px;
  font-weight: 500;
}

.controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: nowrap;
  flex-shrink: 1;
  min-width: 0;
}

.controls label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.controls select {
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(255,255,255,0.9);
  font-size: 14px;
  cursor: pointer;
}

.controls input[type="checkbox"] {
  cursor: pointer;
}

/* Search container */
.search-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.95);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  position: relative;
  flex-shrink: 1;
  min-width: 200px;
  max-width: 300px;
}

.search-icon {
  font-size: 16px;
  color: #666;
  flex-shrink: 0;
}

.search-input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  flex: 1;
  min-width: 80px;
  color: #333;
}

.search-input::placeholder {
  color: #999;
}

.search-match-count {
  font-family: monospace;
  font-size: 14px;
  font-weight: 600;
  color: #1976d2;
  background: #e3f2fd;
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 30px;
  text-align: center;
}

.search-results-summary {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #666;
  background: #f5f5f5;
  padding: 4px 8px;
  border-radius: 10px;
}

.search-menu-btn {
  background: none;
  border: none;
  font-size: 14px;
  color: #666;
  cursor: pointer;
  padding: 0 4px;
  transition: color 0.2s;
}

.search-menu-btn:hover {
  color: #1976d2;
}

.clear-search-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.clear-search-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #666;
}

/* Search help tooltip */
.search-help-tooltip {
  position: fixed;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  min-width: 320px;
  max-width: 400px;
  font-size: 13px;
}

.search-help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #e0e0e0;
  background: #f8f9fa;
  border-radius: 8px 8px 0 0;
}

.search-help-header strong {
  font-size: 14px;
  color: #333;
}

.search-help-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.search-help-close:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #666;
}

.search-help-content {
  padding: 12px 16px;
}

.search-help-section {
  margin-bottom: 16px;
}

.search-help-section:last-child {
  margin-bottom: 0;
}

.search-help-title {
  font-weight: 600;
  color: #1976d2;
  margin-bottom: 6px;
  font-size: 13px;
}

.search-help-example {
  margin-bottom: 4px;
  line-height: 1.6;
}

.search-help-example code {
  background: #e3f2fd;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: monospace;
  font-size: 12px;
  color: #1976d2;
}

.search-help-note {
  font-size: 12px;
  color: #666;
  line-height: 1.6;
  margin-top: 4px;
}

.controls .btn-configure {
  padding: 5px 12px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(255,255,255,0.9);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.controls .btn-configure:hover {
  background: rgba(255,255,255,1);
}

.container {
  flex: 1;
  display: flex;
  gap: 0;
  padding: 10px;
  overflow: hidden;
}

.panel {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease;
  flex: 1;
  min-width: 200px;
}

.panel.tree-panel {
  flex: 0 0 50%;
  position: relative; /* For absolute child elements */
}

.panel.table-panel {
  flex: 0 0 calc(50% - 10px);
}

/* Resize handle */
.resize-handle {
  width: 10px;
  cursor: col-resize;
  background: transparent;
  position: relative;
  flex-shrink: 0;
  transition: background 0.2s;
}

.resize-handle:hover {
  background: rgba(25, 118, 210, 0.1);
}

.resize-handle::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 40px;
  background: #ddd;
  border-radius: 2px;
}

.resize-handle:hover::before {
  background: #1976d2;
}

.resize-handle.dragging {
  background: rgba(25, 118, 210, 0.2);
}

.resize-handle.dragging::before {
  background: #1976d2;
}

.panel.table-panel.collapsed {
  max-width: 40px;
  min-width: 40px;
  flex: 0 0 40px;
}

.panel.table-panel.collapsed .table-container {
  display: none;
}

.panel.table-panel.collapsed .panel-header {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  padding: 16px 8px;
  white-space: nowrap;
  height: 100%;
}

.panel.table-panel.collapsed .panel-title {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.panel.table-panel.collapsed .collapse-icon {
  transform: rotate(180deg);
}

.panel.table-panel.collapsed .panel-header-actions {
  display: none;
}

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

.panel-header.collapsible {
  cursor: pointer;
  user-select: none;
}

.panel-header.collapsible:hover {
  background: #e9ecef;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.collapse-icon {
  font-size: 12px;
  color: #666;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mapping-info {
  font-size: 12px;
  color: #1976d2;
  font-weight: normal;
  padding-right: 8px;
  border-right: 1px solid #e0e0e0;
  margin-right: 8px;
}

.selection-info {
  font-size: 12px;
  color: #666;
  font-weight: normal;
}

.btn-small {
  padding: 4px 12px;
  font-size: 12px;
  background: #1976d2;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-small:hover {
  background: #1565c0;
}

.btn-small:active {
  background: #0d47a1;
}

.tree-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

.tree-container canvas {
  cursor: default;
}

.tree-container canvas:hover {
  cursor: pointer;
}

.table-container {
  flex: 1;
  overflow: auto;
  padding: 10px;
}

#metadata-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#metadata-table thead {
  position: sticky;
  top: 0;
  background: #f8f9fa;
  z-index: 10;
}

#metadata-table th {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid #e0e0e0;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  user-select: none;
}

#metadata-table th.sortable {
  cursor: pointer;
  transition: background 0.2s;
}

#metadata-table th.sortable:hover {
  background: #e3f2fd;
}

#metadata-table th.checkbox-col {
  width: 40px;
  text-align: center;
  padding: 10px 8px;
}

.header-content {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.header-name {
  font-weight: 600;
}

.label-field-indicator {
  font-size: 14px;
  line-height: 1;
  opacity: 0.8;
  cursor: pointer;
}

.sort-indicator {
  font-size: 10px;
  color: #1976d2;
  margin-left: 4px;
}

#metadata-table td.checkbox-col {
  width: 40px;
  text-align: center;
  padding: 8px;
}

#metadata-table input[type="checkbox"] {
  cursor: pointer;
  width: 16px;
  height: 16px;
}

#metadata-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
}

#metadata-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

#metadata-table tbody tr:hover {
  background: #f5f5f5;
}

#metadata-table tbody tr.selected {
  background: #e3f2fd;
}

#metadata-table tbody tr.selected:hover {
  background: #bbdefb;
}

#metadata-table tbody tr.mapped-to-tree td:first-child::before {
  content: '🌲';
  font-size: 10px;
  margin-right: 4px;
}

#metadata-table tbody tr.unmapped-row {
  opacity: 0.5;
}

#metadata-table tbody tr.unmapped-row td {
  color: #999;
}

#metadata-table tbody tr.hover-highlight {
  background: #fff3cd;
  border-left: 3px solid #ffc107;
}

#metadata-table tbody tr.hover-highlight.selected {
  background: #e3f2fd;
  border-left: 3px solid #1976d2;
}

.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.95);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid #e0e0e0;
  border-top-color: #1976d2;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading p {
  margin-top: 20px;
  color: #666;
  font-size: 14px;
}

canvas {
  display: block;
}

/* Phylocanvas Control Menu */
.phylocanvas-control-menu {
  position: absolute;
  top: 10px;
  z-index: 100;
}

/* Nodes & Labels button - leftmost */
.phylocanvas-control-menu:has(#nodes-labels-btn) {
  right: 450px;
}

/* Layout button - rightmost */
.phylocanvas-control-menu:has(#tree-layout-btn) {
  right: 10px;
}

/* Metadata Blocks button - middle */
.phylocanvas-control-menu:has(#metadata-blocks-btn) {
  right: 110px;
}

/* Tooltip button */
.phylocanvas-control-menu:has(#tooltip-menu-btn) {
  right: 280px;
}

/* Save Settings button */
.phylocanvas-save-settings-btn {
  position: absolute;
  top: 10px;
  left: 68px;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-10px);
  transition: all 0.3s ease;
}

.phylocanvas-save-settings-btn.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

.save-settings-button {
  background: white;
  border: 1px solid #ddd;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.2s;
  font-size: 18px;
}

.save-settings-button:hover {
  background: #f5f5f5;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transform: scale(1.05);
}

.save-settings-button:active {
  transform: scale(0.95);
}

.save-settings-button:disabled,
.save-settings-button.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: auto;
}

.save-settings-button:disabled:hover,
.save-settings-button.disabled:hover {
  background: white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transform: none;
}

.phylocanvas-control-menu .menu-trigger {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  transition: all 0.2s;
}

.phylocanvas-control-menu .menu-trigger:hover {
  background: #f5f5f5;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.phylocanvas-control-menu .menu-trigger span:first-child {
  font-size: 16px;
}

.phylocanvas-control-menu .menu-content {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 8px;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  width: 360px;
  display: none;
  flex-direction: column;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  overflow-x: hidden;
}

.phylocanvas-control-menu .menu-content::-webkit-scrollbar {
  width: 8px;
}

.phylocanvas-control-menu .menu-content::-webkit-scrollbar-track {
  background: #f5f5f5;
}

.phylocanvas-control-menu .menu-content::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.phylocanvas-control-menu .menu-content::-webkit-scrollbar-thumb:hover {
  background: #999;
}

.phylocanvas-control-menu .menu-content-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.phylocanvas-control-menu .menu-column {
  display: flex;
  flex-direction: column;
}

.phylocanvas-control-menu .menu-column:first-child {
  border-right: 1px solid #e0e0e0;
}

.phylocanvas-control-menu .menu-content.open {
  display: flex;
}

.phylocanvas-control-menu .menu-header {
  padding: 14px 20px;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 600;
  font-size: 13px;
  color: #333;
  background: #f8f9fa;
  border-radius: 4px 4px 0 0;
  margin-top: 8px;
}

.phylocanvas-control-menu .menu-header:first-child {
  margin-top: 0;
}

.phylocanvas-control-menu .menu-section {
  padding: 0;
}

.phylocanvas-control-menu .menu-item {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.2s;
  gap: 12px;
  font-size: 13px;
  min-height: 36px;
}

.phylocanvas-control-menu .menu-item:hover {
  background: #f5f5f5;
}

.phylocanvas-control-menu .menu-item input[type="radio"] {
  cursor: pointer;
}

.phylocanvas-control-menu .menu-item span {
  user-select: none;
}

/* Metadata fields search */
.metadata-fields-search {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.metadata-fields-search:focus {
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

.metadata-fields-search::placeholder {
  color: #999;
}

/* Field color item with collapsible palette controls */
.phylocanvas-control-menu .field-color-item {
  display: block;
  padding: 0;
  cursor: default;
  transition: background 0.2s;
  border-bottom: 1px solid #f0f0f0;
}

.phylocanvas-control-menu .field-color-item:last-child {
  border-bottom: none;
}

.phylocanvas-control-menu .field-color-item:hover {
  background: #f8f9fa;
}

/* Checkbox row - always visible */
.phylocanvas-control-menu .field-checkbox-row {
  padding: 8px 12px;
}

.phylocanvas-control-menu .field-checkbox-row label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

.phylocanvas-control-menu .field-checkbox-row label input[type="checkbox"] {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin: 0;
  cursor: pointer;
}

.phylocanvas-control-menu .field-checkbox-row .field-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: #333;
  font-weight: normal;
}

/* Palette controls - shown only when checked */
.phylocanvas-control-menu .field-palette-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 12px 12px 36px;
  background: #f8f9fa;
}

.phylocanvas-control-menu .field-palette-select {
  padding: 4px 8px;
  border-radius: 3px;
  border: 1px solid #ddd;
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.2s;
}

.phylocanvas-control-menu .field-palette-select:hover {
  border-color: #1976d2;
}

.phylocanvas-control-menu .field-palette-select:focus {
  outline: none;
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

/* Field palette preview in metadata blocks menu */
.phylocanvas-control-menu .field-palette-preview {
  display: flex;
  gap: 2px;
  height: 20px;
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
  background: white;
}

.phylocanvas-control-menu .field-palette-preview .palette-color {
  flex: 1;
  min-width: 0;
  border-radius: 0;
}

/* Scrollable metadata blocks section */
.phylocanvas-control-menu .metadata-blocks-section {
  max-height: 350px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #ccc #f5f5f5;
  padding: 0;
  margin: 0;
}

.phylocanvas-control-menu .metadata-blocks-section::-webkit-scrollbar {
  width: 8px;
}

.phylocanvas-control-menu .metadata-blocks-section::-webkit-scrollbar-track {
  background: #f5f5f5;
  border-radius: 4px;
}

.phylocanvas-control-menu .metadata-blocks-section::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.phylocanvas-control-menu .metadata-blocks-section::-webkit-scrollbar-thumb:hover {
  background: #999;
}

.phylocanvas-control-menu .menu-divider {
  margin: 8px 0;
  border: none;
  border-top: 1px solid #e0e0e0;
}

.phylocanvas-control-menu .slider-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
  padding: 12px 20px;
}

.phylocanvas-control-menu .slider-item input[type="range"] {
  width: 100%;
  cursor: pointer;
}

.phylocanvas-control-menu .slider-item span:last-child {
  font-size: 11px;
  color: #666;
  text-align: right;
}

/* Toggle item styling */
.phylocanvas-control-menu .toggle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
}

.phylocanvas-control-menu .toggle-item span {
  flex: 1;
}

/* Compact menu styles */
.phylocanvas-control-menu .compact-menu .menu-section.compact {
  padding: 8px 12px;
}

.phylocanvas-control-menu .compact-menu .menu-item.compact {
  padding: 6px 12px;
  min-height: 28px;
}

.phylocanvas-control-menu .compact-menu .toggle-item.compact {
  padding: 6px 12px;
}

.phylocanvas-control-menu .menu-subsection-title {
  font-size: 11px;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  padding: 0 12px;
}

.phylocanvas-control-menu .compact-menu .slider-item {
  padding: 6px 12px;
  gap: 6px;
}

/* iOS-style toggle switch */
.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background: #ccc;
  outline: none;
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.3s;
  margin-left: auto;
}

.toggle-switch:checked {
  background: #4CAF50;
}

.toggle-switch::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: white;
  top: 2px;
  left: 2px;
  transition: transform 0.3s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch:checked::before {
  transform: translateX(20px);
}

.toggle-switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Tooltip menu specific styles */
.tooltip-search-container {
  padding: 0;
  margin-bottom: 6px;
}

.tooltip-search-input {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}

.tooltip-search-input:focus {
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

.tooltip-search-input::placeholder {
  color: #999;
}

.tooltip-fields-section {
  max-height: 300px;
  overflow-y: auto;
  padding: 4px 0 !important;
}

.tooltip-field-item {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.2s;
  gap: 8px;
}

.tooltip-field-item:hover {
  background: #f5f5f5;
}

.tooltip-field-checkbox {
  cursor: pointer;
  width: 16px;
  height: 16px;
  margin: 0;
}

/* Phylocanvas Scale Bar */
.phylocanvas-scalebar {
  position: absolute;
  z-index: 350;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #333;
  padding: 8px 12px;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  font-family: monospace;
  font-size: 12px;
}

.scalebar-line {
  height: 2px;
  background: #333;
  margin-bottom: 4px;
  position: relative;
}

.scalebar-line::before,
.scalebar-line::after {
  content: '';
  position: absolute;
  width: 2px;
  height: 8px;
  background: #333;
  top: -3px;
}

.scalebar-line::before {
  left: 0;
}

.scalebar-line::after {
  right: 0;
}

.scalebar-label {
  text-align: center;
  color: #333;
  font-weight: 600;
}

/* Scale Bar Drag Handle */
.scalebar-header {
  cursor: move;
  user-select: none;
}

/* Scale Bar Dragging State */
.phylocanvas-scalebar.dragging {
  opacity: 0.8;
  cursor: move;
  z-index: 350;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

/* Phylocanvas Legend */
.phylocanvas-legend {
  position: absolute;
  z-index: 250;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #ddd;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  font-size: 12px;
  max-width: 250px;
  max-height: 400px;
  /* Flex layout for sticky header + tabs */
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Legend column layout */
.phylocanvas-legend.columns-1 {
  max-width: 250px;
}

.phylocanvas-legend.columns-2 {
  max-width: 400px;
}

.phylocanvas-legend.columns-3 {
  max-width: 550px;
}

.phylocanvas-legend.columns-4 {
  max-width: 700px;
}

.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 12px 6px 12px;
  border-bottom: 2px solid #1976d2;
  cursor: move;
  user-select: none;
  flex-shrink: 0;
}

.legend-title {
  font-weight: 700;
  font-size: 13px;
  color: #333;
  flex: 1;
}

.legend-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  color: #1976d2;
  transition: transform 0.2s, background 0.2s;
  border-radius: 3px;
  line-height: 1;
  flex-shrink: 0;
}

.legend-collapse-btn:hover {
  background: rgba(25, 118, 210, 0.1);
}

.phylocanvas-legend.collapsed .legend-content {
  display: none;
}

.phylocanvas-legend.collapsed .legend-collapse-btn {
  transform: rotate(-90deg);
}

.phylocanvas-legend.collapsed .legend-header {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 12px;
}

.phylocanvas-legend.dragging {
  opacity: 0.8;
  cursor: move;
  z-index: 300;
}

/* Legend tab bar - fixed below header */
.legend-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 8px 12px;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

/* Hide tabs when legend is collapsed */
.phylocanvas-legend.collapsed .legend-tabs {
  display: none;
}

/* Hide tabs when only one field (cleaner look) */
.phylocanvas-legend.single-field .legend-tabs {
  display: none;
}

/* Individual tab button */
.legend-tab {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  background: #e0e0e0;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-transform: uppercase;
  color: #666;
  transition: all 0.15s ease;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-tab:hover {
  background: #d0d0d0;
}

.legend-tab.active {
  background: #1976d2;
  color: white;
}

/* Leaf colors tab - distinct green styling */
.legend-tab-leaf-colors {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.legend-tab-leaf-colors:hover {
  background: #c8e6c9;
}

.legend-tab-leaf-colors.active {
  background: #43a047;
  color: white;
  border-color: #43a047;
}

/* Metadata block tab - distinct blue styling */
.legend-tab-metadata {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}

.legend-tab-metadata:hover {
  background: #bbdefb;
}

.legend-tab-metadata.active {
  background: #1976d2;
  color: white;
  border-color: #1976d2;
}

/* Scrollable content area */
.legend-content {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding: 8px 12px;
}

/* Tab panel - hidden by default */
.legend-tab-panel {
  display: none;
}

.legend-tab-panel.active {
  display: block;
}

.legend-field {
  margin-bottom: 12px;
}

.legend-field:last-child {
  margin-bottom: 0;
}

.legend-field-name {
  font-weight: 600;
  color: #555;
  margin-bottom: 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.legend-items {
  display: grid;
  grid-template-columns: repeat(var(--legend-columns, 2), 1fr);
  gap: 4px 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.legend-color-clickable {
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.legend-color-clickable:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  border-color: rgba(0,0,0,0.4);
}

.legend-label {
  color: #333;
  font-size: 12px;
  word-wrap: break-word;
  flex: 1;
}

.legend-label-clickable {
  cursor: pointer;
  padding: 2px 4px;
  margin: -2px -4px;
  border-radius: 3px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.legend-label-clickable:hover {
  background-color: rgba(25, 118, 210, 0.1);
  color: #1976d2;
}

.legend-label-clickable:active {
  background-color: rgba(25, 118, 210, 0.2);
}

/* Modal */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  color: #333;
}

.modal-close {
  background: none;
  border: none;
  font-size: 28px;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background 0.2s;
}

.modal-close:hover {
  background: #f5f5f5;
  color: #333;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-body p {
  margin: 0 0 16px 0;
  color: #666;
  font-size: 14px;
}

.fields-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: #f8f9fa;
  border-radius: 4px;
  transition: background 0.2s;
}

.field-item:hover {
  background: #e9ecef;
}

.field-item input[type="checkbox"] {
  margin-right: 10px;
  cursor: pointer;
  width: 18px;
  height: 18px;
}

.field-item label {
  cursor: pointer;
  flex: 1;
  font-size: 14px;
  color: #333;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn-primary {
  padding: 8px 20px;
  background: #1976d2;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #1565c0;
}

.btn-secondary {
  padding: 8px 16px;
  background: #f5f5f5;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-secondary:hover {
  background: #e9ecef;
  border-color: #bbb;
}

/* Color confirmation modal */
.color-confirm-modal .modal-content {
  max-width: 340px;
}

.color-confirm-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.color-confirm-info {
  text-align: center;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.color-confirm-field {
  font-size: 12px;
  color: #888;
  margin-bottom: 2px;
}

.color-confirm-value {
  font-weight: 600;
  color: #333;
  font-size: 15px;
}

.color-confirm-picker-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 8px;
}

.color-confirm-picker-row label {
  font-size: 13px;
  color: #555;
  min-width: 80px;
}

.color-confirm-input {
  width: 60px;
  height: 36px;
  padding: 0;
  border: 2px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  background: none;
}

.color-confirm-input::-webkit-color-swatch-wrapper {
  padding: 2px;
}

.color-confirm-input::-webkit-color-swatch {
  border: none;
  border-radius: 4px;
}

.color-confirm-input::-moz-color-swatch {
  border: none;
  border-radius: 4px;
}

.color-confirm-hex {
  font-family: monospace;
  font-size: 13px;
  color: #666;
  background: white;
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  width: 80px;
  text-transform: uppercase;
}

.color-presets-section {
  margin-top: 4px;
}

.color-presets-label {
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.color-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.color-preset {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}

.color-preset:hover {
  transform: scale(1.15);
  border-color: rgba(0, 0, 0, 0.3);
}

.color-preset.selected {
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.3);
}

.color-confirm-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  background: #f0f4f8;
  border-radius: 8px;
  margin-top: 4px;
}

.color-preview-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.color-preview-swatch {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 2px solid rgba(0, 0, 0, 0.1);
}

.color-preview-label {
  font-size: 10px;
  color: #888;
  text-transform: uppercase;
}

.color-preview-arrow {
  font-size: 18px;
  color: #aaa;
}

.btn-primary:disabled {
  background: #bbb;
  cursor: not-allowed;
  opacity: 0.6;
}

.btn-load {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.btn-load:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.btn-load:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.load-icon {
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.load-label {
  line-height: 1;
}

.btn-help {
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
}

.btn-help:hover {
  background: rgba(255, 255, 255, 0.25);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.btn-help:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.help-icon {
  width: 20px;
  height: 20px;
  background: rgba(255, 255, 255, 0.9);
  color: #1976d2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}

/* Clear Filter Button */
.btn-clear-filter {
  padding: 8px 16px;
  background: rgba(244, 67, 54, 0.2);
  color: white;
  border: 1px solid rgba(244, 67, 54, 0.5);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.btn-clear-filter:hover {
  background: rgba(244, 67, 54, 0.4);
  border-color: rgba(244, 67, 54, 0.7);
  box-shadow: 0 2px 8px rgba(244, 67, 54, 0.3);
  transform: translateY(-1px);
}

.btn-clear-filter:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(244, 67, 54, 0.2);
}

.clear-filter-icon {
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-filter-label {
  line-height: 1;
}

/* Clear Selection Button */
.btn-clear-selection {
  padding: 8px 16px;
  background: rgba(255, 152, 0, 0.2);
  color: white;
  border: 1px solid rgba(255, 152, 0, 0.5);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.btn-clear-selection:hover {
  background: rgba(255, 152, 0, 0.4);
  border-color: rgba(255, 152, 0, 0.7);
  box-shadow: 0 2px 8px rgba(255, 152, 0, 0.3);
  transform: translateY(-1px);
}

.btn-clear-selection:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(255, 152, 0, 0.2);
}

.clear-selection-icon {
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.clear-selection-label {
  line-height: 1;
}

/* Clear Selection Button - Tree Panel Overlay */
.btn-clear-selection-tree {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1001;  /* Above lasso canvas (z-index: 1000) */
  padding: 8px 16px;
  background: rgba(255, 152, 0, 0.9);
  color: white;
  border: 1px solid rgba(255, 152, 0, 0.7);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-clear-selection-tree:hover {
  background: rgba(255, 152, 0, 1);
  border-color: rgba(255, 152, 0, 0.9);
  box-shadow: 0 4px 12px rgba(255, 152, 0, 0.4);
  transform: translateY(-1px);
}

.btn-clear-selection-tree:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(255, 152, 0, 0.3);
}

.btn-clear-selection-tree .clear-selection-icon {
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-clear-selection-tree .clear-selection-label {
  line-height: 1;
}

/* Disable Lasso Button - Tree Panel Overlay */
.btn-disable-lasso {
  position: absolute;
  top: 10px;
  right: 180px;
  z-index: 1001;  /* Above lasso canvas (z-index: 1000) */
  padding: 8px 16px;
  background: rgba(33, 150, 243, 0.9);
  color: white;
  border: 1px solid rgba(33, 150, 243, 0.7);
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
  display: none;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.btn-disable-lasso:hover {
  background: rgba(33, 150, 243, 1);
  border-color: rgba(33, 150, 243, 0.9);
  box-shadow: 0 4px 12px rgba(33, 150, 243, 0.4);
  transform: translateY(-1px);
}

.btn-disable-lasso:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(33, 150, 243, 0.3);
}

.btn-disable-lasso .lasso-icon {
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-disable-lasso .lasso-label {
  line-height: 1;
}

.help-label {
  line-height: 1;
}

/* Upload Modal Styles */
.upload-section {
  margin-bottom: 24px;
}

.upload-section:last-of-type {
  margin-bottom: 20px;
}

.upload-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 12px;
}

.dropzone {
  border: 2px dashed #ddd;
  border-radius: 8px;
  padding: 30px 20px;
  text-align: center;
  transition: all 0.3s;
  background: #fafafa;
  cursor: pointer;
}

.dropzone:hover {
  border-color: #1976d2;
  background: #f0f8ff;
}

.dropzone.dragover {
  border-color: #1976d2;
  background: #e3f2fd;
  border-style: solid;
}

.dropzone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.dropzone-icon {
  font-size: 40px;
}

.dropzone-content p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.file-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #e3f2fd;
  border-radius: 6px;
  margin-top: 12px;
}

.file-info.hidden {
  display: none;
}

.file-info-icon {
  font-size: 24px;
}

.file-info-details {
  flex: 1;
}

.file-info-name {
  font-weight: 600;
  color: #333;
  font-size: 14px;
  margin-bottom: 4px;
}

.file-info-size {
  font-size: 12px;
  color: #666;
}

.file-info-remove {
  background: none;
  border: none;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
}

.file-info-remove:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #666;
}

.upload-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.upload-note {
  margin-top: 20px;
  padding: 12px;
  background: #fff3cd;
  border-left: 4px solid #ffc107;
  border-radius: 4px;
  font-size: 13px;
  color: #856404;
  line-height: 1.6;
}

.upload-note strong {
  color: #664d03;
}

.upload-help {
  font-size: 13px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 16px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 4px;
  border-left: 3px solid #1976d2;
}

.upload-help strong {
  color: #1976d2;
}

.privacy-note {
  font-size: 12px;
  color: #155724;
  line-height: 1.5;
  margin-top: 12px;
  margin-bottom: 16px;
  padding: 10px 12px;
  background: #d4edda;
  border-radius: 4px;
  border-left: 3px solid #28a745;
}

.privacy-note strong {
  color: #0c5328;
}

.file-list-container {
  max-height: 300px;
  overflow-y: auto;
  padding: 12px;
}

.file-list-container.hidden {
  display: none;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  transition: all 0.2s;
}

.file-list-item:hover {
  background: #e3f2fd;
  border-color: #1976d2;
}

.file-item-icon {
  font-size: 24px;
  flex-shrink: 0;
}

.file-item-details {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-weight: 600;
  color: #333;
  font-size: 13px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-size {
  font-size: 11px;
  color: #666;
}

.file-type-selector {
  padding: 6px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: white;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.file-type-selector:hover {
  border-color: #1976d2;
  background: #f0f8ff;
}

.file-type-selector:focus {
  outline: none;
  border-color: #1976d2;
  box-shadow: 0 0 0 2px rgba(25, 118, 210, 0.1);
}

.file-item-remove {
  background: none;
  border: none;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.file-item-remove:hover {
  background: rgba(211, 47, 47, 0.1);
  color: #d32f2f;
}

/* Tree Context Menu */
.tree-context-menu {
  position: fixed;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  min-width: 200px;
  z-index: 10000;
  display: none;
  padding: 4px 0;
  font-size: 13px;
}

.tree-context-menu.visible {
  display: block;
}

.tree-context-menu .context-menu-item {
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.2s;
  color: #333;
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.tree-context-menu .context-menu-item:hover {
  background: #f5f5f5;
}

.tree-context-menu .context-menu-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.tree-context-menu .context-menu-separator {
  height: 1px;
  background: #e0e0e0;
  margin: 4px 0;
}

.tree-context-menu .context-menu-icon {
  width: 16px;
  text-align: center;
  font-size: 14px;
}

.tree-context-menu .context-menu-label {
  flex: 1;
}

.tree-context-menu .context-menu-submenu {
  position: relative;
}

.tree-context-menu .context-menu-submenu::after {
  content: '▶';
  font-size: 10px;
  color: #999;
  margin-left: auto;
}

/* Toast Notification */
.phylo-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #323232;
  color: white;
  padding: 12px 24px;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
  z-index: 10001;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 200px;
  text-align: center;
  pointer-events: none;
}

.phylo-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Toast variants */
.phylo-toast.success {
  background: #4caf50;
}

.phylo-toast.error {
  background: #f44336;
}

.phylo-toast.info {
  background: #1976d2;
}

/* Color Control Container */
.color-control-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.color-toggle-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.color-toggle-label input[type="checkbox"] {
  cursor: pointer;
}

.color-control-container select {
  padding: 5px 10px;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  background: rgba(255,255,255,0.9);
  font-size: 14px;
  cursor: pointer;
}

.color-control-container select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.palette-btn {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.2s;
}

.palette-btn:hover:not(:disabled) {
  background: rgba(255, 255, 255, 1);
}

.palette-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Palette Menu */
.palette-menu {
  position: fixed;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  min-width: 300px;
  max-width: 400px;
  max-height: min(80vh, 500px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.palette-menu.hidden {
  display: none;
}

.palette-menu-header {
  padding: 12px 16px;
  background: #f5f5f5;
  border-bottom: 1px solid #e0e0e0;
  font-weight: 600;
  font-size: 14px;
  color: #333;
  flex-shrink: 0;
}

.palette-menu-content {
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  scrollbar-width: thin;
  scrollbar-color: #ccc #f5f5f5;
}

.palette-menu-content::-webkit-scrollbar {
  width: 8px;
}

.palette-menu-content::-webkit-scrollbar-track {
  background: #f5f5f5;
  border-radius: 4px;
}

.palette-menu-content::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}

.palette-menu-content::-webkit-scrollbar-thumb:hover {
  background: #999;
}

.palette-item {
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  margin-bottom: 6px;
  transition: background 0.2s;
}

.palette-item:hover {
  background: #f0f0f0;
}

.palette-item.selected {
  background: #e3f2fd;
  border-left: 3px solid #1976d2;
}

.palette-name {
  font-size: 13px;
  font-weight: 500;
  color: #333;
  margin-bottom: 6px;
}

.palette-preview {
  display: flex;
  gap: 2px;
  height: 20px;
}

.palette-color {
  flex: 1;
  min-width: 0;
  border-radius: 2px;
}

.palette-category {
  font-size: 11px;
  color: #999;
  text-transform: uppercase;
  font-weight: 600;
  padding: 8px 12px 4px;
  margin-top: 8px;
}

.palette-category:first-child {
  margin-top: 0;
}

/* Help Modal Styles */
.help-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid #f0f0f0;
}

.help-section:last-child {
  margin-bottom: 0;
  padding-bottom: 0;
  border-bottom: none;
}

.help-section h4 {
  font-size: 17px;
  font-weight: 600;
  color: #1976d2;
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e3f2fd;
}

.help-section p {
  margin: 0 0 14px 0;
  color: #444;
  line-height: 1.7;
  font-size: 14px;
}

.help-section p:last-child {
  margin-bottom: 0;
}

.help-section ul,
.help-section ol {
  margin: 0 0 14px 0;
  padding-left: 24px;
  color: #444;
  line-height: 1.7;
  font-size: 14px;
}

.help-section ul:last-child,
.help-section ol:last-child {
  margin-bottom: 0;
}

.help-section ul li,
.help-section ol li {
  margin-bottom: 10px;
  padding-left: 4px;
}

.help-section ul li:last-child,
.help-section ol li:last-child {
  margin-bottom: 0;
}

.help-section ul li strong,
.help-section ol li strong {
  color: #1976d2;
  font-weight: 600;
}

.help-section ol {
  counter-reset: item;
  list-style-type: none;
  padding-left: 0;
}

.help-section ol li {
  counter-increment: item;
  position: relative;
  padding-left: 32px;
}

.help-section ol li:before {
  content: counter(item);
  position: absolute;
  left: 0;
  top: 0;
  background: #1976d2;
  color: white;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.help-note {
  background: #f0f8ff;
  border-left: 4px solid #1976d2;
  padding: 12px 14px;
  border-radius: 4px;
  font-size: 13.5px;
  color: #1565c0;
  margin: 14px 0;
  line-height: 1.6;
}

.help-note strong {
  color: #0d47a1;
  font-weight: 600;
}

.license-section {
  background: #f8f9fa;
  padding: 16px;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
}

.license-info {
  background: white;
  border: 1px solid #e0e0e0;
  padding: 12px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.6;
  margin-top: 8px;
}

.license-info small {
  font-size: 12px;
  color: #666;
  display: block;
  margin-top: 8px;
}

.license-info a {
  color: #1976d2;
  text-decoration: none;
  transition: color 0.2s;
}

.license-info a:hover {
  color: #1565c0;
  text-decoration: underline;
}

/* Collapsible Menu System */
.phylocanvas-collapsible-menu {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  pointer-events: none;
}

.main-menu-toggle {
  background: white;
  border: 1px solid #ddd;
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transition: all 0.3s ease;
  font-size: 24px;
  z-index: 201;
  pointer-events: auto;
}

.main-menu-toggle:hover {
  background: #f5f5f5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transform: scale(1.05);
}

.main-menu-toggle.active {
  background: #1976d2;
  border-color: #1976d2;
  box-shadow: 0 4px 16px rgba(25, 118, 210, 0.4);
}

.main-menu-toggle.active .toggle-icon {
  filter: brightness(0) invert(1);
}

.menu-options-column {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.menu-options-column.expanded {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto;
}

.menu-option-btn {
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
  transition: all 0.2s ease;
  font-size: 14px;
  font-weight: 500;
  color: #333;
  min-width: 160px;
  white-space: nowrap;
}

.menu-option-btn:hover {
  background: #f5f5f5;
  box-shadow: 0 3px 10px rgba(0,0,0,0.15);
  transform: translateX(2px);
}

.menu-option-btn.active {
  background: #e3f2fd;
  border-color: #1976d2;
  color: #1976d2;
  box-shadow: 0 3px 10px rgba(25, 118, 210, 0.3);
}

.menu-option-btn .option-icon {
  font-size: 20px;
  line-height: 1;
}

.menu-option-btn .option-label {
  flex: 1;
  text-align: left;
}

.menu-option-btn:disabled,
.menu-option-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #f0f0f0;
  pointer-events: auto;
}

.menu-option-btn:disabled:hover,
.menu-option-btn.disabled:hover {
  background: #f0f0f0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transform: none;
}

.main-menu-toggle:disabled,
.main-menu-toggle.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: auto;
}

.main-menu-toggle:disabled:hover,
.main-menu-toggle.disabled:hover {
  background: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  transform: none;
}

/* Message for disabled settings buttons - positioned at save button line */
.menu-options-column.settings-disabled::after {
  content: 'Settings is open in a separate window';
  position: fixed;
  top: 18px;
  left: 120px;
  background: rgba(0, 0, 0, 0.8);
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1000;
}

/* Hide the old menu trigger buttons */
.phylocanvas-control-menu .menu-trigger {
  display: none;
}

/* Adjust menu content positioning for the new system */
.phylocanvas-control-menu {
  position: static;
}

.phylocanvas-control-menu .menu-content {
  position: fixed;
  z-index: 150;
  display: flex;
  visibility: hidden;
  opacity: 0;
  transition: opacity 0.2s ease;
  width: 360px; /* Fixed width to prevent dimension changes during render */
  max-height: calc(100vh - 100px); /* Ensure menu doesn't exceed viewport */
  overflow-y: auto;
  overflow-x: hidden;
  /* Position will be set dynamically by JavaScript */
}

.phylocanvas-control-menu .menu-content.open {
  visibility: visible;
  opacity: 1;
}

/* Tableau Extension Specific Styles */

/* Worksheet Info Badge */
.worksheet-info {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.9);
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 13px;
  color: #333;
}

.worksheet-info.hidden {
  display: none;
}

.worksheet-label {
  font-weight: 500;
  color: #666;
}

.worksheet-name {
  font-weight: 600;
  color: #1976d2;
}

/* Configuration Required Message */
.config-required-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: white;
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  text-align: center;
  z-index: 100;
}

.config-required-message.hidden {
  display: none;
}

.config-required-content h3 {
  color: #1976d2;
  margin-bottom: 16px;
  font-size: 24px;
}

.config-required-content p {
  color: #666;
  margin-bottom: 24px;
  font-size: 16px;
}

/* Tableau Note in Upload Modal */
.tableau-note {
  background: #e3f2fd;
  border-left: 4px solid #1976d2;
  padding: 12px;
  margin: 16px 0;
  border-radius: 4px;
  color: #0d47a1;
}

.tableau-note strong {
  font-weight: 600;
}

/* Responsive Design - Media Queries */

/* Medium screens: Hide button labels, show only icons */
@media (max-width: 900px) {
  .controls {
    gap: 12px;
  }

  .header .logo {
    height: 45px;
  }

  /* Hide text labels on buttons, keep icons */
  .btn-load .load-label,
  .btn-help .help-label,
  .btn-configure .configure-label,
  .btn-clear-filter .clear-filter-label,
  .btn-clear-selection .clear-selection-label {
    display: none;
  }

  .btn-load,
  .btn-help,
  .btn-configure,
  .btn-clear-filter,
  .btn-clear-selection {
    padding: 8px 12px;
  }

  /* Make search container and input more flexible */
  .search-container {
    min-width: 180px;
    max-width: 240px;
    flex-shrink: 1;
  }

  .search-input {
    flex: 1;
    min-width: 70px;
  }

  /* Hide renderer label text */
  .controls label {
    font-size: 0;
  }

  .controls label select {
    font-size: 14px;
  }

  /* Hide worksheet info on medium screens */
  .worksheet-info {
    display: none !important;
  }
}

/* Small screens: Compact layout */
@media (max-width: 700px) {
  .header {
    padding: 5px 38px 5px 8px;
    gap: 6px;
  }

  .controls {
    gap: 6px;
    justify-content: flex-end;
  }

  .header-toggle-btn {
    width: 30px;
    height: 30px;
  }

  .header .logo {
    height: 40px;
  }

  /* Make buttons more compact with icon only */
  .btn-load,
  .btn-help,
  .btn-configure,
  .btn-clear-filter,
  .btn-clear-selection {
    padding: 6px 10px;
    border-radius: 50%;
    min-width: 36px;
    min-height: 36px;
  }

  .load-icon,
  .help-icon,
  .configure-icon,
  .clear-filter-icon,
  .clear-selection-icon {
    font-size: 20px;
  }

  /* Very compact search with better flexibility */
  .search-container {
    padding: 4px 8px;
    min-width: 120px;
    max-width: 160px;
    flex-shrink: 2;
  }

  .search-input {
    flex: 1;
    min-width: 50px;
    font-size: 12px;
  }

  .search-icon {
    font-size: 14px;
  }

  .search-results-summary {
    font-size: 10px;
    padding: 2px 4px;
  }

  .search-menu-btn {
    font-size: 12px;
  }

  /* Hide renderer selector on very small screens */
  .controls label {
    display: none;
  }
}

/* Extra small screens: Stack header */
@media (max-width: 500px) {
  .header {
    flex-direction: column;
    flex-wrap: wrap;
    padding: 8px 38px 8px 8px;
    gap: 8px;
    align-items: stretch;
  }

  .header-brand {
    width: 100%;
    justify-content: flex-start;
    order: 1;
  }

  .controls {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 6px;
    order: 2;
  }

  .header .logo {
    height: 35px;
  }

  .search-container {
    flex: 1 1 auto;
    max-width: 100%;
    min-width: 0;
  }

  .search-input {
    flex: 1;
    min-width: 60px;
  }

  .search-results-summary {
    flex-shrink: 0;
  }
}

/* ===========================================
   Compact Mode (Adaptive Settings)
   =========================================== */

/* Hide phylocanvas floating menus when in compact mode - buttons still work but open tabbed dialog */
.tree-container.compact-mode .phylocanvas-control-menu,
.tree-container.compact-mode .phylocanvas-color-menu,
.tree-container.compact-mode .phylocanvas-nodes-labels-menu,
.tree-container.compact-mode .phylocanvas-metadata-blocks-menu,
.tree-container.compact-mode .phylocanvas-tooltip-menu,
.tree-container.compact-mode .phylocanvas-save-settings {
  display: none !important;
}
