:root {
  --accent: #5423e7;
  --accent-soft: #f0ecff;
  --ink: #1a1a1a;
  --muted: #777b87;
  --line: #e4e5eb;
  --workspace: #f4f5f7;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; 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: 3px; }
#header { min-height: 54px; background: var(--accent); color: white; padding: 12px 22px; display: flex; align-items: center; justify-content: space-between; gap: 16px; font-size: 15px; font-weight: 600; }
.header-divider { padding: 0 10px; opacity: .45; font-weight: 400; }
#header-actions { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
#header a { color: white; text-decoration: none; font-size: 13px; font-weight: 400; opacity: .9; }
#btn-toggle-data, .mobile-mode { color: white; background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.35); border-radius: 5px; padding: 5px 10px; font-size: 12px; }
.mobile-mode { display: none; }
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: 9px; 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 13px; border-radius: 5px; font-size: 13px; }
.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: 12px 10px; border: 1px solid transparent; border-radius: 6px; margin-bottom: 5px; background: transparent; color: var(--ink); }
.tpl-item:hover { background: var(--workspace); }
.tpl-item.active { background: var(--accent-soft); border-color: var(--accent); }
.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: 7px; 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; }
#preview-scroll { flex: 1; min-height: 0; overflow: auto; padding: 20px 16px; background: #eceef2; scroll-behavior: auto; }
#preview-page { position: relative; margin: 0 auto; flex-shrink: 0; box-shadow: 0 3px 16px rgba(20,25,40,.1); background: white; }
#preview-frame { 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 var(--line); border-radius: 5px; 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: #50535f; background: white; border: 1px solid var(--line); 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; border: 1px solid #ead8a2; border-radius: 6px; 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: #60636e; font-weight: 500; margin-bottom: 6px; }
.field input, .field textarea { width: 100%; border: 1px solid #d9dce5; border-radius: 5px; 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: var(--accent); box-shadow: 0 0 0 2px rgba(84,35,231,.10); }
.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 #c9c1e7; border-radius: 5px; 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 a { font-size: 11px; }
  #btn-toggle-data { display: none; }
  .mobile-mode { display: inline-block; font-size: 11px; padding: 5px 7px; }
  .mobile-mode.active { background: white; color: var(--accent); border-color: white; }
  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; } }
