:root {
  --bg: #0f1020;
  --bg-elev: #181a2e;
  --panel: #202442;
  --panel-2: #2a2f54;
  --line: #46508f;
  --text: #eef2ff;
  --muted: #aab4de;
  --ok: #5ee27a;
  --warn: #ffd166;
  --bad: #ff6b6b;
  --info: #71c7ff;
  --accent: #a78bfa;
  --shadow: rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  background: linear-gradient(180deg, #0b0c18 0%, var(--bg) 100%);
  color: var(--text);
}

.app-shell { min-height: 100vh; padding: 20px; }
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
  margin-bottom: 20px;
}
.eyebrow { color: var(--muted); text-transform: uppercase; letter-spacing: .18em; font-size: 12px; }
h1 { margin: 6px 0 0; font-size: 32px; }
.topbar-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.view-root { display: grid; gap: 20px; }
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01)), var(--panel);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px var(--shadow);
  border-radius: 16px;
  padding: 16px;
}
.loading-panel { min-height: 220px; display: grid; place-items: center; }
.muted { color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px;
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; border: 1px solid currentColor;
}
.pill-neutral { color: var(--muted); }
.pill-ok { color: var(--ok); }
.pill-warn { color: var(--warn); }
.pill-bad { color: var(--bad); }
.pill-info { color: var(--info); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.link-button, .back-button {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 10px 12px; border-radius: 10px; text-decoration: none; cursor: pointer;
}
.link-button:hover, .back-button:hover { filter: brightness(1.08); }

.corridor {
  position: relative; overflow: hidden; min-height: 420px;
  background: linear-gradient(180deg, #191c35 0%, #15182c 52%, #0f1324 52%, #12172b 100%);
}
.corridor::before {
  content: ""; position: absolute; inset: 48% 0 auto 0; height: 5px; background: rgba(255,255,255,0.08);
}
.door-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; margin-top: 20px; }
.door-card {
  display: block; color: inherit; text-decoration: none; padding: 16px; border-radius: 14px;
  border: 1px solid var(--line); background: rgba(13, 16, 32, 0.54);
}
.door-card:hover { transform: translateY(-2px); transition: .18s ease; }
.door {
  height: 210px; border-radius: 12px 12px 8px 8px; position: relative; margin-bottom: 14px;
  border: 4px solid #5d4a34; background: linear-gradient(180deg, #6f5538, #4d3928);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,0.06);
}
.door::before {
  content: ""; position: absolute; inset: 18px 20px 42px; border: 3px solid rgba(255,255,255,0.08); border-radius: 8px;
}
.door::after {
  content: ""; width: 12px; height: 12px; border-radius: 999px; background: #f9d56e;
  position: absolute; right: 26px; top: 100px; box-shadow: 0 0 12px rgba(249,213,110,0.5);
}
.door-topline { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.door-title { font-size: 18px; font-weight: 700; }
.door-subtitle { color: var(--muted); font-size: 13px; }
.badge-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.badge {
  padding: 6px 8px; border-radius: 8px; background: rgba(255,255,255,0.05); color: var(--text); font-size: 12px;
  border: 1px solid rgba(255,255,255,0.08);
}

.room-layout { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.room-scene {
  min-height: 520px; position: relative;
  background: linear-gradient(180deg, #212541 0%, #1f2640 58%, #171d33 58%, #0f1427 100%);
  overflow: hidden;
}
.room-scene::before {
  content: ""; position: absolute; inset: 0; background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}
.agent-grid {
  position: relative; z-index: 1; display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)); gap: 18px;
}
.agent-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: rgba(11, 15, 32, 0.56);
}
.agent-card.active { outline: 2px solid var(--accent); box-shadow: 0 0 0 4px rgba(167,139,250,.16); }
.agent-card.failed { outline: 2px solid var(--bad); }
.agent-avatar {
  width: 72px; height: 72px; border-radius: 12px; margin-bottom: 12px; border: 3px solid rgba(255,255,255,0.12);
  background: linear-gradient(180deg, #7c8cff, #4656a8);
  position: relative;
}
.agent-avatar::before, .agent-avatar::after {
  content: ""; position: absolute; background: #0a0d19;
}
.agent-avatar::before { width: 34px; height: 14px; top: 16px; left: 18px; border-radius: 10px; }
.agent-avatar::after { width: 26px; height: 8px; top: 42px; left: 22px; border-radius: 4px; }
.agent-name { font-weight: 700; margin-bottom: 6px; }
.agent-meta { color: var(--muted); font-size: 13px; }
.progress-bar {
  margin-top: 10px; height: 8px; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.08);
}
.progress-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--info), var(--accent)); }
.side-stack { display: grid; gap: 16px; }
.key-value { display: grid; grid-template-columns: 110px 1fr; gap: 8px; font-size: 14px; }
.job-list { display: grid; gap: 10px; }
.job-item { border: 1px solid rgba(255,255,255,.08); border-radius: 10px; padding: 10px; background: rgba(255,255,255,.02); }
.empty-state { color: var(--muted); }

.scene-floor-line {
  position: absolute; left: 0; right: 0; bottom: 122px; height: 6px; background: rgba(255,255,255,0.08);
}
.scene-label {
  position: absolute; right: 16px; bottom: 16px; z-index: 1; color: var(--muted); font-size: 12px; letter-spacing: .12em; text-transform: uppercase;
}
.agent-state-pill {
  display: inline-flex; margin-top: 8px; padding: 4px 8px; border-radius: 999px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  border: 1px solid rgba(255,255,255,0.12);
}
.agent-state-pill.working { color: var(--info); }
.agent-state-pill.waiting { color: var(--warn); }
.agent-state-pill.done { color: var(--ok); }
.agent-state-pill.failed { color: var(--bad); }
.agent-state-pill.idle { color: var(--muted); }
.agent-drawer {
  position: fixed; top: 20px; right: 20px; width: min(360px, calc(100vw - 40px)); max-height: calc(100vh - 40px); overflow: auto;
  background: linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.02)), var(--panel);
  border: 1px solid var(--line); box-shadow: 0 18px 40px var(--shadow); border-radius: 16px; padding: 16px; z-index: 30;
}
.agent-drawer.hidden { display: none; }
.agent-drawer-close {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 8px 10px; cursor: pointer;
}
.agent-drawer-header { display: flex; justify-content: space-between; align-items: start; gap: 12px; margin-bottom: 12px; }
.agent-drawer h3 { margin: 0; }
.agent-card { cursor: pointer; }

@media (max-width: 980px) {
  .room-layout { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .agent-grid, .door-grid { grid-template-columns: 1fr; }
  .agent-drawer { left: 20px; right: 20px; width: auto; }
}
