:root {
  --bg: #f0f2f5;
  --card-bg: #fff;
  --text: #1a1a2e;
  --text-secondary: #6b7280;
  --temp-color: #ef4444;
  --humi-color: #3b82f6;
  --pres-color: #8b5cf6;
  --lux-color: #f59e0b;
  --co2-color: #14b8a6;
  --success: #10b981;
  --danger: #ef4444;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.navbar {
  background: var(--card-bg);
  box-shadow: var(--shadow);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.navbar-brand {
  font-size: 18px;
  font-weight: 700;
  margin-right: auto;
}

.navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}
.navbar-user {
  font-size: 13px;
  color: var(--text);
}
.navbar-logout {
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}
.navbar-logout:hover {
  color: var(--danger);
}
.navbar-time {
  font-size: 13px;
  color: var(--text-secondary);
}

.page-footer {
  padding: 16px 24px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 20px;
}

.status-bar.online {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.status-bar.offline {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.status-bar.connecting {
  background: #f0f2f5;
  color: #4b5563;
  border: 1px solid #d1d5db;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-bar.online .status-dot {
  background: var(--success);
}
.status-bar.offline .status-dot {
  background: var(--danger);
  animation: pulse 2s infinite;
}
.status-bar.connecting .status-dot {
  background: #9ca3af;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}
.status-summary {
  margin-left: auto;
  font-size: 12px;
  opacity: 0.8;
}

.sensor-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.sensor-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
  transition: box-shadow 0.2s;
}
.sensor-card:hover {
  box-shadow: var(--shadow-lg);
}
.sensor-card.active {
  box-shadow: 0 0 0 2px var(--success);
}

.sensor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.sensor-id {
  font-size: 14px;
  font-weight: 600;
  font-family: SFMono-Regular, Consolas, monospace;
}

.sensor-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 8px;
}

.sensor-location {
  font-size: 12px;
  color: var(--text-secondary);
  background: #f0f2f5;
  padding: 2px 8px;
  border-radius: 4px;
}

.sensor-metrics {
  display: grid;
  gap: 10px;
}
.sensor-metrics.cols-1 {
  grid-template-columns: 1fr;
}
.sensor-metrics.cols-2 {
  grid-template-columns: 1fr 1fr;
}
.sensor-metrics.cols-many {
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.metric {
  position: relative;
  text-align: center;
  padding: 14px 10px;
  border-radius: 10px;
  cursor: pointer;
  transition:
    transform 0.15s,
    box-shadow 0.15s,
    background 0.15s;
  overflow: hidden;
}

.metric::after {
  content: "📈";
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 10px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}
.metric:hover::after {
  opacity: 0.5;
}
.metric:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.metric.temp {
  background: #fef2f2;
}
.metric.temp:hover {
  background: #fee2e2;
}
.metric.humi {
  background: #eff6ff;
}
.metric.humi:hover {
  background: #dbeafe;
}
.metric.pres {
  background: #f5f3ff;
}
.metric.pres:hover {
  background: #ede9fe;
}
.metric.lux {
  background: #fffbeb;
}
.metric.lux:hover {
  background: #fef3c7;
}
.metric.co2 {
  background: #f0fdfa;
}
.metric.co2:hover {
  background: #ccfbf1;
}

.metric-label {
  font-size: 11px;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
  margin-bottom: 6px;
  font-weight: 500;
}

.metric-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 2px;
  min-height: 2em;
}

.metric-value span:first-child {
  display: inline-block;
  min-width: 3ch;
  text-align: right;
}
.metric-placeholder {
  opacity: 0.3;
}
.metric.temp .metric-value {
  color: var(--temp-color);
}
.metric.humi .metric-value {
  color: var(--humi-color);
}
.metric.pres .metric-value {
  color: var(--pres-color);
}
.metric.lux .metric-value {
  color: var(--lux-color);
}
.metric.co2 .metric-value {
  color: var(--co2-color);
}

.metric-unit {
  font-size: 14px;
  font-weight: 500;
  opacity: 0.6;
  margin-left: 1px;
}

.sensor-footer {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.sensor-time {
  font-size: 11px;
  color: var(--text-secondary);
}
.sensor-time.placeholder {
  opacity: 0.3;
}
.sensor-alert {
  font-size: 11px;
  font-weight: 500;
}
.sensor-alert.ok {
  color: var(--success);
}
.sensor-alert.warn {
  color: #f59e0b;
}
.sensor-alert.waiting {
  color: var(--text-secondary);
}

.empty {
  text-align: center;
  padding: 80px 0;
  color: var(--text-secondary);
}
.empty .icon {
  font-size: 56px;
  margin-bottom: 16px;
  opacity: 0.4;
}

.empty .spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border: 4px solid #e5e7eb;
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (width <= 720px) {
  .sensor-grid {
    grid-template-columns: 1fr;
  }
}

/* ── x-cloak: hide before Alpine initializes ── */
[x-cloak] {
  display: none !important;
}

/* ── 折线图弹窗 ── */
.chart-overlay {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-enter {
  transition:
    opacity 0.2s,
    transform 0.2s;
}
.chart-enter-start {
  opacity: 0;
  transform: scale(0.95);
}

.chart-modal {
  background: #fff;
  border-radius: 16px;
  width: 800px;
  max-width: 94vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid #f0f0f0;
}
.chart-title {
  font-size: 16px;
  font-weight: 700;
}
.chart-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: 12px;
}

.chart-close {
  width: 32px;
  height: 32px;
  border: none;
  background: #f0f2f5;
  border-radius: 8px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.chart-close:hover {
  background: #e5e7eb;
  color: var(--text);
}

.chart-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid #f0f0f0;
}
.chart-windows {
  display: flex;
  gap: 4px;
}

.chart-windows button {
  padding: 5px 14px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.15s;
}
.chart-windows button:hover {
  border-color: var(--text);
  color: var(--text);
}

.chart-windows button.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.chart-value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.chart-canvas-wrap {
  padding: 16px;
  position: relative;
  height: 320px;
}

.chart-canvas-wrap canvas {
  display: block;
}
