:root {
  --bg: #121011;
  --panel: rgba(24, 22, 23, 0.82);
  --line: rgba(255, 255, 255, 0.08);
  --text: #ecebea;
  --muted: #8e8a88;
  --red: #e5534b;
  --working: #4ade80;
  --idle: #d6d3d1;
  --sleeping: #7c8cff;
  --off: #57534e;
  --error: #e5534b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  background: radial-gradient(120% 90% at 50% 40%, #1d1a1b 0%, var(--bg) 60%, #0b0a0a 100%);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }
button { font: inherit; color: inherit; cursor: pointer; }

/* --- HUD haut --- */
.hud-top {
  position: fixed; top: 16px; left: 16px; right: 360px;
  display: flex; flex-direction: column; gap: 12px; pointer-events: none;
}
.ribbon {
  display: inline-block; background: var(--red); color: #fff;
  font-weight: 600; letter-spacing: 0.32em; font-size: 13px;
  padding: 7px 14px 7px 16px; border-radius: 3px;
}
.host { margin-top: 8px; font-size: 13px; color: var(--muted); display: flex; gap: 12px; }
.live { color: var(--working); }
.live.down { color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 13px; display: flex; align-items: center; gap: 7px;
  backdrop-filter: blur(10px);
}
.chip b { font-weight: 700; font-variant-numeric: tabular-nums; }
.chip i, .legend i, .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

.s-working { background: var(--working); box-shadow: 0 0 8px var(--working); }
.s-idle { background: var(--idle); }
.s-sleeping { background: var(--sleeping); }
.s-off { background: var(--off); }
.s-error { background: var(--error); box-shadow: 0 0 8px var(--error); }

/* --- Panneau equipe --- */
.panel {
  position: fixed; top: 16px; right: 16px; bottom: 16px; width: 328px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(14px); display: flex; flex-direction: column; overflow: hidden;
}
.panel-toggle { display: none; }
.panel-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.panel-head { padding: 16px 16px 10px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0 0 10px; font-size: 15px; font-weight: 700; }
.filters { display: flex; gap: 6px; }
.filters button {
  background: transparent; border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 10px; font-size: 12px; color: var(--muted);
}
.filters button.on { background: var(--red); border-color: var(--red); color: #fff; }
.list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.list li {
  display: grid; grid-template-columns: 10px 1fr auto; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.list li:hover, .list li.sel { background: rgba(255, 255, 255, 0.06); }
.list .nm { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .rl { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .cpu { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.list .warn { color: var(--red); font-weight: 700; margin-left: 4px; }
.list .grp { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; padding: 12px 10px 4px; cursor: default; display: block; }
.list .grp:hover { background: none; }

/* --- Fiche agent --- */
.detail {
  position: fixed; left: 16px; bottom: 64px; width: 400px; max-height: calc(100vh - 220px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(14px); padding: 16px; overflow-y: auto;
  transition: opacity 0.2s, transform 0.2s;
}
.detail.hidden { opacity: 0; transform: translateY(10px); pointer-events: none; }
.detail .close {
  position: absolute; top: 10px; right: 12px; background: none; border: 0;
  font-size: 22px; color: var(--muted);
}
.d-head { display: flex; gap: 12px; align-items: center; }
.d-dot { width: 12px; height: 12px; border-radius: 50%; }
.d-head h3 { margin: 0; font-size: 17px; }
.d-role { font-size: 12px; color: var(--muted); }
.d-status { margin: 12px 0 4px; font-size: 13px; }
.d-sec { margin: 14px 0 6px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.12em; }
.units { width: 100%; border-collapse: collapse; font-size: 12px; }
.units td { padding: 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.units td:last-child { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.units .bad { color: var(--red); }
.logs {
  font: 11px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; color: #c9c5c2;
  background: rgba(0, 0, 0, 0.35); border-radius: 8px; padding: 8px 10px;
  max-height: 200px; overflow-y: auto; white-space: pre-wrap; word-break: break-word;
}
.logs .t { color: var(--muted); }

/* --- Bas --- */
.hud-bottom {
  position: fixed; left: 16px; bottom: 16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  right: 360px;
}
.tog {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 12px; backdrop-filter: blur(10px);
}
.tog.on { border-color: var(--red); color: #fff; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-left: 8px; flex-wrap: wrap; }
.legend span { display: flex; align-items: center; gap: 6px; }

/* --- Etiquettes 3D --- */
.tag {
  font-size: 11px; font-weight: 600; color: #fff; white-space: nowrap;
  background: rgba(14, 12, 13, 0.85); border: 1px solid var(--line);
  padding: 3px 8px; border-radius: 999px; display: flex; align-items: center; gap: 5px;
  opacity: 0; transform: translateY(-4px); transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.tag .dot { width: 6px; height: 6px; }
body.show-names .tag, .tag.hover, .tag.sel, .tag.working { opacity: 1; transform: none; }
.tag.sel { border-color: var(--red); }
.badge {
  width: 18px; height: 18px; border-radius: 50%; background: var(--red); color: #fff;
  font-size: 12px; font-weight: 800; display: grid; place-items: center;
  box-shadow: 0 0 12px var(--red); animation: bob 1.2s ease-in-out infinite; pointer-events: none;
}
.zzz { color: var(--sleeping); font-weight: 800; font-size: 13px; animation: float 2.6s ease-in-out infinite; pointer-events: none; }
@keyframes bob { 50% { transform: translateY(-4px); } }
@keyframes float { 0% { opacity: 0; transform: translate(0, 4px); } 50% { opacity: 1; } 100% { opacity: 0; transform: translate(6px, -10px); } }

/* --- Mobile --- */
@media (max-width: 760px) {
  .hud-top { right: 16px; }
  .chip { padding: 4px 9px; font-size: 12px; }
  .panel { top: auto; left: 16px; right: 16px; width: auto; height: 46px; bottom: 16px; transition: height 0.25s; }
  .panel.open { height: 52vh; }
  .panel-toggle {
    display: block; background: none; border: 0; padding: 13px 16px; text-align: left;
    font-weight: 700; font-size: 14px; border-bottom: 1px solid var(--line);
  }
  .hud-bottom { bottom: 72px; right: 16px; }
  .legend { display: none; }
  .detail { left: 16px; right: 16px; width: auto; bottom: 72px; max-height: 50vh; z-index: 5; }
}
