/* SNOWPACK Dashboard - Styles */
@import url('https://fonts.googleapis.com/css2?family=SF+Pro+Display:wght@300;400;500;600;700&display=swap');

/* Reset */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f8fafc;
  color: #1e293b;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

/* Map */
#map {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  background: #f1f5f9;
}

/* Control Panel */
.control-panel {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 340px;
  max-height: calc(100vh - 40px);
  max-height: calc(100dvh - 40px);
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  overflow: hidden;
  z-index: 1000;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.8);
  background: rgba(248, 250, 252, 0.8);
  flex-shrink: 0;
}

.panel-title {
  font-size: 20px;
  font-weight: 600;
  color: #0f172a;
  margin-bottom: 4px;
  letter-spacing: -0.025em;
}

.data-source {
  font-size: 12px;
  color: #64748b;
  font-weight: 500;
}

.panel-content {
  padding: 0;
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(100vh - 140px);
  max-height: calc(100dvh - 140px);
  -webkit-overflow-scrolling: touch;
}

.panel-content::-webkit-scrollbar {
  width: 6px;
}

.panel-content::-webkit-scrollbar-track {
  background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.5);
  border-radius: 10px;
}

/* Sections */
.section {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.6);
}

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

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 16px;
  letter-spacing: -0.025em;
}

/* Dataset Toggle */
.dataset-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.dataset-btn {
  flex: 1;
  padding: 10px 16px;
  background: #f8fafc;
  border: 2px solid #e2e8f0;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dataset-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.dataset-btn.active {
  background: rgba(14, 165, 233, 0.1);
  border-color: #0ea5e9;
  color: #0ea5e9;
}

/* Visualization Select */
.viz-select {
  width: 100%;
  padding: 12px 16px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: all 0.2s ease;
}

.viz-select:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.viz-select:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

/* Timeline Section */
.timeline-section {
  background: rgba(20, 59, 94, 0.05);
  border: 1px solid rgba(20, 59, 94, 0.1);
  border-radius: 12px;
  padding: 16px;
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.timeline-btn {
  background: #143B5E;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.timeline-btn:hover {
  background: #0f2d47;
}

.timeline-btn:disabled {
  background: #cbd5e1;
  cursor: not-allowed;
}

.timeline-slider {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: 10px;
  outline: none;
  cursor: pointer;
  appearance: none;
}

.timeline-slider::-webkit-slider-thumb {
  appearance: none;
  width: 18px;
  height: 18px;
  background: #143B5E;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(20, 59, 94, 0.3);
}

.timeline-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  background: #143B5E;
  border-radius: 50%;
  border: none;
  cursor: pointer;
}

.timeline-date {
  font-size: 13px;
  color: #475569;
  font-weight: 500;
  text-align: center;
  margin-top: 8px;
}

/* Slider Group */
.slider-group {
  margin-bottom: 20px;
}

.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.slider-label {
  font-size: 13px;
  font-weight: 500;
  color: #64748b;
  min-width: 35px;
}

.slider {
  flex: 1;
  height: 6px;
  background: #e2e8f0;
  border-radius: 10px;
  outline: none;
  cursor: pointer;
  appearance: none;
  transition: all 0.2s ease;
}

.slider:hover {
  background: #cbd5e1;
}

.slider::-webkit-slider-thumb {
  appearance: none;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #0ea5e9, #0369a1);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
  transition: all 0.2s ease;
}

.slider::-webkit-slider-thumb:hover {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, #0ea5e9, #0369a1);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(14, 165, 233, 0.3);
}

.slider-value {
  font-size: 13px;
  font-weight: 600;
  color: #0f172a;
  background: #f1f5f9;
  padding: 4px 8px;
  border-radius: 6px;
  min-width: 45px;
  text-align: center;
}

/* Toggle Grid */
.toggle-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.toggle-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-item:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.toggle-item.active {
  background: rgba(14, 165, 233, 0.1);
  border-color: #0ea5e9;
}

