:root {
  --bg: #f4f6f8;
  --panel-bg: #ffffff;
  --border: #d9dee3;
  --text: #1f2a37;
  --muted: #8a94a0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --node-bg: #ffffff;
  --node-border: #3b82f6;
  --node-selected: #dbeafe;
  --connector: #9ca3af;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.navbar-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.navbar-right { display: flex; align-items: center; gap: 10px; }
.brand { font-size: 16px; }
.navbar-field { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.navbar-field select { min-width: 180px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  overflow: hidden;
}
.panel {
  background: var(--panel-bg);
  overflow: auto;
  padding: 14px;
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }
.panel-center { background: var(--bg); padding: 0; }
.panel h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 12px; }

.btn {
  cursor: pointer;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: #f0f3f6; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0c4c4; }
.btn-danger:hover { background: #fdeaea; }
.btn-block { width: 100%; margin-top: 8px; }

.fields-list { list-style: none; padding: 0; margin: 0; }
.field-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: #fff;
  cursor: grab;
}
.field-item.dragging { opacity: .4; }
.field-item.drag-over { border-color: var(--primary); }
.field-item-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.field-item-label { font-weight: 600; font-size: 13px; }
.field-item-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.field-item-actions { display: flex; gap: 4px; }
.icon-btn {
  border: none; background: none; cursor: pointer; font-size: 13px; padding: 2px 4px; border-radius: 4px; color: var(--muted);
}
.icon-btn:hover { background: #eef1f4; color: var(--text); }
.req-badge { color: var(--danger); font-size: 11px; }

.field-form { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.field-form label, .node-editor label, .modal label {
  display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted);
}
.field-form input[type="text"], .field-form select,
.node-editor input, .node-editor select, .node-editor textarea,
.modal input, .modal select {
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 13px; color: var(--text); background: #fff;
}
.checkbox-row { flex-direction: row !important; align-items: center; gap: 6px; color: var(--text) !important; font-size: 13px !important; }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }

.diagram {
  width: 100%;
  height: 100%;
  overflow: auto;
  padding: 30px;
  display: flex;
  justify-content: center;
}
.diagram-inner { display: inline-block; }
.empty-state { color: var(--muted); text-align: center; margin-top: 60px; }

.tree-root-wrap { display: flex; gap: 40px; align-items: flex-start; }
ul.tree, ul.tree ul {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}
ul.tree { display: flex; }
ul.tree li {
  position: relative;
  padding: 28px 12px 0;
  text-align: center;
}

ul.tree li::before, ul.tree li::after {
  content: "";
  position: absolute;
  top: 0;
  height: 28px;
  border-top: 2px solid var(--connector);
  width: 50%;
}
ul.tree li::before { left: 0; }
ul.tree li::after { right: 0; border-left: 2px solid var(--connector); }
ul.tree li:only-child::after, ul.tree li:only-child::before { display: none; }
ul.tree li:first-child::before, ul.tree li:last-child::after { border: none; }
ul.tree li:last-child::before { border-right: 2px solid var(--connector); border-radius: 0 6px 0 0; }
ul.tree li:first-child::after { border-radius: 6px 0 0 0; }
ul.tree ul::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  height: 28px;
  border-left: 2px solid var(--connector);
}
ul.tree ul { padding-top: 28px; display: flex; }

.node-box {
  display: inline-block;
  min-width: 120px;
  max-width: 200px;
  background: var(--node-bg);
  border: 2px solid var(--node-border);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  position: relative;
  transition: background .15s, box-shadow .15s;
}
.node-box:hover { box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.node-box.selected { background: var(--node-selected); border-color: var(--primary-dark); }
.node-title { font-weight: 600; font-size: 13px; word-break: break-word; }
.node-line { font-size: 11px; color: var(--muted); word-break: break-word; }
.node-empty { font-style: italic; color: var(--muted); font-size: 12px; }
.node-add-child {
  position: absolute;
  bottom: -10px; right: -10px;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: none;
  align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.node-box:hover .node-add-child { display: flex; }

.node-editor { display: flex; flex-direction: column; gap: 12px; }
.node-editor .editor-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.node-editor .editor-actions .btn { width: 100%; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal-box {
  background: #fff; border-radius: 10px; padding: 20px; width: 360px; max-width: 90vw;
  display: flex; flex-direction: column; gap: 12px;
}
.modal-box h3 { margin: 0; }
.modal-box form { display: flex; flex-direction: column; gap: 10px; }
.modal-or { text-align: center; font-size: 12px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 13px; z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); }
