:root {
  --bg: #101318;
  --panel: #161b22;
  --card: #1c232c;
  --line: #2a323d;
  --text: #e6edf3;
  --dim: #8b98a8;
  --accent: #4ea1ff;
  --good: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  --law: #a371f7;
  --entity: #39c5cf;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
}

a { color: var(--accent); }
button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px 9px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: #1f6feb; border-color: #1f6feb; color: #fff; }
button.danger { background: #3d1d1c; border-color: #6b2c2a; color: #ffb4ad; }
button:disabled { opacity: .45; cursor: default; }
input:focus, select:focus, textarea:focus { outline: 2px solid #1f6feb55; }

/* ---------- top bar ---------- */
header {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
header h1 { font-size: 15px; margin: 0; letter-spacing: .3px; }
header .sub { color: var(--dim); font-size: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 20px;
  padding: 2px 10px; font-size: 12px; color: var(--dim);
}
.chip b { color: var(--text); font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
#btn-logout { border-radius: 20px; padding: 4px 14px; color: var(--dim); }
.tabs button { border-radius: 20px; padding: 4px 14px; background: transparent; border-color: transparent; color: var(--dim); }
.tabs button.on { background: var(--card); border-color: var(--line); color: var(--text); }

/* ---------- layout ---------- */
main { padding: 14px 16px; }
.view { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.view > * { min-width: 0; }
.view > .panel { flex: 1; }
/* the graph screen stacks: control bar on top, canvas below, legend last */
#view-graph { flex-direction: column; }
#view-graph > .panel { flex: 0 0 auto; width: 100%; }
.col-list { width: 40%; min-width: 380px; }
.col-detail { flex: 1; min-width: 0; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.panel > h2 { font-size: 13px; margin: 0 0 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .6px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ---------- list ---------- */
.mem {
  display: block; width: 100%; text-align: left; background: var(--card);
  border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: var(--radius); padding: 9px 11px; margin-bottom: 8px;
}
.mem:hover { border-color: var(--accent); }
.mem.sel { border-left-color: var(--accent); background: #202b38; }
.mem .body { color: var(--text); }
.mem .meta { color: var(--dim); font-size: 12px; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 3px; background: #263140; color: #9fc6ff; }
.tag.law { background: #2d2440; color: #cdaaff; }
.tag.entity { background: #14343a; color: #7ee3ea; }
.tag.schema { background: #14351f; color: #7ee39a; }
.tag.domain { background: #3a2f14; color: #e3c47e; }
.tag.prospective { background: #3a1428; color: #e37eb3; }
.tag.retired { background: #2a2a2a; color: #9a9a9a; }
.empty { color: var(--dim); padding: 18px; text-align: center; }

/* ---------- detail ---------- */
.kv { display: grid; grid-template-columns: 108px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--dim); }
.kv dd { margin: 0; word-break: break-word; }
.bar { height: 6px; border-radius: 3px; background: #242f3b; overflow: hidden; min-width: 90px; }
.bar i { display: block; height: 100%; background: var(--accent); }
.bodytext { white-space: pre-wrap; word-break: break-word; font-size: 15px; line-height: 1.6; }
.rel { display: flex; gap: 8px; align-items: baseline; padding: 5px 0; border-bottom: 1px dashed #232c36; }
.rel:last-child { border-bottom: 0; }
.rel .dir { color: var(--dim); width: 26px; }
.rel .w { color: var(--warn); font-variant-numeric: tabular-nums; width: 46px; }
.rel button { background: none; border: none; color: var(--accent); padding: 0; text-align: left; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 5px 8px; border-bottom: 1px solid #212a34; vertical-align: top; }
th { color: var(--dim); font-weight: 500; position: sticky; top: 0; background: var(--panel); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.toast { position: fixed; right: 16px; bottom: 16px; background: #1f6feb; color: #fff; padding: 9px 14px; border-radius: var(--radius); box-shadow: 0 6px 20px #0008; z-index: 30; }
.toast.bad { background: #a32020; }
small.hint { color: var(--dim); }
pre.raw { background: #12171d; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; overflow: auto; font-size: 12px; }

/* ---------- graph ---------- */
#graph-wrap { position: relative; width: 100%; height: calc(100vh - 260px); min-height: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.graph-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); text-align: center; padding: 24px; line-height: 1.9; }
#graph { width: 100%; height: 100%; display: block; cursor: grab; }
#graph text { pointer-events: none; font-size: 11px; fill: var(--text); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; color: var(--dim); font-size: 12px; margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* ---------- login ---------- */
.login-shell { min-height: 100vh; display: grid; place-items: center; }
.login-card { width: 330px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 22px; }
.login-card h1 { font-size: 16px; margin: 0 0 4px; }
.login-card label { display: block; margin: 12px 0 4px; color: var(--dim); font-size: 12px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; margin-top: 16px; }
.login-err { color: var(--bad); font-size: 12px; margin-top: 10px; min-height: 16px; }
