:root {
  --bg: #e4e9ef; --scene-bg: #dfe5ec; --card: rgba(255,255,255,0.94); --card-solid: #fff; --ink: #1b1f24; --muted: #66707c;
  --line: rgba(20,30,40,0.12); --accent: #2F6BFF; --shadow: 0 6px 24px rgba(20,30,50,0.14);
  --test: #b0369d; --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0d1116; --scene-bg: #10151b; --card: rgba(24,29,36,0.94); --card-solid: #1a1f26; --ink: #e8ebef; --muted: #98a2ae;
  --line: rgba(255,255,255,0.1); --shadow: 0 6px 24px rgba(0,0,0,0.5); color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1116; --scene-bg: #10151b; --card: rgba(24,29,36,0.94); --card-solid: #1a1f26; --ink: #e8ebef; --muted: #98a2ae;
    --line: rgba(255,255,255,0.1); --shadow: 0 6px 24px rgba(0,0,0,0.5); color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: var(--ink); background: var(--card-solid); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--accent); }
button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: 12px; }
.tag-test { display: inline-block; background: var(--test); color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; margin-left: 5px; vertical-align: middle; letter-spacing: .03em; }

/* top bar */
#bar { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; align-items: center; gap: 10px; z-index: 20; pointer-events: none; }
#bar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 8px; background: var(--card); padding: 7px 12px; border-radius: var(--radius); box-shadow: var(--shadow); white-space: nowrap; }
.brand .logo { width: 18px; height: 18px; border-radius: 5px; background: var(--accent); }
.brand .sub { color: var(--muted); }
.live { color: #9aa3ad; font-size: 12px; } .live.on { color: #1fa463; }
#tools { display: flex; gap: 6px; align-items: center; background: var(--card); padding: 6px; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; scrollbar-width: none; margin-left: auto; }
#tools::-webkit-scrollbar { display: none; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; border-radius: 0; padding: 6px 8px; }
.needs .count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #8a9099; color: #fff; font-size: 12px; text-align: center; }
.needs.has .count { background: #f0a500; } .needs.alert .count { background: #e03b3b; }
.needs.alert { border-color: #e03b3b; }
.only-mobile { display: none; }

#testbar, #empty, #offline { position: absolute; left: 50%; transform: translateX(-50%); top: 64px; z-index: 19; background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); padding: 8px 12px; display: flex; gap: 10px; align-items: center; max-width: calc(100% - 20px); }
#testbar { border-left: 4px solid var(--test); }
#empty { top: auto; bottom: 60px; color: var(--muted); text-align: center; }
#offline { top: 110px; border-left: 4px solid #e03b3b; }
#loading { position: absolute; inset: 0; display: grid; place-items: center; font-size: 16px; color: var(--muted); background: var(--bg); z-index: 50; }

/* connections row */
#connections { position: absolute; left: 10px; bottom: 10px; z-index: 18; display: flex; align-items: center; gap: 8px; background: var(--card); box-shadow: var(--shadow); padding: 6px 10px; border-radius: var(--radius); max-width: calc(100% - 20px); overflow-x: auto; }
#connections .chips { display: flex; gap: 6px; }
.chip { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; background: var(--c); opacity: .75; transition: box-shadow .3s, opacity .3s; flex: none; }
.chip.active { opacity: 1; box-shadow: 0 0 0 3px #ffd34d, 0 0 16px 4px rgba(255, 211, 77, .85); animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px #ffd34d, 0 0 6px 1px rgba(255, 211, 77, .5); } }

/* floating labels */
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
#labels[data-mode="clean"] { display: none; }
.label { position: absolute; left: 0; top: 0; transform-origin: 50% 100%; will-change: transform; pointer-events: none; }
.label.clickable { pointer-events: auto; cursor: pointer; }
.agent-label { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.agent-label .bubble { background: var(--card-solid); color: var(--ink); border-radius: 10px; padding: 4px 8px; font-size: 12px; max-width: 190px; box-shadow: var(--shadow); position: relative; text-align: center; border: 1px solid var(--line); }
.agent-label .bubble:after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: var(--card-solid); }
.agent-label .bubble .t { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 174px; }
.agent-label .bubble .s { font-size: 10px; color: var(--muted); }
.agent-label .bubble:empty { display: none; }
#labels[data-mode="pro"] .bubble, #labels[data-mode="pro"] .sign-label { display: none; }
.name-tag { background: rgba(20,24,30,0.82); color: #fff; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.name-tag i { width: 8px; height: 8px; border-radius: 50%; background: var(--c, #8a9099); display: inline-block; }
.place-label { background: rgba(20,24,30,0.7); color: #fff; padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; letter-spacing: .04em; }
.sign-label { background: var(--card-solid); border-top: 4px solid var(--c); border-radius: 10px; box-shadow: var(--shadow); padding: 8px 10px; min-width: 200px; font-size: 12px; }
.sign-label h4 { margin: 0; font-size: 14px; display: flex; justify-content: space-between; gap: 10px; }
.sign-label .ms { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0; }
.sign-label .ms div { text-align: center; } .sign-label .ms b { display: block; font-size: 14px; }
.sign-label .st { display: flex; justify-content: space-between; gap: 6px; color: var(--muted); }
.sign-label .st b { color: var(--ink); }

/* side panel */
#panel { position: absolute; top: 64px; right: 10px; bottom: 10px; width: min(380px, calc(100% - 20px)); background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); z-index: 30; display: flex; flex-direction: column; backdrop-filter: blur(8px); }
#panel[hidden], #board[hidden] { display: none; }
#panel .close, #board .close { position: absolute; top: 8px; right: 8px; width: 32px; height: 32px; padding: 0; font-size: 20px; line-height: 1; border-radius: 50%; z-index: 2; }
#panel .content { overflow-y: auto; padding: 14px 16px 18px; }
#panel header { display: flex; gap: 10px; align-items: center; margin-right: 34px; }
#panel header .dot { width: 14px; height: 40px; border-radius: 6px; background: var(--c); flex: none; }
#panel h2 { margin: 0; font-size: 18px; }
#panel h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.count { color: var(--muted); font-weight: 400; }
.row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; } .row.gap { gap: 8px; margin-top: 10px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; color: #fff; background: var(--c); white-space: nowrap; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.card p { margin: 6px 0; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 7px 0; border-bottom: 1px solid var(--line); }
.list li.task { cursor: pointer; }
.list li.need-warning { border-left: 3px solid #e03b3b; padding-left: 8px; }
.list li.need-waiting { border-left: 3px solid #f0a500; padding-left: 8px; }
.agents { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.agents li { display: flex; align-items: center; gap: 6px; padding: 5px 6px; border-radius: 8px; cursor: pointer; border: 1px solid var(--line); }
.agents .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 6px; }
.metric { border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.metric .v { font-size: 18px; font-weight: 700; } .metric .k { color: var(--muted); font-size: 12px; }
.sub { margin: 8px 0 4px; cursor: pointer; }

/* task board */
#board { position: absolute; inset: 64px 10px 10px; background: var(--card); box-shadow: var(--shadow); border-radius: var(--radius); z-index: 29; display: flex; flex-direction: column; padding: 12px; backdrop-filter: blur(8px); }
.board-head { display: flex; align-items: baseline; gap: 12px; margin-right: 40px; }
.board-head h2 { margin: 0 0 8px; font-size: 18px; }
.cols { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 10px; overflow: auto; }
.col { background: rgba(127,127,127,0.08); border-radius: 10px; padding: 8px; overflow-y: auto; }
.col h3 { margin: 2px 4px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; }
.bcard { background: var(--card-solid); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; border-left: 4px solid var(--c); box-shadow: 0 1px 3px rgba(0,0,0,.08); cursor: pointer; }
.bcard.bad { outline: 2px solid #e03b3b; }

@media (max-width: 760px) {
  .brand .sub { display: none; }
  .only-mobile { display: block; margin-left: auto; }
  #tools { display: none; position: absolute; top: 48px; right: 0; left: 0; flex-wrap: wrap; overflow: visible; }
  #bar.open #tools { display: flex; }
  #panel { top: auto; left: 0; right: 0; bottom: 0; width: 100%; max-height: 62%; border-radius: 16px 16px 0 0; }
  #board { inset: 56px 0 0; border-radius: 0; }
  .cols { grid-template-columns: repeat(4, 80vw); }
  #testbar { top: 58px; font-size: 12px; padding: 5px 8px; white-space: nowrap; }
  #testbar button { padding: 4px 8px; }
  #connections span.muted { display: none; }
  .agent-label .bubble { max-width: 130px; font-size: 11px; } .agent-label .bubble .t { max-width: 116px; }
  .sign-label { min-width: 160px; }
}
