* {
  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 5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

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

.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: 20px;
  align-items: center;
}

.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;
}

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

.search-input {
  border: none;
  background: transparent;
  outline: none;
  font-size: 14px;
  width: 120px;
  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%;
}

.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;
}

.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: 80vh;
  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: 50;
  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;
}

/* Phylocanvas Legend */
.phylocanvas-legend {
  position: absolute;
  z-index: 150;
  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);
  padding: 12px;
  font-size: 12px;
  max-width: 250px;
  max-height: 400px;
  overflow-y: auto;
}

.legend-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 10px;
  color: #333;
  border-bottom: 2px solid #1976d2;
  padding-bottom: 6px;
}

.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: flex;
  flex-direction: column;
  gap: 4px;
}

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

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

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

/* 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;
}

.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;
}

.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: 24px;
}

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

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

.help-section p {
  margin: 0 0 12px 0;
  color: #555;
  line-height: 1.6;
}

.help-section ul {
  margin: 0 0 12px 0;
  padding-left: 20px;
  color: #555;
  line-height: 1.8;
}

.help-section ul li {
  margin-bottom: 8px;
}

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

.help-section ul li strong {
  color: #333;
  font-weight: 600;
}

.help-note {
  background: #f0f8ff;
  border-left: 3px solid #1976d2;
  padding: 10px 12px;
  border-radius: 4px;
  font-size: 13px;
  color: #1565c0;
  margin: 12px 0;
}

.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;
  right: 10px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.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;
}

.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;
}

/* 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 */
  /* Position will be set dynamically by JavaScript */
}

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