:root {
  --c-maroon: #264a3b; --c-rose: #c9a227; --c-rose2: #3d6351;
  --c-pagebg: #f6f4ea; --c-circle: #e4eadb; --c-band: #e9efe0; --c-ink: #223c31;
  --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: #f4f5ec; 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(36,71,58,.08); overflow-x: auto; }
.step-btn { flex: 1; min-width: 90px; padding: 12px 8px; font-size: 15px; font-family: inherit; border: 2px solid #dde5d0; background: #fff; color: #2f5a48; 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: #7d8a72; 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 #dde5d0; 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 #dde5d0; 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 #dde5d0; border-radius: 10px; }
.svc-item { background: #fff; border: 2px solid #e2e8d5; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.svc-item.on { border-color: var(--c-rose); background: #eef2e5; }
.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: #7d8a72; display: block; margin-bottom: 4px; }
.svc-fields input { font-size: 15px; font-family: inherit; padding: 10px; border: 2px solid #dde5d0; 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 #e2e8d5; }
.hidden { display: none; }
hr { border: none; border-top: 1px solid #dde5d0; margin: 26px 0; }

/* ============ PDF page styling (A4 @96dpi = 794x1123) — sage + shiny gold ============ */
#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); }
.gtxt { display: block; }
.gbar { height: 4px; background: linear-gradient(90deg, #7a5c14 0%, #c9a227 22%, #f6e27a 45%, #fff6c8 50%, #f6e27a 55%, #c9a227 78%, #7a5c14 100%); }
.dias { display: flex; justify-content: center; gap: 26px; }
.dia { width: 13px; height: 13px; transform: rotate(45deg); background: linear-gradient(135deg, #f6e27a 0%, #c9a227 45%, #8a6318 100%); box-shadow: 0 0 6px rgba(201,162,39,.45); }
.bcirc { position: absolute; border-radius: 50%; background: rgba(255,255,255,.045); }

/* --- arch frame (rounded top, metallic gold border) --- */
.arch { width: 250px; height: 330px; padding: 5px; border-radius: 125px 125px 16px 16px; background: linear-gradient(160deg, #8a6318 0%, #c9a227 30%, #f6e27a 48%, #fff8d2 52%, #e9c96a 58%, #a8801c 78%, #6d5112 100%); box-shadow: 0 10px 30px rgba(0,0,0,.28); }
.arch-in { width: 100%; height: 100%; border-radius: 120px 120px 11px 11px; background: linear-gradient(170deg, #2b5243 0%, #254838 55%, #1e3b2e 100%); display: flex; align-items: center; justify-content: center; }
.arch-in img { width: 68%; }

/* --- Cover --- */
.p-cover { background: var(--c-pagebg); }
.cv-left { position: absolute; left: 0; top: 0; bottom: 0; width: 305px; background: linear-gradient(170deg, #2b5243 0%, #264a3b 50%, #1e3a2e 100%); display: flex; flex-direction: column; align-items: center; }
.cv-arch { margin-top: 130px; }
.cv-left .dias { margin-top: 34px; }
.cv-brand { margin-top: 22px; }
.cv-leftfoot { position: absolute; bottom: 44px; width: 100%; text-align: center; color: #cfddc9; font-size: 12px; line-height: 1.9; letter-spacing: .4px; }
.cv-right { position: absolute; left: 305px; right: 0; top: 0; bottom: 0; }
.cv-no { position: absolute; top: 66px; right: 64px; }
.cv-title.cv-title-sm { font-size: 46px; }
.cv-title.cv-title-ord { font-size: 40px; }
.cv-title { position: absolute; top: 148px; left: 72px; width: 340px; font-family: var(--f-head); font-size: 64px; font-weight: 500; line-height: 1.12; color: #264a3b; }
.cv-bar { position: absolute; top: 330px; left: 72px; width: 130px; }
.cv-sub { position: absolute; top: 352px; left: 72px; font-family: var(--f-head); font-style: italic; font-size: 21px; color: #6c7d6d; }
.cv-card { position: absolute; left: 64px; right: 56px; bottom: 72px; background: #eef1e2; border-radius: 6px; padding: 26px 32px 30px; }
.cv-cardbar { position: absolute; left: 0; top: 0; bottom: 0; width: 6px; border-radius: 6px 0 0 6px; background: linear-gradient(180deg, #7a5c14 0%, #c9a227 25%, #f6e27a 50%, #c9a227 75%, #7a5c14 100%); }
.cv-kicker { margin-bottom: 10px; }
.p-cover .cname { font-family: var(--f-head); font-size: 33px; color: #264a3b; margin-bottom: 8px; font-weight: 600; }
.p-cover .cline { font-size: 16.5px; color: #3c4f43; line-height: 1.55; font-weight: 500; }
.p-cover .pill .gtxt { position: relative; z-index: 2; }
.p-cover .pill { display: inline-block; margin-top: 16px; padding: 10px 26px 12px; border-radius: 999px; background: linear-gradient(120deg, #2b5243, #1e3a2e); box-shadow: 0 4px 12px rgba(30,58,46,.35); }

/* --- Inner pages --- */
.p-inner .band { position: absolute; top: 0; left: 0; right: 0; height: 246px; background: linear-gradient(165deg, #2b5243 0%, #264a3b 55%, #203f31 100%); overflow: hidden; }
.p-inner .bandline { position: absolute; top: 246px; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, #7a5c14 0%, #c9a227 22%, #f6e27a 48%, #fff6c8 50%, #f6e27a 52%, #c9a227 78%, #7a5c14 100%); }
.p-inner .head { position: relative; padding: 52px 64px 0; display: flex; align-items: flex-start; gap: 28px; }
.p-inner .head img { width: 118px; }
.p-inner .headtxt { padding-top: 34px; }
.p-inner .kicker { margin-bottom: 8px; }
.p-inner .ptitle { font-family: var(--f-head); font-style: italic; font-size: 46px; color: #ffffff; font-weight: 500; line-height: 1.12; }
.p-inner .prule { width: 96px; margin-top: 14px; }
.p-inner .cards { position: relative; display: flex; gap: 14px; margin: 92px 64px 0; }
.p-inner .icard { flex: 1; position: relative; background: #fff; border-radius: 6px; padding: 13px 14px 13px 20px; box-shadow: 0 3px 12px rgba(38,74,59,.10); }
.p-inner .icbar { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; border-radius: 6px 0 0 6px; background: linear-gradient(180deg, #7a5c14 0%, #c9a227 25%, #f6e27a 50%, #c9a227 75%, #7a5c14 100%); }
.p-inner .iclabel { margin-bottom: 5px; }
.p-inner .icard .txt { font-size: 14px; color: #2e4034; line-height: 1.55; font-weight: 600; }
.p-inner table { width: calc(100% - 128px); margin: 22px 64px 0; border-collapse: collapse; }
.p-inner thead th { background: #264a3b; color: #efd478; font-size: 13.5px; letter-spacing: 2px; font-weight: 600; text-align: left; padding: 11px 14px; }
.p-inner tbody td { font-size: 14.5px; color: #2e4034; padding: 8px 14px; font-weight: 500; }
.p-inner tbody tr:nth-child(even) td { background: #edf1e3; }
.p-inner tbody tr:nth-child(odd) td { background: #fff; }
.p-inner .numc { display: inline-flex; width: 24px; height: 24px; border-radius: 50%; background: #264a3b; color: #fff; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 500; }
.p-inner .note { margin: 18px 64px 0; display: flex; justify-content: center; }
.p-foot { position: absolute; bottom: 30px; left: 64px; right: 64px; padding-top: 12px; display: flex; justify-content: space-between; align-items: flex-start; }
.p-foot .footline { position: absolute; top: 0; left: 0; right: 0; height: 2px; background: linear-gradient(90deg, #7a5c14 0%, #c9a227 30%, #f6e27a 50%, #c9a227 70%, #7a5c14 100%); }
.p-foot .fl { font-size: 13.5px; color: #41543f; line-height: 1.5; font-weight: 500; }
.p-foot .fl .co { color: #5c6d62; font-size: 13px; }
.p-foot .fr { font-size: 12.5px; color: #b08a1e; font-weight: 500; }

/* --- Agreement --- */
.ag-parties { margin: 102px 64px 0; }
.p-inner .ag-parties + .cards { margin-top: 10px; }
.ag-h { margin: 26px 64px 0; text-align: center; }
.ag-h span { font-family: var(--f-head); font-size: 26px; color: #264a3b; font-weight: 600; }
.ag-hbar { width: 90px; margin: 8px auto 0; }
.ag-list { margin: 18px 64px 0; }
.ag-item { display: flex; align-items: flex-start; gap: 14px; padding: 7px 0; }
.ag-dia { width: 9px; height: 9px; margin: 7px 0 0 4px; flex: none; }
.ag-txt { font-size: 16px; color: #2e4034; line-height: 1.5; font-weight: 500; }
.ag-meta { color: #55665c; font-size: 14px; }
.ag-refnote { margin: 92px 64px 0; display: flex; justify-content: center; }
.signblk { margin: 26px 64px 0; text-align: right; }
.signblk .sb1 { font-size: 13.5px; color: #41543f; font-weight: 500; }
.signblk .sb2 { font-family: var(--f-head); font-size: 20px; color: #264a3b; font-weight: 600; margin-top: 4px; }
.signblk .sb3 { font-size: 13.5px; color: #41543f; font-weight: 500; }

/* --- Back cover --- */
.p-back { background: linear-gradient(165deg, #2b5243 0%, #264a3b 50%, #1e3a2e 100%); }
.bk-arch { position: absolute; top: 118px; left: 272px; }
.bk-thanks { position: absolute; top: 512px; width: 100%; text-align: center; font-family: var(--f-head); font-style: italic; font-size: 58px; color: #ffffff; font-weight: 500; }
.bk-bar { position: absolute; top: 610px; left: 347px; width: 100px; }
.bk-msg { position: absolute; top: 640px; width: 100%; text-align: center; font-size: 18px; color: #eef4ea; line-height: 1.75; font-weight: 400; }
.p-back .dias { position: absolute; top: 742px; left: 0; right: 0; }
.bk-lines { position: absolute; bottom: 92px; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 10px; }

/* --- 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 #dde5d0; 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: #2f5a48; }
.layout-opt small { color: #7d8a72; font-size: 12px; }
.layout-opt.sel { border-color: var(--c-rose); background: #eef2e5; }
.add-row select { font-size: 16px; font-family: inherit; padding: 12px; border: 2px solid #dde5d0; border-radius: 10px; background: #fff; flex: 1; min-width: 150px; }
.thumbs { margin-top: 14px; }
.thumb { display: flex; gap: 12px; background: #fff; border: 2px solid #e2e8d5; 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 #dde5d0; border-radius: 8px; }

/* --- Reference images: PDF pages --- */
.ref-grid { position: relative; display: grid; gap: 14px; margin: 92px 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: #5d6d62; 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, #e7edda 0%, #f4f5ec 260px, #f4f5ec 100%); }
.app-header { background: linear-gradient(120deg, #1e3a2e 0%, var(--c-maroon) 55%, #35604c 100%); border-bottom: 3px solid #c9a227; box-shadow: 0 4px 14px rgba(36,71,58,.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(36,71,58,.08); border: 1px solid #e2e7d6; }
.step-panel h2 { font-family: var(--f-head); font-size: 23px; color: #1e3a2e; border-bottom: 2px solid #e2e8d5; padding-bottom: 8px; }
.step-panel h3 { color: #2f5a48; }
.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(176,138,30,.15); }
.next-btn { background: linear-gradient(120deg, var(--c-maroon), #35604c); box-shadow: 0 4px 14px rgba(36,71,58,.3); letter-spacing: .3px; }
.generate-btn { background: linear-gradient(115deg, #8a6318 0%, #c9a227 30%, #f6e27a 50%, #c9a227 70%, #8a6318 100%); color: #1e3a2e; box-shadow: 0 4px 16px rgba(176,138,30,.45); letter-spacing: .3px; text-shadow: 0 1px 0 rgba(255,246,200,.5); }
.next-btn:active, .generate-btn:active, .small-btn:active { transform: translateY(1px); }
.step-btn { border-radius: 999px; }
.summary { border: 1px solid #e2e8d5; box-shadow: 0 3px 12px rgba(36,71,58,.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(115deg, #8a6318 0%, #c9a227 30%, #f6e27a 50%, #c9a227 70%, #8a6318 100%); color: #1e3a2e; cursor: pointer; box-shadow: 0 6px 18px rgba(36,71,58,.35); }
#previewOverlay { position: fixed; inset: 0; z-index: 30; background: rgba(24,46,36,.55); display: flex; align-items: center; justify-content: center; padding: 14px; }
#previewOverlay.hidden { display: none; }
.pv-card { background: #f4f5ec; 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, #e7edda 0%, #f4f5ec 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,#264a3b,#c9a227);color:#fff;font:500 12px Poppins,sans-serif;cursor:pointer;box-shadow:0 2px 6px rgba(36,71,58,.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}
}

/* --- agreement upgrade: intro, terms, signatures --- */
.ag-intro { margin: 92px 64px 0; font-size: 15.5px; color: #2e4034; line-height: 1.75; text-align: justify; font-weight: 500; }
.ag-intro.sign-note { margin-top: 96px; }
.p-inner .ag-parties { margin-top: 26px; text-align: center; }
.term-list { margin: 96px 64px 0; }
.term-item { display: flex; align-items: flex-start; gap: 14px; padding: 10px 0; border-bottom: 1px solid #e2e7d8; }
.term-item:last-child { border-bottom: none; }
.term-item .numc { margin-top: 2px; flex: none; }
.term-txt { font-size: 15.5px; color: #2e4034; line-height: 1.65; font-weight: 500; }
.sign-grid { display: flex; gap: 22px; margin: 40px 64px 0; }
.sign-col { flex: 1; background: #fff; border-radius: 8px; padding: 18px 20px 22px; box-shadow: 0 3px 12px rgba(38,74,59,.10); position: relative; }
.sign-collab { text-align: center; }
.sig-space { height: 86px; }
.sig-line { display: flex; align-items: flex-end; gap: 10px; margin-top: 14px; }
.sig-lab { font-size: 13px; color: #4a5c50; letter-spacing: 1px; text-transform: uppercase; flex: none; font-weight: 600; }
.sig-fill { flex: 1; border-bottom: 1.5px solid #264a3b; min-height: 20px; font-size: 15px; color: #1d332a; font-weight: 700; padding: 0 4px 2px; }
.wit-grid { display: flex; gap: 22px; margin: 30px 64px 0; }
.wit-row { flex: 1; background: #fff; border-radius: 8px; padding: 14px 20px 18px; box-shadow: 0 3px 12px rgba(38,74,59,.10); }
.wit-lab { text-align: center; margin-bottom: 2px; }

/* --- form: per-agreement wording section (step 5) --- */
#agreeOpts { margin-top: 16px; border: 1px solid #d8dfd2; border-radius: 10px; padding: 14px 16px; background: #fbfaf3; }
#agreeOpts .field { margin-bottom: 10px; }
#agreeOpts label { display: block; font-size: 12.5px; color: #5d6d62; margin-bottom: 4px; }
#agreeOpts input, #agreeOpts textarea { width: 100%; box-sizing: border-box; font: inherit; font-size: 13.5px; padding: 8px 10px; border: 1px solid #cfd8c9; border-radius: 7px; background: #fff; color: #223c31; }
#agreeOpts textarea { resize: vertical; }

/* select all row */
.selall-row { display: flex; gap: 8px; margin: 8px 0 10px; }
