/* ===== Builder UI (form + preview) ===== */
:root { --ui: #1f2a44; --accent: #4f46e5; --line: #e3e6ee; --muted: #6b7280; --bg: #eef0f5; }
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif; color: var(--ui); background: var(--bg); }

.app { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; height: 100vh; }

/* ---------- Form panel ---------- */
.panel { overflow-y: auto; background: #fff; border-right: 1px solid var(--line); padding-bottom: 80px; }
.panel-head { position: sticky; top: 0; z-index: 5; background: #fff; padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.panel-head h1 { margin: 0; font-size: 16px; }
.linkbtn { border: 0; background: none; color: var(--muted); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; }

fieldset { border: 0; margin: 0; padding: 16px 18px 6px; border-bottom: 1px solid var(--line); }
legend { float: left; width: 100%; padding: 0; margin: 0 0 10px; font-weight: 700; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); }
legend + * { clear: both; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.f { display: block; margin-bottom: 10px; font-size: 12px; font-weight: 600; color: #374151; }
label.f input, label.f textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid #cfd5e1; border-radius: 8px; font: inherit; font-size: 14px; font-weight: 400; color: var(--ui); background: #fff;
}
label.f textarea { resize: vertical; min-height: 66px; }
label.f input:focus, label.f textarea:focus { outline: 2px solid #c7c4fb; border-color: var(--accent); }
.hint { font-weight: 400; color: var(--muted); }

.photo-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.photo-thumb { width: 64px; height: 64px; border-radius: 10px; background: #f0f2f7 center/cover no-repeat; border: 1px dashed #b8c0d2; flex: none; display: grid; place-items: center; color: var(--muted); font-size: 11px; text-align: center; }

.card { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 12px; background: #fafbfd; }
.card-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.card-title { flex: 1; font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-body { padding: 10px 10px 2px; }
.icon { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; font-size: 13px; line-height: 1; color: var(--ui); }
.icon:hover { background: #f0f2f7; }
.icon.danger { color: #b3261e; }
.icon:disabled { opacity: .35; cursor: default; }
.add { width: 100%; margin-bottom: 14px; padding: 9px; border: 1px dashed #aab3c8; border-radius: 8px; background: #fff; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }
.add:hover { background: #f5f5ff; }

/* ---------- Preview pane ---------- */
.pane { display: flex; flex-direction: column; min-width: 0; height: 100vh; }
.topbar { flex: none; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 8px; }
.tab { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font: inherit; font-weight: 700; font-size: 13px; color: var(--ui); cursor: pointer; }
.tab[aria-pressed="true"] { border-color: var(--accent); background: #f5f5ff; }
.thumb { width: 26px; height: 34px; border-radius: 3px; border: 1px solid #ccd; background: #fff; position: relative; overflow: hidden; }
.thumb.peach::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 38%; background: #fde9dc; }
.thumb.peach::after { content: ''; position: absolute; left: 6px; top: 5px; width: 8px; height: 8px; border-radius: 50%; background: #8b5a3c; }
.thumb.exec::before { content: ''; position: absolute; left: 3px; right: 3px; top: 8px; height: 2px; background: #4044ad; }
.thumb.exec::after { content: ''; position: absolute; right: 3px; top: 3px; width: 6px; height: 6px; border: 1px solid #5257d8; border-radius: 1px; }
.spacer { flex: 1; }
.pages { font-size: 12px; color: var(--muted); }
.pages.warn { color: #b45309; font-weight: 700; }
.btn { border: 0; border-radius: 8px; padding: 10px 16px; font: inherit; font-weight: 700; cursor: pointer; background: var(--accent); color: #fff; }
.btn:hover { filter: brightness(.94); }
.btn[disabled] { opacity: .6; cursor: progress; }

.scroll { flex: 1; overflow: auto; padding: 22px 16px 60px; display: flex; justify-content: center; align-items: flex-start; }
#preview { flex: none; }

/* Mobile: switch between Edit and Preview */
.mtabs { display: none; }
@media (max-width: 900px) {
  .app { display: block !important; height: auto !important; min-height: 0 !important; overflow: visible !important; }
  .panel { height: auto !important; min-height: 55vh; overflow: visible !important; padding-bottom: 100px; }
  .pane { height: auto !important; min-height: 50vh; overflow: visible !important; }
  .pane .scroll { overflow: visible !important; height: auto !important; }
  .mtabs { display: flex; position: sticky; top: 0; z-index: 30; background: #fff; border-bottom: 1px solid var(--line); }
  .mtabs button { flex: 1; padding: 14px; border: 0; background: none; font: inherit; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent; }
  body[data-view="edit"] .mtabs [data-v="edit"], body[data-view="preview"] .mtabs [data-v="preview"] { color: var(--accent); border-color: var(--accent); }
  body[data-view="edit"] .pane { display: none !important; }
  body[data-view="preview"] .panel { display: none !important; }
  body[data-view="preview"] .pane { display: block !important; }
  body[data-view="edit"] .panel { display: block !important; }
  .topbar { position: sticky; top: 48px; z-index: 25; background: #fff; }
  fieldset { padding-bottom: 12px; }
}

/* page-break guides in the preview (not exported) */
.tpl { position: relative; }
.pbreak { position: absolute; left: 0; right: 0; height: 0; border-top: 2px dashed #ef4444; pointer-events: none; z-index: 5; }
.pbreak::after { content: attr(data-label); position: absolute; right: 8px; top: 3px; padding: 1px 6px; border-radius: 4px; background: #fee2e2; color: #b91c1c; font: 700 10px/1.4 system-ui, Arial, sans-serif; }

/* ---------- panel tabs + design controls ---------- */
.ptabs { display: flex; gap: 4px; padding: 3px; background: #eef0f5; border-radius: 10px; }
.ptab { border: 0; background: none; padding: 7px 16px; border-radius: 8px; font: inherit; font-weight: 700; font-size: 13px; color: var(--muted); cursor: pointer; }
.ptab[aria-pressed="true"] { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

#designTab { padding: 8px 18px 20px; }
.dnote { font-size: 12px; color: var(--muted); margin: 8px 0 4px; }
.dsec { padding: 12px 0; border-bottom: 1px solid var(--line); }
.dsec:last-child { border-bottom: 0; }
.dsec h3 { margin: 0 0 9px; font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: #374151; }
#designTab select { display: block; width: 100%; margin-top: 4px; padding: 8px 10px; border: 1px solid #cfd5e1; border-radius: 8px; font: inherit; font-size: 14px; background: #fff; color: var(--ui); }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #cfd5e1; cursor: pointer; padding: 0; font: 700 10px/1 system-ui, sans-serif; color: #374151; background: #fff; display: grid; place-items: center; position: relative; }
.sw[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent); }
.sw-custom { overflow: hidden; font-size: 16px; }
.sw-custom input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid #cfd5e1; background: #fff; border-radius: 8px; padding: 6px 11px; font: inherit; font-size: 13px; color: var(--ui); cursor: pointer; }
.chip:hover { background: #f5f5ff; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: #eef0ff; color: var(--accent); font-weight: 700; }

.trow { display: grid; grid-template-columns: 96px 1fr 38px 82px; align-items: center; gap: 8px; margin-bottom: 8px; }
.trow .tl { font-size: 13px; }
.trow input[type=range] { width: 100%; accent-color: var(--accent); }
.trow .val { font-size: 12px; font-weight: 600; color: var(--muted); text-align: right; }
.trow select { margin: 0 !important; padding: 5px 6px !important; font-size: 12px !important; }
.chk { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 14px; cursor: pointer; }
.chk input { width: 16px; height: 16px; accent-color: var(--accent); }
