.states-page {
  width: 100%;
  box-sizing: border-box;
}

.states-loading,
.states-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  gap: 1rem;
  color: #718096;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #e2e8f0;
  border-top-color: #2c5282;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.title-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.states-header {
  background: white;
  border-radius: 0.75rem;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.header-content {
  margin-bottom: 2rem;
}

.header-content h1 {
  font-size: 2rem;
  font-weight: 700;
  color: #1a1a1a;
  margin-bottom: 0.5rem;
}

.header-content p {
  color: #666;
  font-size: 1.125rem;
}

.national-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

.stat-box {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stat-label {
  font-size: 0.875rem;
  color: #718096;
  font-weight: 500;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #2c5282;
}

.states-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.search-section {
  flex: 1;
  max-width: 400px;
}

.search-box {
  display: flex;
  align-items: center;
  background: white;
  border: 2px solid #e2e8f0;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  gap: 0.75rem;
  transition: border-color 0.2s ease;
}

.search-box:focus-within {
  border-color: #2c5282;
}

.search-box svg {
  color: #718096;
  font-size: 1.25rem;
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1rem;
  color: #1a1a1a;
}

.control-buttons {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.sort-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
}

.sort-controls label {
  font-size: 0.875rem;
  color: #4a5568;
  font-weight: 500;
}

.sort-select {
  border: none;
  outline: none;
  background: none;
  color: #1a1a1a;
  font-size: 0.875rem;
  cursor: pointer;
}

.view-controls {
  display: flex;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  overflow: hidden;
  align-items: center;
  gap: 0px;
  justify-content: space-between;
}

.view-controls .view-controls {
  display: flex;
  background: none;
  border: none;
  border-radius: 0;
  overflow: visible;
  justify-content: flex-start;
  flex: 1;
}

.view-btn {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 0.875rem;
  color: #4a5568;
  transition: all 0.2s ease;
}

.view-btn:not(:last-child) {
  border-right: 1px solid #e2e8f0;
}

.view-btn.active {
  background: #2c5282;
  color: white;
}

/* Export controls within view-controls */
.view-controls .export-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.view-controls .export-controls .export-btn {
  background: #3b82f6;
  color: white;
  border: 1px solid #3b82f6;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.view-controls .export-controls .export-btn:hover {
  background: #2563eb;
  border-color: #2563eb;
  transform: translateY(-1px);
}

.view-controls .export-controls .export-btn:disabled {
  background: #9ca3af;
  border-color: #9ca3af;
  cursor: not-allowed;
  transform: none;
}

.download-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  color: #4a5568;
  cursor: pointer;
  transition: all 0.2s ease;
}

.download-btn:hover:not(:disabled) {
  background: #f7fafc;
  border-color: #cbd5e0;
}

.download-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.performance-insights {
  background: white;
  border-radius: 0.75rem;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.insights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 1.5rem;
}

.insight-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  background: #f8fafc;
  border-radius: 0.75rem;
  border-left: 4px solid transparent;
  transition: all 0.2s ease;
}

.insight-card:hover {
  background: #f1f5f9;
  transform: translateY(-2px);
}

.insight-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 1.5rem;
}

.insight-icon.high {
  background: rgba(34, 197, 94, 0.1);
  color: #22c55e;
}

.insight-icon.medium {
  background: rgba(245, 158, 11, 0.1);
  color: #f59e0b;
}

.insight-icon.low {
  background: rgba(239, 68, 68, 0.1);
  color: #ef4444;
}

.insight-content h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: #374151;
  margin: 0 0 0.25rem 0;
}

.insight-count {
  font-size: 1.75rem;
  font-weight: 700;
  color: #111827;
  margin: 0;
  line-height: 1;
}

.insight-desc {
  font-size: 0.75rem;
  color: #6b7280;
  margin: 0.25rem 0 0 0;
}

.chart-section {
  background: white;
  border-radius: 0.75rem;
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.chart-section h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 1.5rem;
}

.content-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.content-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a1a1a;
  margin: 0;
}

.active-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
}

.filter-label {
  font-size: 0.875rem;
  color: #1e40af;
  font-weight: 500;
}

.clear-filter {
  background: none;
  border: none;
  color: #6b7280;
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s ease;
}

.clear-filter:hover {
  background: rgba(107, 114, 128, 0.1);
  color: #374151;
}

.filter-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid #e2e8f0;
}

.filter-controls label {
  font-size: 0.875rem;
  color: #4a5568;
  font-weight: 500;
}

/* Ultra-small devices fixes (iPhone SE width ~375px) */
@media (max-width: 400px) {
  .states-header,
  .performance-insights,
  .chart-section {
    padding: 1rem;
    border-radius: 0.5rem;
  }

  .header-content h1 {
    font-size: clamp(1.125rem, 4.5vw, 1.375rem);
  }

  .header-content p {
    font-size: 0.9375rem;
  }

  .states-controls {
    gap: 0.75rem;
  }

  .control-buttons {
    width: 100%;
  }

  .filter-controls,
  .sort-controls,
  .view-controls,
  .download-btn {
    width: 100%;
  }

  .sort-controls,
  .filter-controls {
    justify-content: space-between;
    gap: 0.5rem;
  }

  .sort-select {
    max-width: 60%;
  }

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

  .content-header h2 {
    font-size: 1.125rem;
  }

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

/* Prevent horizontal overflow from any child */
.states-page,
.states-page * {
  min-width: 0;
}

/* Ensure charts and containers don't overflow */
.chart-section canvas,
.chart-section svg,
.chart-section .apexcharts-canvas,
.chart-section .recharts-wrapper,
.chart-section .chart-container {
  max-width: 100%;
  width: 100% !important;
  height: auto;
  overflow: hidden;
}

.states-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.states-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.no-states {
  text-align: center;
  padding: 3rem;
  background: #f7fafc;
  border-radius: 0.75rem;
  color: #718096;
}

@media (max-width: 768px) {
  .states-header {
    padding: 1.5rem;
  }

  .header-content h1 {
    font-size: 1.5rem;
  }

  .national-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .states-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .search-section {
    max-width: 100%;
  }

  .control-buttons {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .filter-controls,
  .sort-controls {
    width: 100%;
    justify-content: space-between;
  }
  
  .view-controls {
    width: 100%;
  }
  
  .download-btn {
    width: 100%;
    justify-content: center;
  }

  .insights-grid {
    grid-template-columns: 1fr;
  }
  
  .content-header {
    flex-direction: column;
    align-items: flex-start;
  }

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