:root {
  color-scheme: dark;
  --bg: #050505;
  --panel: #101010;
  --text: #e8eaed;
  --muted: #7c838d;
  --cyan: #ff2d2d;
  --cyan-bright: #ff5555;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ff5c7a;
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 45, 45, 0.34);
  --glow: rgba(255, 45, 45, 0.18);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle 46rem at 78% -12%, rgba(255, 45, 45, 0.13), transparent 58%),
    radial-gradient(circle 38rem at 10% 16%, rgba(255, 107, 26, 0.07), transparent 55%),
    linear-gradient(180deg, #080808 0%, var(--bg) 58%, #070505 100%);
  color: var(--text);
  font-family: Sora, Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 100% 4px;
  opacity: 0.18;
}

.ambient-grid {
  position: fixed;
  inset: auto -10vw 0;
  z-index: -1;
  height: 46vh;
  pointer-events: none;
  transform: perspective(700px) rotateX(56deg) scale(1.25);
  transform-origin: bottom center;
  background-image:
    linear-gradient(to right, rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(255, 45, 45, 0.14) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: linear-gradient(to top, rgba(0, 0, 0, 0.88), transparent 72%);
  opacity: 0.7;
}

.shell { width: min(1220px, calc(100vw - 36px)); margin: 0 auto; padding: 24px 0 42px; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 92px;
  margin-bottom: 22px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: rgba(10, 10, 10, 0.78);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.36), inset 0 1px 0 rgba(191, 195, 201, 0.08);
}

