.dashboard {
  animation: fadeIn 0.3s ease-in;
}

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

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

.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);
  }
}

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

.dashboard-title-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1rem;
  position: relative;
  padding: var(--spacing-6) 0;
}

.dashboard-title-section::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary-500) 0%, var(--civic-gold-500) 50%, var(--civic-green-500) 100%);
  border-radius: var(--radius-full);
}

/* removed data freshness badge styles */

.dashboard-header h1 {
  font-size: 2.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-700) 0%, var(--civic-gold-600) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  margin: 0 0 var(--spacing-2) 0;
}

.dashboard-header p {
  font-size: 1.125rem;
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.01em;
  margin: 0;
}

.data-context-notice {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary-50) 0%, var(--slate-50) 100%);
  border: 1px solid var(--primary-200);
  border-left: 4px solid var(--primary-500);
  padding: var(--spacing-4) var(--spacing-5);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  margin: 1rem 0;
  font-size: 14px;
  color: #0c4a84;
}

.notice-icon {
  flex-shrink: 0;
  font-size: 18px;
  color: var(--primary-600);
}

.dashboard-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.5rem;
}

.dashboard-search {
  flex: 1;
  max-width: 600px;
}

.dashboard-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: var(--spacing-6);
  margin: var(--spacing-8) 0;
}

.metric-card {
  background: var(--bg-gradient-card);
  border-radius: var(--radius-2xl);
  padding: var(--spacing-6);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-card);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
  display: flex;
  gap: 1rem;
  /* Allow text blocks to shrink instead of forcing overflow */
  min-width: 0;
}

.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent 0%, currentColor 50%, transparent 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.metric-card:hover::before {
  opacity: 1;
}

.metric-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-card-elevated);
  border-color: var(--border-color-hover);
}

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

.metric-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
}

.metric-card:hover .metric-icon {
  transform: scale(1.1);
  box-shadow: var(--shadow-md);
}

.metric-blue .metric-icon {
  background: linear-gradient(135deg, var(--primary-100) 0%, var(--primary-200) 100%);
  color: var(--primary-700);
}

.metric-blue::before {
  background: linear-gradient(90deg, transparent 0%, var(--primary-500) 50%, transparent 100%);
}

.metric-green .metric-icon {
  background: linear-gradient(135deg, var(--civic-green-100) 0%, var(--civic-green-200) 100%);
  color: var(--civic-green-700);
}

.metric-green::before {
  background: linear-gradient(90deg, transparent 0%, var(--civic-green-500) 50%, transparent 100%);
}

.metric-yellow .metric-icon {
  background: linear-gradient(135deg, var(--civic-gold-100) 0%, var(--civic-gold-200) 100%);
  color: var(--civic-gold-700);
}

.metric-yellow::before {
  background: linear-gradient(90deg, transparent 0%, var(--civic-gold-500) 50%, transparent 100%);
}

.metric-red .metric-icon {
  background: linear-gradient(135deg, var(--civic-red-100) 0%, var(--civic-red-200) 100%);
  color: var(--civic-red-700);
}

.metric-red::before {
  background: linear-gradient(90deg, transparent 0%, var(--civic-red-500) 50%, transparent 100%);
}

.metric-orange .metric-icon {
  background: linear-gradient(135deg, var(--civic-gold-100) 0%, var(--civic-gold-200) 100%);
  color: var(--civic-gold-700);
}

.metric-orange::before {
  background: linear-gradient(90deg, transparent 0%, var(--civic-gold-600) 50%, transparent 100%);
}

.metric-content {
  flex: 1;
  min-width: 0;
}

.metric-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 0 var(--spacing-2) 0;
}

/* Preserve proper capitalization for MPs title */
.metric-title.preserve-case {
  text-transform: none;
}

.metric-value {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-primary);
  margin: var(--spacing-3) 0 var(--spacing-1) 0;
  line-height: 1.1;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

.metric-description {
  font-size: 0.813rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin: 0;
}

.metric-period {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  margin: 0.25rem 0 0 0;
  font-weight: 500;
  opacity: 0.8;
}

.dashboard-info {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr));
  gap: 2rem;
}

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

.info-card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #1a1a1a;
  margin-bottom: 1rem;
}

.info-card p {
  color: #666;
  line-height: 1.6;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  align-items: start;
}