.toggle-item.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.toggle-checkbox {
  width: 16px;
  height: 16px;
  border: 2px solid #cbd5e1;
  border-radius: 4px;
  background: white;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.toggle-checkbox.checked {
  background: #0ea5e9;
  border-color: #0ea5e9;
}

.toggle-checkbox.checked::after {
  content: '✓';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 10px;
  font-weight: bold;
}

.toggle-label {
  font-size: 13px;
  font-weight: 500;
  color: #475569;
}

/* Canopy Section */
.canopy-section {
  background: rgba(34, 197, 94, 0.05);
  border: 1px solid rgba(34, 197, 94, 0.1);
  border-radius: 12px;
  padding: 16px;
}

.canopy-grid {
  display: flex;
  gap: 12px;
}

.canopy-toggle {
  flex: 1;
}

.canopy-toggle .toggle-item.active {
  background: rgba(34, 197, 94, 0.1);
  border-color: #22c55e;
}

.canopy-toggle .toggle-checkbox.checked {
  background: #22c55e;
  border-color: #22c55e;
}

/* Profile Section */
.profile-section {
  background: rgba(14, 165, 233, 0.1);
  border: 1px solid rgba(14, 165, 233, 0.1);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
}

.profile-section .toggle-item.active {
  background: rgba(14, 165, 233, 0.1);
  border-color: #0369a1;
}

.profile-section .toggle-checkbox.checked {
  background: #0ea5e9;
  border-color: #0ea5e9;
}

.profile-status {
  font-size: 11px;
  color: #64748b;
  margin-top: 8px;
}

.profile-status.loading {
  color: #0ea5e9;
}

.profile-status.success {
  color: #22c55e;
}

.profile-status.error {
  color: #ef4444;
}

/* Criteria Display */
.criteria-display {
  background: rgba(239, 138, 98, 0.05);
  border: 1px solid rgba(239, 138, 98, 0.1);
  border-radius: 10px;
  padding: 12px;
  margin-top: 16px;
}

.criteria-text {
  font-size: 12px;
  color: #64748b;
  line-height: 1.4;
}

.criteria-highlight {
  color: #ef8a62;
  font-weight: 600;
}

/* Legend */
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-text {
  font-size: 13px;
  color: #64748b;
}

.property-legend {
  display: none;
}

.property-legend.active {
  display: block;
}

.color-scale {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.color-scale-band {
  display: flex;
  align-items: center;
  height: 28px;
  border-radius: 6px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.property-stats {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
}

.property-stats-text {
  font-size: 11px;
  color: #64748b;
  line-height: 1.4;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-item {
  background: #f8fafc;
  padding: 12px;
  border-radius: 8px;
  text-align: center;
}

.stat-number {
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  display: block;
}

.stat-label {
  font-size: 11px;
  color: #64748b;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Profile Popup Overlay */
.profile-popup-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(6px);
  z-index: 2999;
  display: none;
  pointer-events: none;
}

.profile-popup-overlay.active {
  display: block;
  pointer-events: auto;
  animation: fadeIn 0.2s ease;
}

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

/* Profile Popup */
.profile-popup {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: linear-gradient(to bottom, #ffffff 0%, #fafbfc 100%);
  border-radius: 24px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.25);
  z-index: 3000;
  max-width: 1400px;
  width: 95%;
  max-height: 95vh;
  overflow-y: auto;
  overflow-x: hidden;
  display: none;
}

.profile-popup.active {
  display: block;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translate(-50%, -48%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.profile-popup::-webkit-scrollbar {
  width: 10px;
}

.profile-popup::-webkit-scrollbar-track {
  background: transparent;
}

.profile-popup::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 36px;
  margin: 0 36px;
  background: white;
  border-bottom: 1px solid #e8eaed;
  border-radius: 24px 24px 0 0;
}

.profile-title {
  font-size: 26px;
  font-weight: 700;
  color: #1a1a1a;
}

.close-btn {
  background: #f5f5f5;
  border: none;
  padding: 0;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s;
  flex-shrink: 0;
}

.close-btn:hover {
  background: #e8e8e8;
  transform: rotate(90deg);
}

.x-icon {
  width: 18px;
  height: 18px;
  stroke: #666;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.profile-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 32px 36px 24px 36px;
  padding: 20px;
  background-color: #f8f9fa;
  border-radius: 12px;
  overflow-x: hidden;
}

.info-item {
  display: flex;
  flex-direction: column;
}

.info-label {
  font-size: 11px;
  color: #666;
  text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
}

.info-value {
  font-size: 16px;
  color: #333;
  font-weight: 600;
}

.profile-content {
  margin: 0 36px 24px 36px;
  padding: 30px;
  background-color: #f8f9fa;
  border-radius: 12px;
  overflow-x: hidden;
}

#profileSvg {
  width: 95%;
  height: 800px;
  box-sizing: border-box;
}

.loading-message {
  text-align: center;
  padding: 40px;
  font-size: 16px;
  color: #64748b;
}

.error-message {
  text-align: center;
  padding: 40px;
  font-size: 16px;
  color: #ef4444;
}

/* Leaflet Overrides */
.leaflet-control-layers {
  background: rgba(255, 255, 255, 0.95) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  border-radius: 12px !important;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1) !important;
}

.leaflet-control-layers-toggle {
  width: 40px !important;
  height: 40px !important;
  background-size: 20px 20px !important;
}

.leaflet-control-layers-expanded {
  padding: 12px 16px !important;
  color: #475569 !important;
}

.leaflet-control-layers-base label,
.leaflet-control-layers-overlays label {
  font-size: 10px !important;
  font-weight: 500 !important;
  padding: 6px 0 !important;
}

.leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, 0.98) !important;
  backdrop-filter: blur(20px) !important;
  border-radius: 12px !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.2) !important;
}

