/* Left Sidebar - Dataset Controls */
#unified-legend {
  position: absolute;
  top: 40px;
  left: 20px;
  bottom: 20px;
  background: transparent;
  padding: 16px;
  border-radius: 12px;
  font-size: 11px;
  max-height: calc(100vh - 60px);
  width: 160px;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Scrollable Content Area */
#scrollableContent {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: 12px;
  min-height: 0;
}

/* Fixed Controls at Bottom */
#fixedControls {
  flex-shrink: 0;
  padding: 0;
  margin: 0;
}

#datasetColorsLegend,
#unifiedColorsLegend {
  position: absolute;
  left: 200px;
  bottom: 30px;
  background: transparent;
  padding: 12px;
  border-radius: 8px;
  font-size: 10px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  width: 140px;
  pointer-events: none;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
}

/* Right Sidebar - Prediction Controls */
#predColorsLegend {
  position: absolute;
  right: 200px;
  bottom: 20px;
  background: transparent;
  padding: 12px;
  border-radius: 8px;
  font-size: 10px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  width: 140px;
  pointer-events: none;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
}

#colorsLegend {
  position: absolute;
  left: 200px;
  bottom: 20px;
  background: transparent;
  padding: 12px;
  border-radius: 8px;
  font-size: 10px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  width: 140px;
  pointer-events: none;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
}

#colorsLegend *,
#datasetColorsLegend *,
#unifiedColorsLegend *,
#predColorsLegend * {
  pointer-events: auto;
}

#colorsLegend h4,
#datasetColorsLegend h4,
#unifiedColorsLegend h4,
#predColorsLegend h4 {
  margin: 0 0 8px 0;
  font-size: 11px;
  font-weight: 200;
  color: #4ED9D9;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(78, 217, 217, 0.15);
}

.colors-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.color-item {
  display: flex;
  align-items: center;
  padding: 2px 4px;
  border-radius: 3px;
  transition: all 0.2s;
  line-height: 1.2;
}

.color-item:hover {
  background: #1B1F25;
}

.color-item span {
  color: #FFFFFF;
  font-size: 9px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.color-item .color-box {
  width: 8px;
  height: 8px;
  margin-right: 5px;
  border-radius: 2px;
  border: 1px solid rgba(78, 217, 217, 0.3);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

/* Custom scrollbar for colors legend */
#colorsLegend::-webkit-scrollbar,
#datasetColorsLegend::-webkit-scrollbar,
#unifiedColorsLegend::-webkit-scrollbar,
#predColorsLegend::-webkit-scrollbar {
  width: 4px;
}

#colorsLegend::-webkit-scrollbar-track,
#datasetColorsLegend::-webkit-scrollbar-track,
#unifiedColorsLegend::-webkit-scrollbar-track,
#predColorsLegend::-webkit-scrollbar-track {
  background: #1B1F25;
  border-radius: 2px;
}

#colorsLegend::-webkit-scrollbar-thumb,
#datasetColorsLegend::-webkit-scrollbar-thumb,
#unifiedColorsLegend::-webkit-scrollbar-thumb,
#predColorsLegend::-webkit-scrollbar-thumb {
  background: rgba(78, 217, 217, 0.4);
  border-radius: 2px;
}

#colorsLegend::-webkit-scrollbar-thumb:hover,
#datasetColorsLegend::-webkit-scrollbar-thumb:hover,
#unifiedColorsLegend::-webkit-scrollbar-thumb:hover,
#predColorsLegend::-webkit-scrollbar-thumb:hover {
  background: rgba(78, 217, 217, 0.6);
}

/* Custom scrollbar for scrollable content */
#scrollableContent::-webkit-scrollbar {
  width: 6px;
}

#scrollableContent::-webkit-scrollbar-track {
  background: #1B1F25;
  border-radius: 3px;
}

#scrollableContent::-webkit-scrollbar-thumb {
  background: rgba(78, 217, 217, 0.4);
  border-radius: 3px;
}

#scrollableContent::-webkit-scrollbar-thumb:hover {
  background: rgba(78, 217, 217, 0.6);
}

#unified-legend * {
  pointer-events: auto;
}

.control-buttons {
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex-shrink: 0;
}

.style-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
}

