@font-face {
  font-family: 'SF Pro Display';
  src: local("SF Pro Display"), local("SFProDisplay-Regular"), local("Roboto"), local("Helvetica Neue"), sans-serif;
}

:root {
  --bg: #f5f6fa;
  --card-bg: #ffffff;
  --text-main: #333333;
  --text-sub: #666666;
  --text-muted: #999999;
  --primary: #1890ff;
  --success: #52c41a;
  --warning: #faad14;
  --danger: #ff4d4f;
  --info: #1890ff;
  
  --temp-color: #ff5757;
  --humi-color: #3b8cff;
  
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.06);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  background-color: var(--bg);
}

.app-main {
  flex: 1;
  padding: 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: calc(70px + env(safe-area-inset-bottom));
}

.section {
  margin-bottom: 20px;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 0 4px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-main);
}

.section-state {
  font-size: 14px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--text-muted);
}

.state-dot.online {
  background-color: var(--success);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
}

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

/* Metric Cards */
.metric-head {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  text-transform: capitalize;
}

#card-temp .metric-head { color: var(--temp-color); }
#card-humi .metric-head { color: var(--humi-color); }

.metric-body {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.metric-value {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-main);
}

.metric-unit {
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 400;
}

/* Control Cards */
.control-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.control-label {
  font-size: 15px;
  color: var(--text-main);
  font-weight: 500;
}

.control-input {
  display: flex;
  align-items: center;
  background: #f0f2f5;
  border-radius: var(--radius-md);
  padding: 4px;
  justify-content: space-between;
}

.btn-icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: #ffffff;
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0,0,0,0.05);
  transition: all 0.2s;
}

.btn-icon:active {
  background: #e6e6e6;
  transform: scale(0.95);
}

.input-display {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--text-main);
  background: transparent;
  border: none;
  outline: none;
  width: 100%;
}

/* Chart Cards */
.chart-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 4px;
}

.badge.red { background: var(--temp-color); box-shadow: 0 2px 8px rgba(255, 87, 87, 0.3); }
.badge.blue { background: var(--humi-color); box-shadow: 0 2px 8px rgba(59, 140, 255, 0.3); }

.chart-title {
  font-size: 13px;
  color: var(--text-muted);
  background: #f5f5f5;
  padding: 2px 8px;
  border-radius: 4px;
}

.chart-body-wrapper {
  background: #f0f2f5;
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chart-canvas {
  width: 100%;
  height: 140px;
}

.chart-label {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
  font-weight: 500;
}

/* Footer Tabbar */
.app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-top: 1px solid rgba(0,0,0,0.05);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
  max-width: 600px;
  margin: 0 auto;
}

.tabbar {
  display: flex;
  justify-content: space-around;
  padding: 8px 12px;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex: 1;
  transition: color 0.2s;
}

.tab-item.active {
  color: var(--primary);
}

.tab-icon {
  font-size: 20px;
  margin-bottom: 2px;
}

.tab-text {
  font-size: 11px;
  font-weight: 500;
}

/* Responsive adjustments */
@media (max-width: 360px) {
  .grid-2 {
    gap: 12px;
  }
  
  .metric-value {
    font-size: 20px;
  }
}
