:root {
  /* Chrome retheme to match citrine.com.sg: near-black bg + indigo/purple accent.
     Status colours (green/amber/red/grey) are BMS language — left unchanged. */
  --dt-bg: #05070d;
  --dt-panel: rgba(10, 13, 23, 0.8);
  --dt-panel-strong: rgba(13, 16, 28, 0.9);
  --dt-line: rgba(255, 255, 255, 0.1);
  --dt-line-strong: rgba(141, 164, 232, 0.42);
  --dt-text: #f5f7fd;
  --dt-muted: #a5afc7;
  --dt-faint: #7a87a3;
  --dt-cyan: #5d7cff;
  --dt-blue: #8fa4e8;
  --dt-green: #64df89;
  --dt-yellow: #f4c35c;
  --dt-red: #ff5c5c;
  --dt-grey: #aebcc1;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--dt-bg);
  color: var(--dt-text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  min-width: 320px;
}

#app.digital-twin-viewer {
  position: relative;
  width: 100%;
  height: 100vh;
  min-height: 620px;
  overflow: hidden;
  isolation: isolate;
  background: #05070d;
}

#plant-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  z-index: 0;
}

.viewer-vignette {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(1, 7, 12, 0.46), rgba(1, 7, 12, 0.02) 34%, rgba(1, 7, 12, 0.42)),
    linear-gradient(90deg, rgba(1, 7, 12, 0.52), rgba(1, 7, 12, 0) 36%, rgba(1, 7, 12, 0.46));
}

.topbar,
.plant-kpi-bar,
.camera-panel,
.equipment-readout,
.alarm-banner,
.loading-card,
.tag-layer,
.flow-direction-layer {
  position: absolute;
}

.topbar,
.plant-kpi-bar,
.camera-panel,
.equipment-readout,
.alarm-banner,
.loading-card {
  color: var(--dt-text);
  border: 1px solid var(--dt-line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(13, 16, 28, 0.86), rgba(8, 10, 20, 0.74));
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.customer-hidden-debug {
  display: none !important;
}

.digital-twin-topbar {
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 12;
  min-height: 78px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 13px 15px;
}

.legacy-stop-nav {
  display: none !important;
}

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

.status-dot {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--dt-yellow);
  box-shadow: 0 0 0 6px rgba(244, 195, 92, 0.15), 0 0 22px rgba(244, 195, 92, 0.62);
}

.status-dot.is-ready {
  background: var(--dt-green);
  box-shadow: 0 0 0 6px rgba(100, 223, 137, 0.16), 0 0 22px rgba(100, 223, 137, 0.7);
}

.status-dot.is-comms-lost {
  background: var(--dt-yellow);
  box-shadow: 0 0 0 6px rgba(244, 195, 92, 0.16), 0 0 22px rgba(244, 195, 92, 0.72);
  animation: alarm-dot 1.25s ease-in-out infinite;
}

/* Communication Lost banner: amber, distinct from the red equipment-trip alarm. */
.alarm-banner.is-comms-lost {
  border-color: rgba(244, 195, 92, 0.55);
  background: rgba(214, 158, 46, 0.18);
}

.alarm-banner.is-comms-lost strong {
  color: #ffd479;
}

.alarm-banner.is-comms-lost .alarm-indicator {
  background: var(--dt-yellow);
  box-shadow: 0 0 10px rgba(244, 195, 92, 0.85);
}

/* Glanceable data-feed status pill in the toolbar. */
.comms-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  align-self: center;
  height: 34px;
  padding: 0 11px;
  border-radius: 999px;
  border: 1px solid var(--dt-line);
  background: rgba(255, 255, 255, 0.045);
  font-size: 11px;
  font-weight: 820;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}

.comms-status .comms-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--dt-green);
  box-shadow: 0 0 8px rgba(100, 223, 137, 0.85);
}

.comms-status.is-live .comms-label {
  color: #9fe9b6;
}

.comms-status.is-lost {
  border-color: rgba(244, 195, 92, 0.55);
  background: rgba(214, 158, 46, 0.16);
}

.comms-status.is-lost .comms-dot {
  background: var(--dt-yellow);
  box-shadow: 0 0 9px rgba(244, 195, 92, 0.95);
  animation: alarm-dot 1.25s ease-in-out infinite;
}

.comms-status.is-lost .comms-label {
  color: #ffd479;
}

/* HA failover: live, but running on the secondary (JACE backup) source — amber,
   but a STEADY dot (no alarm pulse) to read "still live, just on backup". */
.comms-status.is-backup {
  border-color: rgba(244, 195, 92, 0.5);
  background: rgba(214, 158, 46, 0.14);
}

