/* 基础布局 */
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, 'PingFang SC', 'Noto Sans SC', 'Microsoft YaHei', sans-serif;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid #e5e7eb;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 {
  font-size: 18px;
  margin: 0;
}
.app-header .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
button {
  padding: 6px 10px;
  border: 1px solid #d1d5db;
  background: #f9fafb;
  border-radius: 6px;
  cursor: pointer;
}
button:hover {
  background: #f3f4f6;
}

.container {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100% - 54px);
  min-height: 0;
}
.panel {
  padding: 12px;
  border-bottom: 1px solid #f3f4f6;
}
.left {
  border-right: 1px solid #e5e7eb;
  overflow: auto;
}
.right {
  display: grid;
  grid-template-rows: 1fr;
  height: 100%;
  min-height: 0;
}
.right > .panel {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

h2 {
  font-size: 14px;
  margin: 0 0 8px;
  color: #111827;
}
#state-list,
#event-list {
  list-style: none;
  padding: 0;
  margin: 0;
}
#state-list li,
#event-list li {
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  transition:
    box-shadow 0.15s ease,
    border-color 0.15s ease;
}
#state-list li.active,
#event-list li.active {
  box-shadow: 0 0 0 2px #2563eb;
  border-color: #c7d2fe;
}
.item-title {
  display: grid;
  gap: 2px;
  flex: 1;
  min-width: 0;
}
.state-name,
.event-name {
  font-weight: 600;
  font-size: 13px;
  color: #111827;
  word-break: break-word;
}
.meta {
  font-size: 12px;
  color: #6b7280;
  word-break: break-word;
  white-space: normal;
  line-height: 1.2;
}
.badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 11px;
  border-radius: 999px;
  border: 1px solid #c7d2fe;
  background: #eef2ff;
  color: #3730a3;
  width: 43px;
}
.badge-initial {
}
.item-actions {
  display: flex;
  gap: 6px;
}
.item-actions button {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: 8px;
}

#lifecycle-editor {
  display: grid;
  gap: 8px;
}
#lifecycle-editor .row {
  display: grid;
  gap: 6px;
}
#lifecycle-editor label {
  font-size: 12px;
  color: #374151;
}
#lifecycle-editor textarea {
  width: 100%;
  min-height: 64px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}
#lifecycle-editor .tip {
  color: #6b7280;
  font-size: 12px;
}

#graph {
  width: 100%;
  flex: 1;
  min-height: 0;
  background: #fff;
  border-top: 1px solid #f3f4f6;
  border-bottom: 1px solid #f3f4f6;
}
#ts-preview {
  width: 100%;
  height: 220px;
  border: none;
  border-top: 1px solid #f3f4f6;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  background: #0b1021;
  color: #e5e7eb;
  border-radius: 0;
}

/* dagre-d3 样式 */
.node rect {
  stroke: #94a3b8;
  fill: #ffffff;
  rx: 6px;
  ry: 6px;
}
.node .label {
  font-size: 12px;
}
.edgePath path {
  stroke: #94a3b8;
  fill: none;
  stroke-width: 1.5px;
}
.edgeLabel rect {
  fill: #f9fafb;
}
.initial-marker rect {
  stroke: #2563eb;
}

/* 右键菜单样式 */
#ctx-menu {
  position: absolute;
  z-index: 50;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}
#ctx-menu button {
  display: block;
  width: 160px;
  text-align: left;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
}
#ctx-menu button:hover {
  background: #f3f4f6;
}
#ctx-menu button.danger {
  color: #dc2626;
}
#ctx-menu .ctx-sep {
  height: 1px;
  background: #f3f4f6;
  margin: 6px 0;
}
#ctx-life {
  max-width: 420px;
  padding: 6px 8px;
}
#ctx-life .field {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}
#ctx-life .field .field-label {
  font-size: 12px;
  color: #374151;
}
#ctx-life textarea {
  width: 100%;
  min-height: 84px;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fafafa;
  font-size: 13px;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  resize: vertical;
}
#ctx-life .ctx-tip {
  background: #f9fafb;
  border: 1px solid #eef2f7;
  padding: 6px 8px;
  border-radius: 6px;
}
#ctx-life .ctx-tip {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}
#ctx-life-code {
  margin: 0;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 8px;
  font-size: 12px;
  max-height: 200px;
  overflow: auto;
}

/* 粘贴 Config 模态框样式 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
}
.modal .modal-body {
  width: min(560px, 92vw);
  max-height: 90vh;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
  display: grid;
  gap: 10px;
  animation: modalIn 0.12s ease-out;
}
.modal .modal-body h3 {
  margin: 0;
  font-size: 16px;
}
.modal .modal-body .tip {
  font-size: 12px;
  color: #6b7280;
}
#paste-text {
  width: 100%;
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
}

/* 细节：更舒适的滚动条（支持的浏览器生效即可） */
textarea::-webkit-scrollbar,
#ts-preview::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
textarea::-webkit-scrollbar-thumb,
#ts-preview::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
  border: 2px solid #eef2f7;
}
textarea::-webkit-scrollbar-track,
#ts-preview::-webkit-scrollbar-track {
  background: #f1f5f9;
  border-radius: 10px;
}
.modal .modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* —— 自定义表单弹窗优化 —— */
.transition-form {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
}
.modal .modal-body label {
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: #374151;
}
.modal .modal-body input[type='text'],
.modal .modal-body select {
  width: 100%;
  height: 34px;
  padding: 6px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
}
.modal .modal-body textarea {
  width: 100%;
  min-height: 96px;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  line-height: 1.5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  resize: vertical;
}
.modal .modal-body input[type='text']:focus,
.modal .modal-body select:focus,
#ctx-life textarea:focus,
#paste-text:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}
.modal .modal-actions button:first-child {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}
.modal .modal-actions button:first-child:hover {
  background: #1d4ed8;
}
.modal .modal-actions button:last-child {
  background: #f3f4f6;
}

@keyframes modalIn {
  from {
    transform: translateY(6px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (min-width: 640px) {
  .transition-form {
    grid-template-columns: 1fr 1fr;
  }
  .transition-form > label {
    min-width: 0;
  }
}
