:root {
  --c-maroon: #6e1f2e; --c-rose: #b76e79; --c-rose2: #c08083;
  --c-pagebg: #fdecea; --c-circle: #f4c7c4; --c-band: #f8d8d5; --c-ink: #4a2b30;
  --f-head: 'Playfair Display', serif; --f-body: 'Poppins', sans-serif;
}
/* ============ App (form) styling ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--f-body); background: #fdf3f1; color: var(--c-ink); }
.app-header { display: flex; align-items: center; gap: 14px; padding: 18px 20px; background: var(--c-maroon); color: #fff; }
.app-logo { width: 64px; height: auto; background:#fff; border-radius: 50%; padding: 6px; }
.app-header h1 { font-size: 20px; font-weight: 600; }
.app-header p { font-size: 13px; opacity: .85; }
.steps { display: flex; gap: 6px; padding: 10px; background: #fff; position: sticky; top: 0; z-index: 5; box-shadow: 0 2px 8px rgba(110,31,46,.08); overflow-x: auto; }
.step-btn { flex: 1; min-width: 90px; padding: 12px 8px; font-size: 15px; font-family: inherit; border: 2px solid #e8c4c6; background: #fff; color: #7a3040; border-radius: 10px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.step-btn.active { background: var(--c-maroon); color: #fff; border-color: var(--c-maroon); }
main { max-width: 780px; margin: 0 auto; padding: 18px 14px 60px; }
.step-panel h2 { font-size: 19px; margin: 18px 0 12px; }
.step-panel h3 { font-size: 16px; margin: 22px 0 10px; }
.hint { font-size: 13px; color: #a0606a; margin-bottom: 10px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px; }
.field input { width: 100%; font-size: 17px; font-family: inherit; padding: 14px 14px; border: 2px solid #e8c4c6; border-radius: 12px; background: #fff; color: #333; }
.field input:focus { outline: none; border-color: var(--c-rose); }
.search { width: 100%; font-size: 16px; font-family: inherit; padding: 12px 14px; border: 2px solid #e8c4c6; border-radius: 12px; margin-bottom: 12px; }
.next-btn, .generate-btn { width: 100%; padding: 16px; font-size: 18px; font-weight: 600; font-family: inherit; border: none; border-radius: 12px; background: var(--c-maroon); color: #fff; cursor: pointer; margin-top: 18px; }
.generate-btn { background: var(--c-rose); font-size: 20px; }
.small-btn { padding: 12px 18px; font-size: 15px; font-family: inherit; border: none; border-radius: 10px; background: var(--c-rose); color: #fff; cursor: pointer; font-weight: 500; }
.small-btn.danger { background: #c0392b; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-row input { flex: 1; min-width: 140px; font-size: 15px; font-family: inherit; padding: 12px; border: 2px solid #e8c4c6; border-radius: 10px; }
.svc-item { background: #fff; border: 2px solid #f0d5d3; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.svc-item.on { border-color: var(--c-rose); background: #fdf0ee; }
.svc-head { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.svc-head input[type=checkbox] { width: 26px; height: 26px; accent-color: var(--c-rose); flex: none; cursor: pointer; }
.svc-head .svc-name { font-size: 16px; font-weight: 500; }
.svc-fields { display: none; gap: 10px; margin-top: 10px; padding-left: 38px; flex-wrap: wrap; }
.svc-item.on .svc-fields { display: flex; }
.svc-fields label { font-size: 12px; color: #a0606a; display: block; margin-bottom: 4px; }
.svc-fields input { font-size: 15px; font-family: inherit; padding: 10px; border: 2px solid #e8c4c6; border-radius: 8px; width: 130px; }
.svc-fields input.rate { width: 100%; min-width: 220px; flex: 1; }
.summary { background: #fff; border-radius: 12px; padding: 16px; font-size: 15px; line-height: 1.7; border: 2px solid #f0d5d3; }
.hidden { display: none; }
hr { border: none; border-top: 1px solid #e8c4c6; margin: 26px 0; }

/* ============ PDF page styling (A4 @96dpi = 794x1123) ============ */
#pdfStage { position: fixed; left: -9999px; top: 0; }
.p-page { width: 794px; height: 1123px; position: relative; overflow: hidden; background: var(--c-pagebg); font-family: var(--f-body); }
.circ { position: absolute; border-radius: 50%; background: var(--c-circle); }

