/* ========== Design Tokens (与豆苗AI统一风格) ========== */
:root {
  --brand-500: #10B981;
  --brand-600: #059669;
  --brand-50: #ECFDF5;
  --brand-100: #D1FAE5;
  --ink-900: #0F172A;
  --ink-600: #475569;
  --ink-400: #94A3B8;
  --paper: #FAFAF7;
  --card: #FFFFFF;
  --line: #E5E7EB;
  --danger: #EF4444;
  --radius-card: 16px;
  --radius-item: 12px;
  --radius-btn: 10px;
  --shadow-card: 0 1px 2px rgba(15,23,42,.04), 0 4px 12px rgba(15,23,42,.04);
}

/* Dark Mode */
.dark {
  --paper: #0F172A;
  --card: #1E293B;
  --line: #334155;
  --ink-900: #F1F5F9;
  --ink-600: #CBD5E1;
  --ink-400: #64748B;
  --brand-50: #064E3B;
  --brand-100: #065F46;
}

/* ========== Reset & Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Noto Sans SC", "Inter", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink-900);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

/* ========== Navbar ========== */
.navbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
}
.dark .navbar { background: var(--card); }
.navbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.navbar-logo img {
  height: 32px;
  width: auto;
  display: block;
}
.navbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink-900);
  line-height: 1.2;
}
.navbar-subtitle {
  font-size: 12px;
  color: var(--ink-400);
  line-height: 1.2;
  margin-top: 2px;
}
.theme-toggle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}
.dark .theme-toggle { background: var(--card); border-color: var(--line); color: var(--ink-600); }
.theme-toggle:hover { background: var(--brand-50); }
.dark .theme-icon-sun { display: none !important; }
.dark .theme-icon-moon { display: block !important; }

/* ========== Brand Header ========== */
.brand-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  background: linear-gradient(135deg, var(--brand-50), var(--brand-100));
  border-radius: var(--radius-card);
  margin-bottom: 28px;
}
.brand-logo-wrap { flex-shrink: 0; }
.brand-logo-img { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; }
.brand-logo-fallback { display: none; width: 64px; height: 64px; border-radius: 16px; background: var(--brand-500); place-items: center; color: #fff; }
.brand-title { font-size: 20px; font-weight: 700; color: var(--ink-900); }
.brand-sub { font-size: 13px; color: var(--ink-600); margin-top: 2px; }

/* ========== Block ========== */
.block { margin-bottom: 24px; }
.block-head { margin-bottom: 12px; }
.block-title { font-size: 15px; font-weight: 600; color: var(--ink-900); }
.block-desc { font-size: 12px; color: var(--ink-400); margin-top: 2px; }

/* ========== Form Card ========== */
.form-card {
  background: var(--card);
  border-radius: var(--radius-card);
  padding: 20px;
  box-shadow: var(--shadow-card);
}
.field-input {
  width: 100%; padding: 10px 14px; font-size: 14px; font-family: inherit;
  border: 1.5px solid var(--line); border-radius: var(--radius-item);
  background: var(--card); color: var(--ink-900);
  transition: border-color .15s, box-shadow .15s;
  resize: vertical;
}
.field-input:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px var(--brand-50);
}
.field-textarea { min-height: 160px; resize: vertical; }

/* ========== Buttons ========== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 24px; font-size: 14px; font-weight: 600; font-family: inherit;
  border: none; border-radius: var(--radius-btn); cursor: pointer;
  transition: all .15s cubic-bezier(.4,0,.2,1);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand-500); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-600); }
.btn-secondary { background: var(--card); color: var(--brand-500); border: 1.5px solid var(--brand-500); }
.btn-secondary:hover:not(:disabled) { background: var(--brand-50); }
.btn-outline {
  background: var(--card); color: var(--ink-600);
  border: 1.5px solid var(--line);
}
.btn-outline:hover:not(:disabled) { border-color: var(--ink-400); }
.btn-sm { padding: 6px 14px; font-size: 12px; }

/* ========== Selector Grid ========== */
.selector-grid { display: grid; gap: 8px; }
.selector-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.selector-item {
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: var(--radius-item); padding: 12px 10px;
  cursor: pointer; text-align: center;
  transition: all .15s cubic-bezier(.4,0,.2,1);
  font-size: 13px; color: var(--ink-600);
}
.selector-item:hover { border-color: var(--ink-400); transform: translateY(-1px); }
.selector-item.active {
  border-color: var(--brand-500); border-width: 2px;
  background: var(--brand-50); color: var(--brand-600);
  font-weight: 600;
}
.selector-icon { font-size: 22px; margin-bottom: 4px; display: block; }
.selector-name { font-weight: 500; }

