:root {
  --bg: #1e1e1e;
  --panel: #252525;
  --panel-2: #2c2c2c;
  --line: #383838;
  --text: #dcddde;
  --muted: #9a9a9a;
  --accent: #b23a34;
  --gold: #d9aa45;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, "Segoe UI", Inter, Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* top bar */
.top {
  height: 52px; flex: none; display: flex; align-items: center; gap: 14px;
  padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 800; border: 2px solid #7a211d;
}
.brand b { display: block; font-size: 14px; line-height: 1.1; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
.search { flex: 1; max-width: 460px; margin: 0 auto; }
.search input {
  width: 100%; height: 32px; padding: 0 12px; border-radius: 6px;
  background: var(--bg); border: 1px solid var(--line); outline: none;
}
.search input:focus { border-color: var(--gold); }
.btn {
  height: 32px; padding: 0 12px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--panel-2); white-space: nowrap;
}
.btn:hover { border-color: #555; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #1b1b1b; font-weight: 600; }
.btn.gold span { background: rgba(0,0,0,.2); border-radius: 10px; padding: 1px 7px; margin-left: 4px; }
.btn.ghost { background: transparent; }
.icon { background: none; border: 0; font-size: 20px; width: 34px; height: 34px; border-radius: 6px; }
.icon:hover { background: var(--panel-2); }
.only-mobile { display: none; }

/* layout */
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 290px 1fr 370px; }
aside { background: var(--panel); min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
#side { border-right: 1px solid var(--line); }
#note { border-left: 1px solid var(--line); overflow-y: auto; padding: 20px 22px 40px; display: block; }

/* sidebar */
.side-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--line); background: transparent; border-radius: 12px;
  padding: 2px 9px; font-size: 12px; color: var(--muted);
}
.chip.on { background: var(--gold); border-color: var(--gold); color: #1b1b1b; font-weight: 600; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.stats { margin-top: 8px; font-size: 12px; color: var(--muted); }
.tree, .results { flex: 1; overflow-y: auto; padding: 8px 6px 30px; }
.tree ul { list-style: none; margin: 0; padding: 0 0 0 14px; }
.tree > ul { padding-left: 0; }
.row {
  display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 5px;
  cursor: pointer; white-space: nowrap; overflow: hidden;
}
.row:hover { background: var(--panel-2); }
.row.sel { background: #3a2c2b; color: #fff; }
.row.dim { opacity: .35; }
.row .caret { width: 12px; flex: none; color: var(--muted); font-size: 10px; text-align: center; transition: transform .12s; }
.row .caret.open { transform: rotate(90deg); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.row .txt { overflow: hidden; text-overflow: ellipsis; }
.row .inplan { margin-left: auto; color: var(--gold); font-size: 11px; }
.results .row { display: block; white-space: normal; padding: 6px 8px; }
.results .crumb { font-size: 11px; color: var(--muted); }
.results .empty { padding: 14px; color: var(--muted); }

/* graph */
#graphWrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: var(--bg); }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#cv.grabbing { cursor: grabbing; }
#cv.pointing { cursor: pointer; }
.gctl, .zoom {
  position: absolute; background: rgba(37,37,37,.92); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; display: flex; gap: 12px; align-items: center; font-size: 13px;
}
.gctl { top: 12px; right: 12px; }
.gctl select { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; margin-left: 4px; }
.zoom { bottom: 12px; right: 12px; gap: 4px; padding: 4px; }
.zoom button { background: none; border: 0; min-width: 30px; height: 28px; border-radius: 5px; }
.zoom button:hover { background: var(--panel-2); }
.hint { position: absolute; left: 14px; top: 14px; max-width: min(420px, 55%); font-size: 12px; color: #6f6f6f; pointer-events: none; }
.hint.live { color: var(--text); font-size: 13px; background: rgba(37,37,37,.92); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.hint.live b { color: #fff; display: block; }

/* note panel */
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.crumbs a { color: var(--muted); text-decoration: none; cursor: pointer; }
.crumbs a:hover { color: var(--text); text-decoration: underline; }
#note h1 { font-size: 24px; line-height: 1.2; margin: 0 0 10px; display: flex; align-items: center; gap: 10px; }
#note h1 .dot { width: 12px; height: 12px; }
.badges { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 14px; }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); }
.badge.core { color: var(--gold); border-color: #6a5527; }
.desc { font-size: 15px; margin: 0 0 16px; }
.actions { display: flex; gap: 8px; margin-bottom: 22px; flex-wrap: wrap; }
#note h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 8px; font-weight: 600; }
.links { display: flex; flex-direction: column; gap: 2px; }
.link {
  display: flex; gap: 8px; align-items: baseline; text-align: left; background: none; border: 0;
  padding: 5px 8px; border-radius: 5px; width: 100%;
}
.link:hover { background: var(--panel-2); }
.link .dot { position: relative; top: -1px; }
.link b { font-weight: 500; color: #c9b6ff; }
.link small { color: var(--muted); display: block; font-size: 12px; }
#note textarea {
  width: 100%; min-height: 110px; resize: vertical; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 10px; outline: none;
}
#note textarea:focus { border-color: var(--gold); }
.welcome p { color: var(--muted); }
.welcome .legend { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.note-close { display: none; float: right; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-card { width: min(640px, 100%); max-height: 86vh; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-body { padding: 14px 18px; overflow-y: auto; }
.modal-body h4 { margin: 14px 0 6px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.modal-body .item { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; border-bottom: 1px solid #303030; }
.modal-body .item span { flex: 1; }
.modal-body .item small { color: var(--muted); display: block; }
.modal-body .item button { background: none; border: 0; color: var(--muted); }
.modal-body .item button:hover { color: #fff; }
.modal-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }

/* small screens */
@media (max-width: 900px) {
  .only-mobile { display: block; }
  .brand small, .hint { display: none; }
  main { grid-template-columns: 1fr; position: relative; }
  #side {
    position: absolute; z-index: 20; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
    transform: translateX(-100%); transition: transform .18s;
  }
  body.show-side #side { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.6); }
  #note {
    position: absolute; z-index: 15; left: 0; right: 0; bottom: 0; max-height: 58%;
    border-left: 0; border-top: 1px solid var(--line); padding: 16px;
    transform: translateY(100%); transition: transform .18s;
  }
  body.show-note #note { transform: none; }
  .note-close { display: block; }
  .zoom { bottom: auto; top: 60px; }
}

@media print {
  body { background: #fff; color: #000; overflow: visible; display: block; }
  .top, main, .modal-foot, .modal-head button, .modal-body .item button { display: none !important; }
  .modal { position: static; background: none; display: block; padding: 0; }
  .modal-card { border: 0; max-height: none; background: #fff; width: 100%; }
  .modal-body { overflow: visible; }
  .modal-body .item small { color: #444; }
  .modal-body .item { border-color: #ccc; }
}

/* ───────── v2: gate, admin bar, editors, client maps ───────── */
body.gated > .top, body.gated > main, body.gated > .adminbar { visibility: hidden; }
.gate { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: none; place-items: center; padding: 20px; }
body.gated .gate { display: grid; }
.gate-card { width: min(380px, 100%); text-align: center; }
.gate-logo { width: 100%; height: auto; display: block; margin-bottom: 10px; }
.gate-card h1 { font-size: 20px; margin: 0 0 18px; font-weight: 600; }
.gate-msg { color: var(--muted); min-height: 1.5em; }
.gate form { display: flex; flex-direction: column; gap: 10px; }
.gate input { height: 40px; padding: 0 12px; border-radius: 6px; background: var(--panel); border: 1px solid var(--line); outline: none; }
.gate input:focus { border-color: var(--gold); }
.gate .btn { height: 40px; }
.gate-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }

button.brand { background: none; border: 0; padding: 0; text-align: left; }
.brand img.mark { width: 34px; height: 34px; border-radius: 0; border: 0; background: none; object-fit: contain; }
.brand span { display: block; }

.adminbar {
  flex: none; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 6px 14px; background: #2a2322; border-bottom: 1px solid var(--line); font-size: 13px;
}
.adminbar[hidden] { display: none; }
.adminbar select { background: var(--bg); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; margin-left: 4px; max-width: 220px; }
.adminbar .btn { height: 28px; }
.adminbar .spacer { flex: 1; }
.adminbar .who, .save { color: var(--muted); font-size: 12px; }
.save.bad { color: #ff8a80; }
body.editing .adminbar { background: #3a2a14; }

.legend {
  position: absolute; left: 14px; bottom: 14px; display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted);
  background: rgba(37,37,37,.92); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; max-width: 60%;
}
.legend[hidden] { display: none; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }

.badge.solid { color: #fff; border-color: transparent; font-weight: 600; }
.callout { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 6px; padding: 10px 12px; margin: 0 0 12px; }
.callout p { margin: 4px 0 0; white-space: pre-wrap; }
.callout.internal { border-left-color: #b23a34; }
.tip { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.err { color: #ff8a80; min-height: 1.2em; margin: 6px 0 0; }

.editor { border: 1px solid #5a4520; background: #2b2619; border-radius: 8px; padding: 12px; margin: 0 0 18px; display: flex; flex-direction: column; gap: 10px; }
.editor h3 { margin: 0 !important; color: var(--gold) !important; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.field input[type=text], .field textarea, .field select, .editor > select, .modal input[type=text] {
  background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; font-size: 14px; color: var(--text); outline: none; width: 100%;
}
.field textarea { min-height: 64px !important; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--gold); }
.editor .actions { margin: 0; }
.editor .chips { margin: 0; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline small { color: var(--muted); }
.btn.danger { background: transparent; border-color: #7a2f2a; color: #ff8a80; }
.btn.danger:hover { background: #4a1f1c; }
.btn[disabled] { opacity: .4; cursor: default; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; color: var(--text); margin-bottom: 12px; }
.linkedit { display: flex; align-items: center; gap: 8px; padding: 3px 4px; }
.linkedit span:nth-child(2) { flex: 1; }
.linkedit button, .reciperow .x { background: none; border: 0; color: var(--muted); font-size: 16px; }
.linkedit button:hover, .reciperow .x:hover { color: #fff; }
.reciperow { display: flex; align-items: center; }
.reciperow .link { flex: 1; }

.brandcard { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: 0 0 16px; }
.brandcard img { max-width: 160px; max-height: 70px; display: block; margin-bottom: 8px; }
.brandcard p { margin: 0 0 6px; }
.brandcard a { color: #c9b6ff; }
.swatches { display: flex; gap: 6px; margin: 8px 0; }
.swatches span { width: 26px; height: 26px; border-radius: 5px; border: 1px solid rgba(255,255,255,.2); }

.score { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 8px; margin: 0 0 6px; }
.score div { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--muted); }
.score b { display: block; font-size: 22px; color: var(--text); line-height: 1.2; }
.bars { display: flex; flex-direction: column; gap: 2px; }
.bar { background: none; border: 0; text-align: left; padding: 5px 8px; border-radius: 5px; width: 100%; }
.bar:hover { background: var(--panel-2); }
.bar .bl { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.bar .bl small { margin-left: auto; color: var(--muted); }
.bar .track { display: flex; height: 5px; background: #3a3a3a; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar .track i { display: block; height: 100%; }

.share { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.share.off { opacity: .55; }
.share .url { flex: 1; min-width: 160px; font-size: 12px !important; color: var(--muted) !important; }
.modal .inline > input[type=text] { flex: 1; min-width: 180px; }
.tl { display: flex; gap: 10px; padding: 4px 0; border-bottom: 1px solid #303030; font-size: 13px; }
.tl small { color: var(--muted); flex: none; width: 118px; }
.modal-foot[hidden] { display: none; }
.modal-card { width: min(680px, 100%); }

@media (max-width: 900px) {
  .adminbar .who { display: none; }
  .legend { bottom: auto; top: 104px; left: 10px; max-width: 80%; }
}
@media print { .adminbar, .gate { display: none !important; } }

[hidden] { display: none !important; }
