/* ===== MAP SIDEBAR STYLES ===== */

.map-sidebar {
  position: fixed;
  top: 65px;
  right: 20px;
  width: 320px;
  height: calc(100vh - 85px);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  overflow: hidden;

  /* Hidden by default */
  transform: translateX(calc(100% + 40px));
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
  pointer-events: none;
}

.map-sidebar.visible {
  transform: translateX(0);
  opacity: 1;
  pointer-events: all;
}

/* Sidebar Header */
.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  background: #f8f9fa;
  border-radius: 8px 8px 0 0;
}

.sidebar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

/* Sidebar View Controls */
.sidebar-view-controls {
  padding: 16px 20px;
  border-bottom: 1px solid #eee;
  background: #f8f9fa;
}

.view-control-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.view-control-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.view-2d-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fff;
  border: 2px solid #007bff;
  border-radius: 6px;
  color: #007bff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  pointer-events: auto;
  /* Ensure button is always clickable */
  position: relative;
  z-index: 1000;
  /* Ensure button is on top */
}

.view-2d-button:hover:not(:disabled) {
  background: #007bff;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 123, 255, 0.3);
}

.view-2d-button:active:not(:disabled) {
  transform: translateY(0);
}

.view-2d-button:disabled {
  background: #f8f9fa;
  border-color: #dee2e6;
  color: #6c757d;
  cursor: not-allowed;
  opacity: 0.6;
}

.view-2d-button.active {
  background: #28a745;
  border-color: #28a745;
  color: white;
}

.view-2d-button.active:hover {
  background: #218838;
  border-color: #1e7e34;
}

.view-button-icon {
  font-size: 16px;
  display: flex;
  align-items: center;
}

.view-button-text {
  font-weight: 500;
}

/* Wall Toggle Button Styles */
.wall-toggle-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin-top: 8px;
  background: #fff;
  border: 2px solid #6c757d;
  border-radius: 6px;
  color: #6c757d;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  pointer-events: auto;
  position: relative;
  z-index: 1000;
  width: 100%;
}

.wall-toggle-button:hover:not(:disabled) {
  background: #6c757d;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(108, 117, 125, 0.3);
}

.wall-toggle-button:active:not(:disabled) {
  transform: translateY(0);
}

.wall-toggle-button:disabled {
  background: #f8f9fa;
  border-color: #dee2e6;
  color: #adb5bd;
  cursor: not-allowed;
  opacity: 0.6;
}

.wall-toggle-button.walls-visible {
  background: #d4edda;
  border-color: #28a745;
  color: #155724;
}

.wall-toggle-button.walls-visible:hover:not(:disabled) {
  background: #28a745;
  border-color: #1e7e34;
  color: white;
}

.wall-toggle-button.walls-hidden {
  background: #f8d7da;
  border-color: #dc3545;
  color: #721c24;
}

.wall-toggle-button.walls-hidden:hover:not(:disabled) {
  background: #dc3545;
  border-color: #c82333;
  color: white;
}

.wall-icon {
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
}

.wall-button-text {
  font-weight: 500;
  white-space: nowrap;
}

.view-status-indicator {
  font-size: 12px;
  color: #6c757d;
  font-style: italic;
  text-align: center;
  padding: 4px 0;
}

/* Sidebar Content */
.sidebar-content {
  height: calc(100% - 140px);
  /* Adjusted for view controls */
  overflow-y: auto;
  padding: 0;
}

/* Custom scrollbar for sidebar content */
.sidebar-content::-webkit-scrollbar {
  width: 6px;
}

.sidebar-content::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.sidebar-content::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Resize Handle */
.sidebar-resize-handle {
  position: absolute;
  left: -6px;
  top: 0;
  bottom: 0;
  width: 12px;
  cursor: ew-resize;
  background: transparent;
  z-index: 1001;
}

.sidebar-resize-handle:hover {
  background: rgba(0, 123, 255, 0.1);
}

