:root {
  --bg: #08090b;
  --card-bg: #14171b;
  --card-top: rgba(255, 255, 255, 0.05);
  --card-border: rgba(255, 255, 255, 0.07);
  --row-border: rgba(255, 255, 255, 0.05);
  --text: #f5f6f7;
  --text-dim: #868d97;
  --text-faint: #565c65;
  --brand: #2dd4bf;
  --green: #3ee684;
  --green-glow: rgba(62, 230, 132, 0.35);
  --yellow: #f2c94c;
  --yellow-glow: rgba(242, 201, 76, 0.3);
  --red: #ff5c5c;
  --red-glow: rgba(255, 92, 92, 0.35);
  --blue: #4fa3e0;
  --gray: #565c65;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  position: relative;
}

.bg-glow {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 60% 45% at 15% 0%, rgba(45, 212, 191, 0.09), transparent 60%),
    radial-gradient(ellipse 50% 40% at 100% 10%, rgba(79, 163, 224, 0.07), transparent 60%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2.6vh 3vw 2vh;
}

.topbar h1 {
  display: flex;
  align-items: center;
  gap: 0.8vw;
  font-size: 2.5vw;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.03em;
  color: var(--text);
}

.brand-dot {
  width: 0.75vw;
  height: 0.75vw;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 1vw rgba(45, 212, 191, 0.7);
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.82); }
}

.clock-wrap {
  text-align: right;
}

.clock {
  font-size: 2.1vw;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  color: var(--text);
}

.date {
  font-size: 1vw;
  color: var(--text-dim);
  margin-top: 0.2vh;
}

.offline-banner {
  margin: 0 3vw 1vh;
  padding: 0.9vh 1.2vw;
  background: rgba(255, 92, 92, 0.1);
  border: 1px solid rgba(255, 92, 92, 0.4);
  color: var(--red);
  border-radius: 12px;
  font-size: 1.2vw;
  font-weight: 500;
  text-align: center;
}

.offline-banner.hidden { display: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  align-items: start;
  align-content: start;
  gap: 1.8vh 1.6vw;
  padding: 0 3vw 2vh;
}

.card {
  position: relative;
  background:
    linear-gradient(180deg, var(--card-top), transparent 40%),
    var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 1.8vh 1.5vw 1.6vh;
  display: flex;
  flex-direction: column;
  gap: 1vh;
  box-shadow: 0 1.2vh 3vh -1vh rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;
  overflow: hidden;
  animation: fadeIn 0.4s ease both;
}

.card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent, var(--brand)), transparent 85%);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8vw;
}

.card-title {
  display: flex;
  align-items: center;
  gap: 0.8vw;
  min-width: 0;
}

.card-icon {
  flex-shrink: 0;
  width: 2.3vw;
  height: 2.3vw;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent, var(--brand)) 16%, transparent);
}

.card-icon svg {
  width: 1.2vw;
  height: 1.2vw;
  color: var(--accent, var(--brand));
}

.card-name-wrap {
  min-width: 0;
}

