/* Graph Tool Modal Styles */
:root {
  --graph-dark-bg: #141414;
  --graph-dark-secondary: #1e1e1e;
  --graph-dark-tertiary: #2a2a2a;
  --graph-accent: #ff8800;
  --graph-accent-hover: #ff6600;
  --graph-text: #ffffff;
  --graph-text-secondary: #aaaaaa;
  --graph-border: #333333;
  --graph-shadow: rgba(0, 0, 0, 0.5);
  --graph-grid: #333333;
  --graph-axis: #555555;
  --graph-point: #ff8800;
  --graph-line: #ff6600;
}

/* Graph Tool Button */
.graph-tool-button {
  background: linear-gradient(135deg, #96009b, #96009b);
  color: white !important;
  border: none;
  border-radius: 12px;
  padding: 8px 15px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 4px 0 #610064, 0 6px 15px rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  letter-spacing: 1px;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.graph-tool-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 0 #610064, 0 8px 20px rgba(0, 0, 0, 0.3);
}

.graph-tool-button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #610064, 0 3px 10px rgba(0, 0, 0, 0.2);
}

/* Graph Tool Modal */
.graph-modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: rgba(0, 0, 0, 0.7);
  opacity: 0;
  transition: opacity 0.3s ease-out;
  will-change: opacity;
}

/* Prevent background interaction when modal is open */
body.graph-modal-open {
  /* Remove position: fixed to allow scrolling */
  /* overflow-y: scroll !important; Keep scrollbar visible */
  /* pointer-events: none; */
}

/* Re-enable pointer events for the modal itself */
body.graph-modal-open .graph-modal {
  pointer-events: auto;
}

/* Scrollable containers within the modal */
.graph-modal .table-container,
.graph-modal .data-sets-container {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
  overscroll-behavior: contain; /* Prevent scroll chaining */
}

.graph-modal.visible {
  opacity: 1;
}

.graph-content {
  background-color: var(--graph-dark-bg);
  margin: 0;
  padding: 15px;
  border: none;
  width: 90%;
  max-width: 1100px;
  border-radius: 26px;
  box-shadow: 0 8px 32px var(--graph-shadow);
  color: var(--graph-text);
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-height: 90vh;
  position: fixed;
  top: 50%;
  left: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.7);
  transition: opacity 0.3s ease-out, transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
  overflow: hidden;
  box-sizing: border-box;
  will-change: transform, opacity;
}

.graph-modal.visible .graph-content {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.graph-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
  padding: 0 5px;
}

.graph-title {
  font-size: 22px;
  font-weight: bold;
  color: var(--graph-text);
}

.graph-close {
  color: var(--graph-text-secondary);
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  transition: color 0.2s ease;
}

.graph-close:hover {
  color: var(--graph-text);
}

.graph-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
  overflow: hidden;
  height: calc(90vh - 80px);
  width: 100%;
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .graph-body {
    flex-direction: row;
  }
}

/* Graph Container */
.graph-container {
  flex: 2;
  background-color: var(--graph-dark-secondary);
  border-radius: 16px;
  padding: 15px;
  min-height: 300px;
  position: relative;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
  overflow: hidden;
  width: 100%;
  box-sizing: border-box;
}

#graph-canvas {
  width: 100%;
  height: 100%;
  min-height: 300px;
  cursor: default;
}

#graph-canvas.interactive-canvas {
  cursor: pointer;
}

/* Controls Container */
.graph-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 15px;
  max-width: 100%;
  overflow: hidden;
  height: 100%;
  min-width: 0;
  box-sizing: border-box;
}

@media (min-width: 768px) {
  .graph-controls {
    max-width: 280px;
    min-width: 250px;
  }
}

/* Range Controls */
.graph-range-controls {
  background-color: var(--graph-dark-secondary);
  border-radius: 16px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  width: 100%;
  box-sizing: border-box;
}

.range-controls-row {
  display: flex;
  gap: 10px;
  width: 100%;
}

