* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #1d2733; background: #f4f6f9; display: flex; flex-direction: column; height: 100vh;
}
header { padding: 10px 18px; background: #16263b; color: #fff; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; }
header h1 { margin: 0; font-size: 16px; font-weight: 600; }
header .sub { font-size: 12px; opacity: .8; margin-top: 2px; }
#distBtn { flex: 0 0 auto; background: #2563eb; color:white; font-weight:bold;}

/* distribution modal */
.modal { position: fixed; inset: 0; background: rgba(15,25,40,.45); z-index: 100;
  display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modalBox { background: #fff; width: min(920px, 92vw); max-height: 88vh;
  border-radius: 10px; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 12px 44px rgba(10,20,40,.32); }
.modalHead { display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: #16263b; color: #fff; font-weight: 600; }
.modalHead span:last-child { cursor: pointer; font-size: 18px; }
.modalBody { padding: 14px 18px; overflow-y: auto; font-size: 13px; }
.modalBody h3 { font-size: 13px; margin: 16px 0 6px; color: #16263b; }
.modalBody table { border-collapse: collapse; width: 100%; font-size: 12px; margin: 4px 0 8px; }
.modalBody th, .modalBody td { text-align: left; padding: 3px 8px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
.modalBody th { color: #5a6b80; font-weight: 600; }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.jclick { color: #1d4ed8; cursor: pointer; }
.jclick:hover { text-decoration: underline; }

#main { flex: 1 1 auto; display: flex; min-height: 0; }

#sidebar {
  width: 360px; flex: 0 0 360px; overflow-y: auto; padding: 12px;
  background: #fff; border-right: 1px solid #dce2ea;
}
.panel { margin-bottom: 16px; }
.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: #5a6b80; margin: 0 0 8px; }

textarea, input { width: 100%; font: inherit; font-size: 15px; padding: 8px; border: 1px solid #c6cfdb; border-radius: 6px; resize: vertical; }
.row { display: flex; gap: 8px; margin-top: 8px; }
button { font: inherit; font-size: 13px; padding: 7px 14px; border: 0; border-radius: 6px; background: #2563eb; color: #fff; cursor: pointer; }
button.secondary { background: #e2e8f0; color: #1d2733; }
button:hover { filter: brightness(1.05); }

.muted { color: #6b7a8d; font-size: 12px; }
.small { font-size: 13px; }
#interpretation { margin-top: 8px; min-height: 14px; }
#interpretation.active { color: #1d2733; background: #eef4ff; border: 1px solid #cfe0ff; padding: 7px 9px; border-radius: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px; border-radius: 14px;
  font-size: 13px; cursor: pointer; border: 1px solid transparent; user-select: none; background: #eef1f5;
}
.chip .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.chip.off { opacity: .35; }
.chips.small .chip { background: #eef4ff; }

#plotWrap { flex: 1 1 auto; position: relative; min-width: 0; background:
  radial-gradient(circle at 30% 20%, #ffffff, #eef1f5); }
#plot { width: 100%; height: 100%; display: block; cursor: grab; }
#plot.panning { cursor: grabbing; }
#plot circle, #plot polygon, #plot .judgeLabel { cursor: pointer; }
#plot .node.dim { opacity: .06; }
#plot .judgeLabel.dim { opacity: 0; }
#plot .node.focused, #plot .node.sel { stroke: #111; stroke-width: 2.5px; }
#plot .edge { stroke: #94a3b8; fill: none; pointer-events: none; }
#plot .judgeLabel { font-size: 11px; fill: #16263b; paint-order: stroke; stroke: #fff; stroke-width: 3px; font-weight: 600; pointer-events: none; }
#plot .damageLabel { font-size: 11px; fill: #7a3b12; paint-order: stroke; stroke: #fff; stroke-width: 3px; font-weight: 700; pointer-events: none; }
#plot .damageLabel.dim { opacity: 0; }

/* layer controls */
.layers { display: flex; flex-direction: column; gap: 6px; font-size: 15px; }
.layers .ly { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.layers .ly input[type="checkbox"] { margin: 0; flex: 0 0 auto; width:15% !important;}
.lygrp { display: inline-flex; align-items: center; gap: 7px; }
.sw { flex: 0 0 auto; width: 14px; height: 14px; border-radius: 50%; }
.sw.path { background: #2563eb; }
.sw.case { background: #fff; border: 2px solid #475569; }
.sw.judge { background: #16263b; border-radius: 0; clip-path: polygon(50% 0, 0 100%, 100% 100%); }
.sw.damage { background: #e8702a; border-radius: 0;
  clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }

/* cluster distribution bar */
.distbar { display: flex; height: 14px; border-radius: 4px; overflow: hidden; margin: 6px 0; border: 1px solid #e2e8f0; }
.distbar .seg { height: 100%; }
.distlegend { font-size: 11px; color: #6b7a8d; display: flex; flex-wrap: wrap; gap: 6px; }
.distlegend .di { display: inline-flex; align-items: center; gap: 3px; }
.distlegend .dot { width: 8px; height: 8px; border-radius: 50%; }
.linklist { margin-top: 6px; max-height: 200px; overflow-y: auto; }
.linklist .li { font-size: 12px; padding: 3px 0; border-bottom: 1px dashed #eef1f5; cursor: pointer; }
.linklist .li:hover { background: #f3f7ff; }
.jlink { color: #1d4ed8; cursor: pointer; text-decoration: underline dotted; white-space: nowrap; }
.jlink:hover { color: #0b3bd1; }

#tooltip {
  position: absolute; pointer-events: none; background: rgba(17,25,38,.95); color: #fff;
  font-size: 12px; padding: 7px 9px; border-radius: 6px; max-width: 300px; z-index: 20; line-height: 1.4;
}
#tooltip.hidden { display: none; }
#plotHint { position: absolute; right: 10px; bottom: 8px; background: rgba(255,255,255,.8); padding: 3px 8px; border-radius: 6px; }

/* detail */
#detail .meta { font-size: 12px; margin-bottom: 8px; }
#detail .meta b { color: #16263b; }
#detail .tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: #eef1f5; margin: 0 4px 4px 0; }
#detail .endpoints { background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 6px; padding: 8px; margin: 8px 0; font-size: 12px; }
#detail .endpoints .w { color: #1d4ed8; }
#detail .endpoints .d { color: #b91c1c; }
.nodelist { margin-top: 8px; border-top: 1px solid #eef1f5; }
.noderow { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px dashed #eef1f5; font-size: 12px; }
.noderow .ix { color: #9aa7b6; flex: 0 0 22px; text-align: right; }
.noderow .body { flex: 1 1 auto; }
.noderow.group { opacity: .6; }
.noderow .lab { font-weight: 600; }
.noderow .rel { color: #7c3aed; font-size: 11px; }
.noderow .sec { color: #6b7a8d; font-size: 11px; }
.noderow .txt { color: #2b3a4d; }

/* glossary floating */
#glossary {
  position: fixed; right: 16px; bottom: 16px; width: 500px; max-height: 70vh;
  background: #fff; border: 1px solid #cfd8e3; border-radius: 10px; box-shadow: 0 8px 26px rgba(20,40,70,.18);
  z-index: 50; display: flex; flex-direction: column; overflow: hidden;
}
#glossaryHead { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; cursor: pointer; background: #16263b; color: #fff; font-size: 15px; font-weight: 600; }
#glossaryBody { padding: 10px 12px; overflow-y: auto; font-size: 14px; }
#glossary.collapsed #glossaryBody { display: none; }
#glossary.collapsed #glossaryToggle { transform: none; }
#glossary:not(.collapsed) #glossaryToggle { transform: rotate(90deg); }
#glossaryBody h4 { margin: 10px 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #5a6b80; }
#glossaryBody .gdef { margin-bottom: 7px; }
#glossaryBody .gname { font-weight: 600; }
#glossaryBody .gname .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
