* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Roboto, sans-serif;
  background: #f5f6f8;
  color: #222;
}

/* 工具栏 */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: #fff;
  border-bottom: 1px solid #e3e6ea;
  position: sticky; top: 0; z-index: 10;
  flex-wrap: wrap; gap: 10px;
}
.title h1 { font-size: 18px; font-weight: 600; }
.subtitle { font-size: 12px; color: #888; }
.subtitle code { background: #eef0f3; padding: 1px 5px; border-radius: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  padding: 7px 14px; border: 1px solid #d0d4da; background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 13px; color: #333;
  transition: background .15s;
}
.btn:hover { background: #f0f2f5; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.btn-primary:hover { background: #2f6fe0; }
.btn-danger { color: #c0392b; }
.btn-icon { background: none; border: none; font-size: 18px; cursor: pointer; color: #888; line-height: 1; }
.btn-icon:hover { color: #333; }

/* 工作区：左列编辑 / 右列 JSON 预览 */
.workspace {
  display: flex; gap: 20px; align-items: flex-start;
  padding: 20px; max-width: 1600px; margin: 0 auto;
}
.editor-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 16px; }

/* 左侧预设栏 */
.preset-col {
  flex: 0 0 220px; display: flex; flex-direction: column;
  position: sticky; top: 76px; max-height: calc(100vh - 96px);
}
.preset-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.preset-title { font-size: 13px; font-weight: 600; color: #555; }
.preset-list { display: flex; flex-direction: column; gap: 8px; overflow: auto; }
.preset-card {
  background: #fff; border: 1px solid #e3e6ea; border-radius: 8px;
  padding: 10px 12px; cursor: pointer; transition: border-color .15s, background .15s;
}
.preset-card:hover { border-color: #3b82f6; background: #eef4ff; }
.preset-card .pname { font-size: 13px; font-weight: 600; color: #333; }
.preset-card .pdesc { font-size: 11px; color: #999; margin-top: 2px; line-height: 1.4; }
.preset-card .pcount { font-size: 11px; color: #3b82f6; margin-top: 4px; }
.preset-msg { font-size: 12px; color: #999; padding: 16px 4px; text-align: center; line-height: 1.5; }
.preset-msg.error { color: #c0392b; }

/* 本地缓存 */
.save-section { margin-top: 16px; border-top: 1px solid #e3e6ea; padding-top: 12px; }
.save-input-row { display: flex; gap: 6px; margin-bottom: 8px; }
.save-input-row input {
  flex: 1; min-width: 0; padding: 5px 8px; border: 1px solid #d0d4da;
  border-radius: 6px; font-size: 12px;
}
.save-input-row input:focus { outline: none; border-color: #3b82f6; }
.save-card {
  display: flex; align-items: center; justify-content: space-between;
  background: #fff; border: 1px solid #e3e6ea; border-radius: 8px;
  padding: 7px 10px; gap: 6px;
}
.save-card .save-name {
  flex: 1; min-width: 0; font-size: 13px; color: #333; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.save-card .save-name:hover { color: #3b82f6; }
.save-ops { display: flex; gap: 4px; flex-shrink: 0; }
.save-ops button {
  background: none; border: none; cursor: pointer; font-size: 13px;
  color: #999; padding: 0 2px; line-height: 1;
}
.save-ops button:hover { color: #333; }
.save-ops button.del:hover { color: #c0392b; }
.save-rename-input {
  flex: 1; min-width: 0; padding: 2px 4px; border: 1px solid #3b82f6;
  border-radius: 4px; font-size: 13px;
}
.save-rename-input:focus { outline: none; }
.json-col {
  flex: 0 0 460px; display: flex; flex-direction: column;
  position: sticky; top: 76px;
}
.json-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.json-title { font-size: 13px; font-weight: 600; color: #555; }
#json-output {
  width: 100%; min-height: 72vh; padding: 12px;
  border: 1px solid #d0d4da; border-radius: 8px; background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; line-height: 1.5; color: #333;
  resize: none; white-space: pre; overflow: auto;
}
@media (max-width: 900px) {
  .workspace { flex-direction: column; }
  .preset-col { flex: none; width: 100%; position: static; max-height: none; }
  .preset-list { flex-direction: row; flex-wrap: wrap; }
  .preset-card { flex: 1 1 200px; }
  .json-col { flex: none; width: 100%; position: static; }
  #json-output { min-height: 320px; }
}
/* 中间编辑区：上下主从两栏 */
.key-editor, .block-editor {
  background: #fff; border: 1px solid #e3e6ea; border-radius: 10px;
  padding: 14px 16px;
}
.editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 10px; flex-wrap: wrap; }
.section-title { font-size: 13px; font-weight: 600; color: #555; }
.editor-info { font-size: 12px; color: #888; }
.editor-head-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hidden { display: none; }

/* 上栏：key 列表（标签式，横向换行） */
.key-list { display: flex; flex-wrap: wrap; gap: 8px; max-height: 340px; overflow: auto; }
.key-item {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 6px 5px 10px; border: 1px solid #e3e6ea; border-radius: 16px;
  cursor: pointer; font-size: 13px; background: #fff;
  transition: border-color .15s, background .15s;
}
.key-item:hover { border-color: #93b4f5; background: #f5f9ff; }
.key-item.active { border-color: #3b82f6; background: #eef4ff; }
.key-item img { image-rendering: pixelated; }
.key-item .kname { white-space: nowrap; color: #333; }
.key-item.placeholder .kname { color: #999; font-style: italic; }
.key-item .kcount { font-size: 11px; color: #3b82f6; }
.key-item .kdel { background: none; border: none; cursor: pointer; color: #999; font-size: 13px; padding: 0 2px; line-height: 1; }
.key-item .kdel:hover { color: #c0392b; }
.key-empty { font-size: 12px; color: #999; padding: 16px 4px; text-align: center; }

/* 下栏：方块编辑（复用 value-chip） */
.value-chip img { image-rendering: pixelated; }
.values { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.value-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 8px; background: #f0f2f5; border-radius: 6px; font-size: 13px;
}
.value-chip .rm { cursor: pointer; color: #999; padding: 0 3px; font-size: 14px; }
.value-chip .rm:hover { color: #c0392b; }
.add-value {
  padding: 4px 10px; border: 1px dashed #b0b6be; background: transparent;
  border-radius: 6px; cursor: pointer; font-size: 13px; color: #666;
}
.add-value:hover { background: #f0f2f5; color: #333; }
.block-empty-tip { text-align: center; color: #999; padding: 32px 12px; font-size: 13px; }

/* 选择器模态 */
.picker {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; justify-content: center; align-items: center;
  z-index: 100; padding: 24px 16px; overflow: auto;
}
.picker.hidden { display: none; }
.picker-panel {
  background: #fff; border-radius: 12px; width: 100%; max-width: 1080px;
  max-height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden;
  padding: 16px; box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.picker-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; flex-shrink: 0; }
.picker-header h2 { font-size: 16px; }
.picker-title-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.picker-hint { font-size: 12px; color: #888; }
.picker-search { flex-shrink: 0; }
.picker-search input {
  width: 100%; padding: 9px 12px; border: 1px solid #d0d4da;
  border-radius: 6px; font-size: 14px;
}
.picker-search input:focus { outline: none; border-color: #3b82f6; }
.picker-tags-row { display: flex; align-items: flex-start; gap: 10px; margin: 10px 0; flex-shrink: 0; }
.picker-tags { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; max-height: 96px; overflow: auto; }
.picker-side-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.tag {
  padding: 3px 10px; border: 1px solid #d0d4da; border-radius: 12px;
  cursor: pointer; font-size: 12px; background: #fff; color: #555; user-select: none;
}
.tag:hover { background: #f0f2f5; }
.tag.active { background: #3b82f6; color: #fff; border-color: #3b82f6; }
/* 分组标签：display:contents 让组内标签参与外层换行，分组名作为内联分隔 */
.tag-group { display: contents; }
.tag-glabel { font-size: 11px; color: #9aa3af; font-weight: 600; margin-left: 4px; user-select: none; }
.picker-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 6px; flex: 1 1 auto; min-height: 0; overflow: auto; padding: 2px;
  user-select: none; -webkit-user-select: none;
}
.picker-item {
  position: relative; display: flex; flex-direction: column; align-items: center;
  padding: 6px 4px; border: 1px solid #eee; border-radius: 6px;
  cursor: pointer; text-align: center; transition: border-color .12s, background .12s;
}
.picker-item img { width: 40px; height: 40px; image-rendering: pixelated; -webkit-user-drag: none; }
.picker-item:hover { background: #eef4ff; border-color: #3b82f6; }
.picker-item.selected { background: #e6f4ea; border-color: #34a853; }
.picker-item.excluded { opacity: 0.35; cursor: not-allowed; }
.picker-item.excluded:hover { background: #fff; border-color: #eee; }
.picker-item .pid { margin-top: 3px; text-align: center; }
.picker-item .pid .cn { display: block; font-size: 11px; color: #222; line-height: 1.2; word-break: break-all; }
.picker-item .pid .did { display: block; font-size: 9px; color: #999; line-height: 1.2; word-break: break-all; }
.picker-item .check {
  position: absolute; top: 2px; right: 2px;
  background: #34a853; color: #fff; border-radius: 50%;
  width: 16px; height: 16px; font-size: 11px; line-height: 16px; text-align: center; font-weight: bold;
}
.picker-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; font-size: 12px; color: #888; flex-shrink: 0; }
.picker-foot-actions { display: flex; gap: 8px; }
@media (max-width: 600px) {
  .picker { padding: 12px 8px; }
  .picker-panel { max-height: calc(100vh - 24px); }
  .picker-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
  .picker-item img { width: 32px; height: 32px; }
}