.range-control {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.label-with-button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.label-with-button label {
  font-size: 13px;
  color: var(--graph-text-secondary);
  font-weight: bold;
}

.range-control input {
  background-color: var(--graph-dark-tertiary);
  border: 1px solid var(--graph-border);
  border-radius: 8px;
  padding: 6px;
  color: var(--graph-text);
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
}

.range-control input:focus {
  outline: none;
  border-color: var(--graph-accent);
}

/* Input with button */
.input-with-button {
  display: flex;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.input-with-button input {
  flex: 1;
  min-width: 0;
}

.edit-title-btn {
  background-color: var(--graph-dark-tertiary);
  color: var(--graph-text-secondary);
  border: 1px solid var(--graph-border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.edit-title-btn:hover {
  background-color: var(--graph-accent);
  color: white;
  border-color: var(--graph-accent);
}

/* Data Table */
.graph-data-table {
  background-color: var(--graph-dark-secondary);
  border-radius: 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 15px 10px;
  background-color: var(--graph-dark-secondary);
  border-bottom: 1px solid var(--graph-border);
  position: sticky;
  top: 0;
  z-index: 5;
  width: 100%;
  box-sizing: border-box;
}

.table-title {
  font-size: 14px;
  font-weight: bold;
  color: var(--graph-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 65%;
}

.active-data-set-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100px;
  display: inline-block;
  vertical-align: bottom;
}

.add-point-btn {
  background-color: var(--graph-accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  flex-shrink: 0;
}

.add-point-btn:hover {
  background-color: var(--graph-accent-hover);
}

.table-container {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 15px 15px;
  flex: 1;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.data-table th {
  text-align: left;
  padding: 8px 5px;
  font-size: 12px;
  color: var(--graph-text-secondary);
  border-bottom: 1px solid var(--graph-border);
  position: sticky;
  top: 0;
  background-color: var(--graph-dark-secondary);
  z-index: 2;
}

.data-table th:first-child {
  width: 10%;
  text-align: center;
}

.data-table th:nth-child(2),
.data-table th:nth-child(3) {
  width: 35%;
}

.data-table th:last-child {
  width: 20%;
  padding: 4px 2px;
}

.data-table td {
  padding: 5px;
  border-bottom: 1px solid var(--graph-border);
  vertical-align: middle;
}

.data-table td.point-number {
  text-align: center;
  font-size: 12px;
  font-weight: bold;
  color: var(--graph-text-secondary);
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 4px;
}

.data-table input {
  background-color: var(--graph-dark-tertiary);
  border: 1px solid var(--graph-border);
  border-radius: 6px;
  padding: 6px;
  color: var(--graph-text);
  font-size: 12px;
  width: 100%;
  box-sizing: border-box;
}

.data-table input:focus {
  outline: none;
  border-color: var(--graph-accent);
}

.remove-point-btn {
  background-color: transparent;
  color: var(--graph-text-secondary);
  border: none;
  cursor: pointer;
  font-size: 14px;
  transition: color 0.2s ease;
  display: flex;
  justify-content: center;
  width: 100%;
}

.remove-point-btn:hover {
  color: #ff4444;
}

/* Graph Options */
.graph-options {
  background-color: var(--graph-dark-secondary);
  border-radius: 16px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.option-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.option-group label {
  font-size: 13px;
  color: var(--graph-text);
  cursor: pointer;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 18px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--graph-dark-tertiary);
  transition: .4s;
  border-radius: 20px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--graph-text-secondary);
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: var(--graph-accent);
}

input:checked + .toggle-slider:before {
  transform: translateX(18px);
  background-color: white;
}

.export-btn {
  background-color: var(--graph-accent);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px 15px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s ease;
  margin-top: 5px;
  text-align: center;
  width: 100%;
  box-sizing: border-box;
}

.export-btn:hover {
  background-color: var(--graph-accent-hover);
}

/* Animations */
@keyframes graphFadeIn {
  from { 
    opacity: 0;
  }
  to { 
    opacity: 1;
  }
}

@keyframes graphFadeOut {
  from { 
    opacity: 1;
  }
  to { 
    opacity: 0;
  }
}

@keyframes graphPopOut {
  0% { 
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7);
  }
  100% { 
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes graphPopIn {
  0% { 
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% { 
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.7);
  }
}

/* Responsive Adjustments */
@media screen and (max-width: 768px) {
  .graph-content {
    width: 95%;
    padding: 10px;
  }
  
  .graph-container {
    min-height: 250px;
  }
  
  #graph-canvas {
    min-height: 250px;
  }
  
  .graph-title {
    font-size: 18px;
  }
}

/* Tooltip Styles */
.graph-tooltip {
  position: absolute;
  background-color: var(--graph-dark-bg);
  border: 1px solid var(--graph-border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  color: var(--graph-text);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.graph-tooltip.visible {
  opacity: 1;
}

/* Accessibility Focus Styles */
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--graph-accent);
  outline-offset: 2px;
}

/* Scrollbar Styling */
.table-container::-webkit-scrollbar {
  width: 6px;
}

.table-container::-webkit-scrollbar-track {
  background: var(--graph-dark-tertiary);
  border-radius: 6px;
}

.table-container::-webkit-scrollbar-thumb {
  background: var(--graph-border);
  border-radius: 6px;
}

.table-container::-webkit-scrollbar-thumb:hover {
  background: var(--graph-accent);
}

/* Data Sets Manager */
.data-sets-manager {
  background-color: var(--graph-dark-secondary);
  border-radius: 16px;
  padding: 15px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.data-sets-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.data-sets-title {
  font-size: 14px;
  font-weight: bold;
  color: var(--graph-text);
}

.add-data-set-btn {
  background-color: var(--graph-accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.add-data-set-btn:hover {
  background-color: var(--graph-accent-hover);
}

.data-sets-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 150px;
  overflow-y: auto;
  padding-right: 5px;
}

.data-set-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: var(--graph-dark-tertiary);
  border-radius: 8px;
  padding: 8px;
  transition: background-color 0.2s ease;
}

.data-set-item.active {
  background-color: rgba(255, 136, 0, 0.15);
  border: 1px solid rgba(255, 136, 0, 0.3);
}

.data-set-color {
  flex-shrink: 0;
}

.data-set-color-input {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
  background: none;
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: 0 0 0 1px var(--graph-border);
}

.data-set-color-input::-webkit-color-swatch-wrapper {
  padding: 0;
}

.data-set-color-input::-webkit-color-swatch {
  border: none;
  border-radius: 50%;
}

.data-set-color-input::-moz-color-swatch {
  border: none;
  border-radius: 50%;
}

.data-set-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.data-set-name-input {
  background-color: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 2px 4px;
  color: var(--graph-text);
  font-size: 13px;
  width: 100%;
  box-sizing: border-box;
}

.data-set-name-input:focus {
  outline: none;
  background-color: rgba(0, 0, 0, 0.2);
  border-color: var(--graph-border);
}

.data-set-points-count {
  font-size: 11px;
  color: var(--graph-text-secondary);
}

.data-set-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.data-set-select-btn {
  background-color: var(--graph-dark-bg);
  color: var(--graph-text-secondary);
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.data-set-select-btn:hover {
  background-color: var(--graph-accent);
  color: white;
}

.data-set-select-btn.active {
  background-color: var(--graph-accent);
  color: white;
}

.data-set-remove-btn {
  background-color: transparent;
  color: var(--graph-text-secondary);
  border: none;
  border-radius: 4px;
  width: 20px;
  height: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.data-set-remove-btn:hover {
  color: #ff4444;
  background-color: rgba(255, 68, 68, 0.1);
}

/* Scrollbar for data sets container */
.data-sets-container::-webkit-scrollbar {
  width: 6px;
}

.data-sets-container::-webkit-scrollbar-track {
  background: var(--graph-dark-tertiary);
  border-radius: 6px;
}

.data-sets-container::-webkit-scrollbar-thumb {
  background: var(--graph-border);
  border-radius: 6px;
}

.data-sets-container::-webkit-scrollbar-thumb:hover {
  background: var(--graph-accent);
}

/* Title Edit Modal */
.title-edit-modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  justify-content: center;
  align-items: center;
}

.title-edit-content {
  background-color: var(--graph-dark-bg);
  border-radius: 16px;
  padding: 20px;
  width: 300px;
  box-shadow: 0 8px 32px var(--graph-shadow);
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.title-edit-content h3 {
  color: var(--graph-text);
  font-size: 18px;
  margin: 0;
  text-align: center;
}

#title-edit-input {
  background-color: var(--graph-dark-tertiary);
  border: 1px solid var(--graph-border);
  border-radius: 8px;
  padding: 10px;
  color: var(--graph-text);
  font-size: 14px;
  width: 100%;
  box-sizing: border-box;
}

#title-edit-input:focus {
  outline: none;
  border-color: var(--graph-accent);
}

.title-edit-buttons {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.title-edit-save,
.title-edit-cancel {
  flex: 1;
  padding: 8px 0;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
}

.title-edit-save {
  background-color: var(--graph-accent);
  color: white;
}

.title-edit-save:hover {
  background-color: var(--graph-accent-hover);
}

.title-edit-cancel {
  background-color: var(--graph-dark-tertiary);
  color: var(--graph-text-secondary);
}

.title-edit-cancel:hover {
  background-color: #444444;
  color: var(--graph-text);
}

/* Clear Button */
.clear-points-btn {
  background-color: #555555;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: background-color 0.2s ease;
  width: 100%;
  text-align: center;
}

.clear-points-btn:hover {
  background-color: #777777;
}

/* Add styles for the movable legend */
.movable-legend {
  position: absolute;
  background-color: rgba(30, 30, 30, 0.85);
  border: 1px solid rgba(85, 85, 85, 0.8);
  border-radius: 12px;
  padding: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  cursor: grab;
  user-select: none;
  z-index: 10;
  box-sizing: border-box;
  min-width: 150px;
  min-height: 30px;
  overflow: visible;
  backdrop-filter: blur(2px);  /* Add slight blur effect for modern look */
}

.legend-items-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
  height: 100%;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 4px;
  box-sizing: border-box;
  margin-bottom: 12px; /* Increased from 8px to 12px for more bottom spacing */
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-basis: calc(50% - 8px);
  min-width: 0;
  max-width: 200px; /* Limit maximum width to prevent excessive spacing */
  box-sizing: border-box;
  margin-bottom: 4px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

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

.legend-color {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border-width: 2px;
  border-style: solid;
  flex-shrink: 0;
}

.legend-text {
  color: rgba(170, 170, 170, 1);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

/* Resize handles - make completely invisible by default */
.resize-handle {
  position: absolute;
  background-color: transparent; /* Make handles transparent by default */
  z-index: 20;
  transition: background-color 0.2s ease;
  opacity: 0; /* Make completely invisible */
}

/* Corner resize handles */
.resize-nw, .resize-ne, .resize-se, .resize-sw {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}

/* Edge resize handles */
.resize-n, .resize-s {
  width: 20px;
  height: 8px;
  left: calc(50% - 10px);
  border-radius: 4px;
}

.resize-e, .resize-w {
  width: 8px;
  height: 20px;
  top: calc(50% - 10px);
  border-radius: 4px;
}

/* Position the handles */
.resize-n {
  top: -4px;
}

.resize-s {
  bottom: -4px;
}

.resize-e {
  right: -4px;
}

.resize-w {
  left: -4px;
}

.resize-nw {
  top: -6px;
  left: -6px;
}

.resize-ne {
  top: -6px;
  right: -6px;
}

.resize-se {
  bottom: -6px;
  right: -6px;
}

.resize-sw {
  bottom: -6px;
  left: -6px;
}

/* Hover effect for resize handles - only show color on hover */
.resize-handle:hover {
  background-color: rgba(255, 136, 0, 0.7);
  opacity: 1; /* Only show on hover */
}