:root {
  --bg: #0b1220;
  --room-bg: #05080f;
  --panel: #172233;
  --panel-2: #1f2d42;
  --title-a: #2b6ca3;
  --title-b: #1d4f7c;
  --border: #070b14;
  --text: #e8eef7;
  --muted: #8ea0b8;
  --green: #4caf3b;
  --green-d: #2f7d22;
  --red: #c9423a;
  --pixel: 'Silkscreen', ui-monospace, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
code { background: #0c1422; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px;
  background: linear-gradient(#22344d, #16233a);
  border-bottom: 2px solid var(--border);
  box-shadow: inset 0 -1px 0 #2f4766;
}
.logo { display: flex; align-items: center; gap: 10px; font-family: var(--pixel); font-size: 18px; letter-spacing: 1px; white-space: nowrap; }
.logo-mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  background: #f7c331; color: #3a2400; border: 2px solid var(--border); border-radius: 6px;
  font-size: 13px; box-shadow: inset 0 -3px 0 #c99412;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px;
  background: #0e1726; border: 1px solid #2a3b55; font-size: 12px; color: var(--muted);
}
.chip b { color: var(--text); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.btn {
  padding: 6px 12px; border-radius: 6px;
  background: linear-gradient(#3a5578, #2a4060); border: 2px solid var(--border);
  box-shadow: inset 0 1px 0 #5b7aa3; font-weight: 600; white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn-green { background: linear-gradient(#5fc24c, var(--green-d)); box-shadow: inset 0 1px 0 #8fe07e; }
.btn-red { background: linear-gradient(#e0564d, #9e2c25); box-shadow: inset 0 1px 0 #f08a83; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.on { background: linear-gradient(#f7c331, #c99412); color: #3a2400; box-shadow: inset 0 1px 0 #ffe08a; }
.conn { color: #c9423a; font-size: 14px; }
.conn.ok { color: #5fdd7a; }

/* ---------- layout ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 360px; min-height: 0; }
.stage { position: relative; background: radial-gradient(ellipse at 50% 40%, #0d1626, var(--room-bg) 70%); min-height: 0; overflow: hidden; }
#room { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.room-label {
  position: absolute; left: 12px; bottom: 12px;
  padding: 5px 10px; border-radius: 6px; background: rgba(0,0,0,.55); border: 1px solid #2a3b55;
  font-family: var(--pixel); font-size: 11px; color: var(--muted);
}
.empty {
  position: absolute; left: 50%; bottom: 56px; transform: translateX(-50%);
  text-align: center; color: var(--muted); background: rgba(0,0,0,.5); padding: 8px 16px; border-radius: 8px; border: 1px solid #2a3b55;
}
.empty p { margin: 2px 0; }

/* ---------- side panels ---------- */
.side { display: flex; flex-direction: column; gap: 10px; padding: 10px; background: #0e1726; border-left: 2px solid var(--border); min-height: 0; }
.panel { background: var(--panel); border: 2px solid var(--border); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 2px 0 #000a; }
.panel.grow { flex: 1; min-height: 0; }
.panel-title {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: linear-gradient(var(--title-a), var(--title-b));
  border-bottom: 2px solid var(--border); font-family: var(--pixel); font-size: 12px; letter-spacing: .5px;
}
.panel-title .count { margin-left: auto; background: #0008; padding: 0 7px; border-radius: 999px; font-size: 11px; }
.x { margin-left: auto; background: #c9423a; border: 2px solid var(--border); border-radius: 4px; width: 20px; height: 20px; line-height: 12px; padding: 0; font-weight: 700; }
.panel-body { padding: 10px; }
.list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.list .none { color: var(--muted); text-align: center; padding: 20px 0; }

.card {
  display: grid; grid-template-columns: 44px 1fr; gap: 8px; align-items: center;
  padding: 6px; border-radius: 6px; background: var(--panel-2); border: 1px solid #2a3b55; text-align: left; width: 100%;
}
.card:hover { border-color: #4a6a92; }
.card.sel { border-color: #f7c331; box-shadow: 0 0 0 1px #f7c331; }
.portrait { width: 44px; height: 44px; border-radius: 6px; background: #0c1422; image-rendering: pixelated; }
.portrait.big { width: 64px; height: 64px; }
.card-top { display: flex; align-items: center; gap: 6px; }
.card-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-time { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.card-msg { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: #0c1422; white-space: nowrap; }

.d-head { display: flex; gap: 10px; align-items: center; }
.d-name { font-size: 16px; font-weight: 700; }
.d-id { color: var(--muted); font-size: 11px; margin-top: 3px; word-break: break-all; }
.d-task { margin: 10px 0 0; color: var(--text); background: #0c1422; padding: 6px 8px; border-radius: 6px; font-size: 12px; }
.d-task:empty { display: none; }
.d-sub { margin: 10px 0 4px; font-family: var(--pixel); font-size: 10px; color: var(--muted); }
.log { list-style: none; margin: 0 0 10px; padding: 0; max-height: 190px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; }
.log li { display: grid; grid-template-columns: 52px 10px 1fr; gap: 6px; align-items: baseline; font-size: 12px; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.log .dot { align-self: center; }

/* ---------- help dialog ---------- */
dialog { padding: 0; border: 2px solid var(--border); border-radius: 8px; background: var(--panel); color: var(--text); width: min(620px, calc(100vw - 32px)); }
dialog::backdrop { background: #000a; }
.help p { margin: 0 0 10px; }
.help pre { background: #0c1422; padding: 10px; border-radius: 6px; overflow-x: auto; font-size: 12px; margin: 0 0 10px; }

/* ---------- mobiel ---------- */
@media (max-width: 860px) {
  body { overflow: auto; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .chips { order: 3; flex-basis: 100%; }
  .layout { grid-template-columns: 1fr; }
  .stage { height: 62vh; }
  .side { border-left: 0; border-top: 2px solid var(--border); }
}

/* ---------- v0.2: kamers, inbox, details ---------- */
.rooms {
  position: absolute; z-index: 2; left: 12px; top: 12px; right: 12px;
  display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none;
}
.room-tab {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 6px; border: 2px solid var(--border);
  background: linear-gradient(#2a3d58, #1f2e44); box-shadow: inset 0 1px 0 #44608a; font-weight: 600; font-size: 12px;
}
.room-tab:hover { filter: brightness(1.15); }
.room-tab.active { background: linear-gradient(#f7c331, #c99412); color: #3a2400; box-shadow: inset 0 1px 0 #ffe08a; }
.room-tab .n { background: #0006; color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; }
.room-tab.active .n { background: #3a240033; color: #3a2400; }
.room-tab .badge { background: #ffd23f; color: #3a2c00; border: 1px solid #3a2c00; border-radius: 999px; padding: 0 6px; font-size: 11px; font-weight: 800; }
.room-tab.add { padding: 5px 11px; }
.room-form { position: absolute; z-index: 3; left: 12px; top: 52px; display: flex; gap: 6px; background: var(--panel); border: 2px solid var(--border); border-radius: 8px; padding: 6px; }
.room-form input, .apr input, .apr textarea {
  background: #0c1422; color: var(--text); border: 1px solid #2a3b55; border-radius: 6px; padding: 6px 8px; font: inherit;
}
.room-form input:focus, .apr input:focus, .apr textarea:focus { outline: 2px solid #4fc3ff; outline-offset: 0; }

.coin { display: inline-grid; place-items: center; width: 14px; height: 14px; border-radius: 50%; background: #f7c331; color: #3a2400; font-size: 9px; font-weight: 800; }
.count.warn { background: #ffd23f; color: #3a2c00; }

.inbox { border-color: #8a6a00; box-shadow: 0 0 0 1px #ffd23f55, 0 2px 0 #000a; flex-shrink: 0; }
.inbox .panel-title { background: linear-gradient(#c99412, #8a6400); color: #fff; }
.inbox-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; }
.apr { background: var(--panel-2); border: 1px solid #5a4a16; border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.apr-head { display: grid; grid-template-columns: 32px 1fr auto; gap: 8px; align-items: start; }
.portrait.small { width: 32px; height: 32px; }
.apr-who { min-width: 0; }
.apr-room { color: var(--muted); font-size: 11px; margin-left: 4px; }
.apr-title { font-weight: 700; margin-top: 1px; }
.apr-time { color: var(--muted); font-size: 11px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.apr-msg { margin: 0; color: #cfd8e6; font-size: 12px; }
.apr-detail summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.apr-detail pre, .apr textarea { margin: 4px 0 0; background: #0c1422; padding: 6px 8px; border-radius: 6px; font: 11px/1.4 ui-monospace, monospace; max-height: 160px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
.apr-label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); }
.apr textarea { width: 100%; resize: vertical; }
.apr-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.apr-err { color: #ff8a8a; font-size: 12px; }
.link { background: none; border: 0; padding: 0; color: #8fd3ff; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
button:disabled { opacity: .5; cursor: progress; }

.card.sub { margin-left: 14px; width: calc(100% - 14px); }
.card-main { min-width: 0; }
.card-meta { display: flex; align-items: center; gap: 6px; }
.role { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.d-ask { margin-top: 10px; padding: 6px 8px; border-radius: 6px; background: #3a2c00; color: #ffd23f; font-size: 12px; }
.d-facts { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 10px 0 0; font-size: 12px; }
.d-facts dt { color: var(--muted); }
.d-facts dd { margin: 0; overflow-wrap: anywhere; }
.d-links { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.d-links:empty { display: none; }
.d-links a { text-decoration: none; }
.log .muted { color: var(--muted); display: block; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: #0e1726; border: 2px solid #f7c331; border-radius: 8px; padding: 8px 14px; box-shadow: 0 6px 20px #000a;
  max-width: calc(100vw - 32px);
}

/* ---------- teams per sector ---------- */
.btn-yellow { background: linear-gradient(#f7c331, #c99412); color: #3a2400; box-shadow: inset 0 1px 0 #ffe08a; }
dialog.wide { width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 48px); }
dialog.wide .panel-body { overflow-y: auto; max-height: calc(100vh - 110px); }
.muted { color: var(--muted); }
.intro { margin: 0 0 12px; }
.teams { display: flex; flex-direction: column; gap: 14px; }
.team { background: var(--panel-2); border: 2px solid var(--border); border-radius: 8px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.team-head { display: flex; gap: 12px; align-items: flex-start; }
.team-head h3 { margin: 0; font-size: 16px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.team-head p { margin: 4px 0 0; color: #cfd8e6; }
.team-icon { font-size: 30px; line-height: 1; }
.team .pill.on { color: #5fdd7a; }
.team-rooms { display: flex; gap: 6px; flex-wrap: wrap; }
.team-rooms small { color: var(--muted); }
.team-agents { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.team-agents li { display: grid; grid-template-columns: 32px 1fr; gap: 8px; background: #0f1828; border: 1px solid #2a3b55; border-radius: 6px; padding: 8px; font-size: 12px; }
.team-agents li > div { min-width: 0; }
.team-meta { margin-top: 3px; color: #9fb3cc; }
.small-link { font-size: 11px; margin-top: 4px; }
.team-prompt { margin: 6px 0 0; background: #0b1220; border-radius: 6px; padding: 8px; font: 11px/1.45 ui-monospace, monospace; white-space: pre-wrap; max-height: 260px; overflow: auto; }
.team-compliance summary { cursor: pointer; color: var(--muted); }
.team-compliance ul { margin: 6px 0 0; padding-left: 18px; color: #cfd8e6; font-size: 12px; }
.team-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.team-company { flex: 1 1 200px; background: #0c1422; color: var(--text); border: 1px solid #2a3b55; border-radius: 6px; padding: 7px 9px; font: inherit; }
@media (max-width: 860px) { .top-actions { flex-wrap: wrap; } }
.live-banner { margin: 0 0 4px; padding: 8px 10px; border-radius: 6px; background: #2a2210; border: 1px solid #5a4a16; color: #ffe08a; font-size: 12px; }
.live-banner.ok { background: #102a18; border-color: #1f6b35; color: #9df0b4; }
.team .pill.live { color: #ff8a5c; }
.d-run { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.d-run label { font-family: var(--pixel); font-size: 10px; color: var(--muted); }
.d-run textarea { background: #0c1422; color: var(--text); border: 1px solid #2a3b55; border-radius: 6px; padding: 6px 8px; font: inherit; resize: vertical; }
.d-run button { align-self: flex-start; }
.d-hint { font-size: 12px; margin: 10px 0 0; }
.d-result { margin-top: 10px; font-size: 12px; }
.d-result summary { cursor: pointer; color: var(--muted); }
.d-result div { white-space: pre-wrap; background: #0c1422; padding: 6px 8px; border-radius: 6px; margin-top: 4px; max-height: 200px; overflow: auto; }

/* ---------- kantoorbouwer ---------- */
.stage-actions { position: absolute; right: 12px; bottom: 12px; z-index: 2; display: flex; gap: 6px; }
.stage-actions .n { background: #0006; border-radius: 999px; padding: 0 6px; font-size: 11px; }
.stage-actions .badge { background: #ffd23f; color: #3a2c00; border-radius: 999px; padding: 0 6px; font-size: 11px; font-weight: 800; }
.editor { flex: 1; min-height: 0; overflow: auto; border-color: #8a6a00; }
.editor .panel-title { background: linear-gradient(#c99412, #8a6400); }
body.editing .side > .panel:not(.editor) { display: none; }
.ed-help { margin: 0; font-size: 12px; }
.editor-body { display: flex; flex-direction: column; gap: 10px; }
.ed-tools { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; }
.ed-tool { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; border-radius: 6px; background: var(--panel-2); border: 1px solid #2a3b55; font-size: 11px; }
.ed-tool span { font-size: 18px; line-height: 1.1; }
.ed-tool:hover { border-color: #4a6a92; }
.ed-tool.on { border-color: #f7c331; box-shadow: 0 0 0 1px #f7c331; background: #2b2a1c; }
.ed-tool.erase.on { border-color: #ff5d5d; box-shadow: 0 0 0 1px #ff5d5d; background: #2b1c1c; }
.ed-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; font-size: 12px; }
.ed-row label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
.ed-row input, .ed-row select { background: #0c1422; color: var(--text); border: 1px solid #2a3b55; border-radius: 6px; padding: 5px 7px; font: inherit; }
.ed-row input { width: 70px; }
.ed-actions { display: flex; gap: 6px; }
body.editing .room-label { display: none; }

/* ---------- prikbord ---------- */
.board { flex: 1; min-height: 0; overflow: auto; border-color: #1f6b35; }
.board .panel-title { background: linear-gradient(#2f8f46, #1f6b35); }
body.board-open .side > .panel.grow, body.board-open #detail { display: none; }
.board-body { display: flex; flex-direction: column; gap: 10px; }
.campagnes { background: #102a18; border: 1px solid #1f6b35; border-radius: 6px; padding: 8px; }
.campagnes h4 { margin: 0 0 4px; font-size: 13px; }
.small { font-size: 12px; margin: 0 0 6px; }
.camp-form { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 11px; }
.camp-form label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); }
.camp-form label.check { flex-direction: row; align-items: center; gap: 6px; grid-column: span 2; }
.camp-form input[type=number] { background: #0c1422; color: var(--text); border: 1px solid #2a3b55; border-radius: 6px; padding: 4px 6px; font: inherit; }
.camp-actions { grid-column: span 2; display: flex; gap: 6px; }
.board-add summary { cursor: pointer; color: #9df0b4; font-size: 12px; }
.board-add form { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.board-add input, .board-add textarea, .board-add select { background: #0c1422; color: var(--text); border: 1px solid #2a3b55; border-radius: 6px; padding: 6px 8px; font: inherit; }
.board-items { display: flex; flex-direction: column; gap: 8px; }
.bcard { background: var(--panel-2); border: 1px solid #2a3b55; border-radius: 6px; padding: 8px; font-size: 12px; }
.bcard.overgeslagen { opacity: .55; }
.bcard header { display: flex; align-items: center; gap: 6px; }
.bkind { color: var(--muted); font-size: 11px; }
.bscore { margin-left: auto; background: #0c1422; border: 1px solid #2a3b55; border-radius: 999px; padding: 0 7px; font-weight: 700; font-size: 11px; }
.small-x { width: 18px; height: 18px; font-size: 11px; line-height: 10px; }
.bcard header .small-x { margin-left: 4px; }
.bcard header .bscore + .small-x { margin-left: 4px; }
.bcard h4 { margin: 4px 0; font-size: 13px; }
.bcard h4 a { color: #8fd3ff; text-decoration: none; }
.bnote { margin: 0 0 4px; color: #9df0b4; }
.bcard summary { cursor: pointer; color: var(--muted); }
.btext { white-space: pre-wrap; margin-top: 4px; background: #0c1422; border-radius: 6px; padding: 6px 8px; max-height: 240px; overflow: auto; }
.bcard footer { margin-top: 4px; font-size: 11px; }

/* ---------- werkplaats ---------- */
.werkplaats { background: #0f1f2a; border: 1px solid #2c6b8f; border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.werkplaats h4 { margin: 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.werkplaats a { color: #8fd3ff; }
.werkplaats code { font-size: 11px; color: #cfe3f5; }
.werkplaats .camp-actions { flex-wrap: wrap; }
.werkplaats a.btn { text-decoration: none; color: inherit; display: inline-flex; align-items: center; }
.werkplaats label.check { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.wp-pill { font-size: 11px; font-weight: 600; border-radius: 999px; padding: 1px 8px; background: #1b2a3c; color: var(--muted); }
.wp-pill.ok { color: #5fdd7a; }
.wp-pill.busy { color: #ffd23f; }
.wp-pill.off { color: #9aa7b8; }
.wp-commits { margin: 4px 0 0; padding-left: 16px; max-height: 140px; overflow: auto; }
.wp-secret { font-family: ui-monospace, monospace; background: #0c1422; padding: 0 4px; border-radius: 4px; user-select: all; }
.wp-log summary { cursor: pointer; color: var(--muted); font-size: 12px; }
.wp-log pre { background: #070d16; color: #b9c7d8; font-size: 10.5px; line-height: 1.35; max-height: 260px; overflow: auto; padding: 6px; border-radius: 4px; white-space: pre-wrap; word-break: break-all; margin: 4px 0 0; }

/* inloggen (Clerk) */
body.login-open .layout, body.login-open .topbar .chips, body.login-open .top-actions { visibility: hidden; }
.login { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 50; background: var(--room-bg, #0b1220); padding: 16px; }
.login-title { font-family: 'Silkscreen', monospace; font-size: 20px; color: #fff; }
.user-slot { display: flex; align-items: center; gap: 10px; }
.login-msg { color: #cfd8e6; text-align: center; max-width: 360px; line-height: 1.5; }