.comms-status.is-backup .comms-dot {
  background: var(--dt-yellow);
  box-shadow: 0 0 9px rgba(244, 195, 92, 0.9);
}

.comms-status.is-backup .comms-label {
  color: #ffd479;
}

/* Fullscreen / kiosk presentation mode: hide the Citrine eyebrow + subtitle
   and slightly enlarge the KPIs for a clean, edge-to-edge showcase look. */
#app.is-fullscreen .eyebrow,
#app.is-fullscreen .subtitle {
  display: none;
}

#app.is-fullscreen .kpi-tile {
  min-height: 66px;
}

#app.is-fullscreen .kpi-tile strong {
  font-size: 19px;
}

#app.is-fullscreen .kpi-tile span {
  font-size: 11px;
}

/* Below desktop width the labelled toolbar gets cramped — go icon-only so it
   has breathing room (tooltips still explain each button). */
@media (max-width: 1024px) {
  .tour-button span,
  .panel-toggle-button span,
  .ui-toggle-button span,
  #walk-toggle span,
  .comms-status .comms-label {
    display: none;
  }

  .comms-status {
    padding: 0 8px;
    gap: 0;
  }

  /* The full label is hidden here, so surface the HA source as a compact tag
     (set via data-src in setCommsDot). Green = Supervisor, amber = JACE/backup. */
  .comms-status[data-src]:not([data-src=""])::after {
    content: attr(data-src);
    margin-left: 6px;
    font-size: 10px;
    font-weight: 820;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #9fe9b6;
  }

  .comms-status.is-backup[data-src]:not([data-src=""])::after,
  .comms-status.is-lost[data-src]:not([data-src=""])::after {
    color: #ffd479;
  }
}

.eyebrow,
.panel-heading span,
.search-label,
.equipment-card-kicker,
.loading-brand {
  display: block;
  color: var(--dt-cyan);
  font-size: 11px;
  font-weight: 820;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--dt-text);
  font-size: 22px;
  line-height: 1.1;
  font-weight: 840;
  letter-spacing: 0;
  white-space: normal;
}

.subtitle {
  max-width: 780px;
  margin: 5px 0 0;
  color: var(--dt-muted);
  font-size: 13px;
  line-height: 1.35;
}

button,
input {
  font: inherit;
}

button {
  letter-spacing: 0;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button,
.camera-preset-button,
.tag-mode-button,
.equipment-action {
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  color: var(--dt-text);
  background: rgba(255, 255, 255, 0.075);
  cursor: pointer;
  transition: border-color 0.16s ease, background 0.16s ease, transform 0.16s ease, color 0.16s ease;
}

.icon-button:hover,
.camera-preset-button:hover,
.tag-mode-button:hover,
.equipment-action:hover,
.camera-preset-button.is-active,
.tag-mode-button.is-active {
  border-color: var(--dt-line-strong);
  background: rgba(93, 124, 255, 0.32);
}

.icon-button:active,
.camera-preset-button:active,
.tag-mode-button:active,
.equipment-action:active {
  transform: translateY(1px);
}

.icon-button {
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.tour-button {
  width: auto;
  padding: 0 13px;
}

.panel-toggle-button {
  width: auto;
  padding: 0 13px;
}

.icon-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.3;
}

.tour-button span,
.panel-toggle-button span {
  color: var(--dt-muted);
  font-size: 12px;
  font-weight: 780;
}

.panel-toggle-button.is-panel-hidden {
  border-color: rgba(93, 124, 255, 0.46);
  background: rgba(93, 124, 255, 0.26);
}

.plant-kpi-bar {
  top: 108px;
  left: 16px;
  right: 16px;
  z-index: 11;
  display: grid;
  grid-template-columns: repeat(7, minmax(118px, 1fr));
  gap: 8px;
  padding: 9px;
}

.kpi-tile {
  min-width: 0;
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.055);
}

.kpi-tile span {
  color: var(--dt-faint);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0;
  text-transform: uppercase;
  white-space: nowrap;
}

.kpi-tile strong {
  overflow-wrap: anywhere;
  color: #fff;
  font-size: 16px;
  line-height: 1.05;
  font-weight: 860;
  font-variant-numeric: tabular-nums;
}

.kpi-mode strong {
  color: var(--dt-green);
}

.kpi-alarm {
  border-color: rgba(255, 92, 92, 0.34);
  background: rgba(255, 92, 92, 0.12);
}

.kpi-alarm strong {
  color: #ffb5b5;
}

