/* Dashboard specific styles */
:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-card: #ffffff;
  --text-primary: #2d3748;
  --text-secondary: #718096;
  --border-color: #e2e8f0;
  --shadow-sm: 0 8px 32px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 12px 40px rgba(0, 0, 0, 0.15);
  --primary-color: #667eea;
  --success-color: #48bb78;
  --warning-color: #f6ad55;
  --danger-color: #f56565;
  --chart-bg: #ffffff;
  --overlay-bg: rgba(255, 255, 255, 0.9);
}

[data-theme="dark"] {
  --bg-primary: #1a202c;
  --bg-secondary: #2d3748;
  --bg-card: #2d3748;
  --text-primary: #f7fafc;
  --text-secondary: #cbd5e0;
  --border-color: #4a5568;
  --shadow-sm: 0 8px 32px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 12px 40px rgba(0, 0, 0, 0.5);
  --primary-color: #7f9cf5;
  --success-color: #68d391;
  --warning-color: #f6ad55;
  --danger-color: #fc8181;
  --chart-bg: #2d3748;
  --overlay-bg: rgba(45, 55, 72, 0.95);
}

.dashboard-container {
  padding: 0;
  margin: 0;
}

.stats-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  flex: 1 1 200px;
  background: var(--bg-card);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-md);
}

.stat-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(
    90deg,
    var(--primary-color),
    var(--secondary-color)
  );
}

.stat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--secondary-color)
  );
  color: white;
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.stat-trend {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  margin-top: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.stat-trend.trend-up {
  color: var(--success-color);
  background: rgba(72, 187, 120, 0.1);
}

.stat-trend.trend-down {
  color: var(--danger-color);
  background: rgba(245, 101, 101, 0.1);
}

.stat-trend.trend-neutral {
  color: var(--text-secondary);
  background: rgba(128, 128, 128, 0.1);
}

.trend-arrow {
  font-size: 1rem;
}

.stat-change {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.stat-change.positive {
  color: var(--success-color);
}

.stat-change.negative {
  color: var(--danger-color);
}

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

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.chart-card {
  background: var(--bg-card);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  overflow: hidden;
  transition: all 0.3s ease;
}

.chart-card:hover {
  box-shadow: var(--shadow-md);
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid #f0f0f0;
  flex-wrap: wrap;
  gap: 1rem;
}

.chart-title {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--dark-color);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-container {
  position: relative;
  height: 300px;
  width: 100%;
}

.chart-container.large {
  height: 800px;
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  z-index: 10;
}

.refresh-btn {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--secondary-color)
  );
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.refresh-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.data-table {
  background: white;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  margin-bottom: 2rem;
}

.table-header {
  background: linear-gradient(
    135deg,
    var(--primary-color),
    var(--secondary-color)
  );
  color: white;
  padding: 1rem 1.5rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.map-controls,
.table-controls {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.map-controls .filter-select {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: var(--dark-color);
  font-size: 0.85rem;
  padding: 0.4rem 0.8rem;
}

#geographicMap {
  background: #f8f9fa;
  position: relative;
  border-radius: 12px;
  overflow: hidden;
}

.map-legend {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background: rgba(255, 255, 255, 0.95);
  padding: 15px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  font-size: 12px;
}

.btn-export {
  background: white;
  border: 1px solid #e2e8f0;
  color: #4a5568;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-export:hover {
  background: #f7fafc;
  border-color: #cbd5e0;
  color: #2d3748;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 2px;
}

.trend-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
  border-radius: 12px;
  font-weight: 500;
}

.trend-up {
  background: rgba(40, 167, 69, 0.1);
  color: var(--success-color);
}

.trend-down {
  background: rgba(220, 53, 69, 0.1);
  color: var(--danger-color);
}

.trend-stable {
  background: rgba(108, 117, 125, 0.1);
  color: #6c757d;
}

.table-content {
  max-height: 400px;
  overflow-y: auto;
}

.table-content table {
  width: 100%;
  border-collapse: collapse;
}

.table-content th,
.table-content td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #f0f0f0;
}

.table-content th {
  background: #f8f9fa;
  font-weight: 600;
  color: var(--dark-color);
  position: sticky;
  top: 0;
  z-index: 5;
}

.table-content tr:hover {
  background: #f8f9fa;
}

.metric-badge {
  background: linear-gradient(135deg, var(--info-color), #5bc0de);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
}

.filter-bar {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.filter-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.filter-select {
  padding: 0.5rem 1rem;
  border: 2px solid #e9ecef;
  border-radius: 8px;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Loading States */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-bg);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(2px);
}

.loading-overlay.active {
  display: flex;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s ease-in-out infinite;
  border-radius: 4px;
}

@keyframes loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton-text {
  height: 12px;
  margin-bottom: 6px;
}

.skeleton-card {
  height: 100px;
  border-radius: 12px;
}

/* Responsive design */
@media (max-width: 1024px) {
  .dashboard-container {
    padding: 1rem;
  }

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

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

@media (max-width: 768px) {
  h1 {
    font-size: 1.75rem;
  }

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

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

  .filter-bar {
    flex-direction: column;
    gap: 0.75rem;
  }

  .filter-group {
    width: 100%;
  }

  .btn-export {
    width: 100%;
    justify-content: center;
  }

  .btn-export-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
  }

  .chart-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chart-title {
    font-size: 1rem;
  }

  /* Make tables scrollable on mobile */
  .chart-card table {
    font-size: 0.875rem;
  }

  /* Touch-friendly buttons */
  button,
  .btn-export,
  .filter-select {
    min-height: 44px; /* iOS recommended touch target size */
    touch-action: manipulation;
  }

  /* Collapsible sections */
  .stat-card {
    cursor: pointer;
    transition: all 0.3s ease;
  }

  .stat-card:active {
    transform: scale(0.98);
  }
}

@media (max-width: 480px) {
  .dashboard-container {
    padding: 0.75rem;
  }

  h1 {
    font-size: 1.5rem;
  }

  .stat-value {
    font-size: 1.75rem;
  }

  .chart-card {
    padding: 0.75rem;
  }

  .chart-container {
    height: 250px;
  }

  /* Stack map controls vertically on very small screens */
  #mapControls {
    flex-direction: column;
    gap: 0.5rem;
  }
}

/* Loading animation */
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

.loading {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Custom scrollbar */
.table-content::-webkit-scrollbar {
  width: 8px;
}

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

.table-content::-webkit-scrollbar-thumb {
  background: var(--primary-color);
  border-radius: 4px;
}

.table-content::-webkit-scrollbar-thumb:hover {
  background: var(--secondary-color);
}