.sidebar-resize-handle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 30px;
  background: #ddd;
  border-radius: 2px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.sidebar-resize-handle:hover::before {
  opacity: 1;
}

/* Toggle Button */
.sidebar-toggle-btn {
  position: fixed;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  background: #007bff;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0, 123, 255, 0.3);
  z-index: 10001;
  transition: all 0.2s ease;
}

.sidebar-toggle-btn:hover {
  background: #0056b3;
  transform: scale(1.05);
  box-shadow: 0 4px 15px rgba(0, 123, 255, 0.4);
}

.sidebar-toggle-btn:active {
  transform: scale(0.95);
}

.sidebar-toggle-btn.sidebar-open {
  background: #6c757d;
}

.sidebar-toggle-btn.sidebar-open:hover {
  background: #545b62;
}

/* Toggle Button Tooltip */
.sidebar-toggle-tooltip {
  position: fixed;
  background: rgba(33, 37, 41, 0.95);
  color: white;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 10002;
  max-width: 250px;
  transform: translateX(10px);
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  pointer-events: none;
}

.sidebar-toggle-tooltip.visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
  pointer-events: all;
}

.tooltip-header {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 8px;
  color: #ffffff;
}

.tooltip-content {
  margin-bottom: 8px;
}

.tooltip-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

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

.tooltip-label {
  font-size: 12px;
  color: #ced4da;
}

.tooltip-indicators {
  display: flex;
  gap: 4px;
  align-items: center;
}

.tooltip-indicator {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: #6c757d;
  border: 1px solid #495057;
}

.tooltip-indicator.circle {
  border-radius: 50%;
  background: #adb5bd;
}

.tooltip-indicator.line {
  height: 3px;
  background: #17a2b8;
  border: none;
}

.tooltip-footer {
  font-size: 11px;
  color: #6c757d;
  font-style: italic;
  text-align: center;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #495057;
}

/* ===== LEGEND STYLES ===== */

.legend-section {
  border-bottom: 1px solid #f0f0f0;
}

.legend-section:last-child {
  border-bottom: none;
}

.legend-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  cursor: pointer;
  background: #fff;
  transition: background-color 0.2s ease;
  user-select: none;
}

.legend-header:hover {
  background: #f8f9fa;
}

.legend-header:focus {
  outline: 2px solid #007bff;
  outline-offset: -2px;
}

.legend-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.legend-chevron {
  font-size: 12px;
  color: #666;
  transition: transform 0.2s ease;
}

.legend-header[aria-expanded="false"] .legend-chevron {
  transform: rotate(-90deg);
}

.legend-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 20px;
}

.legend-items.expanded {
  max-height: 300px;
  padding: 0 20px 16px 20px;
}

/* Scrollable legend sections */
.legend-scroll-wrapper {
  position: relative;
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: #c1c1c1 #f1f1f1;
}

.legend-scroll-wrapper::-webkit-scrollbar {
  width: 6px;
}

.legend-scroll-wrapper::-webkit-scrollbar-track {
  background: #f8f9fa;
  border-radius: 3px;
}

.legend-scroll-wrapper::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
  transition: background-color 0.2s ease;
}

.legend-scroll-wrapper::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

.legend-scroll-content {
  padding: 0;
}