.camera-panel {
  top: 192px;
  left: 16px;
  z-index: 10;
  width: 264px;
  max-height: calc(100% - 270px);
  overflow: auto;
  padding: 13px;
}

/* ---- 24h plant trend chart (bottom-left, above the alarm banner) ---- */
.plant-trend-card {
  position: absolute;
  left: 16px;
  bottom: 76px;
  z-index: 11;
  width: clamp(560px, 38vw, 960px);
  max-width: calc(100% - 32px);
  padding: 14px 16px 12px;
  color: var(--dt-text);
  border: 1px solid var(--dt-line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(13, 16, 28, 0.86), rgba(8, 10, 20, 0.74));
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.digital-twin-viewer.is-trend-hidden .plant-trend-card {
  display: none;
}

.trend-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 8px;
}

.trend-kicker {
  display: block;
  color: var(--dt-cyan);
  font-size: 11px;
  font-weight: 820;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.trend-title strong {
  color: #fff;
  font-size: 16px;
  font-weight: 840;
  font-variant-numeric: tabular-nums;
}

.trend-range {
  margin-top: 2px;
  padding: 4px 28px 4px 9px;
  border: 1px solid var(--dt-line-strong);
  border-radius: 6px;
  background-color: rgba(93, 124, 255, 0.1);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%235d7cff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  color: #fff;
  font: 840 16px "Space Grotesk", system-ui, sans-serif;
  letter-spacing: 0.01em;
  cursor: pointer;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

.trend-range:hover {
  border-color: var(--dt-cyan);
}

.trend-range:focus-visible {
  outline: 2px solid var(--dt-cyan);
  outline-offset: 1px;
}

.trend-range option {
  background: #0b0e1c;
  color: #fff;
}

.trend-legend {
  display: grid;
  gap: 3px;
  text-align: right;
}

.trend-key {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--dt-muted);
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.trend-key i {
  width: 9px;
  height: 3px;
  border-radius: 2px;
  background: var(--dt-cyan);
}

.trend-key-load i {
  background: var(--dt-grey);
  opacity: 0.55;
}

.trend-key-offline {
  color: var(--dt-yellow);
}

.trend-key-offline i {
  width: 16px;
  height: 0;
  border-top: 2px dashed var(--dt-yellow);
  border-radius: 0;
  background: none;
}

.trend-key b {
  color: #fff;
  font-weight: 840;
  font-variant-numeric: tabular-nums;
}

.trend-actions {
  display: flex;
  gap: 6px;
  flex: 0 0 auto;
}

.trend-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border: 1px solid var(--dt-line-strong);
  border-radius: 6px;
  background: rgba(93, 124, 255, 0.1);
  color: var(--dt-text);
  font: 800 11px/1 "Space Grotesk", system-ui, sans-serif;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.trend-action-btn:hover {
  background: rgba(93, 124, 255, 0.24);
  border-color: var(--dt-cyan);
  color: #fff;
}

.trend-action-btn svg {
  width: 13px;
  height: 13px;
}

.trend-canvas-wrap {
  position: relative;
  height: clamp(224px, 26vh, 420px);
}

/* Desktop only: shrink the chart on shorter windows so it clears the camera
   panel above and the alarm banner below. (Mobile has its own rule below.) */
@media (min-width: 721px) and (max-height: 860px) {
  .trend-canvas-wrap {
    height: clamp(190px, 28vh, 230px);
  }
}

#trend-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.trend-canvas-wrap.has-data #trend-canvas {
  cursor: crosshair;
}

.trend-tooltip {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  min-width: 118px;
  padding: 6px 8px;
  border: 1px solid var(--dt-line-strong);
  border-radius: 6px;
  background: rgba(8, 10, 20, 0.95);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  font-variant-numeric: tabular-nums;
}

.trend-tooltip[hidden] {
  display: none;
}

.trend-tooltip .tt-time {
  margin-bottom: 4px;
  color: #fff;
  font-size: 12px;
  font-weight: 840;
}

.trend-tooltip .tt-row {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--dt-muted);
  font-size: 11px;
  font-weight: 680;
  white-space: nowrap;
}

.trend-tooltip .tt-row + .tt-row {
  margin-top: 2px;
}

.trend-tooltip .tt-row b {
  margin-left: auto;
  color: #fff;
  font-weight: 820;
}

.trend-tooltip i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.trend-tooltip .tt-eff {
  background: var(--dt-cyan);
}

.trend-tooltip .tt-load {
  background: var(--dt-grey);
}

.trend-tooltip .tt-offline {
  background: var(--dt-yellow);
  box-shadow: 0 0 7px rgba(244, 195, 92, 0.55);
}