.brand { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand-mark { width: clamp(128px, 16vw, 176px); height: auto; flex: 0 0 auto; object-fit: contain; filter: drop-shadow(0 0 22px var(--glow)); }
.brand-copy { min-width: 0; }
h1 { margin: 0; font-family: Orbitron, Sora, Inter, sans-serif; font-size: 24px; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.eyebrow { margin: 0 0 8px; color: var(--cyan-bright); font-family: Orbitron, Sora, Inter, sans-serif; font-size: 11px; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; }
.sub { margin-top: 10px; color: var(--muted); font-size: 16px; }
.pill { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: 999px; background: rgba(255, 45, 45, 0.1); color: var(--text); font-family: "SFMono-Regular", Consolas, monospace; font-size: 13px; font-weight: 800; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 999px; background: var(--green); box-shadow: 0 0 16px var(--green); }

.grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.card { position: relative; overflow: hidden; background: linear-gradient(135deg, rgba(255, 255, 255, 0.045), transparent 38%), var(--panel); border: 1px solid var(--border); border-radius: 22px; padding: 22px; box-shadow: 0 20px 64px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(191, 195, 201, 0.055); }
.hero::after { content: ""; position: absolute; right: -80px; bottom: -120px; width: 320px; height: 320px; border-radius: 999px; background: radial-gradient(circle, rgba(255, 45, 45, 0.2), transparent 68%); pointer-events: none; }
.hero { grid-column: span 7; }
.room { grid-column: span 5; }
.sensors, .notes { grid-column: span 6; }
.wide { grid-column: span 12; }

.metric-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; }
.metric, .reading, .device { border: 1px solid rgba(255, 255, 255, 0.055); border-radius: 14px; background: rgba(5, 5, 5, 0.48); }
.metric { min-height: 108px; padding: 16px; }
.label { color: var(--muted); font-size: 14px; font-weight: 700; margin-bottom: 12px; }
.value { font-family: "SFMono-Regular", Consolas, monospace; font-size: clamp(56px, 8vw, 104px); font-weight: 800; letter-spacing: -0.08em; line-height: 0.92; color: var(--text); }
.unit { margin-left: 6px; color: var(--muted); font-size: 20px; }
.small-value { font-family: "SFMono-Regular", Consolas, monospace; font-size: 24px; font-weight: 800; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.section-title { color: var(--cyan-bright); font-family: Orbitron, Sora, Inter, sans-serif; font-size: 15px; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; }
.muted { color: var(--muted); }
.reading-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(138px, 1fr)); gap: 12px; }
.reading { min-height: 92px; padding: 14px; }
.devices { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.device { padding: 18px; min-height: 138px; }
.device-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.device-name { font-size: 20px; font-weight: 900; }
.state { padding: 6px 10px; border-radius: 999px; background: rgba(18, 196, 139, 0.14); color: var(--green); font-weight: 800; text-transform: capitalize; }
.state.offline, .state.failed { background: rgba(255, 92, 122, 0.14); color: var(--red); }
.state.stale { background: rgba(255, 176, 32, 0.14); color: var(--yellow); }
.command-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.command-actions button { border: 1px solid rgba(255, 45, 45, 0.28); border-radius: 999px; min-height: 40px; padding: 0 16px; background: rgba(255, 45, 45, 0.1); color: var(--text); font-weight: 900; }
.command-actions button.primary { background: var(--cyan); color: var(--text); }
.command-actions button.danger { background: rgba(255, 92, 122, 0.16); color: #fecaca; border-color: rgba(255, 92, 122, 0.35); }
button:disabled { opacity: .45; }
.command-status { margin-top: 10px; min-height: 18px; color: var(--muted); font-size: 13px; line-height: 1.35; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.warn { color: var(--yellow); }
.error { color: var(--red); }
.notes-list { display: grid; gap: 10px; line-height: 1.45; }
.note { border-radius: 12px; background: rgba(5, 5, 5, 0.48); padding: 12px 14px; }

.overlay { position: fixed; inset: 0; background: rgba(4, 6, 27, 0.82); display: none; align-items: center; justify-content: center; padding: 24px; z-index: 20; }
.overlay.visible { display: flex; }
.modal { width: min(520px, 100%); background: #111827; border: 1px solid rgba(248, 113, 113, 0.5); border-radius: 20px; padding: 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); text-align: center; }
.modal h2 { margin: 0 0 12px; color: #fecaca; }
.modal p { margin: 0 0 18px; line-height: 1.5; color: #e5e7eb; }
.modal button { border: none; border-radius: 999px; padding: 12px 18px; background: #dc2626; color: white; font-weight: 700; }
.admin-hotspot { position: fixed; top: 0; right: 0; width: 96px; height: 96px; z-index: 10; }
.admin-panel { width: min(620px, 100%); background: #101010; border: 1px solid rgba(255, 45, 45, 0.34); border-radius: 20px; padding: 24px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45); }
.admin-panel h2 { margin: 0 0 10px; }
.admin-panel p { color: var(--muted); line-height: 1.5; }
.admin-panel input { width: 100%; margin: 8px 0 12px; border: 1px solid rgba(157, 163, 184, 0.35); border-radius: 12px; padding: 12px 14px; background: #020617; color: var(--text); font-size: 16px; }
.admin-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; margin-top: 14px; }
.admin-panel button { border: none; border-radius: 999px; padding: 12px 16px; background: rgba(255, 45, 45, 0.12); color: var(--text); font-weight: 800; }
.admin-panel button.primary { background: var(--cyan); color: var(--text); }
.admin-panel button.danger { background: var(--red); color: white; }
.admin-log { max-height: 340px; margin-top: 14px; overflow: auto; color: var(--muted); white-space: pre-wrap; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; line-height: 1.45; }

.invite-card { grid-column: span 12; display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 18px; align-items: center; }
.invite-copy { color: var(--muted); line-height: 1.5; margin: 0 0 14px; }
.invite-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.invite-actions button { border: none; border-radius: 999px; padding: 12px 16px; background: var(--cyan); color: var(--text); font-weight: 900; }
.invite-status { color: var(--muted); font-size: 13px; font-weight: 800; }
.invite-qr { min-height: 220px; display: grid; place-items: center; border-radius: 18px; background: #f7f4ef; color: #111827; padding: 12px; overflow: hidden; font-weight: 900; }
.invite-qr svg { width: 100%; height: auto; display: block; }

@media (max-width: 820px) {
  header { align-items: flex-start; flex-direction: column; }
  .brand { align-items: flex-start; flex-direction: column; gap: 12px; }
  .brand-mark { width: 132px; }
  .hero, .room, .sensors, .notes { grid-column: span 12; }
  .invite-card { grid-template-columns: 1fr; }
  .invite-qr { width: min(240px, 100%); margin: 0 auto; }
  .metric-row { grid-template-columns: 1fr; }
}
