/* App UI (not the PDF template) */
:root {
  --bg: #f4f4f2; --panel: #fff; --line: #e2e2de; --text: #1d1d1f; --muted: #6b6b70;
  --accent-ui: #2f5fd0; --danger: #c0392b; --ok: #2e8b57; --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }

.btn { border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f0ee; }
.btn.primary { background: var(--accent-ui); border-color: var(--accent-ui); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn.icon { padding: 3px 7px; font-size: 13px; line-height: 1.2; color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }
.linkbtn { border: 0; background: none; color: var(--accent-ui); cursor: pointer; padding: 2px 0; font-size: 14px; }

input[type=text], input[type=email], input[type=tel], input[type=date], input[type=password], input[type=number], input:not([type]), select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff; width: 100%;
}
textarea { resize: none; overflow: hidden; line-height: 1.35; min-height: 36px; }
input:focus, textarea:focus, select:focus { outline: 2px solid #c9d6f5; border-color: var(--accent-ui); }
label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 3px; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  background: #fff; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.status.err { color: var(--danger); }
.testmode { background: #fff4d6; color: #7a5a00; font-size: 13px; padding: 6px 16px; border-bottom: 1px solid #f0dfa8; }

/* login + list */
.center { max-width: 760px; margin: 0 auto; padding: 24px 16px 60px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.login { max-width: 360px; margin: 12vh auto; }
.login h2 { margin: 0 0 14px; }
.login .row { margin-bottom: 10px; }
.err { color: var(--danger); font-size: 14px; }
.showlist { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.showrow { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.showrow .name { flex: 1; min-width: 0; cursor: pointer; }
.showrow .name b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.showrow .name span { font-size: 13px; color: var(--muted); }
.swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* editor layout */
.editor { display: grid; grid-template-columns: minmax(380px, 520px) 1fr; height: calc(100vh - 53px); }
.editor.hasbanner { height: calc(100vh - 85px); }
.leftpane { overflow-y: auto; padding: 14px 14px 80px; border-right: 1px solid var(--line); }
.rightpane { overflow: auto; background: #dcdcd8; position: relative; }
.preview-scale { transform-origin: top left; }
.preview-scale .im-doc { background: transparent; }
.tabs { display: none; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.panel > summary, .panel > .ph { padding: 11px 14px; font-weight: 600; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: "▸"; color: var(--muted); font-size: 12px; transition: transform .15s; }
.panel[open] > summary::before { transform: rotate(90deg); }
.panel .pb { padding: 2px 14px 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { margin-bottom: 10px; }
.colors { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.colors button { width: 26px; height: 26px; border-radius: 5px; border: 2px solid transparent; cursor: pointer; }
.colors button.sel { border-color: #000; }
.colors input[type=color] { width: 34px; height: 30px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.logo-prev { max-height: 60px; max-width: 220px; display: block; margin: 6px 0; padding: 6px; border-radius: 4px; }

.check { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 15px; color: var(--text); margin: 0; cursor: pointer; }
.check input { width: 17px; height: 17px; margin: 0; flex: none; }
.nested { margin-left: 25px; padding-left: 10px; border-left: 2px solid var(--line); }
.inline { display: flex; align-items: center; gap: 8px; }
.inline input { width: auto; }
.inline .num { width: 70px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 8px; }

/* section editor */
.sec { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: #fff; }
.sec.hidden-sec { opacity: .55; }
.sec-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); background: #fafaf8; border-radius: var(--radius) var(--radius) 0 0; }
.sec-head input { font-weight: 600; border-color: transparent; background: transparent; padding: 5px 6px; }
.sec-head input:hover { border-color: var(--line); background: #fff; }
.sec-type { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; white-space: nowrap; }
.sec-body { padding: 8px 10px 10px; }
.item { display: grid; grid-template-columns: 38px 1fr auto; gap: 6px; align-items: start; margin-bottom: 6px; }
.item .n { padding-top: 8px; font-size: 13px; color: var(--muted); text-align: right; }
.item .acts { display: flex; gap: 2px; padding-top: 4px; opacity: .35; }
.item:hover .acts, .item:focus-within .acts { opacity: 1; }
.item .gen { font-size: 10px; color: #8a8a8f; }
.subs { grid-column: 2 / 4; margin: -2px 0 4px 16px; }
.subs .item { grid-template-columns: 34px 1fr auto; }
.item .n .handle { cursor: grab; color: #b5b5b8; margin-right: 3px; letter-spacing: -2px; user-select: none; }
.item.dragging { opacity: .4; }
.item.over { box-shadow: 0 -2px 0 var(--accent-ui); }
.subnotes { grid-column: 2 / 4; }
.item.note textarea { font-style: italic; color: #444; }
.item.note textarea.bold { font-weight: 700; font-style: normal; }
.item.note textarea.underline { text-decoration: underline; }
.btn.fmt { min-width: 26px; }
.btn.fmt.on { background: #e3eafc; border-color: var(--accent-ui); color: var(--accent-ui); }
.adds { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.adds select { width: auto; font-size: 13px; padding: 4px 6px; }
.group { margin-bottom: 10px; }
.group-title { display: flex; gap: 6px; margin-bottom: 6px; }
.group-title input { font-weight: 600; }
.newsec { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 20px; }

/* photo grid (editor) */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pcard { border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: #fafafa; }
.pcard.dragging { opacity: .4; }
.pcard.over { outline: 2px solid var(--accent-ui); }
.pcard .thumb { aspect-ratio: 4/3; background: #111; cursor: pointer; position: relative; overflow: hidden; }
.pcard .thumb > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pcard .thumb .cropbtn { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 3px; opacity: 0; transition: opacity .15s; }
.pcard .thumb:hover .cropbtn { opacity: 1; }
.modal.wide { max-width: 640px; }
.cropframe { position: relative; width: 100%; aspect-ratio: 4/3; background: #111; overflow: hidden; cursor: grab; touch-action: none; border-radius: 4px; outline: 2px solid #f0a500; }
.cropframe:active { cursor: grabbing; }
.cropframe img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.pcard .thumb .order { position: absolute; left: 4px; top: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 5px; border-radius: 3px; }
.pcard .thumb .pending { position: absolute; right: 4px; top: 4px; background: #f0a500; color: #000; font-size: 11px; padding: 1px 5px; border-radius: 3px; }
.pcard .pf { padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.pcard .pf input { padding: 4px 6px; font-size: 13px; }
.pcard .pf .row { display: flex; gap: 4px; }
.pcard .cap { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 16px; padding: 6px 12px; cursor: pointer; font-size: 14px; user-select: none; }
.chip.on { background: var(--accent-ui); border-color: var(--accent-ui); color: #fff; }
.chips.small .chip { padding: 2px 8px; font-size: 12px; }

/* phone capture */
.capture { max-width: 520px; margin: 0 auto; padding: 14px 14px 120px; }
.capture .big { font-size: 22px; padding: 12px; text-align: center; }
.capture .shoot { width: 100%; font-size: 20px; padding: 18px; border-radius: 12px; margin-top: 14px; }
.capture .preview-cap { font-size: 15px; margin: 10px 0 4px; min-height: 20px; color: var(--muted); text-align: center; }
.capture .recent { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 18px; }
.capture .recent div { aspect-ratio: 4/3; background: #222; border-radius: 6px; position: relative; overflow: hidden; }
.capture .recent img { width: 100%; height: 100%; object-fit: cover; display: block; -webkit-touch-callout: default; }
.capture .recent span { position: absolute; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; padding: 2px 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.capture .recent .wait { outline: 3px solid #f0a500; }
.qstatus { text-align: center; font-size: 14px; margin-top: 10px; color: var(--muted); }
.qstatus.warn { color: #9a6700; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 10px; padding: 18px; width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal h3 { margin: 0 0 12px; }
.modal .btns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.qr { display: flex; gap: 14px; align-items: center; }
.qr img, .qr canvas { width: 140px; height: 140px; }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px; z-index: 200; }

/* narrow screens: editor becomes tabbed */
@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; height: auto; }
  .editor.hasbanner { height: auto; }
  .tabs { display: flex; gap: 6px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 53px; z-index: 9; }
  .editor .rightpane { display: none; min-height: 70vh; }
  .editor.show-preview .leftpane { display: none; }
  .editor.show-preview .rightpane { display: block; }
  .leftpane { border-right: 0; }
}

/* print: only the PDF pages */
#print-root { position: absolute; left: -100000px; top: 0; width: 800px; visibility: hidden; }
@media print {
  #app, .toast, .modal-bg { display: none !important; }
  #print-root { position: static; width: auto; visibility: visible; }
  html, body { background: #fff; }
  #print-root .im-doc { padding: 0; background: #fff; }
  #print-root .im-page { margin: 0; box-shadow: none; }
}