.trend-tooltip .tt-row-offline,
.trend-tooltip .tt-row-offline b {
  color: #ffd479;
}

.trend-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 14px;
  color: var(--dt-faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.trend-canvas-wrap.has-data .trend-empty {
  display: none;
}

.panel-heading {
  display: grid;
  gap: 3px;
  margin-bottom: 11px;
}

.panel-heading strong {
  color: #fff;
  font-size: 16px;
  line-height: 1.1;
  font-weight: 840;
}

.camera-preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.camera-preset-button {
  min-width: 0;
  padding: 0 9px;
  color: rgba(245, 248, 247, 0.84);
  font-size: 12px;
  font-weight: 780;
  line-height: 1.1;
}

.camera-preset-button.is-active {
  color: #fff;
}

.tag-tools {
  display: grid;
  gap: 9px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.search-label {
  color: var(--dt-muted);
}

#equipment-search {
  width: 100%;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 7px;
  padding: 0 10px;
  color: #fff;
  background: rgba(1, 8, 13, 0.58);
  outline: none;
}

#equipment-search::placeholder {
  color: rgba(226, 239, 239, 0.38);
}

#equipment-search:focus {
  border-color: rgba(93, 124, 255, 0.62);
  box-shadow: 0 0 0 3px rgba(93, 124, 255, 0.12);
}

.tag-mode-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.tag-mode-button {
  width: 100%;
  min-height: 34px;
  padding: 0 9px;
  color: rgba(245, 248, 247, 0.78);
  font-size: 11px;
  font-weight: 780;
  text-align: center;
}

.flow-switch {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 38px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--dt-muted);
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  user-select: none;
}

.flow-switch input {
  appearance: none;
  width: 42px;
  height: 24px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  outline: none;
  position: relative;
}

.flow-switch input::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  top: 2px;
  left: 3px;
  border-radius: 50%;
  background: #f5f8f7;
  transition: transform 0.18s ease;
}

.flow-switch input:checked {
  background: rgba(93, 124, 255, 0.4);
}

.flow-switch input:checked::after {
  transform: translateX(17px);
}

.digital-twin-equipment {
  top: 192px;
  right: 16px;
  bottom: auto;
  z-index: 10;
  width: min(390px, calc(100vw - 32px));
  max-height: calc(100% - 270px);
  overflow: auto;
  display: grid;
  gap: 12px;
  padding: 14px;
  transition: opacity 0.16s ease, transform 0.18s ease, visibility 0.18s ease;
}

.digital-twin-viewer.is-equipment-panel-hidden #equipment-readout {
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 24px));
  visibility: hidden;
}

/* Guided-tour equipment card: keep the useful status and live metrics visible,
   but remove secondary actions so the 3D equipment remains the main focus. */
.digital-twin-viewer.is-tour-active #equipment-readout {
  width: min(340px, calc(100vw - 32px));
  max-height: calc(100% - 330px);
  box-shadow: 0 18px 52px rgba(0, 0, 0, 0.48), 0 0 0 1px rgba(93, 124, 255, 0.12);
}

.digital-twin-viewer.is-tour-active #equipment-readout .equipment-actions,
.digital-twin-viewer.is-tour-active #equipment-readout .equipment-mini-trend,
.digital-twin-viewer.is-tour-active #equipment-readout .equipment-note,
.digital-twin-viewer.is-tour-active #equipment-readout .equipment-card-source {
  display: none;
}

/* User-controlled show/hide for the KPI bar and camera presets. */
.plant-kpi-bar,
.camera-panel {
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}

.digital-twin-viewer.is-kpi-hidden .plant-kpi-bar {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(-10px);
}

.digital-twin-viewer.is-camera-hidden .camera-panel {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(-10px);
}

.ui-toggle-button.is-off {
  opacity: 0.5;
}

.equipment-panel-head,
.equipment-card-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.equipment-card-title {
  margin-top: 3px;
  color: #fff;
  font-size: 20px;
  line-height: 1.16;
  font-weight: 850;
  overflow-wrap: anywhere;
}

.equipment-status-pill {
  min-width: 84px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  padding: 7px 9px;
  color: #fff;
  font-size: 12px;
  font-weight: 860;
  text-align: center;
  white-space: nowrap;
}

.status-running .equipment-status-pill,
.equipment-card.status-run .equipment-status-pill {
  border-color: rgba(100, 223, 137, 0.72);
  background: rgba(100, 223, 137, 0.17);
}

