* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  height: 100vh; display: flex; flex-direction: column;
  background: #f5f5f7; color: #333; overflow: hidden;
}

.header {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 16px; background: #fff; border-bottom: 1px solid #e0e0e0;
  z-index: 10;
}
.header h1 { font-size: 16px; color: #c0392b; white-space: nowrap; margin-right: 8px; }
select, input[type="text"], button, .file-label {
  padding: 6px 10px; border: 1px solid #ccc; border-radius: 6px;
  font-size: 13px; background: #fff; cursor: pointer; color: #333;
}
input[type="text"] { cursor: text; min-width: 140px; }
button:hover, .file-label:hover { background: #f0f0f0; }
button.primary { background: #c0392b; color: #fff; border-color: #c0392b; }
button.primary:hover { background: #a93226; }
.file-label input { display: none; }
.spacer { flex: 1; }
label.check { display: flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer; }

.main { flex: 1; display: flex; position: relative; overflow: hidden; }
/* min-width:0 让画布容器在 flex 里能正常缩小，否则内部 canvas 的固有宽度会把详情面板压到 33px */
#cy { flex: 1; height: 100%; min-width: 0; }

#detail {
  width: 320px; flex-shrink: 0; background: #fff; border-left: 1px solid #e0e0e0;
  padding: 16px; overflow-y: auto; display: none;
}
#detail.open { display: block; }
#detail h2 { font-size: 18px; margin-bottom: 4px; color: #c0392b; }
#detail .meta { font-size: 12px; color: #888; margin-bottom: 12px; }
#detail .desc { font-size: 13px; line-height: 1.6; margin-bottom: 16px; }
#detail h3 { font-size: 14px; margin: 12px 0 8px; border-bottom: 1px solid #eee; padding-bottom: 4px; }
.rel-item { font-size: 13px; padding: 6px 0; border-bottom: 1px dashed #eee; position: relative; }
.rel-del {
  position: absolute; right: 0; top: 6px;
  cursor: pointer; color: #bbb; font-size: 16px; line-height: 1;
  padding: 0 3px; border-radius: 3px;
}
.rel-del:hover { color: #fff; background: #e74c3c; }
.rel-edit {
  position: absolute; right: 26px; top: 6px;
  cursor: pointer; color: #bbb; font-size: 14px; line-height: 1;
  padding: 0 4px; border-radius: 3px;
}
.rel-edit:hover { color: #fff; background: #3498db; }
.rel-item .tag { display: inline-block; padding: 1px 6px; border-radius: 4px; color: #fff; font-size: 11px; margin-right: 6px; }
#detail .close { float: right; cursor: pointer; color: #999; font-size: 20px; line-height: 1; }
#detail .close:hover { color: #333; }

#legend {
  position: absolute; left: 12px; bottom: 12px; background: rgba(255,255,255,0.95);
  border: 1px solid #e0e0e0; border-radius: 8px; padding: 10px 12px;
  font-size: 12px; max-width: 220px; z-index: 5;
}
#legend h4 { font-size: 12px; margin-bottom: 6px; color: #666; }
.legend-item { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.legend-line { width: 20px; height: 2px; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none; align-items: center; justify-content: center; z-index: 100; }
.modal.open { display: flex; }
.modal-content { background: #fff; border-radius: 10px; padding: 20px; width: 90%; max-width: 460px; max-height: 90vh; overflow-y: auto; }
.modal-content h3 { margin-bottom: 14px; color: #c0392b; }
.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 12px; color: #666; margin-bottom: 4px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 7px 10px; border: 1px solid #ccc; border-radius: 6px;
  font-size: 13px; font-family: inherit;
}
.form-row textarea { resize: vertical; min-height: 60px; }
.fchecks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.form-row .fcheck { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: #333; margin: 0; }
.form-row .fcheck input { width: auto; margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-actions button { padding: 7px 16px; }

@media (max-width: 700px) {
  #detail { position: absolute; right: 0; top: 0; height: 100%; width: 80%; box-shadow: -2px 0 10px rgba(0,0,0,0.1); }
  .header h1 { display: none; }
}