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

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
}

header {
  background: #1a1d27;
  padding: 20px 32px;
  border-bottom: 1px solid #2d3148;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #a78bfa;
}

#last-updated {
  font-size: 0.85rem;
  color: #64748b;
}

main {
  padding: 24px 32px;
  max-width: 1400px;
  margin: 0 auto;
}

/* Cards */
#cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-bottom: 40px;
}

#no-data {
  text-align: center;
  color: #64748b;
  padding: 60px;
  font-size: 1.1rem;
}

.hidden { display: none; }

.card {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 12px;
  padding: 20px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-location {
  font-size: 1rem;
  font-weight: 600;
  color: #c4b5fd;
}

.battery-badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
}
.battery-good { background: #16a34a33; color: #4ade80; }
.battery-mid  { background: #d9770633; color: #fb923c; }
.battery-low  { background: #dc262633; color: #f87171; }

.pm25-value {
  font-size: 2.4rem;
  font-weight: 700;
  margin-bottom: 4px;
  line-height: 1;
}

.pm25-unit {
  font-size: 0.9rem;
  color: #94a3b8;
}

.aqi-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 6px;
  margin-top: 6px;
  margin-bottom: 14px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.aqi-good        { background: #16a34a33; color: #4ade80; }
.aqi-moderate    { background: #ca8a0433; color: #fbbf24; }
.aqi-sensitive   { background: #c2410c33; color: #fb923c; }
.aqi-unhealthy   { background: #dc262633; color: #f87171; }
.aqi-very-unhealthy { background: #7c3aed33; color: #c084fc; }

.card-divider {
  border: none;
  border-top: 1px solid #2d3148;
  margin-bottom: 14px;
}

.card-metrics {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.metric {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: #94a3b8;
}

.metric span:first-child {
  font-size: 1rem;
  width: 20px;
  text-align: center;
}

.metric strong {
  color: #e2e8f0;
  margin-left: 2px;
}

/* Device name */
.card-device {
  font-size: 0.8rem;
  color: #64748b;
  margin-bottom: 10px;
}

/* Map */
#map-section {
  margin-bottom: 40px;
}

#map-section h2 {
  font-size: 1.1rem;
  color: #94a3b8;
  margin-bottom: 16px;
}

#map {
  height: 420px;
  border-radius: 12px;
  border: 1px solid #2d3148;
  z-index: 0;
}

.leaflet-popup-content-wrapper {
  background: #1a1d27;
  color: #e2e8f0;
  border: 1px solid #2d3148;
  border-radius: 10px;
}

.leaflet-popup-tip {
  background: #1a1d27;
}

.leaflet-popup-content {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 0.85rem;
  line-height: 1.7;
  margin: 10px 14px;
}

.popup-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #c4b5fd;
  margin-bottom: 4px;
}

.popup-device {
  font-size: 0.78rem;
  color: #64748b;
  margin-bottom: 6px;
}

.popup-pm25 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 2px;
}

/* Chart */
#chart-section h2 {
  font-size: 1.1rem;
  color: #94a3b8;
  margin-bottom: 16px;
}

#location-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.tab-btn {
  background: #1a1d27;
  border: 1px solid #2d3148;
  color: #94a3b8;
  padding: 6px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: all 0.15s;
}

.tab-btn:hover {
  border-color: #a78bfa;
  color: #c4b5fd;
}

.tab-btn.active {
  background: #2d1f63;
  border-color: #7c3aed;
  color: #c4b5fd;
}

.chart-container {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 12px;
  padding: 20px;
  height: 320px;
}

#pm25-chart {
  width: 100% !important;
  height: 100% !important;
}

/* Export Section */
#export-section {
  margin-top: 40px;
  margin-bottom: 40px;
}

#export-section h2 {
  font-size: 1.1rem;
  color: #94a3b8;
  margin-bottom: 16px;
}

.export-controls {
  background: #1a1d27;
  border: 1px solid #2d3148;
  border-radius: 12px;
  padding: 20px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px;
}

.export-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.export-field label {
  font-size: 0.8rem;
  color: #64748b;
  font-weight: 500;
}

.export-field select,
.export-field input[type="date"] {
  background: #0f1117;
  border: 1px solid #2d3148;
  border-radius: 8px;
  color: #e2e8f0;
  padding: 8px 12px;
  font-size: 0.875rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s;
}

.export-field select:focus,
.export-field input[type="date"]:focus {
  border-color: #7c3aed;
}

.export-btn {
  background: #2d1f63;
  border: 1px solid #7c3aed;
  color: #c4b5fd;
  padding: 8px 20px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.15s;
  white-space: nowrap;
}

.export-btn:hover {
  background: #3b2882;
  border-color: #a78bfa;
  color: #e9d5ff;
}
