/* JBNX Brain — mem.jbnx.io
   Static stylesheet. No inline styles are used anywhere; JS only sets colors via element.style (CSSOM). */

:root {
  --bg: #07080c;
  --panel: #10121a;
  --panel-2: #151826;
  --input: #0b0d14;
  --border: #23263a;
  --border-2: #343857;
  --text: #e6e8ef;
  --muted: #8b90a5;
  --accent: #7c5cff;
  --accent-hover: #8f74ff;
  --accent-weak: rgba(124, 92, 255, 0.16);
  --ok: #4cc38a;
  --warn: #f2b64a;
  --danger: #ff6b7a;
  --radius: 10px;
  --topbar-h: 96px;
  --panel-w: 460px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: #a99bff; text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.pad { padding: 12px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--panel); color: var(--text);
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--border-2); background: var(--panel-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-danger { color: var(--danger); border-color: rgba(255, 107, 122, 0.4); }
.btn-danger:hover { background: rgba(255, 107, 122, 0.1); border-color: var(--danger); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 32px; height: 32px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.link-btn {
  border: 0; background: none; padding: 0; color: #a99bff; cursor: pointer; font-size: 12px;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Inputs ---------- */
input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="number"], input[type="datetime-local"], select, textarea {
  width: 100%; min-height: 34px; padding: 6px 10px;
  background: var(--input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
}
textarea { resize: vertical; line-height: 1.45; }
input::placeholder, textarea::placeholder { color: #5d6277; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
input[type="search"]::-webkit-search-cancel-button { filter: invert(0.6); }
.select-sm { width: auto; max-width: 180px; height: 34px; min-height: 34px; padding: 0 8px; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; min-width: 0; }
.field > span, .field > legend { font-size: 12px; color: var(--muted); }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 12px 10px; }
.fieldset legend { padding: 0 6px; }
.check { display: inline-flex; align-items: center; gap: 8px; margin-right: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check-grid { display: flex; flex-wrap: wrap; gap: 4px 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-error { color: var(--danger); font-size: 13px; margin: 0 0 12px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.hint-warn, .warn-box {
  margin: 0 0 14px; padding: 9px 12px; border-radius: var(--radius);
  background: rgba(242, 182, 74, 0.1); border: 1px solid rgba(242, 182, 74, 0.35); color: var(--warn); font-size: 13px;
}
.warn-box { color: var(--text); background: rgba(255, 107, 122, 0.1); border-color: rgba(255, 107, 122, 0.45); }
.warn-box strong { color: var(--danger); }

/* ---------- Switch ---------- */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--muted); user-select: none; white-space: nowrap; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 30px; height: 18px; border-radius: 999px; background: var(--border); transition: background 0.15s; flex: none; }
.switch-track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(12px); background: #fff; }
.switch input:checked ~ span:last-child { color: var(--text); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Cards, boot, login ---------- */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.boot { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.login-view { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.login-card { width: 100%; max-width: 360px; padding: 28px 24px 24px; }
.login-title { font-size: 20px; font-weight: 600; margin-bottom: 22px; letter-spacing: 0.01em; }
.login-card .form-error { margin-top: -4px; }

/* ---------- App layout ---------- */
.app-view { position: fixed; inset: 0; }
.graph { position: fixed; inset: 0; z-index: 0; background: var(--bg); overflow: hidden; }
.graph canvas { display: block; outline: none; }
.graph-status {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 5;
  display: flex; align-items: center; gap: 12px; padding: 12px 16px;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); color: var(--muted);
}
.empty {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 4;
  max-width: min(360px, calc(100vw - 32px)); text-align: center; color: var(--muted); pointer-events: none;
}
.stats {
  position: fixed; left: 16px; bottom: 12px; z-index: 6; max-width: calc(100vw - 32px);
  font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
}
.hint { position: fixed; right: 16px; bottom: 12px; z-index: 4; font-size: 12px; color: #5d6277; pointer-events: none; }
body.panel-open .hint { display: none; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  background: rgba(7, 8, 12, 0.88);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px 8px;
}
.tb-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.brand { font-weight: 600; letter-spacing: 0.01em; white-space: nowrap; }
.spacer { flex: 1 1 0; min-width: 0; }
.counts { color: var(--muted); font-size: 12px; white-space: nowrap; }
.who { color: var(--muted); font-size: 12px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search { position: relative; flex: 1 1 260px; max-width: 420px; min-width: 180px; }
.search input { height: 34px; }

.legend {
  display: flex; flex-wrap: nowrap; gap: 6px; margin-top: 8px; padding-bottom: 2px;
  overflow-x: auto; scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.legend:empty { display: none; }
.legend-chip {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  height: 26px; padding: 0 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  font-size: 12px; cursor: pointer; white-space: nowrap;
}
.legend-chip:hover { border-color: var(--border-2); }
.legend-chip .dot { width: 9px; height: 9px; }
.legend-count { color: var(--muted); font-size: 11px; }
.legend-chip.off { color: #5d6277; background: transparent; border-style: dashed; }
.legend-chip.off .dot { opacity: 0.3; }
.legend-chip.off .legend-count { color: #4a4f63; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; background: #9aa0a6; }

/* ---------- Search results ---------- */
.results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  list-style: none; margin: 0; padding: 4px;
  max-height: min(60vh, 420px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border-2); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}
.results-inline { position: static; margin-top: 6px; max-height: 240px; box-shadow: none; }
.result { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.result:hover, .result.active { background: var(--accent-weak); }
.result-title { display: flex; align-items: center; gap: 8px; min-width: 0; }
.result-label { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.result-meta, .result-sum { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-msg { padding: 10px; color: var(--muted); }

/* ---------- Chips ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  height: 22px; padding: 0 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  font-size: 12px; white-space: nowrap;
}
.chip-muted { color: var(--muted); }
.chip-tier-0 { color: #9fb4d6; }
.chip-tier-1 { color: var(--text); }
.chip-tier-2 { color: var(--warn); background: rgba(242, 182, 74, 0.12); border-color: rgba(242, 182, 74, 0.45); }
.chip-tier-3 { color: var(--danger); background: rgba(255, 107, 122, 0.12); border-color: rgba(255, 107, 122, 0.5); }
.chip-state-active, .chip-ok { color: var(--ok); border-color: rgba(76, 195, 138, 0.4); background: rgba(76, 195, 138, 0.1); }
.chip-state-revoked, .chip-state-expired, .chip-bad { color: var(--danger); border-color: rgba(255, 107, 122, 0.4); background: rgba(255, 107, 122, 0.08); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Detail panel ---------- */
.panel {
  position: fixed; z-index: 15;
  top: calc(var(--topbar-h) + 10px); right: 12px; bottom: 12px; width: var(--panel-w); max-width: calc(100vw - 24px);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}
.panel-grip { display: none; }
.panel-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 12px 10px 18px; border-bottom: 1px solid var(--border); }
.panel-title { flex: 1 1 auto; min-width: 0; font-size: 17px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; padding-top: 3px; }
.panel-body { flex: 1 1 auto; overflow-y: auto; padding: 14px 18px 24px; overscroll-behavior: contain; }
.panel-body > * + * { margin-top: 16px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.summary { color: var(--text); }
.body-text { max-height: 340px; overflow-y: auto; padding: 10px 12px; background: var(--input); border: 1px solid var(--border); border-radius: var(--radius); }
.source-line { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.sec-title { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.inline-form { padding: 12px 12px 4px; background: var(--panel-2); border: 1px solid var(--border-2); border-radius: var(--radius); }
.inline-form .form-grid { grid-template-columns: 1fr 120px; }
.inline-form .form-actions { margin-bottom: 8px; }
.picked { font-size: 12px; color: var(--ok); margin: -6px 0 12px; overflow-wrap: anywhere; }
.replace-note { font-size: 12px; color: var(--warn); margin: 0 0 10px; }

.kv { display: grid; grid-template-columns: minmax(70px, 30%) 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.kv dt { color: var(--muted); overflow-wrap: anywhere; }
.kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl th { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: var(--panel-2); }
.tbl-facts { table-layout: fixed; }
.tbl-facts td { overflow-wrap: anywhere; word-break: break-word; }
.tbl-facts .col-attr { width: 26%; }
.tbl-facts .col-val { width: 34%; }
.tbl-facts .col-tier { width: 17%; }
.tbl-facts .col-src { width: 23%; }
.tbl-facts .attr { font-weight: 600; }
.tbl-facts .small { font-size: 12px; color: var(--muted); }
.tbl-facts tr.muted-row td { color: #666b80; }
.tbl-facts tr.muted-row .chip { opacity: 0.7; }
.tbl-facts .val { white-space: pre-wrap; }
.facts-old { margin-top: 10px; }
.facts-old > summary { cursor: pointer; color: var(--muted); font-size: 13px; padding: 4px 0; }
.facts-old .table-wrap { margin-top: 8px; }

.nb-group + .nb-group { margin-top: 12px; }
.nb-rel { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.nb-rel b { color: var(--text); font-weight: 600; }
.nb-list { list-style: none; margin: 0; padding: 0; }
.nb {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 6px 8px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; min-width: 0;
}
.nb:hover { background: var(--accent-weak); }
.nb-dir { color: var(--muted); flex: none; width: 14px; text-align: center; }
.nb-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nb-kind { flex: none; font-size: 11px; color: var(--muted); }
.meta-foot { font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); padding-top: 12px; overflow-wrap: anywhere; }
.meta-foot code { color: var(--muted); }

/* ---------- Drawer (admin) ---------- */
.drawer {
  position: fixed; z-index: 40; top: 0; right: 0; bottom: 0; width: min(820px, 100vw);
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -16px 0 48px rgba(0, 0, 0, 0.5);
}
.drawer-head { display: flex; align-items: center; gap: 16px; padding: 12px 14px 0 18px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 17px; font-weight: 600; padding-bottom: 12px; }
.tabs { display: flex; gap: 4px; flex: 1 1 auto; align-self: flex-end; }
.tab { border: 0; background: none; color: var(--muted); padding: 10px 12px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.drawer-head .icon-btn { margin-bottom: 8px; }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px 28px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.form-card { padding: 16px 16px 8px; margin-bottom: 18px; }
.form-title { font-size: 15px; margin-bottom: 14px; }
.tbl-admin td { min-width: 120px; }
.tbl-admin .stack > * + * { margin-top: 4px; }
.small { font-size: 12px; }
.key-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; padding: 4px 0; }
.key-row.dim { opacity: 0.6; }
.key-row + .key-row { border-top: 1px dashed var(--border); }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tbl-log td { white-space: nowrap; }
.tbl-log td.wrap { white-space: normal; overflow-wrap: anywhere; min-width: 160px; }

/* ---------- Modals ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: rgba(3, 4, 7, 0.7); overflow-y: auto;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 22px 22px 16px; background: var(--panel); border: 1px solid var(--border-2); border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 16px; }
#memory-modal .form-grid { grid-template-columns: 1.2fr 1.2fr 1fr; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 60; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; max-width: calc(100vw - 32px); pointer-events: none; }
.toast {
  pointer-events: auto; max-width: 420px; padding: 10px 14px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--border-2); color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); overflow-wrap: anywhere;
}
.toast-error { border-color: rgba(255, 107, 122, 0.55); color: #ffd0d5; }
.toast-ok { border-color: rgba(76, 195, 138, 0.5); }

/* ---------- Rules the 3d-force-graph bundle would inject as <style> (blocked by CSP style-src 'self') ---------- */
.float-tooltip-kap {
  position: absolute; width: max-content; max-width: max(50%, 150px);
  padding: 6px 9px; border-radius: 8px;
  font: 12px/1.4 var(--font); color: var(--text);
  background: rgba(16, 18, 26, 0.96); border: 1px solid var(--border-2);
  pointer-events: none; z-index: 25;
}
.float-tooltip-kap .tt-title { font-weight: 600; font-size: 13px; }
.float-tooltip-kap .tt-meta { color: var(--muted); }
.scene-container .clickable { cursor: pointer !important; }
.scene-container .grabbable { cursor: move; cursor: grab; cursor: -moz-grab; cursor: -webkit-grab; }
.scene-container .grabbable:active { cursor: grabbing; cursor: -moz-grabbing; cursor: -webkit-grabbing; }
.scene-container canvas:focus { outline: none; }
.scene-nav-info { display: none; }

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .topbar { padding: 8px 12px 6px; }
  .tb-row { gap: 8px 10px; }
  .search { order: 5; flex: 1 1 100%; max-width: none; }
  .who, .hint { display: none; }
  .spacer { display: none; }
  .counts { order: 4; }
  .tb-row .btn { height: 32px; padding: 0 12px; }

  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none;
    height: 62vh; max-height: calc(100vh - var(--topbar-h) - 8px);
    border-radius: 16px 16px 0 0; border-left: 0; border-right: 0; border-bottom: 0;
  }
  .panel-grip { display: block; width: 36px; height: 4px; margin: 8px auto 0; border-radius: 4px; background: var(--border-2); }
  .panel-head { padding-top: 6px; }
  .stats { bottom: 8px; }
  body.panel-open .stats { display: none; }

  .drawer { width: 100vw; border-left: 0; }
  .form-grid, #memory-modal .form-grid { grid-template-columns: 1fr; }
  .inline-form .form-grid { grid-template-columns: 1fr 1fr; }
  .toasts { left: 12px; right: 12px; align-items: stretch; bottom: 12px; }
  .toast { max-width: none; }
  .modal { padding: 18px 16px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