/* --- Cover --- */
.p-cover .tagline { position: absolute; top: 68px; width: 100%; text-align: center; font-size: 15px; letter-spacing: 10px; color: #7a3040; font-weight: 500; }
.p-cover .ring { position: absolute; top: 150px; left: 87px; width: 620px; height: 620px; background: #fff; border: 2px solid #a85a63; border-radius: 50%; }
.p-cover .dot { position: absolute; width: 13px; height: 13px; border-radius: 50%; background: var(--c-maroon); }
.p-cover .ring-inner { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; padding-top: 118px; }
.p-cover .ring-inner img { width: 290px; }
.p-cover .rule { width: 56px; height: 2px; background: var(--c-maroon); margin: 26px 0 20px; }
.p-cover .title { font-family: var(--f-head); font-style: italic; font-size: 46px; color: var(--c-ink); font-weight: 500; }
.p-cover .subtitle { font-size: 16px; color: #999; margin-top: 12px; font-weight: 300; }
.p-cover .card { position: absolute; left: 90px; right: 90px; bottom: 165px; background: #fff; border-radius: 14px; display: flex; padding: 26px 36px; box-shadow: 0 4px 18px rgba(110,31,46,.07); }
.p-cover .card .col-l { flex: 1.2; }
.p-cover .card .col-r { flex: 1; padding-left: 30px; }
.p-label { font-size: 11px; letter-spacing: 3px; color: var(--c-rose); font-weight: 600; margin-bottom: 6px; }
.p-cover .cname { font-family: var(--f-head); font-size: 30px; color: #3a2a2e; margin-bottom: 10px; }
.p-cover .cline { font-size: 15px; color: #888; line-height: 1.5; }
.p-cover .cdate { font-size: 16px; color: #555; margin-bottom: 14px; }
.p-cover .cbudget { font-size: 21px; color: var(--c-rose); font-weight: 600; }
.p-band { position: absolute; bottom: 0; left: 0; right: 0; height: 128px; background: var(--c-maroon); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }
.p-band .l1 { font-size: 17px; font-weight: 400; }
.p-band .l2 { font-size: 15px; opacity: .92; }

/* --- Inner pages --- */
.p-inner .band { position: absolute; top: 0; left: 0; right: 0; height: 300px; background: var(--c-band); overflow: hidden; }
.p-inner .head { position: relative; padding: 52px 64px 0; display: flex; align-items: flex-start; gap: 26px; }
.p-inner .head img { width: 138px; }
.p-inner .kicker { font-size: 13px; letter-spacing: 3px; color: #7a3040; font-weight: 600; margin-top: 14px; }
.p-inner .ptitle { font-family: var(--f-head); font-style: italic; font-size: 50px; color: var(--c-ink); font-weight: 500; line-height: 1.15; margin-top: 6px; }
.p-inner .prule { width: 58px; height: 2px; background: var(--c-maroon); margin-top: 16px; }
.p-inner .cards { position: relative; display: flex; gap: 14px; margin: 20px 64px 0; }
.p-inner .icard { flex: 1; background: #fff; border-radius: 10px; padding: 14px 16px; box-shadow: 0 3px 12px rgba(110,31,46,.06); }
.p-inner .icard .txt { font-size: 12.5px; color: #666; line-height: 1.55; }
.p-inner table { width: calc(100% - 128px); margin: 22px 64px 0; border-collapse: collapse; }
.p-inner thead th { background: var(--c-rose2); color: #fff; font-size: 12.5px; letter-spacing: 2px; font-weight: 600; text-align: left; padding: 10px 14px; }
.p-inner tbody td { font-size: 13px; color: #666; padding: 6.5px 14px; }
.p-inner tbody tr:nth-child(even) td { background: #fbe9e6; }
.p-inner tbody tr:nth-child(odd) td { background: #fff; }
.p-inner .numc { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: var(--c-rose2); color: #fff; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 500; }
.p-inner .note { margin: 18px 64px 0; text-align: center; color: var(--c-rose); font-size: 13.5px; font-weight: 600; }
.p-foot { position: absolute; bottom: 34px; left: 64px; right: 64px; border-top: 1px solid #d9a8a5; padding-top: 12px; display: flex; justify-content: space-between; align-items: flex-start; }
.p-foot .fl { font-size: 12.5px; color: #777; line-height: 1.5; }
.p-foot .fl .co { color: #999; font-size: 12px; }
.p-foot .fr { font-size: 12px; color: #999; }

/* --- Back cover --- */
.p-back .ring2 { position: absolute; top: 190px; left: 152px; width: 490px; height: 490px; background: #fff; border: 2px solid #a85a63; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.p-back .ring2 img { width: 260px; }
.p-back .thanks { position: absolute; top: 740px; width: 100%; text-align: center; font-family: var(--f-head); font-style: italic; font-size: 56px; color: var(--c-ink); }
.p-back .rule2 { position: absolute; top: 828px; left: 369px; width: 56px; height: 2px; background: var(--c-maroon); }
.p-back .msg { position: absolute; top: 856px; width: 100%; text-align: center; font-size: 16px; color: #999; line-height: 1.7; font-weight: 300; }

/* --- Reference images: form UI --- */
.layout-pick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.layout-opt { flex: 1; min-width: 110px; background: #fff; border: 2px solid #e8c4c6; border-radius: 12px; padding: 12px; text-align: center; cursor: pointer; display: block; }
.layout-opt input { display: none; }
.layout-opt span { display: block; font-size: 16px; font-weight: 600; color: #7a3040; }
.layout-opt small { color: #a0606a; font-size: 12px; }
.layout-opt.sel { border-color: var(--c-rose); background: #fdf0ee; }
.add-row select { font-size: 16px; font-family: inherit; padding: 12px; border: 2px solid #e8c4c6; border-radius: 10px; background: #fff; flex: 1; min-width: 150px; }
.thumbs { margin-top: 14px; }
.thumb { display: flex; gap: 12px; background: #fff; border: 2px solid #f0d5d3; border-radius: 12px; padding: 10px; margin-bottom: 8px; align-items: center; }
.thumb img { width: 84px; height: 64px; object-fit: cover; border-radius: 8px; flex: none; }
.thumb .cap-in { flex: 1; font-size: 15px; font-family: inherit; padding: 10px; border: 2px solid #e8c4c6; border-radius: 8px; }

/* --- Reference images: PDF pages --- */
.ref-grid { position: relative; display: grid; gap: 14px; margin: 116px 64px 0; }
.ref-grid .cell { display: flex; flex-direction: column; overflow: hidden; }
.ref-grid .cell .ph { width: 100%; height: calc(100% - 24px); flex: none; object-fit: cover; border-radius: 4px; }
.ref-grid .cell .cap { font-size: 13px; color: #777; text-align: center; padding-top: 6px; flex: none; height: 22px; }
.ref-collage { grid-template-columns: repeat(6, 1fr); grid-auto-rows: 210px; }
.ref-collage .cell:nth-child(6n+1) { grid-column: span 3; grid-row: span 2; }
.ref-collage .cell:nth-child(6n+2), .ref-collage .cell:nth-child(6n+3) { grid-column: span 3; }
.ref-collage .cell:nth-child(6n+4) { grid-column: span 2; }
.ref-collage .cell:nth-child(6n+5) { grid-column: span 4; }
.ref-collage .cell:nth-child(6n+6) { grid-column: span 6; }
.ref-3up { grid-template-columns: repeat(3, 1fr); grid-auto-rows: 560px; }
.ref-2up { grid-template-columns: repeat(2, 1fr); grid-auto-rows: 330px; }
.ref-grid4 { grid-template-columns: repeat(3, 1fr); grid-auto-rows: 330px; }

/* ============ Premium polish ============ */
body { background: linear-gradient(180deg, #f9e2df 0%, #fdf3f1 260px, #fdf3f1 100%); }
.app-header { background: linear-gradient(120deg, #5c1725 0%, var(--c-maroon) 55%, #7d2837 100%); border-bottom: 3px solid #c9a227; box-shadow: 0 4px 14px rgba(110,31,46,.25); }
.app-header h1 { font-family: var(--f-head); font-style: italic; font-size: 24px; }
.step-panel { background: #fff; border-radius: 18px; padding: 20px 16px 24px; box-shadow: 0 6px 24px rgba(110,31,46,.08); border: 1px solid #f6e3e1; }
.step-panel h2 { font-family: var(--f-head); font-size: 23px; color: #5c1725; border-bottom: 2px solid #f0d5d3; padding-bottom: 8px; }
.step-panel h3 { color: #7a3040; }
.field input, .search, .add-row input, .add-row select { transition: border-color .15s, box-shadow .15s; }
.field input:focus, .search:focus, .add-row input:focus { outline: none; border-color: var(--c-rose); box-shadow: 0 0 0 3px rgba(183,110,121,.15); }
.next-btn { background: linear-gradient(120deg, var(--c-maroon), #8a2f42); box-shadow: 0 4px 14px rgba(110,31,46,.3); letter-spacing: .3px; }
.generate-btn { background: linear-gradient(120deg, var(--c-rose), #c9a227); box-shadow: 0 4px 16px rgba(183,110,121,.4); letter-spacing: .3px; }
.next-btn:active, .generate-btn:active, .small-btn:active { transform: translateY(1px); }
.step-btn { border-radius: 999px; }
.summary { border: 1px solid #f0d5d3; box-shadow: 0 3px 12px rgba(110,31,46,.06); }

/* --- live preview --- */
#previewBtn { position: fixed; right: 16px; bottom: 16px; z-index: 20; padding: 14px 20px; font-size: 16px; font-weight: 600; font-family: inherit; border: none; border-radius: 999px; background: linear-gradient(120deg, var(--c-rose), #c9a227); color: #fff; cursor: pointer; box-shadow: 0 6px 18px rgba(110,31,46,.35); }
#previewOverlay { position: fixed; inset: 0; z-index: 30; background: rgba(60,20,28,.55); display: flex; align-items: center; justify-content: center; padding: 14px; }
#previewOverlay.hidden { display: none; }
.pv-card { background: #fdf3f1; border-radius: 16px; width: 100%; max-width: 860px; max-height: 92vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.pv-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--c-maroon); color: #fff; font-weight: 500; font-size: 15px; }
.pv-head button { background: var(--c-rose); border: none; color: #fff; font-family: inherit; font-size: 14px; padding: 8px 14px; border-radius: 8px; cursor: pointer; }
.pv-scroll { overflow: auto; padding: 14px; }
#pvScale { transform-origin: top left; }
#pvInner { width: 794px; height: 1123px; }

.p-inner .head img.badged { background: #fff; border-radius: 14px; padding: 6px; }

/* --- login gate --- */
#loginGate { position: fixed; inset: 0; z-index: 50; background: linear-gradient(180deg, #f9e2df 0%, #fdf3f1 100%); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
#loginGate.hidden { display: none; }
#userChip { cursor: pointer; }

.retry-save-btn{margin-left:8px;padding:3px 14px;border:none;border-radius:999px;background:linear-gradient(135deg,#6e1f2e,#b76e79);color:#fff;font:500 12px Poppins,sans-serif;cursor:pointer;box-shadow:0 2px 6px rgba(110,31,46,.3)}
.retry-save-btn:hover{filter:brightness(1.1)}

@media (max-width:640px){
  .app-header{flex-wrap:wrap;gap:8px 12px;padding:14px 16px}
  .app-header > div{flex:1 1 60%;min-width:0}
  .app-header h1{font-size:19px}
  .app-header p{font-size:11.5px}
  #userChip{order:3;flex-basis:100%;font-size:12px;text-align:left;opacity:.95}
  .app-header .backlink{order:2;margin-left:auto}
}
