* {
  box-sizing: border-box;
}

html,
body,
#app {
  margin: 0;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  font-family: 'PingFang SC', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  background: #f3f4f6;
  color: #111827;
}

.app {
  --er-toolbar-h: 52px;
  --er-rail-w: 40px;
  --side-width: 360px;
  /* JSON 选中高亮：与 demo 简单编辑 / JSON 统一主题蓝 */
  --er-select-bg: #2563eb;
  --er-select-border: #1d4ed8;
  --er-select-fg: #ffffff;
  position: relative;
  display: flex;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  align-items: stretch;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.panel-left {
  /* 兼容旧类名 */
  width: var(--side-width);
  flex-shrink: 0;
  background: #111827;
  color: #e5e7eb;
  border-right: 1px solid #374151;
  padding: 16px 14px 0;
}

/* 中央画布：三栏中的主栏，顶栏属于此处 */
.panel-center {
  flex: 1;
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  height: 100%;
  background: #ffffff;
  overflow: hidden;
}

/* 侧栏槽位：始终 40px 三栏占位 */
.toolbar-slot {
  position: relative;
  z-index: 20;
  flex: 0 0 var(--er-rail-w);
  width: var(--er-rail-w);
  align-self: stretch;
}

/* 侧栏本体：默认填满窄轨；展开为抽屉浮层 */
.toolbar {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100%;
  background: #111827;
  color: #e5e7eb;
  padding: 10px 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: none;
  transition: width 0.2s ease, padding 0.2s ease, box-shadow 0.2s ease;
}

.toolbar-slot-left .toolbar {
  left: 0;
  border-right: 1px solid #374151;
}

.toolbar-slot-right .toolbar {
  right: 0;
  border-left: 1px solid #374151;
}

/* 收起 / 默认：窄轨 */
.toolbar.is-collapsed {
  width: 100%;
  padding: 10px 0;
  overflow: hidden;
  align-items: center;
  box-shadow: none;
}

/* 展开：悬浮抽屉（槽位仍 40px，多一层浮层） */
.toolbar.is-drawer {
  width: var(--side-width);
  padding: 16px 14px 0;
  align-items: stretch;
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.28);
  z-index: 40;
}

.toolbar.is-collapsed .toolbar-body {
  display: none;
}

.toolbar.is-collapsed .toolbar-header-title {
  display: none;
}

.toolbar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.toolbar.is-collapsed .toolbar-header {
  margin-bottom: 0;
  flex-direction: column;
  justify-content: flex-start;
  height: 100%;
}

.toolbar-header-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.toolbar-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toolbar-toggle {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border: 1px solid #4b5563;
  border-radius: 6px;
  background: #1f2937;
  color: #e5e7eb;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.toolbar-toggle:hover {
  background: #374151;
}

.toolbar-collapsed-label {
  display: none;
  margin-top: 12px;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 13px;
  letter-spacing: 0.2em;
  color: #9ca3af;
  cursor: pointer;
  user-select: none;
}

.toolbar.is-collapsed .toolbar-collapsed-label {
  display: block;
}

.toolbar-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.toolbar-left .json-editor {
  flex: 1;
  min-height: 0;
  width: 100%;
  margin: 0;
  resize: none;
}

.toolbar-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-right: 2px;
  display: flex;
  flex-direction: column;
}

.toolbar-section {
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid #374151;
}

.toolbar-section:last-child {
  border-bottom: none;
}

.toolbar-section-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: #9ca3af;
}

.toolbar-hint {
  margin: 0 0 10px;
  font-size: 11px;
  color: #9ca3af;
  line-height: 1.5;
}

.toolbar-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0 16px;
  margin-top: 4px;
  border-top: 1px solid #374151;
  background: #111827;
}

.toolbar-footer .data-status {
  margin: 0;
  min-height: 20px;
  font-size: 12px;
  line-height: 1.45;
  color: #9ca3af;
}

.toolbar-footer .status {
  margin: 0;
  min-height: 20px;
  font-size: 12px;
  line-height: 1.45;
  color: #9ca3af;
}

.toolbar-footer .data-status.is-ok,
.toolbar-footer .status.is-ok {
  color: #34d399;
}

.toolbar-footer .data-status.is-error,
.toolbar-footer .status.is-error {
  color: #f87171;
}

.toolbar-footer-row {
  display: flex;
  gap: 8px;
}

.toolbar-footer-row .toolbar-btn {
  flex: 1;
  width: auto;
}

