:root {
  --accent: #4a6cf7;
  --accent2: #3b82f6;
  --purple: #a855f7;
  --text: #e8eaf4;
  --muted: #8b93b0;
  --label: #b0b8d0;
  --card: rgba(20, 20, 50, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --danger: #ef4444;
  --ok: #22c55e;
  --temp: #f97316;
  --humid: #0ea5e9;
  --photo: #22c55e;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  font-size: 15px;
  line-height: 1.47;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select { font-family: inherit; font-size: 0.9375rem; }
.icon { width: 22px; height: 22px; display: inline-block; vertical-align: middle; }
.icon.sm { width: 16px; height: 16px; }
.muted { color: #5a6080; }
.hidden { display: none !important; }
.mt { margin-top: 24px; }

.app-body {
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 15% 10%, rgba(74,108,247,0.12) 0%, transparent 45%),
    radial-gradient(ellipse at 85% 90%, rgba(168,85,247,0.1) 0%, transparent 42%),
    linear-gradient(135deg, #0f0f1e 0%, #1a1a3e 40%, #0d1b2a 100%);
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(120deg, #0f0f1e 0%, #1a1a3e 55%, #0d1b2a 100%);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  box-shadow: 0 4px 24px rgba(0,0,0,0.35);
}
.topbar::after {
  content: ""; display: block; height: 2px;
  background: linear-gradient(90deg, transparent 8%, rgba(74,108,247,0.45) 50%, transparent 92%);
}
.topbar-inner {
  max-width: 1536px; margin: 0 auto; padding: 10px 24px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 220px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 8px; color: #fff;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4a6cf7, #a855f7);
  box-shadow: 0 4px 16px rgba(74,108,247,0.3);
}
.brand-logo.lg { width: 64px; height: 64px; border-radius: 12px; }
.brand-logo.lg .icon { width: 32px; height: 32px; }
.brand-title { font-size: 1.0625rem; font-weight: 600; }
.brand-sub { color: var(--muted); font-size: 0.8125rem; }
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 4px; border-radius: 999px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.12);
  font-size: 0.8125rem;
}
.chip-avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(74,108,247,0.25); display: flex; align-items: center; justify-content: center;
}
.nav-btn, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: 10px; border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.05); color: #fff; padding: 8px 14px; cursor: pointer;
}
.nav-btn:hover { background: rgba(74,108,247,0.12); border-color: rgba(74,108,247,0.45); }
.nav-btn-logout:hover { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.35); }
.btn.primary {
  background: linear-gradient(135deg, #4a6cf7, #6d4df7);
  border: none; box-shadow: 0 4px 14px rgba(74,108,247,0.35);
}
.btn.primary:hover { transform: translateY(-1px); }
.btn.block { width: 100%; padding: 13px; }
.btn.ghost { background: transparent; }
.btn.outlined { background: transparent; border-color: rgba(74,108,247,0.45); color: #93c5fd; }

.page { max-width: 1536px; margin: 0 auto; padding: 28px 24px 48px; }

.section-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.section-head h2 { margin: 0; font-size: 1.0625rem; font-weight: 600; }
.section-head p { margin: 2px 0 0; color: var(--muted); font-size: 0.8125rem; }
.section-icon {
  width: 44px; height: 44px; border-radius: 8px; color: #fff;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #4a6cf7, #a855f7);
  box-shadow: 0 4px 14px rgba(74,108,247,0.25);
}
.section-icon.cyan { background: linear-gradient(135deg, #0ea5e9, #38bdf8); }
.section-icon.purple { background: linear-gradient(135deg, #7c3aed, #a78bfa); }
.section-icon.amber { background: linear-gradient(135deg, #f59e0b, #fbbf24); }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 16px; display: flex; align-items: center; gap: 12px;
  box-shadow: 0 2px 12px rgba(15,23,42,0.04);
}
.stat-ico {
  width: 48px; height: 48px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.stat-card small { color: var(--muted); display: block; font-size: 0.8125rem; }
.stat-card strong { font-size: 1.25rem; font-weight: 500; }

.sensor-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25); overflow: hidden;
}
.card.accent-blue { border-top: 3px solid var(--accent); }
.card.accent-blue2 { border-top: 3px solid var(--accent2); }
.card.accent-purple { border-top: 3px solid #7c3aed; }
.card.accent-amber { border-top: 3px solid #f59e0b; }
.card-body { padding: 20px 24px; }
.sensor-card { display: block; height: 100%; transition: transform .2s, box-shadow .2s; cursor: pointer; }
.sensor-card:hover { transform: translateY(-3px); box-shadow: 0 12px 32px rgba(15,23,42,0.1); }
.sensor-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.sensor-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.sensor-head h3 { margin: 0; font-size: 1rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.type-chip {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 4px;
  height: 24px; padding: 0 8px; border-radius: 999px; font-size: 0.75rem; font-weight: 500;
}
.alert-strip {
  display: flex; align-items: center; gap: 6px; margin-bottom: 12px;
  padding: 8px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 0.8125rem; font-weight: 500;
}
.metric-row { display: grid; gap: 12px; }
.metric-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.metric-row.cols-2 { grid-template-columns: 1fr 1fr; }
.metric-box {
  text-align: center; padding: 10px; border-radius: 8px; border: 1px solid;
}
.metric-box .val { font-size: 1.25rem; font-weight: 500; line-height: 1.2; }
.metric-box small { color: var(--muted); }
.detail-link { color: var(--accent); text-align: center; display: block; margin-top: 12px; font-size: 0.8125rem; }
.alert-text { color: #fca5a5; margin-top: 12px; font-size: 0.8125rem; }

.alert {
  border-radius: 12px; padding: 14px 16px; margin-bottom: 24px;
  border: 1px solid;
}
.alert.error { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.35); color: #fca5a5; }
.alert.info { background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.3); color: #93c5fd; }
.alert h4 { margin: 0 0 6px; }

.select, .field input, .field select {
  width: 100%; background: rgba(255,255,255,0.05); color: #e0e0f0;
  border: 1px solid rgba(255,255,255,0.12); border-radius: 10px; padding: 10px 12px; outline: none;
}
.select { width: auto; min-width: 200px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 160px; }
.field > span { color: var(--label); font-size: 0.8125rem; }
.field-input {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.12);
  border-radius: 10px; padding: 0 12px;
}
.field-input input { border: 0; background: transparent; color: #e0e0f0; padding: 12px 0; width: 100%; outline: none; }
.field input:focus, .field-input:focus-within, .select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(74,108,247,0.15);
}
.query-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.query-row .btn { height: 42px; }

.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stat-metric { border-radius: 16px; padding: 20px; border: 1px solid; }
.stat-metric h4 { margin: 0 0 12px; display: flex; align-items: center; gap: 8px; font-size: 0.875rem; }
.stat-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; text-align: center; }
.stat-3 small { color: var(--muted); display: block; }

.detail-grid { display: grid; grid-template-columns: 1fr 2fr; gap: 20px; margin-bottom: 24px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 24px; }
.back-link { display: inline-flex; align-items: center; gap: 4px; color: #93c5fd; margin-bottom: 8px; font-size: 0.875rem; }

.tabs {
  display: flex; gap: 4px; overflow: auto; padding: 4px 8px;
  border-bottom: 1px solid var(--line); background: rgba(255,255,255,0.04);
}
.tab {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: transparent; border: 0; color: var(--muted); padding: 14px 16px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; font-size: 0.8125rem; background: rgba(255,255,255,0.04); }
.icon-btn { background: transparent; border: 0; color: var(--label); cursor: pointer; padding: 6px; border-radius: 8px; }
.icon-btn:hover { background: rgba(255,255,255,0.06); }
.icon-btn.danger { color: #fca5a5; }

.panel { border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.panel.blue { background: rgba(74,108,247,0.12); }
.panel.info { background: rgba(59,130,246,0.12); }
.panel.purple { background: rgba(168,85,247,0.12); }
.accordion { border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: rgba(255,255,255,0.03); overflow: hidden; }
.accordion summary { list-style: none; cursor: pointer; padding: 12px 16px; display: flex; align-items: center; gap: 12px; }
.accordion summary::-webkit-details-marker { display: none; }
.accordion .acc-body { padding: 16px; border-top: 1px solid var(--line); background: rgba(255,255,255,0.04); }
.th-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.th-box { border-radius: 12px; padding: 16px; border: 1px solid; margin-bottom: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.push { margin-left: auto; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px;
  border-radius: 999px; border: 1px solid; font-size: 0.75rem;
}
.tag button { background: none; border: 0; color: inherit; cursor: pointer; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-card {
  width: 100%; max-width: 400px; background: #141432; border: 1px solid var(--line);
  border-radius: 16px; padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.login-body {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f0f1e 0%, #1a1a3e 40%, #0d1b2a 100%);
  position: relative; overflow: hidden;
}
.blob {
  position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.15;
  animation: loginFloat 20s ease-in-out infinite; pointer-events: none;
}
.blob-a { width: 400px; height: 400px; background: #4a6cf7; top: -100px; left: -100px; }
.blob-b { width: 300px; height: 300px; background: #a855f7; bottom: -80px; right: -80px; animation-delay: -7s; }
.blob-c { width: 250px; height: 250px; background: #3b82f6; top: 50%; left: 60%; animation-delay: -14s; }
@keyframes loginFloat {
  0%, 100% { transform: translate(0,0) rotate(0); }
  33% { transform: translate(30px,-30px) rotate(120deg); }
  66% { transform: translate(-20px,20px) rotate(240deg); }
}
.login-wrap { position: relative; z-index: 1; width: 100%; max-width: 440px; padding: 24px; }
.login-card {
  background: rgba(20,20,50,0.85); backdrop-filter: blur(30px);
  border: 1px solid rgba(255,255,255,0.12); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5); padding: 40px 32px;
}
.login-hero { text-align: center; margin-bottom: 8px; }
.login-hero h1 { margin: 16px 0 8px; font-size: 1.25rem; font-weight: 500; }
.login-hero p { margin: 0; color: var(--muted); font-size: 0.8125rem; }
.login-card .field { margin-top: 14px; }
.demo-hint { margin-top: 24px; text-align: center; color: #5a6080; font-size: 0.8125rem; line-height: 1.9; }
.demo-hint strong { color: var(--label); font-weight: 500; }

@media (max-width: 1200px) {
  .sensor-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-grid, .stats-grid, .detail-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .sensor-grid, .stat-grid, .stats-grid, .detail-grid { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .select { min-width: 0; width: 100%; }
}
