:root {
  --accent: #5423e7;
  --accent-strong: #3c00bd;
  --accent-soft: #f1ecff;
  --ink: #1d1a26;
  --muted: #645e72;
  --line: #e6e2ee;
  --workspace: #f6f4fa;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; -webkit-font-smoothing: antialiased; color: var(--ink); background: var(--workspace); height: 100dvh; display: flex; flex-direction: column; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#header { min-height: 56px; background: #fff; color: var(--accent-strong); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 15px; font-weight: 600; }
.header-divider { padding: 0 10px; color: #b8b2c6; font-weight: 400; }
#header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
#header a { color: #474255; text-decoration: none; font-size: 13px; font-weight: 500; padding: 6px 10px; border-radius: 8px; }
#header a:hover { color: var(--accent-strong); background: var(--accent-soft); }
#header .header-brand { color: var(--accent-strong); font-size: 15px; font-weight: 600; padding: 0; background: none; }
#header .header-brand:hover { background: none; text-decoration: underline; }
#btn-toggle-data, .mobile-mode { height: 32px; color: #474255; background: #fff; border: 1px solid #e1dcea; border-radius: 8px; padding: 0 12px; font-size: 13px; font-weight: 500; }
#btn-toggle-data:hover, .mobile-mode:hover { border-color: #c4b3f3; color: var(--accent-strong); }
.mobile-mode { display: none; }
#header[hidden], #embedded-toolbar[hidden] { display: none; }
#embedded-toolbar { min-height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 20px; background: #fff; color: var(--ink); border-bottom: 1px solid var(--line); font-size: 15px; }
#embedded-controls { display: flex; align-items: center; gap: 10px; }
#btn-finish-edit { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 16px; font-size: 13px; font-weight: 600; white-space: nowrap; box-shadow: 0 1px 2px rgba(60, 0, 189, .18); }
#btn-finish-edit:hover { background: #4519cf; }
#chat-version-notice { margin: 8px 12px 0; }
#chat-version-notice button { margin-left: 12px; }
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 12px; padding: 12px; overflow: hidden; }
main.show-data { grid-template-columns: 180px minmax(0, 1fr) 390px; }
.panel { min-width: 0; min-height: 0; background: white; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 1px 2px rgba(29, 26, 38, .04); display: flex; flex-direction: column; overflow: hidden; }
.panel-header { min-height: 54px; padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0; font-size: 14px; font-weight: 600; }
.panel-header button { background: var(--accent); color: white; border: 0; padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.muted { color: var(--muted); font-size: 12px; font-weight: 400; }
#template-list { flex: 1; overflow-y: auto; padding: 7px; }
.tpl-item { display: block; width: 100%; text-align: left; padding: 11px 12px; border: 1px solid transparent; border-radius: 8px; margin-bottom: 5px; background: transparent; color: var(--ink); }
.tpl-item:hover { background: var(--workspace); }
.tpl-item.active { background: var(--accent-soft); border-color: #c4b3f3; box-shadow: inset 3px 0 var(--accent); }
.tpl-item.active .tpl-name { color: var(--accent-strong); }
.tpl-name { font-size: 13px; font-weight: 600; display: block; }
.tpl-style { font-size: 11px; color: var(--muted); margin-top: 4px; display: block; }
.preview-heading { white-space: nowrap; }
#render-status { flex: 1; text-align: right; font-size: 11px; font-weight: 400; color: var(--muted); }
#render-status.error { color: #b42318; }
#export-wrap { position: relative; flex-shrink: 0; }
#export-menu { position: absolute; right: 0; top: calc(100% + 6px); background: white; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 6px 18px rgba(30,25,50,.12); width: 190px; padding: 4px; z-index: 20; }
#export-menu[hidden] { display: none; }
#export-menu .export-opt { display: block; width: 100%; text-align: left; background: white; color: var(--ink); border-radius: 4px; padding: 10px; font-weight: 400; }
#export-menu .export-opt:hover { background: var(--accent-soft); }
.export-note { font-size: 11px; line-height: 1.5; color: var(--muted); margin: 4px 10px 8px; }
.export-result { padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--accent-soft); font-size: 12px; line-height: 1.5; flex-shrink: 0; }
.export-result.error { color: #b42318; background: #fff7f5; }
.export-result p { margin: 0; }
.export-actions { display: flex; flex-wrap: wrap; gap: 14px; }
.export-actions a { text-decoration: underline; }
.export-result[hidden], .export-actions [hidden] { display: none; }
#preview-scroll { flex: 1; min-height: 0; overflow: auto; padding: 20px 16px; background: #eae7f0; scroll-behavior: auto; }
#preview-page { position: relative; margin: 0 auto; flex-shrink: 0; border-radius: 2px; box-shadow: 0 1px 2px rgba(29, 26, 38, .08), 0 8px 28px rgba(40, 28, 80, .10); background: white; }
#preview-frame, #preview-frame-back { display: block; position: absolute; top: 0; left: 0; width: 794px; height: 1123px; border: 0; background: white; transform-origin: top left; }
#preview-hint { margin: 0; padding: 9px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; text-align: center; }
#data-panel { display: none; }
main.show-data #data-panel { display: flex; }
.secondary-button { display: inline-flex; align-items: center; border: 1px solid #d6d0e2; border-radius: 8px; padding: 6px 9px; font-size: 12px; font-weight: 400; cursor: pointer; white-space: nowrap; }
.secondary-button:hover { border-color: var(--accent); color: var(--accent); }
.panel-header .secondary-button { color: #474255; background: white; border: 1px solid #d6d0e2; padding: 6px 9px; font-size: 12px; font-weight: 400; }
.editor-note { margin: 0; padding: 11px 16px; line-height: 1.55; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.save-bar { padding: 10px 16px; border-bottom: 1px solid var(--line); font-size: 12px; line-height: 1.5; color: #477052; flex-shrink: 0; }
.save-bar.error { color: #b42318; background: #fff7f5; }
.save-actions { display: flex; flex-wrap: wrap; gap: 5px 14px; }
.save-actions:has(button:not([hidden])) { margin-top: 5px; }
.draft-notice, .verification-card { margin: 10px 16px 0; padding: 11px 13px; border: 1px solid #f0dfb2; border-radius: 10px; background: #fffaf0; font-size: 12px; line-height: 1.6; flex-shrink: 0; }
.draft-notice p, .verification-card p { margin: 0 0 7px; }
.draft-notice button { margin-right: 10px; }
.verification-card { max-height: 190px; overflow-y: auto; }
.verification-card strong { display: block; margin-bottom: 5px; }
.verification-item { padding: 7px 0; border-top: 1px solid #ead8a2; }
.verification-item p { overflow-wrap: anywhere; }
.start-choice { padding: 25px 0; font-size: 13px; line-height: 1.7; }
.start-choice h2 { font-size: 16px; margin: 0 0 10px; }
.start-choice button { display: block; margin-top: 12px; width: 100%; }
.save-actions [hidden], .draft-notice[hidden], .verification-card[hidden] { display: none; }
button:disabled { cursor: default; opacity: .5; }
#form-editor { flex: 1; overflow-y: auto; padding: 0 16px 28px; }
.edit-section { border-bottom: 1px solid var(--line); padding: 15px 0; }
.edit-section:last-child { border-bottom: 0; }
.edit-section > summary { font-size: 14px; font-weight: 650; cursor: pointer; user-select: none; color: #33343a; }
.edit-section > .section-summary { display: flex; align-items: center; gap: 5px; list-style: none; position: relative; min-height: 28px; }
.section-summary::-webkit-details-marker { display: none; }
.section-summary::before { content: '▸'; width: 10px; color: #777b87; flex-shrink: 0; }
.edit-section[open] > .section-summary::before { content: '▾'; }
.section-caption { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-tools { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.section-tool, .section-drag-handle { border: 0; background: transparent; color: #777b87; padding: 4px; border-radius: 4px; font-size: 12px; line-height: 1.2; font-weight: 400; }
.section-drag-handle { font-size: 19px; line-height: 18px; padding: 3px; cursor: grab; touch-action: manipulation; }
.section-tool:hover, .section-drag-handle:hover { color: var(--accent); background: var(--accent-soft); }
.section-remove { font-size: 18px; line-height: 14px; }
.section-remove:hover { color: #b42318; background: #fff2f0; }
.section-tool:disabled { opacity: .3; cursor: default; background: transparent; }
.section-dragging { opacity: .45; }
.drop-before > summary { box-shadow: 0 -3px 0 var(--accent); }
.drop-after > summary { box-shadow: 0 3px 0 var(--accent); }
.section-body > .field { padding: 0; margin: 0 0 14px; }
.section-actions { padding-top: 16px; }
.section-instructions { color: var(--muted); font-size: 11px; line-height: 1.6; margin: 0 0 5px; }
.section-undo { padding: 10px; border-radius: 5px; background: var(--accent-soft); display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0; font-size: 12px; }
.section-undo > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-restore { margin-top: 13px; color: #60636e; font-size: 12px; }
.section-restore > summary { cursor: pointer; }
.section-restore-options { display: flex; gap: 7px; flex-wrap: wrap; padding-top: 10px; }
.section-restore .secondary-button { background: white; color: var(--accent); }
.add-button:disabled, .secondary-button:disabled { opacity: .4; cursor: default; }
.section-body { padding-top: 13px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px 12px; }
.field { min-width: 0; padding: 5px; margin: -5px; border-radius: 6px; transition: background-color .12s; }
.field.full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12px; color: #5d576b; font-weight: 500; margin-bottom: 6px; }
.field input, .field textarea { width: 100%; border: 1px solid #d6d0e2; border-radius: 8px; background: white; padding: 8px 9px; color: var(--ink); font-size: 13px; line-height: 1.55; outline: none; }
.field textarea { display: block; min-height: 88px; resize: vertical; }
.field input::placeholder, .field textarea::placeholder { color: #aaaeb8; }
.field input:focus, .field textarea:focus { border-color: #8d74e8; box-shadow: 0 0 0 3px rgba(84,35,231,.12); }
.field.linked { background: var(--accent-soft); }
.field.linked label, .field.focused label { color: var(--accent); font-weight: 700; }
.field.linked input, .field.linked textarea { border-color: var(--accent); }
.item-editor { margin-top: 15px; padding-top: 14px; border-top: 1px dashed var(--line); }
.item-editor:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.item-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; font-size: 12px; font-weight: 600; }
.item-heading .item-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-button { border: 0; background: transparent; color: var(--accent); font-size: 12px; padding: 3px 0; text-align: left; }
.text-button.remove { color: #858995; font-size: 11px; flex-shrink: 0; }
.text-button.remove:hover { color: #b42318; }
.add-button { border: 1px dashed #c9bdee; border-radius: 8px; background: transparent; color: var(--accent); padding: 8px 10px; width: 100%; font-size: 12px; margin-top: 13px; }
.add-button:hover { background: var(--accent-soft); }
.list-field-row { position: relative; margin-top: 12px; }
.list-field-row .field { margin-right: 18px; }
.list-field-row .remove-line { position: absolute; top: 0; right: 0; border: 0; background: transparent; color: #8b8f99; font-size: 18px; line-height: 18px; padding: 0 2px; }
.list-field-row .remove-line:hover { color: #b42318; }
.list-editor { margin-top: 12px; }
.group-editor { border-radius: 6px; padding: 8px; margin: 0 -8px 12px; }
.group-editor.linked { background: var(--accent-soft); }
.group-editor:focus { outline: 1px solid var(--accent); }
.empty-section { font-size: 12px; color: var(--muted); line-height: 1.5; }
.photo-actions { display: flex; justify-content: flex-end; margin-top: 10px; }
@media (max-width: 1100px) and (min-width: 901px) {
  main.show-data { grid-template-columns: 150px minmax(0, 1fr) 340px; gap: 8px; padding: 8px; }
  #preview-scroll { padding: 14px 10px; }
}
@media (max-width: 900px) and (min-width: 701px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-rows: 108px minmax(0, 1fr); }
  main.show-data { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: 108px minmax(0, 1fr); }
  #template-panel { grid-column: 1 / -1; }
  #template-panel .panel-header { min-height: 32px; padding: 5px 12px; }
  #template-list { display: flex; overflow-x: auto; overflow-y: hidden; gap: 6px; }
  .tpl-item { flex: 0 0 130px; margin-bottom: 0; padding: 8px; }
}
@media (max-width: 700px) {
  #header { min-height: 50px; padding: 10px 12px; font-size: 13px; gap: 8px; }
  #header > span { font-size: 12px; }
  .header-divider { padding: 0 4px; }
  #header-actions { gap: 5px; }
  #header > span { white-space: nowrap; }
  #header a { font-size: 12px; padding: 5px 4px; }
  #header .account-entry { height: 30px; padding: 0 8px; font-size: 12px; }
  #btn-toggle-data { display: none; }
  .mobile-mode { display: inline-block; height: 30px; font-size: 12px; padding: 0 7px; }
  .mobile-mode.active { background: var(--accent-soft); color: var(--accent-strong); border-color: #c4b3f3; font-weight: 600; }
  main, main.show-data { display: flex; flex-direction: column; padding: 8px; gap: 8px; }
  #template-panel { flex: 0 0 100px; }
  #template-panel .panel-header { min-height: 29px; padding: 4px 10px; font-size: 12px; }
  #template-list { display: flex; gap: 5px; overflow-x: auto; overflow-y: hidden; }
  .tpl-item { flex: 0 0 124px; margin-bottom: 0; padding: 8px; }
  #preview-panel { flex: 1; min-height: 0; }
  #preview-scroll { padding: 10px 7px; }
  #data-panel, main.show-data #data-panel { display: none; flex: 1; min-height: 0; }
  main.mobile-edit #preview-panel { display: none; }
  main.mobile-edit #data-panel { display: flex; }
  #render-status { font-size: 10px; }
  .panel-header { min-height: 47px; padding: 9px 11px; font-size: 13px; }
  #form-editor { padding: 0 14px 24px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
