/* Modern CSS Variables */
:root {
  --primary-color: #3b82f6;
  --primary-dark: #2563eb;
  --secondary-color: #64748b;
  --success-color: #10b981;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;
  --background: #f8fafc;
  --surface: #ffffff;
  --surface-secondary: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
}

/* Reset and Base Styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: var(--text-primary);
  line-height: 1.6;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.5rem;
}

/* Header Styles */
.header {
  text-align: center;
  margin-bottom: 0.5rem;
}

.header-content h1 {
  font-size: 1rem;
  font-weight: 700;
  color: white;
  margin-bottom: 0.125rem;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-content p {
  font-size: 0.65rem;
  color: rgba(255, 255, 255, 0.9);
  font-weight: 400;
  max-width: 300px;
  margin: 0 auto;
}

/* Upload Section */
.upload-section {
  margin-bottom: 0.5rem;
}

.upload-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  text-align: center;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.upload-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.upload-icon {
  font-size: 1rem;
  margin-bottom: 0.125rem;
}

.upload-card h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.125rem;
}

.upload-card p {
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
  font-size: 0.65rem;
}

input[type="file"] {
  display: none;
}

.file-input-label {
  display: inline-block;
  background: var(--primary-color);
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  border: none;
  font-size: 0.7rem;
}

.file-input-label:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.upload-hint {
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.6rem;
}

/* Dashboard Layout */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 0.75rem;
}

/* Stats Table Card */
.stats-table-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  height: 100%;
}

.stats-table-card h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.stats-table {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.stats-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.125rem 0;
  border-bottom: 1px solid var(--border-light);
}

.stats-row:last-child {
  border-bottom: none;
}

.stats-label {
  font-size: 0.65rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stats-value {
  font-size: 0.7rem;
  color: var(--text-primary);
  font-weight: 600;
}

.stat-change {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  margin-top: 0.5rem;
  display: inline-block;
}

.stat-change.positive {
  background: rgba(16, 185, 129, 0.1);
  color: var(--success-color);
}

.stat-change.negative {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger-color);
}

/* Chart Section */
.chart-section {
  grid-column: span 2;
}

.chart-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  height: 100%;
}

.chart-card h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.chart-container {
  position: relative;
  height: 400px;
  width: 100%;
  overflow: hidden;
}

canvas {
  width: 100% !important;
  height: 400px !important;
  max-width: 100%;
  max-height: 400px;
}

/* Map Section */
.map-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  height: 100%;
}

.map-card h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

#map {
  height: 250px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow);
}

/* Table Section */
.table-section {
  grid-column: span 2;
}

.table-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
  overflow: hidden;
  height: 100%;
}

.table-card h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.7rem;
}

th {
  background: var(--surface-secondary);
  padding: 0.5rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
}

td {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}

tr:hover {
  background: var(--surface-secondary);
}

tr:nth-child(even) {
  background: rgba(248, 250, 252, 0.5);
}

tr:nth-child(even):hover {
  background: var(--surface-secondary);
}

/* Speed-based styling for table cells */
.speed-cell {
  font-weight: 500;
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  text-align: center;
}

.speed-low { background: rgba(16, 185, 129, 0.1); color: var(--success-color); }
.speed-medium { background: rgba(245, 158, 11, 0.1); color: var(--warning-color); }
.speed-high { background: rgba(239, 68, 68, 0.1); color: var(--danger-color); }

/* Responsive Design */
@media (max-width: 1024px) {
  .dashboard {
    grid-template-columns: 1fr;
  }
  
  .chart-section,
  .table-section {
    grid-column: span 1;
  }
  
  .stats-table-card {
    grid-column: span 1;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 0.5rem;
  }
  
  .header {
    margin-bottom: 1rem;
  }
  
  .header-content h1 {
    font-size: 1.5rem;
  }
  
  .header-content p {
    font-size: 0.85rem;
  }
  
  .upload-section {
    margin-bottom: 1rem;
  }
  
  .upload-card {
    padding: 1rem;
  }
  
  .upload-icon {
    font-size: 2rem;
  }
  
  .upload-card h3 {
    font-size: 1rem;
  }
  
  .upload-card p {
    font-size: 0.85rem;
  }
  
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
  }
  
  .stat-card {
    padding: 0.5rem;
  }
  
  .stat-value {
    font-size: 1rem;
  }
  
  .speed-summary-card {
    grid-column: span 1;
  }
  
  .speed-summary {
    flex-direction: row;
    justify-content: space-between;
    gap: 0.5rem;
  }
  
  .speed-item {
    flex-direction: column;
    align-items: center;
  }
  
  .speed-value {
    font-size: 0.9rem;
  }
  
  .chart-section,
  .map-section,
  .table-section {
    margin-bottom: 0.75rem;
  }
  
  .chart-card,
  .map-card,
  .table-card {
    padding: 0.75rem;
  }
  
  .chart-card h3,
  .map-card h3,
  .table-card h3 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
  }
  
  .chart-container {
    height: 250px;
  }
  
  #map {
    height: 200px;
  }
  
  table {
    font-size: 0.7rem;
  }
  
  th, td {
    padding: 0.4rem 0.2rem;
  }
}

@media (max-width: 480px) {
  .container {
    padding: 0.25rem;
  }
  
  .header-content h1 {
    font-size: 1.25rem;
  }
  
  .header-content p {
    font-size: 0.8rem;
  }
  
  .upload-card {
    padding: 0.75rem;
  }
  
  .upload-icon {
    font-size: 1.75rem;
  }
  
  .upload-card h3 {
    font-size: 0.9rem;
  }
  
  .upload-card p {
    font-size: 0.8rem;
  }
  
  .stat-card {
    padding: 0.4rem;
  }
  
  .stat-value {
    font-size: 0.9rem;
  }
  
  .stat-title {
    font-size: 0.7rem;
  }
  
  .chart-container {
    height: 200px;
  }
  
  #map {
    height: 150px;
  }
  
  .speed-summary {
    flex-direction: column;
    gap: 0.25rem;
  }
  
  .speed-value {
    font-size: 0.8rem;
  }
  
  table {
    font-size: 0.65rem;
  }
  
  th, td {
    padding: 0.3rem 0.15rem;
  }
}

/* Loading States */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  color: var(--text-muted);
}

.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-left: 0.5rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Empty States */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h4 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 0.9rem;
}