.status-stopped .equipment-status-pill,
.equipment-card.status-stop .equipment-status-pill {
  border-color: rgba(174, 188, 193, 0.52);
  background: rgba(174, 188, 193, 0.13);
}

.status-alarm .equipment-status-pill,
.equipment-card.status-alarm .equipment-status-pill {
  border-color: rgba(255, 92, 92, 0.78);
  background: rgba(255, 92, 92, 0.2);
}

.status-manual .equipment-status-pill,
.equipment-card.status-manual .equipment-status-pill,
.status-warning .equipment-status-pill {
  border-color: rgba(244, 195, 92, 0.78);
  background: rgba(244, 195, 92, 0.18);
}

.equipment-card-grid,
.equipment-metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.equipment-card-field {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.06);
}

.equipment-card-field span {
  display: block;
  color: var(--dt-faint);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0;
  text-transform: uppercase;
}

.equipment-card-field strong {
  display: block;
  margin-top: 4px;
  color: #fff;
  font-size: 14px;
  line-height: 1.15;
  font-weight: 840;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.equipment-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.equipment-action {
  padding: 0 6px;
  color: rgba(245, 248, 247, 0.84);
  font-size: 11px;
  font-weight: 820;
}

.equipment-card-source {
  display: none;
}

.equipment-note {
  margin: 0;
  color: var(--dt-muted);
  font-size: 12px;
  line-height: 1.38;
}

.equipment-mini-trend {
  display: grid;
  gap: 7px;
  padding-top: 9px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.equipment-mini-trend header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--dt-faint);
  font-size: 10px;
  font-weight: 820;
  text-transform: uppercase;
}

.equipment-mini-trend strong {
  color: var(--dt-muted);
  font-size: 10px;
}

.equipment-mini-trend svg {
  display: block;
  width: 100%;
  height: 56px;
  overflow: visible;
}

.equipment-mini-trend .trend-grid {
  stroke: rgba(255, 255, 255, 0.1);
  stroke-width: 1;
}

.equipment-mini-trend .trend-fill {
  fill: rgba(93, 124, 255, 0.12);
}

.equipment-mini-trend .trend-line {
  fill: none;
  stroke: var(--dt-cyan);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status-alarm .equipment-mini-trend .trend-line {
  stroke: var(--dt-red);
}

.status-alarm .equipment-mini-trend .trend-fill {
  fill: rgba(255, 92, 92, 0.14);
}

.tag-layer {
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

.equipment-tag {
  position: absolute;
  display: none;
  max-width: 190px;
  min-height: 24px;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(4, 12, 18, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 860;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  pointer-events: auto;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.equipment-tag::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 10px currentColor;
}

.equipment-tag.status-running {
  color: var(--dt-green);
  border-color: rgba(100, 223, 137, 0.44);
}

.equipment-tag.status-stopped {
  color: var(--dt-grey);
  border-color: rgba(174, 188, 193, 0.34);
}

.equipment-tag.status-alarm {
  color: #ff9f9f;
  border-color: rgba(255, 92, 92, 0.62);
  animation: alarm-tag-pulse 1.25s ease-in-out infinite;
}

.equipment-tag.status-manual,
.equipment-tag.status-warning {
  color: var(--dt-yellow);
  border-color: rgba(244, 195, 92, 0.5);
}

.equipment-tag.status-accessory,
.equipment-tag.type-accessory {
  color: #9edcff;
  border-color: rgba(91, 167, 255, 0.44);
  background: rgba(5, 18, 27, 0.78);
}

.equipment-tag.status-support,
.equipment-tag.type-support-foundation {
  color: rgba(224, 235, 238, 0.92);
  border-color: rgba(190, 206, 210, 0.38);
  background: rgba(9, 18, 24, 0.78);
}

.status-accessory .equipment-status-pill {
  border-color: rgba(91, 167, 255, 0.58);
  background: rgba(91, 167, 255, 0.16);
}

.status-support .equipment-status-pill {
  border-color: rgba(190, 206, 210, 0.48);
  background: rgba(190, 206, 210, 0.12);
}

.flow-direction-layer {
  inset: 0;
  z-index: 7;
  pointer-events: none;
}

.flow-direction-label {
  position: absolute;
  display: none;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 8px 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: rgba(3, 12, 18, 0.7);
  color: #f5f8f7;
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.22);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  --flow-angle: 0rad;
}

.flow-direction-label::after {
  content: ">";
  display: inline-block;
  color: currentColor;
  transform: rotate(var(--flow-angle));
  animation: flow-arrow-travel 1.15s ease-in-out infinite;
}

.flow-direction-label.chws,
.flow-direction-label.chwr {
  color: #a7f6ff;
  border-color: rgba(93, 124, 255, 0.45);
}

.flow-direction-label.cdws,
.flow-direction-label.cdwr,
.flow-direction-label.cdw {
  color: #bdf5a0;
  border-color: rgba(100, 223, 137, 0.42);
}

.alarm-banner {
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 12;
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
}

.alarm-banner strong {
  color: #fff;
  font-size: 14px;
  font-weight: 860;
}

.alarm-banner span:last-child {
  color: var(--dt-muted);
  font-size: 13px;
  font-weight: 720;
}

.alarm-indicator {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--dt-red);
  box-shadow: 0 0 0 6px rgba(255, 92, 92, 0.14), 0 0 18px rgba(255, 92, 92, 0.72);
  animation: alarm-dot 1.25s ease-in-out infinite;
}

.alarm-banner.is-normal .alarm-indicator {
  background: var(--dt-green);
  box-shadow: 0 0 0 6px rgba(100, 223, 137, 0.13), 0 0 18px rgba(100, 223, 137, 0.62);
  animation: none;
}

.loading-card {
  left: 50%;
  top: 50%;
  z-index: 40;
  width: min(430px, calc(100vw - 40px));
  display: grid;
  gap: 10px;
  padding: 22px;
  text-align: center;
  transform: translate(-50%, -50%);
}

.loading-card.is-hidden {
  display: none;
}

.loading-title {
  color: #fff;
  font-size: 22px;
  line-height: 1.18;
  font-weight: 860;
}

.loading-message {
  color: var(--dt-muted);
  font-size: 14px;
  font-weight: 720;
}

.progress-track {
  height: 8px;
  margin-top: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
}

#loading-bar {
  width: 0%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--dt-cyan), var(--dt-green));
  transition: width 0.2s ease;
}