.toolbar-btn {
  width: 100%;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.toolbar-btn:hover {
  background: #1d4ed8;
}

.toolbar-btn:active {
  background: #1e40af;
}

.toolbar-btn-reset {
  background: #374151;
}

.toolbar-btn-reset:hover {
  background: #4b5563;
}

.toolbar-btn-reset:active {
  background: #6b7280;
}

.toolbar-row {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12px;
}

.toolbar-row span:first-child {
  color: #d1d5db;
}

.toolbar-row input[type='range'] {
  width: 100%;
  accent-color: #2563eb;
}

.toolbar-row input[type='color'] {
  width: 36px;
  height: 24px;
  padding: 0;
  border: 1px solid #4b5563;
  background: transparent;
  cursor: pointer;
  grid-column: 2 / 4;
  justify-self: start;
}

.toolbar-row input[type='checkbox'] {
  width: 16px;
  height: 16px;
  justify-self: start;
  grid-column: 2 / 4;
}

.toolbar-row select.toolbar-select,
.toolbar-select {
  width: 100%;
  height: 28px;
  padding: 0 8px;
  border: 1px solid #4b5563;
  border-radius: 6px;
  background: #111827;
  color: #e5e7eb;
  font-size: 12px;
  grid-column: 2 / 4;
  justify-self: stretch;
}

.toolbar-row output {
  min-width: 36px;
  text-align: right;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
}

.panel-header {
  flex-shrink: 0;
  margin-bottom: 16px;
}

.panel-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  min-width: 0;
}

.manual-open-btn {
  flex-shrink: 0;
  height: 28px;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.55);
  animation: manual-btn-pulse 1.6s ease-in-out infinite;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.manual-open-btn:hover {
  background: #1d4ed8;
  animation: none;
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.45);
}

.manual-open-btn:active {
  transform: scale(0.96);
  background: #1e40af;
}

@keyframes manual-btn-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.5);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 0 10px rgba(37, 99, 235, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .manual-open-btn {
    animation: none;
  }
  .manual-open-btn:hover {
    transform: none;
  }
}

.panel-desc {
  margin: 6px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: #9ca3af;
}

.panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel-footer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0 16px;
  margin-top: 4px;
  border-top: 1px solid #374151;
}

.status {
  min-height: 20px;
  font-size: 12px;
  color: #9ca3af;
}

.status.is-ok {
  color: #34d399;
}

.status.is-error {
  color: #f87171;
}

.btn-row {
  display: flex;
  gap: 8px;
}

