/* ═══════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════ */
:root {
  --bg:        #0a0d12;
  --bg1:       #0f1318;
  --bg2:       #151a22;
  --bg3:       #1c232e;
  --border:    rgba(255,255,255,0.07);
  --border-hi: rgba(255,255,255,0.14);
  --text:      #c8d0dc;
  --text-dim:  #5a6478;
  --text-hi:   #e8edf5;
  --accent:    #3b82f6;
  --green:     #22c55e;
  --amber:     #eab308;
  --red:       #ef4444;
  --orange:    #f97316;
  --mono:      'IBM Plex Mono', monospace;
  --sans:      'IBM Plex Sans', sans-serif;
  --panel-r:   6px;
  --gap:       6px;
}

/* ═══════════════════════════════════════════════
   RESET & BASE
═══════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  line-height: 1.5;
}

/* ═══════════════════════════════════════════════
   TOPBAR
═══════════════════════════════════════════════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 8px;
  height: 30px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: var(--max-w);
  width: 100%;
}

.topbar-logo {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-hi);
  display: flex;
  align-items: center;
  gap: 6px;
}
.topbar-logo::before {
  content: '';
  display: block;
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 2px;
}

.topbar-sep { flex: 1; }

.topbar-stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-dim);
}
.topbar-stat span { color: var(--text); }

.conn-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 9px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid;
}
.conn-badge.connected { border-color: rgba(34,197,94,0.3); color: var(--green); background: rgba(34,197,94,0.06); }
.conn-badge.disconnected { border-color: rgba(239,68,68,0.3); color: var(--red); background: rgba(239,68,68,0.06); }
.conn-badge .dot {
  width: 5px; height: 5px; border-radius: 50%;
  animation: pulse 1.6s ease-in-out infinite;
}
.conn-badge.connected .dot { background: var(--green); }
.conn-badge.disconnected .dot { background: var(--red); animation: none; opacity: 0.6; }

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ═══════════════════════════════════════════════
   LAYOUT GRID
═══════════════════════════════════════════════ */
:root {
  --max-w: 1600px;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar-inner,
.statusbar-inner {
  max-width: var(--max-w);
  margin: 0 auto;
  width: 100%;
  display: contents;
}

.grid-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
}

.grid {
  flex: 1;
  max-width: var(--max-w);
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: minmax(180px, 2fr) auto auto;
  gap: var(--gap);
  padding: var(--gap);
  min-height: 0;
}

.panel-heatmap { grid-column: 2;      grid-row: 2; aspect-ratio: 4/3; }
.panel-cam-a   { grid-column: 1;      grid-row: 2; aspect-ratio: 4/3; }
.panel-cam-b   { grid-column: 1 / -1; grid-row: 1; }
.panel-floor   { grid-column: 1 / -1; grid-row: 3; aspect-ratio: 4/3; }

/* ═══════════════════════════════════════════════
   PANEL CHROME
═══════════════════════════════════════════════ */
.panel {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: var(--panel-r);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 8px;
  height: 24px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-title {
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 5px;
}

.live-indicator {
  width: 6px; height: 6px; border-radius: 50%;
  animation: pulse 1.4s ease-in-out infinite;
}
.live-indicator.green  { background: var(--green); }
.live-indicator.orange { background: var(--orange); animation-duration: 1.1s; }
.live-indicator.blue   { background: var(--accent); animation-duration: 1.8s; }
.live-indicator.off    { background: var(--text-dim); animation: none; }

.panel-header-sep { flex: 1; }

.tag {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.05em;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}
.tag-green  { background: rgba(34,197,94,0.12);  color: rgba(34,197,94,0.9);  border: 1px solid rgba(34,197,94,0.2); }
.tag-orange { background: rgba(249,115,22,0.12); color: rgba(249,115,22,0.9); border: 1px solid rgba(249,115,22,0.2); }
.tag-blue   { background: rgba(59,130,246,0.12); color: rgba(59,130,246,0.9); border: 1px solid rgba(59,130,246,0.2); }
.tag-dim    { background: rgba(255,255,255,0.04); color: var(--text-dim);     border: 1px solid var(--border); }
.tag-ws     { background: rgba(168,85,247,0.12); color: rgba(168,85,247,0.9); border: 1px solid rgba(168,85,247,0.2); }

.panel-body {
  flex: 1;
  display: flex;
  min-height: 0;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════
   HEATMAP PANEL
═══════════════════════════════════════════════ */
.heatmap-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 10px 10px;
  min-width: 0;
  gap: 6px;
}

#heatmap-canvas {
  flex: 1;
  width: 100%;
  display: block;
  border-radius: 6px;
  border: 1px solid var(--border);
  image-rendering: pixelated;
}