.loading-spinner {
  width: 28px;
  height: 28px;
  margin: 2px auto 0;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-top-color: var(--dt-cyan);
  border-radius: 50%;
  animation: spinner 0.9s linear infinite;
}

@keyframes alarm-dot {
  0%,
  100% {
    opacity: 0.72;
    transform: scale(0.94);
  }
  50% {
    opacity: 1;
    transform: scale(1.08);
  }
}

@keyframes alarm-tag-pulse {
  0%,
  100% {
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28), 0 0 0 rgba(255, 92, 92, 0);
  }
  50% {
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28), 0 0 18px rgba(255, 92, 92, 0.42);
  }
}

@keyframes flow-arrow-travel {
  0% {
    opacity: 0.28;
    transform: rotate(var(--flow-angle)) translateX(-3px);
  }
  48% {
    opacity: 1;
    transform: rotate(var(--flow-angle)) translateX(2px);
  }
  100% {
    opacity: 0.28;
    transform: rotate(var(--flow-angle)) translateX(6px);
  }
}

@keyframes spinner {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media (max-width: 1180px) {
  .plant-kpi-bar {
    grid-template-columns: repeat(4, minmax(118px, 1fr));
  }

  .camera-panel,
  .digital-twin-equipment {
    top: 250px;
  }
}

@media (max-width: 900px) {
  .digital-twin-topbar {
    top: 12px;
    left: 12px;
    right: 12px;
    min-height: 92px;
    padding: 12px;
  }

  h1 {
    font-size: 20px;
  }

  .subtitle {
    font-size: 12px;
  }

  .plant-kpi-bar {
    top: 118px;
    left: 12px;
    right: 12px;
    grid-template-columns: repeat(4, minmax(120px, 1fr));
    overflow-x: auto;
  }

  .camera-panel {
    top: 262px;
    left: 12px;
    width: 236px;
  }

  .digital-twin-equipment {
    top: 262px;
    right: 12px;
    width: min(350px, calc(100vw - 272px));
  }

  .equipment-card-grid,
  .equipment-metric-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  #app.digital-twin-viewer {
    min-height: 680px;
  }

  .digital-twin-topbar {
    grid-template-columns: 1fr auto;
  }

  .tour-button span,
  .panel-toggle-button span,
  .ui-toggle-button span,
  .comms-status .comms-label {
    display: none;
  }

  .comms-status {
    padding: 0 7px;
    gap: 0;
  }

  .plant-kpi-bar {
    top: 126px;
    grid-template-columns: repeat(7, 126px);
  }

  .kpi-tile {
    min-height: 54px;
  }

  .plant-trend-card {
    left: 12px;
    right: 12px;
    bottom: 72px;
    width: auto;
    transform: none;
  }

  .trend-canvas-wrap {
    height: 150px;
  }

  .camera-panel {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 66px;
    width: auto;
    max-height: 188px;
    overflow: auto;
    padding: 10px;
  }

  .camera-preset-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .camera-preset-button {
    min-height: 32px;
    padding: 0 5px;
    font-size: 10px;
  }

  .tag-tools {
    grid-template-columns: 1fr;
  }

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

  .tag-mode-button {
    text-align: center;
    font-size: 10px;
  }

  .digital-twin-equipment {
    left: 10px;
    right: 10px;
    top: 206px;
    width: auto;
    max-height: 248px;
    overflow: auto;
    padding: 11px;
  }

  .equipment-card-title {
    font-size: 17px;
  }

  .equipment-actions {
    grid-template-columns: 1fr;
  }

  .alarm-banner {
    left: 10px;
    right: 10px;
    bottom: 10px;
    min-height: 46px;
    align-items: flex-start;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 5px 9px;
  }

  .alarm-banner span:last-child {
    grid-column: 2;
    font-size: 11px;
  }

}

