:root {
  --ink: #e8f4f6;
  --muted: #9db4ba;
  --line: rgba(255, 255, 255, 0.14);
  --panel: rgba(6, 16, 23, 0.82);
  --accent: #60ddea;
  --accent-soft: rgba(96, 221, 234, 0.32);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0a141a;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
}

#app {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

.topbar {
  position: fixed;
  top: 14px;
  left: 14px;
  right: 14px;
  z-index: 20;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.status-dot {
  flex: 0 0 auto;
  width: 12px;
  height: 12px;
  margin-top: 6px;
  border-radius: 50%;
  background: #5a6a70;
  transition: background 0.3s ease;
}

.status-dot.is-ready {
  background: #2fd86f;
  box-shadow: 0 0 10px rgba(47, 216, 111, 0.7);
}

.eyebrow {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 2px 0 4px;
  font-size: 19px;
  line-height: 1.2;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.tool-button:hover {
  border-color: var(--accent-soft);
  background: rgba(39, 120, 137, 0.32);
}

.tool-button.is-active {
  border-color: rgba(96, 221, 234, 0.55);
  background: rgba(39, 120, 137, 0.4);
}

.tool-button svg {
  width: 18px;
  height: 18px;
}

.view-panel {
  position: fixed;
  left: 14px;
  top: 118px;
  z-index: 20;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  display: grid;
  gap: 10px;
  width: 170px;
}

.panel-title {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.view-grid {
  display: grid;
  gap: 6px;
}

.view-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.view-button:hover,
.view-button.is-active {
  border-color: var(--accent-soft);
  background: rgba(39, 120, 137, 0.35);
}

.info-card[hidden] {
  display: none;
}

.info-card {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 20;
  max-width: 320px;
  padding: 14px 16px;
  border: 1px solid var(--accent-soft);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  display: grid;
  gap: 4px;
}

.info-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.info-card strong {
  font-size: 14.5px;
  line-height: 1.3;
}

.info-source {
  color: var(--muted);
  font-size: 11.5px;
  overflow-wrap: anywhere;
}

.walk-crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 5px;
  height: 5px;
  margin: -2.5px 0 0 -2.5px;
  border-radius: 50%;
  background: rgba(158, 240, 255, 0.9);
  box-shadow: 0 0 0 2px rgba(6, 16, 23, 0.55), 0 0 9px rgba(96, 221, 234, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.walk-hint {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 16px;
  border: 1px solid var(--accent-soft);
  border-radius: 9px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 30;
  text-align: center;
}

.walk-hint strong {
  color: rgba(158, 240, 255, 0.95);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.walk-hint span {
  color: var(--muted);
  font-size: 12px;
}

.walk-crosshair.is-visible,
.walk-hint.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.walk-crosshair.is-visible {
  transform: none;
}

.loading-card {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-content: center;
  gap: 10px;
  text-align: center;
  background: #0a141a;
  transition: opacity 0.4s ease;
}

.loading-card.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-brand {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.loading-title {
  font-size: 21px;
}

.loading-message {
  color: var(--muted);
  font-size: 13px;
}

.progress-track {
  width: 260px;
  height: 5px;
  margin: 8px auto 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  overflow: hidden;
}

#loading-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 0.25s ease;
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
  }

  .subtitle {
    display: none;
  }

  .view-panel {
    top: auto;
    bottom: 14px;
    left: 14px;
    width: auto;
  }

  .view-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .info-card {
    bottom: auto;
    top: 118px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}

/* Zone temperature / humidity tags (demo BMS overlay) */
.zone-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 25;
}

.zone-tag {
  position: absolute;
  transform: translate(-50%, -110%);
  display: grid;
  gap: 2px;
  min-width: 122px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(23, 32, 34, 0.14);
  border-left: 4px solid #17a05c;
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(17, 23, 25, 0.18);
  font-family: "Segoe UI", Arial, sans-serif;
}

.zone-tag .zone-head {
  color: #52606a;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.zone-tag .zone-temp {
  color: #17222a;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.1;
}

.zone-tag .zone-rh {
  color: #5d6a72;
  font-size: 11.5px;
  font-weight: 700;
}

.zone-tag.is-high {
  border-left-color: #e09a10;
}

.zone-tag.is-high .zone-head {
  color: #9a6a00;
}

.zone-tag.is-high .zone-temp {
  color: #9a6a00;
}

/* ---- Smart BMS demo upgrade ---- */

.zone-tag .zone-status {
  color: #17a05c;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.zone-tag .zone-status.is-alarm {
  color: #c62828;
}

.zone-tag.is-alarm {
  border-left-color: #c62828;
  animation: zonePulse 1s ease-in-out infinite;
}

@keyframes zonePulse {
  0%, 100% { box-shadow: 0 8px 22px rgba(17, 23, 25, 0.18); }
  50% { box-shadow: 0 8px 26px rgba(198, 40, 40, 0.55); }
}

.zone-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11.5px;
  line-height: 1.5;
}

.zone-line em {
  color: #5d6a72;
  font-style: normal;
  font-weight: 700;
}

.zone-line b {
  color: #17222a;
  font-weight: 800;
}

.zone-tag.kind-equipment {
  border-left-color: #2563ab;
}

.zone-tag.kind-energy {
  border-left-color: #b8860b;
}

.bms-toast {
  position: fixed;
  top: 118px;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  z-index: 35;
  max-width: min(520px, calc(100vw - 28px));
  padding: 10px 18px;
  border-radius: 9px;
  border: 1px solid var(--accent-soft);
  background: var(--panel);
  backdrop-filter: blur(8px);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.bms-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.bms-toast.is-alarm {
  border-color: rgba(255, 82, 82, 0.65);
  color: #ff8a80;
  animation: zonePulse 1s ease-in-out infinite;
}

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 38;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(4, 10, 14, 0.78);
  backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.intro-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.intro-card {
  max-width: 560px;
  padding: 30px 32px;
  border: 1px solid var(--accent-soft);
  border-radius: 14px;
  background: rgba(6, 16, 23, 0.94);
  display: grid;
  gap: 12px;
  text-align: center;
  justify-items: center;
}

.intro-card h2 {
  margin: 0;
  font-size: 24px;
  color: #fff;
}

.intro-site {
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.intro-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.6;
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.intro-btn {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.intro-btn:hover {
  border-color: var(--accent-soft);
  background: rgba(39, 120, 137, 0.32);
}

.intro-btn.is-primary {
  border-color: rgba(96, 221, 234, 0.5);
  background: rgba(39, 120, 137, 0.45);
  color: #fff;
}

.exit-walk {
  position: fixed;
  top: 118px;
  right: 14px;
  z-index: 32;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid rgba(255, 138, 128, 0.5);
  border-radius: 9px;
  background: rgba(60, 16, 16, 0.85);
  color: #ffb4ad;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  display: none;
}

.exit-walk.is-visible {
  display: block;
}

.joystick {
  position: fixed;
  left: 24px;
  bottom: 96px;
  z-index: 32;
  width: 118px;
  height: 118px;
  border-radius: 50%;
  border: 2px solid rgba(96, 221, 234, 0.4);
  background: rgba(6, 16, 23, 0.55);
  display: none;
  touch-action: none;
}

.joystick.is-visible {
  display: block;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  margin: -26px 0 0 -26px;
  border-radius: 50%;
  background: rgba(96, 221, 234, 0.5);
  border: 2px solid rgba(158, 240, 255, 0.7);
}

.info-card {
  min-width: 250px;
}

.info-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.info-name {
  font-size: 14.5px;
  line-height: 1.3;
}

.info-grid {
  display: grid;
  gap: 5px;
  margin-top: 4px;
}

.info-field {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  font-size: 11.5px;
}

.info-field span {
  color: var(--muted);
  font-weight: 700;
}

.info-field strong {
  color: var(--ink);
  font-weight: 800;
  text-align: right;
}

.info-field.is-ok strong {
  color: #4ade80;
}

.loading-percent {
  font-size: 15px;
  color: var(--accent);
}

.loading-error {
  display: grid;
  gap: 10px;
  justify-items: center;
  margin-top: 8px;
}

.loading-error p {
  margin: 0;
  color: #ff8a80;
  font-size: 13px;
}

@media (max-width: 760px) {
  .exit-walk {
    top: auto;
    bottom: 96px;
    right: 14px;
  }

  .intro-actions {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
}

/* ---- compact BMS pins (dot + leader line + chip) ---- */

.bms-pin {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.bms-pin.is-occluded {
  opacity: 0.25;
}

.pin-chip {
  pointer-events: auto;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border: 1px solid rgba(96, 221, 234, 0.35);
  border-radius: 999px;
  background: rgba(6, 16, 23, 0.88);
  backdrop-filter: blur(6px);
  color: var(--ink);
  font: 700 12px "Segoe UI", Arial, sans-serif;
  white-space: nowrap;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.pin-chip:hover {
  border-color: rgba(96, 221, 234, 0.7);
  background: rgba(20, 45, 55, 0.95);
}

.pin-chip.is-selected {
  border-color: #60ddea;
  background: rgba(39, 120, 137, 0.6);
}

.pin-chip .pin-tag {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.pin-chip b {
  color: #9ef0ff;
  font-weight: 800;
}

.pin-line {
  width: 2px;
  height: 32px;
  background: linear-gradient(rgba(96, 221, 234, 0.55), rgba(96, 221, 234, 0.12));
}

.pin-dot {
  width: 9px;
  height: 9px;
  margin-top: -1px;
  border-radius: 50%;
  background: #2fd86f;
  box-shadow: 0 0 8px rgba(47, 216, 111, 0.8);
}

.kind-equipment .pin-dot {
  background: #4b9fe0;
  box-shadow: 0 0 8px rgba(75, 159, 224, 0.8);
}

.kind-energy .pin-dot {
  background: #e0b23f;
  box-shadow: 0 0 8px rgba(224, 178, 63, 0.8);
}

.bms-pin.is-alarm .pin-chip {
  border-color: rgba(255, 82, 82, 0.75);
}

.bms-pin.is-alarm .pin-chip b {
  color: #ff8a80;
}

.bms-pin.is-alarm .pin-dot {
  background: #ff5252;
  box-shadow: 0 0 10px rgba(255, 82, 82, 0.9);
  animation: pinBlink 0.9s ease-in-out infinite;
}

@keyframes pinBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.info-field.is-bad strong {
  color: #ff8a80;
}