.switcher-container {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.style-switcher {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  border-radius: 8px;
  transition: all 0.2s;
  background: #121418;
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.style-switcher:hover {
  background: #1B1F25;
  border-color: rgba(255, 255, 255, 1);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

.switcher-prev,
.switcher-next {
  background: transparent;
  border: none;
  color: #4ED9D9;
  font-size: 16px;
  cursor: pointer;
  padding: 0 8px;
  transition: opacity 0.2s ease;
}

.switcher-value {
  flex: 1;
  text-align: center;
  font-size: 11px;
  color: #FFFFFF;
  font-weight: 200;
  text-shadow: 0 0 2px rgba(78, 217, 217, 0.2);
}

/* Filter Content Section - Tighter spacing */
.filter-content-section {
  margin-top: 0 !important;
  margin-bottom: 12px;
}

.toggle-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.style-option {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  background: #121418;
  font-size: 10px;
  color: #FFFFFF;
}

.style-option:hover {
  background: #1B1F25;
}

.style-option input[type="radio"] {
  margin-right: 8px;
  accent-color: #4ED9D9;
  cursor: pointer;
}

.style-option span {
  flex: 1;
}

.toggle-option {
  flex: 1;
  margin-bottom: 0;
}

.toggle-option label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  background: #121418;
  font-size: 10px;
  color: #FFFFFF;
  height: 100%;
}

.toggle-option label:hover {
  background: #1B1F25;
}

.toggle-option input[type="checkbox"] {
  margin-right: 6px;
  accent-color: #4ED9D9;
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.toggle-option span {
  flex: 1;
  text-align: left;
  color: #FFFFFF;
}

.legend-item { 
  display: flex; 
  align-items: center; 
  margin-bottom: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  transition: all 0.2s;
}

.legend-item:hover {
  background: rgba(255, 255, 255, 0.1);
}

.color-box { 
  width: 16px; 
  height: 16px; 
  margin-right: 10px; 
  border-radius: 3px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.filter-section {
  margin-bottom: 12px;
  flex-shrink: 0;
}

.filter-section h4 {
  margin: 0 0 6px 0;
  font-size: 11px;
  font-weight: 200;
  color: #4ED9D9;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(78, 217, 217, 0.15);
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 120px;
  overflow-y: auto;
  padding: 6px;
  border-radius: 8px;
  background: #121418;
  backdrop-filter: blur(10px);
}

/* Custom scrollbar for checkbox groups */
.checkbox-group::-webkit-scrollbar {
  width: 4px;
}

.checkbox-group::-webkit-scrollbar-track {
  background: #1B1F25;
  border-radius: 2px;
}

.checkbox-group::-webkit-scrollbar-thumb {
  background: rgba(78, 217, 217, 0.4);
  border-radius: 2px;
}

.checkbox-group::-webkit-scrollbar-thumb:hover {
  background: rgba(78, 217, 217, 0.6);
}

/* Custom scrollbar for legend content */
#legendContent::-webkit-scrollbar {
  width: 4px;
}

#legendContent::-webkit-scrollbar-track {
  background: #1B1F25;
  border-radius: 2px;
}

#legendContent::-webkit-scrollbar-thumb {
  background: rgba(78, 217, 217, 0.4);
  border-radius: 2px;
}

#legendContent::-webkit-scrollbar-thumb:hover {
  background: rgba(78, 217, 217, 0.6);
}

.checkbox-item {
  display: flex;
  align-items: center;
  font-size: 10px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: all 0.2s;
  color: #FFFFFF;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  cursor: pointer;
}

.checkbox-item:hover {
  background: #1B1F25;
}

.checkbox-item input {
  margin-right: 6px;
  cursor: pointer;
  width: 14px;
  height: 14px;
  accent-color: #4ED9D9;
  flex-shrink: 0;
}

#speciesSearch,
#familySearch,
#datasetFamilySearch,
#datasetSpeciesSearch {
  width: 100%;
  padding: 6px 8px;
  font-size: 10px;
  margin-bottom: 6px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 8px;
  background: #121418;
  backdrop-filter: blur(10px);
  color: #FFFFFF;
  outline: none;
  transition: all 0.2s ease;
  box-sizing: border-box;
  font-weight: 200;
}

#speciesSearch::placeholder,
#familySearch::placeholder,
#datasetFamilySearch::placeholder,
#datasetSpeciesSearch::placeholder {
  color: #FFFFFF;
  opacity: 0.5;
}

#speciesSearch:focus,
#familySearch:focus,
#datasetFamilySearch:focus,
#datasetSpeciesSearch:focus {
  border-color: #FFFFFF;
  background: #1B1F25;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

#legendContent {
  margin-top: 12px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

#legendContent h4 {
  margin: 0 0 8px 0;
  font-size: 11px;
  font-weight: 200;
  color: #4ED9D9;
  letter-spacing: 2px;
  text-shadow: 0 0 4px rgba(78, 217, 217, 0.15);
}

#legendContent .legend-item {
  margin-bottom: 6px;
  padding: 4px 6px;
}

#legendContent .legend-item span {
  color: #FFFFFF;
  font-size: 10px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.legend-item { 
  display: flex; 
  align-items: center; 
  margin-bottom: 6px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: all 0.2s;
}

.legend-item:hover {
  background: #1B1F25;
}

.color-box { 
  width: 12px; 
  height: 12px; 
  margin-right: 8px; 
  border-radius: 2px;
  border: 2px solid rgba(78, 217, 217, 0.3);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

/* Filters button + backdrop: only used by the compact (sheet) layout below */
#panels-toggle {
  display: none;
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 1100;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(16, 18, 23, 0.6);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
#panels-toggle:hover {
  color: #FFFFFF;
}
#panel-backdrop {
  display: none;
}

/* Wide but short screens: tighten the left column so it clears the timeline */
@media (max-width: 1100px) {
  #unified-legend {
    width: 150px;
  }
}

/* Compact layout (tablet portrait, phones, short landscape screens): the side panels do not
   fit beside the globe, so they live in a sheet opened by #panels-toggle. */
@media (max-width: 820px), (max-height: 520px) {
  #panels-toggle {
    display: flex;
  }

  #unified-sidebar-container,
  #unifiedColorsLegend {
    display: none !important;
  }

  body.panels-open #panel-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(10, 12, 16, 0.86);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
  }

  body.panels-open #unified-sidebar-container {
    display: block !important;
  }

  body.panels-open #unified-legend {
    position: fixed;
    z-index: 1050;
    top: 68px;
    bottom: 300px;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: min(420px, calc(100% - 32px));
    max-height: none;
    box-sizing: border-box;
    padding: 12px 14px;
    background: rgba(18, 20, 24, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 12px;
  }

  body.panels-open #unified-legend .checkbox-group {
    max-height: none;
  }
}

/* Short landscape screens have no room for a stacked sheet: put the two panels side by side */
@media (max-height: 520px) and (min-width: 600px) {
  body.panels-open #unified-legend {
    top: 64px;
    bottom: 12px;
    left: 16px;
    right: auto;
    margin: 0;
    width: calc(50% - 24px);
  }
}