@media (max-width: 480px) {
  .digital-twin-topbar {
    top: 8px;
    left: 8px;
    right: 8px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto;
    grid-template-areas:
      "brand"
      "tools";
    min-height: 0;
    max-height: none;
    overflow: visible;
    padding: 8px 10px;
    gap: 6px;
    align-items: stretch;
  }

  .brand {
    gap: 8px;
  }

  .brand .status-dot {
    width: 10px;
    height: 10px;
  }

  .eyebrow {
    font-size: 9px;
  }

  h1 {
    overflow: hidden;
    font-size: 14px;
    line-height: 1.08;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  /* The long description eats the phone screen — drop it so the live KPI
     data (cooling load, efficiency, alarms) sits right under the title. */
  .subtitle {
    display: none;
  }

  /* Put all mobile controls on their own row so they never squeeze the title. */
  .toolbar {
    width: 100%;
    display: grid;
    grid-template-columns: auto repeat(8, minmax(0, 1fr));
    align-items: center;
    gap: 4px;
    overflow: visible;
  }

  #walk-toggle span {
    display: none;
  }

  #walk-toggle,
  .toolbar .icon-button {
    width: 100%;
    height: 36px;
    min-height: 36px;
    padding: 0;
  }

  .toolbar .icon-button svg {
    width: 16px;
    height: 16px;
  }

  .comms-status {
    height: 36px;
    min-width: 30px;
    padding: 0 7px;
  }

  .comms-status[data-src]:not([data-src=""])::after {
    display: none;
  }

  /* Compact, swipeable KPI strip pinned just below the slim header. */
  .plant-kpi-bar {
    top: 108px;
    left: 10px;
    right: 10px;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 108px;
    gap: 6px;
    padding: 7px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .kpi-tile {
    min-height: 46px;
    padding: 7px 9px;
    scroll-snap-align: start;
  }

  .kpi-tile span {
    font-size: 9px;
  }

  .kpi-tile strong {
    font-size: 15px;
  }

  .plant-trend-card {
    left: 8px;
    right: 8px;
    bottom: 84px;
    padding: 11px 10px 9px;
  }

  .camera-panel {
    bottom: 84px;
  }

  .trend-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
    gap: 7px 8px;
    margin-bottom: 6px;
  }

  .trend-title {
    min-width: 0;
  }

  .trend-range {
    width: min(180px, 100%);
    font-size: 15px;
  }

  .trend-actions {
    grid-column: 2;
    grid-row: 1;
  }

  .trend-action-btn {
    padding: 6px 8px;
    font-size: 10px;
  }

  .trend-legend {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 4px 11px;
    text-align: left;
  }

  .trend-key {
    font-size: 11px;
  }

  /* Equipment details float above the alarm banner so active alarms remain visible. */
  .digital-twin-equipment {
    top: auto;
    bottom: 84px;
    left: 8px;
    right: 8px;
    width: auto;
    max-width: none;
    max-height: 42vh;
    border-radius: 14px;
    z-index: 25;
    padding: 12px;
  }

  .digital-twin-viewer.is-equipment-panel-hidden #equipment-readout {
    transform: translateY(calc(100% + 24px));
  }

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

  .tag-mode-controls {
    grid-template-columns: 1fr;
  }
}

/* Landscape phones: dock equipment to the right, camera presets to the left,
   slim the header — so the 3D stays visible in the middle instead of buried. */