.leaflet-popup-content {
  margin: 16px !important;
  font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
  font-size: 13px !important;
}

.leaflet-popup h4 {
  color: #1e293b !important;
  margin-bottom: 8px !important;
  font-size: 14px !important;
}

.leaflet-bottom.leaflet-left {
  bottom: 24px;
  left: 24px;
}

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.3);
  font-size: 11px;
  color: #667;
  margin: 0 !important;
}

.leaflet-control-attribution a {
  color: #17abff;
  text-decoration: none;
  transition: color 0.2s;
}

.leaflet-top.leaflet-left {
  top: 24px;
  left: 24px;
}

.leaflet-control-zoom {
  border: none !important;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1) !important;
  border-radius: 12px !important;
}

/* Microregion Stats Section */
.microregion-stats-section {
  background: rgba(168, 85, 247, 0.05);
  border: 1px solid rgba(81, 176, 176, 0.15);
  border-radius: 12px;
  padding: 16px;
  margin-top: 16px;
}

.microregion-stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.microregion-stats-title {
  font-size: 14px;
  font-weight: 600;
  color: #475569;
}

.microregion-stats-toggle {
  font-size: 11px;
  color: #51B0B0;
  cursor: pointer;
  font-weight: 500;
}

.microregion-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.microregion-table th {
  text-align: center;
  padding: 8px 4px;
  background: rgba(81, 176, 176, 0.1);
  color: #51B0B0;
  font-weight: 600;
}

.microregion-table th:first-child {
  text-align: left;
}

.microregion-table td {
  padding: 6px 4px;
  border-bottom: 1px solid rgba(81, 176, 176, 0.1);
  color: #475569;
  text-align: center;
}

.microregion-table td:first-child {
  text-align: left;
}