.card-name {
  font-size: 1.35vw;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.card-kind {
  font-size: 0.85vw;
  color: var(--text-faint);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.card-flag {
  flex-shrink: 0;
  font-size: 0.95vw;
  padding: 0.35vh 0.8vw;
  border-radius: 999px;
  font-weight: 700;
  text-transform: capitalize;
  letter-spacing: 0.01em;
}

.flag-safe, .flag-neutral { background: rgba(62, 230, 132, 0.14); color: var(--green); }
.flag-high { background: rgba(255, 92, 92, 0.14); color: var(--red); }
.flag-low { background: rgba(242, 201, 76, 0.14); color: var(--yellow); }
.flag-unknown { background: rgba(86, 92, 101, 0.2); color: var(--gray); }

/* AQI gradient bar (air quality cards) */
.aqi-bar-wrap {
  position: relative;
  margin: 0.2vh 0.5vw 1vh 0;
  height: 0.9vh;
}

.aqi-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(to right, #9b2fae, #e63e6d, #ff7a45, #ffc93c, #8fe03c, #2fe37a);
  box-shadow: 0 0.4vh 1.2vh -0.3vh rgba(0, 0, 0, 0.6);
}

.aqi-badge {
  position: absolute;
  top: 50%;
  right: -0.2vw;
  transform: translateY(-50%);
  min-width: 2vw;
  height: 2vw;
  padding: 0 0.4vw;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05vw;
  font-weight: 800;
  color: #06140c;
  border: 3px solid var(--card-bg);
  box-shadow: 0 0.3vh 1vh rgba(0, 0, 0, 0.5);
}

.aqi-badge.status-safe, .aqi-badge.status-neutral { background: var(--green); }
.aqi-badge.status-high { background: var(--red); color: #1a0505; }
.aqi-badge.status-low { background: var(--yellow); color: #1a1505; }

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 1.1vw;
  padding: 0.45vh 0;
  border-bottom: 1px solid var(--row-border);
}

.stat-row:last-of-type {
  border-bottom: none;
}

.stat-label {
  color: var(--text-dim);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6vw;
}

.stat-label svg {
  width: 1vw;
  height: 1vw;
  flex-shrink: 0;
  opacity: 0.8;
  color: var(--text-faint);
}

.stat-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 1.1em;
  letter-spacing: -0.01em;
}

.stat-value.status-high { color: var(--red); text-shadow: 0 0 1.2vh var(--red-glow); }
.stat-value.status-low { color: var(--yellow); text-shadow: 0 0 1.2vh var(--yellow-glow); }
.stat-value.status-safe, .stat-value.status-neutral {
  color: var(--green);
  text-shadow: 0 0 1.2vh var(--green-glow);
}

.card-sub {
  margin-top: auto;
  padding-top: 0.6vh;
  display: flex;
  gap: 1vw;
  font-size: 0.95vw;
  color: var(--text-dim);
  font-weight: 500;
}

.dot {
  display: inline-block;
  width: 0.65vw;
  height: 0.65vw;
  border-radius: 50%;
  margin-right: 0.4vw;
  vertical-align: middle;
}

.dot-on { background: var(--green); box-shadow: 0 0 0.8vw var(--green-glow); }
.dot-off { background: var(--gray); }

/* Compact sensor list — deliberately low-key, not a focal card */
.motion-card {
  padding: 1vh 1.5vw;
  opacity: 0.85;
}

.motion-card::before {
  display: none;
}

.motion-card .card-icon {
  width: 1.7vw;
  height: 1.7vw;
}

.motion-card .card-icon svg {
  width: 0.9vw;
  height: 0.9vw;
}

.motion-card .card-name {
  font-size: 1.05vw;
  font-weight: 600;
  color: var(--text-dim);
}

.motion-row {
  display: grid;
  grid-template-columns: 1.3vw 1fr 3.6vw 5vw 0.9vw;
  align-items: center;
  column-gap: 0.9vw;
  padding: 0.55vh 0;
  border-bottom: 1px solid var(--row-border);
}

.motion-row:last-of-type {
  border-bottom: none;
}

.motion-icon {
  width: 1.3vw;
  height: 1.3vw;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.04);
}

.motion-icon svg {
  width: 0.75vw;
  height: 0.75vw;
  color: var(--text-faint);
}

.motion-name {
  font-size: 0.95vw;
  font-weight: 500;
  color: var(--text-dim);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.motion-state {
  font-size: 0.85vw;
  font-weight: 600;
  color: var(--text-faint);
  text-align: right;
  white-space: nowrap;
}

.motion-state.state-active { color: var(--green); text-shadow: 0 0 1vh var(--green-glow); }
.motion-state.state-alert { color: var(--red); text-shadow: 0 0 1vh var(--red-glow); }

.motion-time {
  font-size: 0.9vw;
  color: var(--text-faint);
  text-align: right;
  white-space: nowrap;
}

.statusline {
  position: fixed;
  bottom: 1.4vh;
  right: 3vw;
  font-size: 0.85vw;
  color: var(--text-faint);
  font-weight: 500;
}

.empty {
  color: var(--text-dim);
  font-size: 1.4vw;
  padding: 4vh 0;
  text-align: center;
  grid-column: 1 / -1;
}