/* Scroll fade indicators */
.legend-scroll-fade {
  position: absolute;
  left: 0;
  right: 6px;
  /* Account for scrollbar */
  height: 15px;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.legend-scroll-fade.top {
  top: 0;
  background: linear-gradient(to bottom,
      rgba(255, 255, 255, 0.9) 0%,
      rgba(255, 255, 255, 0) 100%);
}

.legend-scroll-fade.bottom {
  bottom: 0;
  background: linear-gradient(to top,
      rgba(255, 255, 255, 0.9) 0%,
      rgba(255, 255, 255, 0) 100%);
}

/* Content indicator */
.legend-content-indicator {
  padding: 4px 8px;
  font-size: 11px;
  color: #6c757d;
  text-align: center;
  background: #f8f9fa;
  border-top: 1px solid #e9ecef;
  display: none;
  font-style: italic;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #f5f5f5;
  border-radius: 4px;
  transition: background-color 0.2s ease;
}

.legend-item:last-child {
  border-bottom: none;
}

.legend-item:focus {
  outline: 2px solid #007bff;
  outline-offset: 2px;
  background-color: rgba(0, 123, 255, 0.1);
}

.legend-item:focus-visible {
  outline: 2px solid #007bff;
  outline-offset: 2px;
  background-color: rgba(0, 123, 255, 0.1);
}

/* Legend Indicators */
.legend-indicator {
  width: 20px;
  height: 20px;
  border: 1px solid #ccc;
  flex-shrink: 0;
}

.legend-indicator.square {
  border-radius: 2px;
}

.legend-indicator.circle {
  border-radius: 50%;
  border: 2px solid #ddd;
}

.legend-indicator.line {
  height: 4px;
  border-radius: 2px;
  border: none;
}

.legend-label {
  font-size: 14px;
  color: #555;
  line-height: 1.4;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Tablet and smaller screens */
@media (max-width: 1024px) {
  .map-sidebar {
    width: 280px;
    top: 65px;
    height: calc(100vh - 85px);
  }

  .sidebar-toggle-btn {
    top: 20px;
    width: 32px;
    height: 32px;
    font-size: 12px;
  }
}

/* Mobile screens */
@media (max-width: 768px) {
  .map-sidebar {
    width: 100%;
    max-width: 320px;
    right: 10px;
    top: 65px;
    height: calc(100vh - 85px);
  }

  .sidebar-toggle-btn {
    top: 20px;
    right: 15px;
  }

  .legend-header {
    padding: 12px 16px;
  }

  .legend-items.expanded {
    padding: 0 16px 12px 16px;
  }

  .legend-title {
    font-size: 15px;
  }

  .legend-label {
    font-size: 13px;
  }
}

/* Very small screens */
@media (max-width: 480px) {
  .map-sidebar {
    width: calc(100vw - 20px);
    right: 10px;
    left: 10px;
    max-width: none;
  }

  .sidebar-header {
    padding: 12px 16px;
  }

  .sidebar-title {
    font-size: 16px;
  }

  .wall-toggle-button {
    padding: 8px 12px;
    font-size: 13px;
  }

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

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus indicators */
.legend-header:focus-visible {
  outline: 2px solid #007bff;
  outline-offset: -2px;
}

.sidebar-toggle-btn:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .map-sidebar {
    border: 2px solid #000;
    background: #fff;
  }

  .legend-header {
    border-bottom: 1px solid #000;
  }

  .legend-item {
    border-bottom: 1px solid #ccc;
  }

  .legend-indicator {
    border: 2px solid #000;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .map-sidebar {
    transition: none;
  }

  .legend-chevron {
    transition: none;
  }

  .legend-items {
    transition: none;
  }

  .sidebar-toggle-btn {
    transition: none;
  }
}

/* ===== CESIUM INFO BOX ADJUSTMENTS ===== */

/* Ensure info box doesn't get too narrow when sidebar is open */
.cesium-infoBox {
  min-width: 200px;
}

.cesium-infoBox-description {
  word-wrap: break-word;
}

/* ===== DARK MODE SUPPORT (Optional) ===== */
@media (prefers-color-scheme: dark) {
  .map-sidebar {
    background: rgba(33, 37, 41, 0.98);
    border-color: #495057;
    color: #fff;
  }

  .sidebar-header {
    background: #212529;
    border-bottom-color: #495057;
  }

  .sidebar-title {
    color: #fff;
  }

  .legend-header {
    background: #343a40;
    color: #fff;
  }

  .legend-header:hover {
    background: #495057;
  }

  .legend-title {
    color: #fff;
  }

  .legend-label {
    color: #ced4da;
  }

  /* Dark mode 2D view controls */
  .sidebar-view-controls {
    background: #212529;
    border-bottom-color: #495057;
  }

  .view-control-title {
    color: #adb5bd;
  }

  .view-2d-button {
    background: #343a40;
    border-color: #007bff;
    color: #007bff;
  }

  .view-2d-button:hover:not(:disabled) {
    background: #007bff;
    color: #fff;
  }

  .view-2d-button:disabled {
    background: #212529;
    border-color: #495057;
    color: #6c757d;
  }

  .view-2d-button.active {
    background: #28a745;
    border-color: #28a745;
    color: #fff;
  }

  .view-status-indicator {
    color: #6c757d;
  }

  .legend-chevron {
    color: #adb5bd;
  }

  .legend-item {
    border-bottom-color: #495057;
  }

  .legend-section {
    border-bottom-color: #495057;
  }

  .sidebar-content::-webkit-scrollbar-track {
    background: #343a40;
  }

  .sidebar-content::-webkit-scrollbar-thumb {
    background: #6c757d;
  }

  .sidebar-content::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
  }

  .legend-scroll-wrapper::-webkit-scrollbar-track {
    background: #343a40;
  }

  .legend-scroll-wrapper::-webkit-scrollbar-thumb {
    background: #6c757d;
  }

  .legend-scroll-wrapper::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
  }

  .legend-scroll-fade.top {
    background: linear-gradient(to bottom,
        rgba(33, 37, 41, 0.9) 0%,
        rgba(33, 37, 41, 0) 100%);
  }

  .legend-scroll-fade.bottom {
    background: linear-gradient(to top,
        rgba(33, 37, 41, 0.9) 0%,
        rgba(33, 37, 41, 0) 100%);
  }

  .legend-content-indicator {
    background: #343a40;
    border-top-color: #495057;
    color: #adb5bd;
  }
}