.microregion-table .region-name {
  font-weight: 500;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.class-low {
  background: rgba(128, 205, 193, 0.3);
}

.class-moderate {
  background: rgba(1, 133, 113, 0.3);
  color: #065f46;
}

.class-high {
  background: rgba(223, 194, 125, 0.3);
}

.class-very-high {
  background: rgba(166, 97, 26, 0.3);
  color: #92400e;
  font-weight: 600;
}

.microregion-table tr.selected-region {
  background: rgba(14, 165, 233, 0.2) !important;
  outline: 2px solid #0ea5e9;
}

.microregion-table tr.selected-region td {
  font-weight: 600;
}

.filter-indicator {
  font-size: 10px;
  color: #64748b;
  font-style: italic;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(81, 176, 176, 0.1);
}

/* Mobile Responsive */
@media (max-width: 640px) {

/* NiVizPetit Popup Styles */
.nivizpetit-popup {
  max-width: 1200px;
}

.nivizpetit-content {
  margin: 0 36px 24px 36px;
  padding: 20px;
  background-color: #f8f9fa;
  border-radius: 12px;
  overflow: hidden;
  min-height: 400px;
}

.nivizpetit-content > div {
  width: 100%;
  min-height: 380px;
}

@media (max-width: 640px) {
  .nivizpetit-content {
    margin: 0 16px 16px;
    padding: 12px;
    min-height: 300px;
  }
  
  .nivizpetit-content > div {
    min-height: 280px;
  }
}

/* End NiVizPetit Styles */

@media (max-width: 640px) {
  .control-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-height: 50vh;
    max-height: 50dvh;
    border-radius: 16px 16px 0 0;
    animation: none;
  }

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

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

  .section {
    padding: 14px 16px;
  }

  .section-title {
    font-size: 14px;
    margin-bottom: 12px;
  }

  .toggle-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stat-item {
    padding: 10px;
  }

  .stat-number {
    font-size: 16px;
  }

  .dataset-toggle {
    gap: 6px;
  }

  .dataset-btn {
    padding: 8px 12px;
    font-size: 12px;
  }

  .slider-row {
    gap: 8px;
  }

  .slider-label {
    min-width: 30px;
    font-size: 12px;
  }

  .slider-value {
    min-width: 40px;
    font-size: 12px;
    padding: 3px 6px;
  }

  .viz-select {
    padding: 10px 12px;
    font-size: 13px;
  }

  .canopy-grid {
    flex-direction: column;
    gap: 8px;
  }

  .microregion-table {
    font-size: 10px;
  }

  .microregion-table th,
  .microregion-table td {
    padding: 4px 2px;
  }

  .microregion-table .region-name {
    max-width: 60px;
  }

  .profile-popup {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 16px 16px 0 0;
  }

  .profile-popup.active {
    animation: slideUpMobile 0.3s ease;
  }

  @keyframes slideUpMobile {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .profile-header {
    padding: 16px 20px;
    margin: 0 16px;
  }

  .profile-title {
    font-size: 18px;
  }

  .profile-info {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin: 16px;
    padding: 16px;
  }

  .info-value {
    font-size: 14px;
  }

  .profile-content {
    margin: 0 16px 16px;
    padding: 20px;
  }

  #profileSvg {
    height: 500px;
  }

  #nivizPopup {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    max-height: 90vh;
    max-height: 90dvh;
    border-radius: 16px 16px 0 0;
  }

  #nivizControls {
    gap: 6px;
  }

  #nivizControls .timeline-btn {
    padding: 6px 10px;
    font-size: 11px;
  }

  .leaflet-top.leaflet-left {
    top: 12px;
    left: 12px;
  }

  .leaflet-bottom.leaflet-left {
    bottom: 55vh;
    bottom: 55dvh;
    left: 12px;
  }

  .leaflet-bottom.leaflet-right {
    bottom: 55vh;
    bottom: 55dvh;
    right: 12px;
  }

  .leaflet-control-attribution {
    font-size: 9px;
    padding: 6px 10px;
  }
}

@media (max-width: 380px) {
  .control-panel {
    max-height: 55vh;
    max-height: 55dvh;
  }

  .toggle-grid {
    grid-template-columns: 1fr;
  }

  .panel-title {
    font-size: 14px;
  }

  .section {
    padding: 12px 14px;
  }
}
