/* Force body/html to fill the viewport so flex layout can shrink the chart. */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-color);
}

/* The pageWrapper is a column flex container:
   - topSection is flexible in height (depends on panels).
   - mainContainer takes remaining space.
*/
#pageWrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* The top section contains the toolbar + optional panels. */
#topSection {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
}

/* The mainContainer is the bottom area (sidebar + chart). 
   We set it to flex: 1 to fill remaining space. */
#mainContainer {
  flex: 1 1 auto;
  display: flex;
  overflow: hidden; /* No scroll - if the top expands too much, it might overflow the viewport. */
}

/* ---------------------------
   Toolbar with Tabbed Interface
------------------------------ */

#toolbar {
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

/* Tab Bar styling */
.tab-bar {
  display: flex;
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
}

.tab-group {
  display: flex;
}

.local-tabs {
  margin-left: auto;
}

.tab-button {
  padding: 0.6rem 1rem;
  cursor: pointer;
  border: none;
  background: none;
  font-size: 1rem;
  border-bottom: 3px solid transparent;
  transition: border-bottom 0.2s ease;
}

.tab-button.active {
  border-bottom: 3px solid var(--text-color);
  font-weight: bold;
}

/* Tab Content & Panels */
.tab-content {
  padding: 0.5rem 1rem;
}

.tab-panel {
  display: none;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.tab-panel.active {
  display: flex;
}

/* Control Groups */
.control-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.2rem;
}

.control-group label {
  white-space: nowrap;
}

/* Buttons, inputs, and selects styling */
#toolbar button, 
#toolbar select, 
#toolbar input[type="number"],
#toolbar input[type="range"],
#toolbar a.btn-link {
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-primary);
  color: var(--text-color);
  cursor: pointer;
}

/* Narrow numeric input for histogram bounds */
#toolbar input.short-number {
  width: 4ch;
}

/* Remove numeric input spinners */
#toolbar input[type="number"]::-webkit-outer-spin-button,
#toolbar input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
#toolbar input[type="number"] {
  -moz-appearance: textfield;
}

#toolbar button:hover,
#toolbar a.btn-link:hover {
  background-color: var(--bg-secondary);
}

/* ---------------------------
   Responsive Adjustments
------------------------------ */
@media (max-width: 768px) {
  .control-group {
    flex-direction: column;
    align-items: flex-start;
  }
  .control-group label,
  .control-group select,
  .control-group input {
    width: 100%;
  }
  .tab-bar {
    flex-wrap: wrap;
  }
}
  
/* Sidebar list styling */
#robotList {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

/* Generic robot list for dynamic panes */
.robot-list {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

#robotList li {
  margin: 0.25rem 0;
}


/* Panel for adding custom bots appears below the toolbar */
#addBotPanel {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
}

/* Persistent filter sidebar */
#filterSidebar {
  --scrollbar-width: 10px;
  width: 210px; /* account for scrollbar so content isn't cut off */
  flex: 0 0 210px; /* keep sidebar from shrinking */
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 0.5rem;
  box-sizing: border-box;
  background-color: var(--bg-secondary);
  scrollbar-width: thin; /* Firefox */

  /* Add a smooth transition for width, padding, etc. */
  transition: width 0.0s ease, padding 0.0s ease;
}

/* Resizer next to the sidebar */
#filterResizer {
  width: 4px;
  flex: 0 0 4px;
  cursor: col-resize;
  background: var(--border-color);
}


/* Chrome, Edge, and Safari */
#filterSidebar::-webkit-scrollbar {
  width: var(--scrollbar-width);
  height: 12px;
}

#filterSidebar::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

#filterSidebar::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 6px;
  border: 3px solid var(--bg-secondary);
}

/* Collapsed sidebar */
#filterSidebar.collapsed {
  width: 0;              /* Key: shrink to 0 */
  padding: 0;            /* Remove padding so text doesn't show */
  border-right: none;    /* Remove border (optional) */
  overflow: hidden;      /* Hide scrolling content */
}

/* Filter groups */
.filter-group {
  margin-bottom: 0.75rem;
}


/* Title with hide/show toggle */
.filter-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0;
}

.filter-toggle {
  border: none;
  background: none;
  color: var(--text-color);
  cursor: pointer;
  font-size: 0.875rem;
}

.filter-box {
  margin-left: 0.5rem;
}

.selected-options {
  margin-left: 0.5rem;
}

.filter-group .search-box {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 0.25rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-primary);
  color: var(--text-color);
}

.filter-group label {
  display: block;
  margin-bottom: 0.25rem;
}

.filter-group label.excluded {
  text-decoration: line-through;
  opacity: 0.6;
}

/* Checkboxes should match the active theme */
.filter-group input[type="checkbox"] {
  accent-color: var(--text-color);
}

.filter-options {
  max-height: 8rem;
  overflow-y: auto;
  padding-right: var(--scrollbar-width);
  box-sizing: content-box;
  scrollbar-width: thin; /* Firefox */
}

.filter-options::-webkit-scrollbar {
  width: var(--scrollbar-width);
  height: 12px;
}

.filter-options::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.filter-options::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 6px;
  border: 3px solid var(--bg-secondary);
}

.numeric-range {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.numeric-range input {
  width: 4.5rem;
  padding: 0.2rem 0.4rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-primary);
  color: var(--text-color);
}

.filter-separator {
  border: none;
  border-top: 1px solid var(--border-color);
  margin: 0.5rem 0;
}


#chartContainer {
  flex: 1; /* fill the rest horizontally */
  position: relative;
  box-sizing: border-box;
}

.pane-group {
  flex: 1;
  display: flex;
  position: relative;
  min-height: 0; /* allow nested flex groups to shrink */
  min-width: 0;
}