/* Network Toggle Button Styles */
.network-toggle-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin-top: 8px;
  background: #fff;
  border: 2px solid #17a2b8;
  border-radius: 6px;
  color: #17a2b8;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  outline: none;
  pointer-events: auto;
  position: relative;
  z-index: 1000;
  width: 100%;
}

.network-toggle-button:hover:not(:disabled) {
  background: #17a2b8;
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(23, 162, 184, 0.3);
}

.network-toggle-button:active:not(:disabled) {
  transform: translateY(0);
}

.network-toggle-button:disabled {
  background: #f8f9fa;
  border-color: #dee2e6;
  color: #adb5bd;
  cursor: not-allowed;
  opacity: 0.6;
}

.network-toggle-button.network-visible {
  background: #d1ecf1;
  border-color: #17a2b8;
  color: #0c5460;
}

.network-toggle-button.network-visible:hover:not(:disabled) {
  background: #17a2b8;
  border-color: #138496;
  color: white;
}

.network-toggle-button.network-hidden {
  background: #fff3cd;
  border-color: #ffc107;
  color: #856404;
}

.network-toggle-button.network-hidden:hover:not(:disabled) {
  background: #ffc107;
  border-color: #e0a800;
  color: white;
}

.network-icon {
  font-size: 16px;
  line-height: 1;
  display: flex;
  align-items: center;
}

.network-button-text {
  font-weight: 500;
  white-space: nowrap;
}

/* Move info box to the left when sidebar is visible */
body.sidebar-open .cesium-infoBox {
  right: calc(var(--sidebar-width, 320px) + 40px) !important;
  transition: right 0.3s ease;
  max-width: calc(100vw - var(--sidebar-width, 320px) - 80px) !important;
}

/* Default position when sidebar is closed */
body:not(.sidebar-open) .cesium-infoBox {
  right: 20px !important;
  transition: right 0.3s ease;
}