.heatmap-footer {
  display: flex;
  align-items: center;
  gap: 12px;
}
.legend-gradient {
  flex: 1;
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(to right,
    #00007f,
    #0000ff,
    #00ffff,
    #80ff80,
    #ffff00,
    #ff8000,
    #ff0000,
    #7f0000
  );
}
.legend-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.legend-ends {
  display: flex;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-dim);
}

.heatmap-stats {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 5px 6px;
  gap: 4px;
  border-left: 1px solid var(--border);
  min-width: 70px;
  width: 70px;
  flex-shrink: 0;
}

.hstat {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.hstat-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.hstat-val {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 500;
  color: var(--text-hi);
  line-height: 1;
}
.hstat-val.hot { color: var(--red); }
.hstat-val.sm  { font-size: 13px; }

/* ═══════════════════════════════════════════════
   CAMERA PANELS
═══════════════════════════════════════════════ */
.cam-feed {
  flex: 1;
  position: relative;
  background: #060a0f;
  overflow: hidden;
}

.cam-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.cam-overlay-tl,
.cam-overlay-tr,
.cam-overlay-bl,
.cam-overlay-br {
  position: absolute;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.06em;
  color: rgba(255,255,255,0.5);
  line-height: 1.6;
  pointer-events: none;
}
.cam-overlay-tl { top: 8px; left: 10px; }
.cam-overlay-tr { top: 8px; right: 10px; text-align: right; }
.cam-overlay-bl { bottom: 8px; left: 10px; }
.cam-overlay-br { bottom: 8px; right: 10px; text-align: right; }

.rec-dot {
  display: inline-block;
  width: 5px; height: 5px;
  background: var(--red);
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
  animation: pulse 0.8s ease-in-out infinite;
}

.cam-corners {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.cam-corners::before,
.cam-corners::after,
.cam-corners span::before,
.cam-corners span::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border-color: rgba(255,255,255,0.2);
  border-style: solid;
}
.cam-corners::before { top: 8px; left: 8px; border-width: 1px 0 0 1px; }
.cam-corners::after  { top: 8px; right: 8px; border-width: 1px 1px 0 0; }
.cam-corners span::before { bottom: 8px; left: 8px; border-width: 0 0 1px 1px; }
.cam-corners span::after  { bottom: 8px; right: 8px; border-width: 0 1px 1px 0; }

.cam-footer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.cam-chip {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-dim);
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  letter-spacing: 0.04em;
}
.cam-chip.active { color: var(--text); border-color: var(--border-hi); }
.cam-chip-sep { flex: 1; }
.fps-counter {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-dim);
  letter-spacing: 0.05em;
}

/* ═══════════════════════════════════════════════
   FLOORPLAN PANEL
═══════════════════════════════════════════════ */
.floorplan-main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#floorplan-img {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#floorplan-svg {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ═══════════════════════════════════════════════
   MQTT STATUS BAR
═══════════════════════════════════════════════ */
.statusbar {
  height: 18px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}

.statusbar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: var(--max-w);
  width: 100%;
  padding: 0 8px;
}
.statusbar-item {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 5px;
}
.statusbar-item span { color: var(--text); }
.statusbar-sep { flex: 1; }