.action-btn {
  padding: 0.75rem 1rem;
  background-color: #2c5282;
  color: white;
  border: none;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.action-btn:hover:not(:disabled) {
  background-color: #2a4e7c;
  color: white;
}

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

.action-btn-wrapper {
  display: flex;
  flex-direction: column;
  position: relative;
}

.action-btn-wrapper .action-btn {
  width: 100%;
}

/* Charts Section Styles */
.charts-section {
  margin: 3rem 0;
}

/* Global-safe text wrapping for chart descriptions and legends */
.chart-description,
.mp-personality-chart-container,
.state-allocation-chart-container,
.comparison-chart-container,
.chart-footer,
.chart-meta {
  /* Prevent horizontal overflow by allowing natural wrapping */
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

/* Specific: legend/description blocks inside chart containers */
.chart-container .legend,
.chart-container .description,
.mp-personality-chart-container .legend,
.mp-personality-chart-container .description {
  overflow-wrap: anywhere;
  word-break: break-word;
  hyphens: auto;
}

/* Utility: clamp multi-line text to keep cards tidy (progressive enhancement) */
.clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dashboard-section {
  margin-bottom: 2rem;
}

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

.chart-row {
  display: grid;
  /* Prevent mid-width overflow by allowing both columns to shrink */
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr);
  gap: 2rem;
  margin-bottom: 2rem;
}

/* Responsive grid adjustments */
@media (max-width: 1024px) {
  .chart-row {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }
}

@media (max-width: 480px) {
  .chart-row {
    gap: 1rem;
  }
}

.chart-container {
  background: white;
  border-radius: 0.75rem;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  position: relative;
  min-height: 0;
  /* Allow container to grow; control overflow inside inner blocks */
  max-height: none;
  display: flex;
  flex-direction: column;
  /* Ensure grid/flex shrink works to avoid horizontal overflow */
  min-width: 0;
  /* Prevent horizontal scroll on small screens */
  overflow-x: hidden;
  /* Improve text rendering on mobile */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.chart-container.full-width {
  margin-bottom: 2rem;
}

.wip-chart {
  display: flex;
  flex-direction: column;
  /* Avoid forcing horizontal scroll on small screens */
  min-width: 0;
  width: 100%;
  /* Responsive height that works with chart component */
  height: auto;
  min-height: 360px;
}

/* Loading states within charts */
.chart-container .loading-state {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 0.75rem;
  backdrop-filter: blur(2px);
}

.wip-chart .work-in-progress-container {
  width: 100%;
  height: 100%;
}

/* Small mobile breakpoint (320px-480px) */
@media (max-width: 480px) {
  .dashboard-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .dashboard-search {
    max-width: none;
  }

  .metrics-grid {
    gap: 0.75rem;
  }

  .metric-card {
    padding: 0.75rem;
    gap: 0.75rem;
  }

  .metric-value {
    font-size: 1.25rem;
  }

  .chart-container {
    padding: 0.75rem;
    min-height: 0;
  }

  .wip-chart {
    min-height: 300px;
  }

  .chart-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

/* Medium mobile breakpoint (481px-640px) */
@media (min-width: 481px) and (max-width: 640px) {
  .dashboard-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .dashboard-search {
    max-width: none;
  }

  .metrics-grid {
    gap: 1rem;
  }

  .metric-card {
    padding: 1rem;
  }

  .chart-container {
    padding: 1rem;
    min-height: 0;
  }

  .wip-chart {
    min-height: 340px;
  }

  .chart-row {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

@media (max-width: 768px) {
  .dashboard-title-section {
    align-items: flex-start;
  }

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

  .dashboard-header p {
    font-size: 1rem;
  }

  .dashboard-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .dashboard-search {
    max-width: none;
  }

  .dashboard-actions {
    justify-content: center;
  }

  .dashboard-freshness {
    align-self: stretch;
  }

  .metrics-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .dashboard-info {
    grid-template-columns: 1fr;
  }

  .metric-value {
    font-size: 1.5rem;
  }

  .chart-row {
    grid-template-columns: 1fr;
  }

  .chart-container {
    padding: 1rem;
  }

  .wip-chart {
    min-width: auto;
    min-height: 320px;
  }

  .quick-actions {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .action-btn {
    padding: 1rem;
    font-size: 1rem;
    text-align: center;
  }
}

/* Chart component styles */
.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #e5e7eb;
}

.chart-title-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chart-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
}

.chart-icon {
  color: #3b82f6;
}

.chart-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-control-select {
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: 0.375rem;
  background: white;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
}

.chart-control-select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chart-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #f3f4f6;
}

.chart-meta {
  color: var(--text-secondary);
  font-size: 0.75rem;
}

.chart-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 350px;
  color: var(--text-secondary);
  gap: 1rem;
}

.performance-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr));
  gap: 1rem;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: 0.5rem;
}

.stat-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem;
  background: white;
  border-radius: 0.375rem;
  border: 1px solid #e5e7eb;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stat-value {
  font-size: 0.875rem;
  color: var(--text-primary);
  font-weight: 600;
}

@media (max-width: 768px) {
  .performance-stats {
    grid-template-columns: 1fr;
  }
}

.performance-highlights {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem;
  background: #f8fafc;
  border-radius: 0.5rem;
  flex-wrap: wrap;
}

.highlight-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 120px;
}

.highlight-label {
  font-size: 0.75rem;
  color: #6b7280;
  font-weight: 500;
  margin-bottom: 0.25rem;
}

.highlight-value {
  font-size: 0.875rem;
  color: #1f2937;
  font-weight: 600;
}

@media (max-width: 768px) {
  .performance-highlights {
    flex-direction: column;
    align-items: stretch;
    padding: 0.5rem;
    gap: 0.5rem;
  }
  
  .highlight-item {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    text-align: left;
    min-width: auto;
    padding: 0.25rem 0.5rem;
    background: white;
    border-radius: 0.25rem;
    border: 1px solid #f1f5f9;
  }
  
  .highlight-label {
    font-size: 0.7rem;
  }
  
  .highlight-value {
    font-size: 0.8rem;
    font-weight: 700;
  }
}

/* Extra small mobile adjustments */
@media (max-width: 480px) {
  .performance-highlights {
    padding: 0.375rem;
    gap: 0.375rem;
  }
  
  .highlight-item {
    padding: 0.25rem 0.375rem;
  }
  
  .highlight-label {
    font-size: 0.65rem;
    font-weight: 600;
  }
  
  .highlight-value {
    font-size: 0.75rem;
    font-weight: 700;
  }
  
  .chart-title {
    font-size: 1rem;
  }
  
  .chart-header {
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
  }
}