:root {
  --bg: #f3f4f7; --panel: #ffffff; --ink: #161a22; --muted: #667085; --line: #e3e6ec;
  --floor-bg: #2a3140; --accent: #4f8cff; --ok: #1fae6a; --warn: #d99a00; --bad: #d64545; --chip: #eef1f6;
  --shadow: 0 10px 30px rgba(16, 24, 40, .14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --panel: #1a1e28; --ink: #e9edf4; --muted: #98a2b3; --line: #2a3040;
    --floor-bg: #1b202b; --chip: #252b38; --shadow: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --panel: #1a1e28; --ink: #e9edf4; --muted: #98a2b3; --line: #2a3040;
  --floor-bg: #1b202b; --chip: #252b38; --shadow: 0 10px 30px rgba(0, 0, 0, .45); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, system-ui, sans-serif; display: flex; flex-direction: column; overflow: hidden; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12px; } .grow { flex: 1; min-width: 0; }

.top { display: flex; align-items: center; gap: 14px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: #1b1f2a; color: #eef2f8; flex-wrap: wrap; }
.brand { font: 16px Silkscreen, monospace; letter-spacing: 1px; white-space: nowrap; }
.brand span { color: #ffd166; }
.brand.big { font-size: 26px; color: var(--ink); margin-bottom: 8px; }
.hosts { display: flex; gap: 6px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12px; background: rgba(255,255,255,.08); }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: #6b7280; }
.pill.on i { background: #3ddc84; box-shadow: 0 0 6px #3ddc84; }
.counters { display: flex; gap: 12px; font-size: 12px; color: #b9c2d3; flex: 1; }
.counters b { color: #fff; font-size: 14px; }
.counters .warn b { color: #ffd166; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn { font: 500 13px Inter, sans-serif; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 11px; border-radius: 8px; cursor: pointer; }
.top .btn { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.14); color: #eef2f8; }
.btn:hover { filter: brightness(1.08); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--bad); color: var(--bad); }
.btn.icon { width: 34px; height: 34px; padding: 0; font-size: 18px; line-height: 1; }
.btn.small { padding: 3px 8px; font-size: 12px; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: #ffd166; color: #1b1f2a; font-size: 11px; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.demo { background: #ffd166; color: #3a2c00; font-size: 12px; padding: 4px 16px; }
.fatal { position: fixed; inset: auto 16px 16px; padding: 12px; background: var(--bad); color: #fff; border-radius: 8px; }

main { flex: 1; position: relative; min-height: 0; }
.floor { position: absolute; inset: 0; background: var(--floor-bg); }
.floor canvas { display: block; touch-action: none; }
.stage { position: absolute; inset: 0; overflow: hidden; }
.mode-switch { position: absolute; left: 14px; top: 12px; display: flex; background: rgba(15,18,26,.85); border-radius: 9px; padding: 3px; gap: 2px; z-index: 5; }
.labels3d { z-index: 1; }
.mode-switch button { border: 0; background: none; color: #b9c2d3; font: 600 13px Inter, sans-serif; padding: 6px 14px; border-radius: 7px; cursor: pointer; }
.mode-switch button.on { background: #4f8cff; color: #fff; }
.hint { position: absolute; left: 14px; bottom: max(12px, env(safe-area-inset-bottom)); color: #c9d2e0; background: rgba(15,18,26,.7); font-size: 12px; padding: 5px 10px; border-radius: 8px; pointer-events: none; }
.loading { position: absolute; inset: 0; display: grid; place-items: center; color: #dfe6f1; font: 600 15px "Pixelify Sans", sans-serif; background: var(--floor-bg); }
.floor-tools { z-index: 2; }

/* 3D labels */
.labels3d { overflow: hidden; }
.tag3d { display: flex; flex-direction: column; align-items: center; gap: 3px; pointer-events: none; font-family: Inter, sans-serif; }
.tag3d .nm { display: flex; align-items: center; gap: 5px; background: rgba(15,18,26,.86); color: #fff; font: 600 12px Inter, sans-serif; padding: 2px 8px 2px 6px; border-radius: 99px; white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.tag3d .nm i { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; flex: none; }
.tag3d.working .nm i { background: #38bdf8; box-shadow: 0 0 6px #38bdf8; } .tag3d.waiting .nm i { background: #ffd166; } .tag3d.error .nm i { background: #ff5d5d; }
.tag3d.offline .nm i, .tag3d.external .nm i { background: #8b93a1; } .tag3d.offline .nm { opacity: .75; }
.tag3d .sk { display: none; flex-wrap: wrap; justify-content: center; gap: 3px; max-width: 220px; }
.tag3d.near .sk { display: flex; }
.tag3d .sk b { font: 500 10.5px Inter, sans-serif; background: rgba(232,238,248,.92); color: #1d2533; padding: 1px 6px; border-radius: 5px; white-space: nowrap; }
.tag3d .sk b.more { background: rgba(15,18,26,.75); color: #c9d2e0; }
.tag3d.small .nm { font-size: 10px; padding: 1px 6px 1px 4px; }
.tag3d.far .nm { padding: 2px; background: rgba(15,18,26,.7); }
.tag3d.far .nm span { display: none; }
.tag3d.far.near .nm span { display: inline; }
.bubble3d { pointer-events: auto; cursor: pointer; }
.bubble3d .bw { position: relative; margin-bottom: 8px; width: max-content; max-width: 240px; background: #ffffff; color: #172033; border-radius: 10px; padding: 7px 10px; box-shadow: 0 6px 18px rgba(0,0,0,.35); border-left: 4px solid #38bdf8; font: 12px/1.35 Inter, sans-serif; }
.bubble3d .bw::after { content: ''; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fff; }
.bubble3d .bt { font-weight: 700; display: flex; align-items: center; gap: 6px; color: #0b72b9; }
.bubble3d .bt .el { margin-left: auto; font-variant-numeric: tabular-nums; color: #5b6578; font-weight: 600; }
.bubble3d .bk { margin-top: 2px; }
.bubble3d .bl { margin-top: 3px; font: 11px ui-monospace, Consolas, monospace; color: #4a5568; background: #eef3f9; border-radius: 5px; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bubble3d .bc { margin-top: 4px; font-weight: 600; color: #9a6a00; }
.bubble3d.waiting .bw { border-left-color: #f5b830; animation: nudge 1.4s ease-in-out infinite; } .bubble3d.waiting .bt { color: #9a6a00; }
.bubble3d.error .bw { border-left-color: #ff5d5d; } .bubble3d.error .bt { color: #c53030; }
.bubble3d.far .bk, .bubble3d.far .bl, .bubble3d.far .bc { display: none; }
.bubble3d .spin { width: 10px; height: 10px; border: 2px solid #38bdf8; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes nudge { 50% { transform: translateY(-4px); } }
.sign3d { pointer-events: none; white-space: nowrap; }
.sign3d.room { background: rgba(15,18,26,.82); color: #fff; font: 600 13px "Pixelify Sans", sans-serif; padding: 3px 10px; border-radius: 6px; border-bottom: 3px solid var(--c); }
.sign3d.room span { color: #b9c2d3; font-size: 11px; margin-left: 4px; }
.sign3d.building { background: #1b1f2a; color: #fff; font: 15px Silkscreen, monospace; padding: 5px 12px; border-radius: 8px; letter-spacing: 1px; }
.sign3d.building em { font: 600 11px Inter, sans-serif; color: #9ca3af; font-style: normal; margin-left: 6px; }
.sign3d.building.on em { color: #3ddc84; }
.mode2d .sign3d.room { font-size: 11px; }
.floor-tools { position: absolute; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 6px; }
.tooltip { position: absolute; max-width: 270px; padding: 8px 10px; background: rgba(15,18,26,.94); color: #eef2f8; border-radius: 8px; font-size: 12px; pointer-events: none; }
.tooltip span { color: #b9c2d3; }

.list { position: absolute; inset: 0; overflow: auto; padding: 16px; padding-bottom: 40px; }
.bld { max-width: 980px; margin: 0 auto 22px; }
.bld h2 { font: 18px Silkscreen, monospace; display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; }
.bld h2 .pill { background: var(--chip); font-family: Inter, sans-serif; }
.room { border-left: 4px solid var(--c); background: var(--panel); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; box-shadow: var(--shadow); }
.room h3 { font: 600 15px "Pixelify Sans", sans-serif; margin: 0 0 6px; }
.card { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: none; color: inherit; padding: 10px 2px; cursor: pointer; font: inherit; }
.card:first-of-type { border-top: 0; }
.card .nm { display: block; font-weight: 600; }
.card .nm em { font-style: normal; font-size: 11px; color: #b58900; margin-left: 4px; }
.card .rl { display: block; color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.av { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 8px; background: var(--c); color: #fff; font: 13px Silkscreen, monospace; flex: none; image-rendering: pixelated; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--chip); border-radius: 6px; padding: 1px 7px; font-size: 11.5px; }
.chip.none, .chip.more { color: var(--muted); }
.st { font-size: 11.5px; white-space: nowrap; padding: 1px 7px; border-radius: 6px; background: var(--chip); }
.st.idle { color: var(--ok); } .st.working { color: #0ea5e9; } .st.waiting { color: var(--warn); } .st.error { color: var(--bad); } .st.offline, .st.external { color: var(--muted); }

.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(440px, 100vw); background: var(--panel); box-shadow: var(--shadow); display: flex; flex-direction: column; z-index: 20; padding-top: env(safe-area-inset-top); }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer-head .av { width: 42px; height: 42px; }
.d-name { font: 600 17px "Pixelify Sans", sans-serif; }
.drawer-body { flex: 1; overflow: auto; padding: 12px 16px; }
.d-role { margin: 0 0 10px; }
.facts { display: grid; grid-template-columns: 88px 1fr; gap: 4px 10px; font-size: 12.5px; margin: 14px 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; }
.chat-head { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 10px; }
.chat-head h3 { margin: 0; font-size: 14px; }
.chat { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; }
.msg { padding: 8px 10px; border-radius: 10px; white-space: pre-wrap; word-break: break-word; max-width: 92%; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--chip); }
.msg.tool, .msg.status, .msg.system { align-self: flex-start; background: none; color: var(--muted); font-size: 12px; padding: 2px 4px; }
.typing span { animation: blink 1.2s infinite; } .typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .2; } }
.chat-form { display: flex; gap: 8px; padding: 10px 16px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 8px; padding: 8px; font: inherit; }

.panel { position: fixed; inset: 0; background: rgba(10, 12, 18, .5); display: grid; place-items: center; z-index: 30; padding: 16px; }
.panel-card { background: var(--panel); border-radius: 14px; width: min(980px, 100%); max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font: 600 18px "Pixelify Sans", sans-serif; }
.panel-body { overflow: auto; padding: 14px 16px; }
.board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.col h3 { margin: 0 0 8px; font-size: 13px; }
.task { display: block; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--bg); color: inherit; border-radius: 8px; padding: 8px; margin-bottom: 6px; cursor: pointer; font: inherit; }
.task span { display: block; font-size: 12px; color: var(--muted); margin: 2px 0; }
.task em { font-style: normal; font-size: 11px; color: #b58900; }
.appr { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.appr pre { margin: 0; white-space: pre-wrap; word-break: break-word; background: var(--bg); padding: 8px; border-radius: 6px; font-size: 12px; }
.appr input, .appr select { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 6px; padding: 6px; font: inherit; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

.login { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; padding: 16px; }
.login-card { background: var(--panel); padding: 24px; border-radius: 14px; box-shadow: var(--shadow); width: min(380px, 100%); display: flex; flex-direction: column; gap: 10px; }
.login-card input { border: 1px solid var(--line); background: var(--bg); color: var(--ink); border-radius: 8px; padding: 10px; font: inherit; }

@media (max-width: 720px) {
  .top { gap: 8px; padding: 8px 16px; }
  .counters { order: 3; flex-basis: 100%; }
  .board { grid-template-columns: 1fr; }
  .list { padding: 12px 16px; }
  .panel { padding: 0; } .panel-card { max-height: 100vh; height: 100%; border-radius: 0; }
}

/* agents side panel */
.apanel { position: absolute; left: 14px; top: 56px; bottom: 54px; width: 270px; z-index: 4; display: flex; flex-direction: column; background: rgba(17,21,30,.9); color: #e8edf5; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); backdrop-filter: blur(6px); overflow: hidden; }
.apanel.closed { bottom: auto; width: auto; }
.apanel.closed .apanel-body { display: none; }
.apanel-toggle { border: 0; background: rgba(255,255,255,.05); color: #fff; font: 600 13px Inter, sans-serif; text-align: left; padding: 9px 12px; cursor: pointer; display: flex; gap: 8px; align-items: center; }
.apanel-toggle span { color: #98a2b3; font-weight: 500; font-size: 12px; }
.apanel-body { overflow: auto; padding: 4px 6px 10px; }
.ap-b { font: 12px Silkscreen, monospace; color: #ffd166; margin: 10px 6px 2px; letter-spacing: 1px; }
.ap-t { font: 600 12px "Pixelify Sans", sans-serif; color: #c9d2e0; margin: 6px 6px 2px; padding-left: 7px; border-left: 3px solid var(--c); }
.ap-a { display: grid; grid-template-columns: 12px 1fr; column-gap: 7px; width: 100%; text-align: left; border: 0; background: none; color: inherit; padding: 5px 6px; border-radius: 7px; cursor: pointer; font: inherit; }
.ap-a:hover, .ap-a.sel { background: rgba(79,140,255,.18); }
.ap-a .d { grid-row: span 2; width: 9px; height: 9px; border-radius: 50%; margin-top: 4px; background: #3ddc84; }
.ap-a .d.working { background: #38bdf8; box-shadow: 0 0 6px #38bdf8; } .ap-a .d.waiting { background: #ffd166; } .ap-a .d.error { background: #ff5d5d; } .ap-a .d.offline, .ap-a .d.external { background: #6b7280; }
.ap-a .n { font: 600 12.5px Inter, sans-serif; }
.ap-a .w { font-size: 11.5px; color: #98a2b3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.floor .mode-switch { left: auto; right: 14px; }
@media (max-width: 720px) { .apanel { width: calc(100% - 28px); } }