@media (max-height: 500px) and (orientation: landscape) {
  /* Match the app box to the viewport so bottom-anchored panels dock to the
     visible screen (not a 680px min-height that overflows below the fold). */
  #app.digital-twin-viewer {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
  }

  .digital-twin-topbar {
    min-height: 0;
    max-height: 52px;
    overflow: hidden;
  }

  .subtitle {
    display: none;
  }

  h1 {
    font-size: 14px;
  }

  .plant-kpi-bar {
    top: 68px;
    left: 8px;
    right: 8px;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 118px;
    gap: 6px;
    padding: 6px;
    overflow-x: auto;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  /* Trend needs the vertical lane occupied by the KPI strip. The script
     restores the KPI strip as soon as Trend closes. */
  .digital-twin-viewer:not(.is-trend-hidden) #kpi-toggle {
    display: none;
  }

  .kpi-tile {
    min-height: 48px;
    padding: 6px 8px;
    scroll-snap-align: start;
  }

  .plant-trend-card {
    left: 8px;
    right: auto;
    bottom: 76px;
    width: min(560px, calc(100vw - 16px));
    padding: 10px;
  }

  .trend-head {
    margin-bottom: 6px;
  }

  .trend-canvas-wrap {
    height: 120px;
  }

  .digital-twin-equipment {
    top: 136px;
    bottom: 80px;
    right: 8px;
    left: auto;
    width: min(300px, 46vw);
    max-width: none;
    max-height: none;
    border-radius: 12px;
    z-index: 25;
  }

  .digital-twin-viewer.is-equipment-panel-hidden #equipment-readout {
    transform: translateX(calc(100% + 24px));
  }

  .camera-panel {
    left: 8px;
    right: auto;
    bottom: 80px;
    top: auto;
    width: min(280px, 46vw);
    max-height: 132px;
  }
}

/* First-person walk mode */
#walk-toggle {
  width: auto;
  padding: 0 13px;
}

#walk-toggle span {
  color: var(--dt-muted);
  font-size: 12px;
  font-weight: 780;
}

#walk-toggle.is-active {
  border-color: rgba(93, 124, 255, 0.55);
  background: rgba(93, 124, 255, 0.4);
}

#walk-toggle.is-active span {
  color: var(--dt-text);
}

.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(93, 124, 255, 0.8);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 30;
}

.walk-hint {
  position: fixed;
  left: 50%;
  bottom: 74px;
  transform: translateX(-50%) translateY(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 16px;
  border: 1px solid rgba(93, 124, 255, 0.35);
  border-radius: 9px;
  background: rgba(6, 16, 23, 0.82);
  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(--dt-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;
}

/* Touch walk controls (mobile): virtual joystick + exit button. Raised above
   the alarm banner (which bottom-anchors) so they never overlap. */
#joystick {
  position: fixed;
  left: 20px;
  bottom: 76px;
  width: 112px;
  height: 112px;
  border-radius: 999px;
  background: rgba(8, 16, 22, 0.42);
  border: 1px solid rgba(93, 124, 255, 0.4);
  box-shadow: inset 0 0 26px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: 40;
  display: none;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

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

#joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 999px;
  background: rgba(93, 124, 255, 0.6);
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

#exit-walk {
  position: fixed;
  right: 16px;
  bottom: 94px;
  z-index: 40;
  display: none;
  padding: 11px 18px;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(8, 16, 22, 0.8);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  -webkit-tap-highlight-color: transparent;
}

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

/* Guided showcase tour caption */
.tour-caption {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%) translateY(10px);
  max-width: min(760px, calc(100vw - 32px));
  padding: 13px 22px;
  border: 1px solid rgba(93, 124, 255, 0.32);
  border-radius: 10px;
  background: rgba(6, 16, 23, 0.86);
  backdrop-filter: blur(8px);
  color: #e8f6f8;
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
  z-index: 30;
}

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

.fullscreen-message {
  position: fixed;
  left: 50%;
  bottom: 84px;
  z-index: 45;
  width: max-content;
  max-width: min(520px, calc(100vw - 24px));
  transform: translateX(-50%) translateY(8px);
  padding: 10px 14px;
  border: 1px solid rgba(244, 195, 92, 0.5);
  border-radius: 9px;
  background: rgba(8, 10, 20, 0.96);
  color: #ffd479;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.42);
  font-size: 12px;
  font-weight: 720;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}

.fullscreen-message.is-visible {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

@supports (padding: max(0px)) {
  #app.is-fullscreen .digital-twin-topbar {
    top: max(8px, env(safe-area-inset-top));
  }

  #app.is-fullscreen .alarm-banner {
    bottom: max(10px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 700px) {
  .tour-caption {
    bottom: 84px;
    font-size: 13px;
    padding: 10px 14px;
  }
}