.pane-group.horizontal {
  flex-direction: row;
}

.pane-group.vertical {
  flex-direction: column;
}

/* Generic pane styling for dynamically created panes */
.pane {
  flex: 1;
  position: relative;
  border-left: 1px solid var(--border-color);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 100px;
  min-height: 0; /* allow content to scroll instead of expanding */
}

.pane-selected {
  box-shadow: none;
}

.pane-selected > .pane-header {
  background: var(--pane-header-selected);
}

.pane-header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem;
  justify-content: flex-end;
}

.pane-close-btn {
  margin-left: 0;
}

/* Style pane header controls to match toolbar and filters */
.pane-header button,
.pane-header select {
  padding: 0.2rem 0.4rem;
  font-size: 0.9rem;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--bg-primary);
  color: var(--text-color);
  cursor: pointer;
}

.pane-header button:hover {
  background-color: var(--bg-secondary);
}

.pane-content {
  flex: 1;
  position: relative;
  overflow-y: auto;
  min-height: 0; /* prevent flex overflow when content is tall */
}

/* Charts should not scroll */
.chart-pane-content {
  overflow-y: hidden;
}

.pane-resizer.vertical {
  width: 4px;
  flex: 0 0 4px;
  cursor: col-resize;
  background: var(--border-color);
}

.pane-resizer.horizontal {
  height: 4px;
  flex: 0 0 4px;
  cursor: row-resize;
  background: var(--border-color);
}

/* Make the SVG fill its container. */
#chart {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
}

/* Generic SVG used by dynamically created chart panes */
.chart-svg {
  width: 100%;
  height: 100%;
  background-color: var(--bg-primary);
}

/* Elements used in chart panes are hidden via JavaScript */

/* Light mode theme variables */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f5;
  --pane-header-selected: #fafafa;
  --text-color: #000000;
  --border-color: #cccccc;
  color-scheme: light;
}

/* Dark mode theme overrides */
body.dark-mode {
  --bg-primary: #1e1e1e;
  --bg-secondary: #2c2c2c;
  --pane-header-selected: #3a3a3a;
  --text-color: #dddddd;
  --border-color: #555555;
  color-scheme: dark;
}

/* Sidebar list styling */
#robotList {
  list-style-type: none;
  margin: 0;
  padding: 0;
}

#robotList li {
  margin: 0.25rem 0;
}


/* Axis styling to match theme color */
.axis path,
.axis line {
  stroke: var(--text-color);
}
.axis text {
  fill: var(--text-color);
}
/* Axis label styling */
.axis-label {
  fill: var(--text-color);
  font-size: 12px;
  font-family: Arial, sans-serif;
}

/* Gridlines styling */
.x-gridlines .tick line {
  stroke: var(--border-color);
  stroke-opacity: 0.2;  /* somewhat transparent */
}

.y-gridlines .tick line {
  stroke: var(--border-color);
  stroke-opacity: 0.2;
}

/* Hide the axis path for gridlines */
.x-gridlines path.domain,
.y-gridlines path.domain {
  stroke: none;
}



/* Symbol path styling (for pointer). */
.bot-symbol {
  cursor: pointer;
}

/* Popup styling */
.robot-popup {
  pointer-events: none; /* so clicks pass through to the chart below if desired */
}

.popup-bg {
  fill: var(--bg-secondary);
  stroke: var(--text-color);
  rx: 4px;
  ry: 4px;
}

.popup-text {
  font-size: 12px;
  fill: var(--text-color);
  font-family: Arial, sans-serif;
  white-space: pre; /* so we can use \n for multiple lines */
}

.voronoiCell {
  pointer-events: none; /* allow clicks to pass through */
  /* Possibly keep a stroke, low fill-opacity, etc. */
}

.convexHullGroup {
  pointer-events: none; /* allow clicks to pass through */
  /* Possibly keep a stroke, low fill-opacity, etc. */
}

.tooltip {
  position: absolute;
  pointer-events: none;
  font-size: 12px;
  background: var(--bg-secondary);
  color: var(--text-color);
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid var(--text-color);
  white-space: nowrap;
}

/* Tutorial overlay styling */
.tutorial-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  z-index: 10000;
  color: var(--text-color);
  pointer-events: none;
}

.tutorial-box {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 10002;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 1rem;
  max-width: 320px;
  text-align: center;
}

.tutorial-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-color);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}

.tutorial-controls {
  margin-top: 1rem;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.tutorial-overlay button {
  padding: 0.4rem 0.8rem;
  font-size: 0.9rem;
  background: var(--bg-primary);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
}
.tutorial-overlay button:hover {
  background: var(--bg-secondary);
}

.tutorial-highlight {
  position: relative;
  z-index: 10001;
  outline: 3px solid #ff9800;
  box-shadow: 0 0 10px #ff9800;
}

/* Spreadsheet table styling */
.spreadsheet-table {
  width: 100%;
  border-collapse: collapse;
}

.spreadsheet-table th,
.spreadsheet-table td {
  border: 1px solid var(--border-color);
  padding: 4px;
  text-align: left;
}

.spreadsheet-table th {
  cursor: pointer;
}

.spreadsheet-table input {
  width: 100%;
  box-sizing: border-box;
}

/* Stats table styling */
.stats-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

.stats-table caption {
  font-weight: bold;
  margin-bottom: 0.25rem;
}

.stats-table th,
.stats-table td {
  border: 1px solid var(--border-color);
  padding: 4px;
  text-align: left;
}

/* KitBots tool styling */
.kitbots-output {
  display: none;
}

.kitbots-preview {
  padding: 0.5rem;
  overflow-y: auto;
}
