:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e2e4e8;
  --text: #1f2328;
  --muted: #6a717c;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --danger: #c4372b;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 14px; height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand strong { font-size: 16px; margin-right: 10px; }
.brand span { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; align-items: center; }

button {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
}
button:hover { border-color: #c4c8cf; background: #fafbfc; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.06); }
button.small { padding: 3px 8px; font-size: 12px; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); background: #eef0f3; }
button.danger:hover { color: var(--danger); }
button.add { width: 100%; border-style: dashed; color: var(--muted); }

.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.08);
  display: flex; flex-direction: column; padding: 4px; min-width: 180px;
}
.menu-pop[hidden] { display: none; }
.menu-pop button { border: 0; text-align: left; }

.layout { flex: 1; display: grid; grid-template-columns: minmax(380px, 1fr) minmax(420px, 1.1fr); min-height: 0; }
.editor { overflow-y: auto; border-right: 1px solid var(--line); background: var(--bg); }
.tabs {
  position: sticky; top: 0; z-index: 5; display: flex; gap: 4px; padding: 10px 16px 0;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); padding: 8px 10px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
#form { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card > h3 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.card > h3 .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.card-head { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.card-head input { font-weight: 600; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid .full { grid-column: 1 / -1; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); }
input[type=text], textarea, select {
  font: inherit; color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%;
}
textarea { resize: vertical; min-height: 60px; line-height: 1.45; }
textarea.long { min-height: 140px; }
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(31,111,235,.25); border-color: var(--accent); }

.item { border: 1px solid var(--line); border-radius: 6px; padding: 10px; margin-bottom: 10px; background: #fcfcfd; }
.item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; font-size: 12px; color: var(--muted); }
.item-tools { display: flex; gap: 2px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--text); }
.swatches input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; }

.photo-row { display: flex; gap: 14px; align-items: center; }
.photo-row img { width: 84px; height: 84px; object-fit: cover; border-radius: 50%; border: 1px solid var(--line); background: #eee; }
.photo-row img.rect { border-radius: 6px; }
.photo-row .col { display: flex; flex-direction: column; gap: 8px; }

.note { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.5; }
.note.warn { color: #9a6700; }

.preview { display: flex; flex-direction: column; min-height: 0; background: #e9ebef; }
.preview-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 14px; }
.seg button.active { background: var(--text); color: #fff; }
.status { font-size: 12px; color: var(--muted); }
.status.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.preview-frame { flex: 1; position: relative; min-height: 0; }
.preview-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.error {
  position: absolute; left: 16px; right: 16px; bottom: 16px; max-height: 40%; overflow: auto; margin: 0;
  background: #fff4f2; color: var(--danger); border: 1px solid #f3c7c1; border-radius: var(--radius); padding: 10px; font-size: 12px; white-space: pre-wrap;
}
.error[hidden] { display: none; }

.short { display: none; }
.pages { height: 100%; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.pages[hidden] { display: none; }
.page { width: 100%; max-width: 820px; height: auto; background: #fff; box-shadow: 0 2px 12px rgba(0,0,0,.12); border-radius: 2px; }
.page-no { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.bottombar { display: none; }

.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
.sheet[hidden] { display: none; }
.sheet-card { background: var(--panel); width: 100%; max-width: 480px; border-radius: 14px 14px 0 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; }
.sheet-card h3 { margin: 0 0 4px; font-size: 17px; }
.sheet-card p { margin: 0 0 6px; line-height: 1.6; }
.sheet-card button { padding: 12px; font-size: 16px; margin-top: 6px; }

@media (max-width: 900px) {
  body { height: auto; min-height: 100vh; font-size: 15px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .topbar { position: sticky; top: 0; z-index: 20; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .brand strong { font-size: 15px; }
  .brand span, #btn-pdf { display: none; }
  .layout { display: block; }
  .editor { border-right: 0; overflow: visible; }
  .tabs { top: calc(49px + env(safe-area-inset-top)); padding: 0 12px; gap: 0; }
  .tabs button { flex: 1; padding: 12px 4px; font-size: 15px; }
  .long { display: none; }
  .short { display: inline; }
  #form { padding: 12px; gap: 12px; }
  .card { padding: 14px 12px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  label.f { font-size: 13px; }
  /* iOS 输入框字号 < 16px 时聚焦会自动放大页面 */
  input[type=text], textarea, select { font-size: 16px; padding: 10px 11px; }
  label.chk { font-size: 15px; min-height: 36px; }
  label.chk input[type=checkbox] { width: 20px; height: 20px; }
  button { min-height: 40px; }
  button.small { min-width: 40px; min-height: 36px; font-size: 14px; }
  .item { padding: 10px; }
  .item-head { font-size: 13px; }
  .card-head { flex-wrap: wrap; }
  .card-head input { flex: 1 1 100%; }
  .swatch { width: 34px; height: 34px; }
  .photo-row img { width: 72px; height: 72px; }

  .preview { display: none; background: #e9ebef; }
  body.view-preview .editor { display: none; }
  body.view-preview .preview { display: flex; min-height: calc(100vh - 120px); }
  .preview-bar { position: sticky; top: calc(49px + env(safe-area-inset-top)); z-index: 10; padding: 8px 12px; }
  .seg button { padding: 8px 18px; font-size: 15px; }
  .preview-frame { flex: none; }
  .pages { height: auto; overflow: visible; padding: 12px; }
  .error { position: static; margin: 12px; max-height: none; }

  .bottombar {
    display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: rgba(255,255,255,.96);
    border-top: 1px solid var(--line); backdrop-filter: blur(8px);
  }
  .bottombar button { min-height: 44px; font-size: 15px; }
  .bottombar button.active:not(.primary) { background: var(--text); color: #fff; border-color: var(--text); }
}
.preview-frame iframe[hidden] { display: none; }