/* ========== Section Preview ========== */
.section-preview {
  background: var(--card); border-radius: var(--radius-card);
  padding: 16px 20px; box-shadow: var(--shadow-card);
}
.section-preview .preview-title-row {
  display: flex; gap: 8px; align-items: center; margin-bottom: 8px;
}
.preview-summary {
  font-size: 12px; color: var(--ink-600); background: var(--brand-50);
  padding: 8px 12px; border-radius: 8px; margin-bottom: 10px;
}

/* ========== Node Edit Table ========== */
.node-edit-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.node-edit-table th {
  font-size: 11px; color: var(--ink-400); font-weight: 500;
  text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line);
}
.node-edit-table td { padding: 3px 4px; vertical-align: middle; }
.node-edit-table input {
  width: 100%; padding: 6px 8px; font-size: 12px; font-family: inherit;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--ink-900);
}
.node-edit-table input:focus {
  outline: none; border-color: var(--brand-500);
}
.node-edit-table .btn-del {
  width: 24px; height: 24px; padding: 0; border: 1px solid var(--line);
  border-radius: 4px; background: var(--card); color: var(--ink-400);
  cursor: pointer; font-size: 12px; display: flex; align-items: center; justify-content: center;
}
.node-edit-table .btn-del:hover { border-color: var(--danger); color: var(--danger); }
.btn-add-row {
  margin-top: 6px; padding: 4px 12px; font-size: 12px;
  background: var(--card); border: 1px dashed var(--line);
  border-radius: 6px; cursor: pointer; color: var(--ink-400);
}
.btn-add-row:hover { border-color: var(--brand-500); color: var(--brand-500); }

/* ========== Relations ========== */
.relations-section {
  margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line);
}
.relations-title {
  font-size: 12px; font-weight: 600; color: var(--ink-600); margin-bottom: 6px;
}
.relation-item {
  font-size: 12px; color: var(--ink-600); padding: 3px 0;
}
.relation-label {
  color: var(--brand-500); font-weight: 500;
}

/* ========== Result Area (Editor) ========== */
.result-area {
  background: var(--card); border-radius: var(--radius-card);
  box-shadow: var(--shadow-card); overflow: hidden;
  margin-top: 24px;
}
.result-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  font-size: 14px; font-weight: 600; color: var(--ink-900);
  flex-wrap: wrap; gap: 8px;
}
.result-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ========== Editor Body ========== */
.editor-body {
  position: relative;
  width: 100%;
  height: 600px;
  background: #F9FAFB;
  overflow: hidden;
}
.dark .editor-body { background: #0F172A; }

.editor-body svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Node hover effect */
.editor-body .node:hover rect {
  filter: brightness(0.96);
}
.dark .editor-body .node:hover rect {
  filter: brightness(1.15);
}

/* ========== Loading ========== */
.loading-dots { display: inline-flex; gap: 4px; }
.loading-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--brand-500);
  animation: sprout 1.2s ease infinite;
}
.loading-dots span:nth-child(2) { animation-delay: .15s; }
.loading-dots span:nth-child(3) { animation-delay: .3s; }

@keyframes sprout {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-8px); opacity: 1; }
}

/* ========== Toast ========== */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  padding: 10px 24px; border-radius: var(--radius-btn);
  font-size: 13px; font-weight: 500; z-index: 1000;
  animation: toastIn .3s ease;
  max-width: 90vw;
}
.toast-error { background: #FEF2F2; color: var(--danger); border: 1px solid #FECACA; }
.toast-success { background: var(--brand-50); color: var(--brand-600); border: 1px solid var(--brand-100); }
.toast-info { background: #EFF6FF; color: #1D4ED8; border: 1px solid #BFDBFE; }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ========== Footer ========== */
.site-footer {
  border-top: 1px solid var(--line);
  padding: 2rem 0;
}
.dark .site-footer { border-top-color: var(--line); background: var(--card); }
.footer-inner {
  max-width: 72rem; margin: 0 auto; padding: 0 1rem; text-align: center;
}
.footer-brand {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  color: var(--ink-400);
}
.footer-icon { width: 1rem; height: 1rem; }
.footer-text { font-size: 0.875rem; }
.footer-copy {
  margin-top: 0.75rem; font-size: 0.875rem; color: var(--ink-400);
}

/* ========== Responsive ========== */
@media (max-width: 600px) {
  .selector-grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  #app { padding: 16px 12px 40px; }
  .brand-header { padding: 14px 16px; }
  .brand-title { font-size: 17px; }
  .result-header { flex-direction: column; align-items: flex-start; }
  .result-actions { width: 100%; justify-content: flex-start; }
  .editor-body { height: 500px; }
}