.btn {
  flex: 1;
  height: 36px;
  border: none;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover {
  background: #1d4ed8;
}

.btn-muted {
  background: #374151;
}

.btn-muted:hover {
  background: #4b5563;
}

.json-editor {
  flex: 1;
  width: 100%;
  min-height: 240px;
  resize: none;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #0b1220;
  color: #e5e7eb;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre;
  tab-size: 2;
}

.json-editor.is-invalid {
  border-color: #f87171;
}

/* 仅选中片段为蓝色背景（非整框） */
.json-editor::selection {
  background: var(--er-select-bg);
  color: var(--er-select-fg);
}

.json-editor::-moz-selection {
  background: var(--er-select-bg);
  color: var(--er-select-fg);
}

.paper-wrap {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  cursor: grab;
  user-select: none;
  background: #ffffff;
}

.paper-wrap.is-panning {
  cursor: grabbing;
}

.paper-host {
  min-width: 100%;
  min-height: 100%;
}

.paper-host .joint-element,
.table-paper-host .joint-element {
  cursor: move !important;
}

.paper-host .joint-link,
.table-paper-host .joint-link {
  cursor: default !important;
  pointer-events: none;
}

/* 四周间距虚线预览（仅画布展示，导出不截入）——样式与 demo 一致 */
.padding-guide {
  position: absolute;
  z-index: 8;
  pointer-events: none;
  box-sizing: border-box;
}

.padding-guide-frame {
  position: absolute;
  inset: 0;
  border: 2px dashed #2563eb;
  box-sizing: border-box;
  background: rgba(37, 99, 235, 0.04);
}

.padding-guide-label {
  position: absolute;
  padding: 2px 6px;
  border-radius: 3px;
  background: #2563eb;
  color: #fff;
  font-size: 11px;
  line-height: 1.3;
  white-space: nowrap;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

.padding-guide-label.is-top {
  left: 50%;
  top: 4px;
  transform: translateX(-50%);
}

.padding-guide-label.is-bottom {
  left: 50%;
  bottom: 4px;
  transform: translateX(-50%);
}

.padding-guide-label.is-left {
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.08em;
}

.padding-guide-label.is-right {
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.08em;
}

.padding-guide-tip {
  position: absolute;
  left: 50%;
  top: -26px;
  transform: translateX(-50%);
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(17, 24, 39, 0.88);
  color: #e5e7eb;
  font-size: 11px;
  white-space: nowrap;
  font-family: 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

/* 中间画布顶栏：属于中央画布栏 */
.main-toolbar {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  height: var(--er-toolbar-h);
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  column-gap: 16px;
  padding: 0 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.main-toolbar-start {
  justify-self: start;
  min-width: 0;
  display: flex;
  align-items: center;
}

.main-toolbar-mid {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* 顶栏「操作手册」：紧挨缩小按钮前 */
.toolbar-manual-btn {
  flex-shrink: 0;
  height: 34px;
  padding: 0 12px;
  border: 1px solid #2563eb;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.45);
  animation: manual-btn-pulse 1.6s ease-in-out infinite;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.toolbar-manual-btn:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  animation: none;
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.toolbar-manual-btn:active {
  transform: scale(0.97);
  background: #1e40af;
}

.main-toolbar-end {
  justify-self: end;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* 视图切换：与 zoom-cluster 同款白底描边 */
.toolbar-tabs {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.toolbar-tab {
  height: 28px;
  min-width: 0;
  padding: 0 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #374151;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.toolbar-tab:hover {
  background: #f3f4f6;
  color: #111827;
}

.toolbar-tab.is-active {
  background: #2563eb;
  color: #fff;
}

.toolbar-tab.is-active:hover {
  background: #1d4ed8;
  color: #fff;
}

/* 缩放控件组 */
.zoom-cluster {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.zoom-cluster .zoom-btn {
  height: 28px;
  min-width: 28px;
  padding: 0 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #111827;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.zoom-cluster .zoom-btn:hover {
  background: #f3f4f6;
}

.zoom-cluster .zoom-btn.is-reset {
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
}

.zoom-cluster .zoom-value {
  min-width: 44px;
  padding: 0 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: #111827;
  font-variant-numeric: tabular-nums;
}

.zoom-cluster.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}

.zoom-cluster.is-disabled .zoom-btn,
.zoom-cluster.is-disabled .zoom-value {
  cursor: not-allowed;
  color: #9ca3af;
}

.main-toolbar-tip {
  display: inline-block;
  max-width: min(420px, 100%);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  color: #b45309;
  background: #fffbeb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-toolbar-label {
  font-size: 12px;
  color: #6b7280;
  margin-right: 4px;
}

.main-toolbar-sep {
  width: 1px;
  height: 20px;
  background: #d1d5db;
  margin: 0 4px;
}

/* 兼容旧 zoom-btn（侧栏外若仍有引用） */
.zoom-btn {
  height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  color: #111827;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.zoom-btn:hover {
  background: #f3f4f6;
}

.zoom-btn.is-active {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.zoom-btn.is-active:hover {
  background: #1d4ed8;
}

.zoom-value {
  min-width: 48px;
  text-align: center;
  font-size: 12px;
  color: #374151;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 1100px) {
  .main-toolbar {
    column-gap: 10px;
    padding: 0 12px;
  }

  .main-toolbar-tip {
    max-width: 220px;
  }
}

@media (max-width: 820px) {
  .main-toolbar-end {
    display: none;
  }

  .main-toolbar {
    grid-template-columns: 1fr auto 1fr;
  }

  .main-toolbar-mid {
    justify-self: center;
  }
}

.view-pane {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.view-pane.is-active {
  display: flex;
}

.tables-host {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #f3f4f6;
}

.table-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.table-card-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 12px 14px 10px;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
  text-align: center;
}

.table-card-title {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: #111827;
  text-align: center;
}

.table-card-desc {
  margin: 0;
  font-size: 12px;
  color: #6b7280;
  text-align: center;
}

.table-card-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 14px 16px;
  border-top: 1px solid #e5e7eb;
  background: #fff;
}

.table-download-btn {
  flex-shrink: 0;
  height: 36px;
  min-width: 120px;
  padding: 0 20px;
  border: 1px solid #2563eb;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.table-download-btn:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.table-paper-wrap {
  position: relative;
  height: 500px;
  overflow-x: auto;
  overflow-y: auto;
  background: #fff;
}

.table-paper-stage {
    position: relative;
    margin: 0 auto;
    min-height: 100%;
    /* 给虚线框上方提示条留出空间（与完整 ER tip top:-26px 一致） */
    padding-top: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}

.table-paper-host {
  position: relative;
  flex-shrink: 0;
  overflow: visible;
  background: #fff;
}

.table-paper-host .joint-paper {
  border: none !important;
}

