/* ============================================================================
   /create — self-serve invitation builder
   ========================================================================== */

:root {
  --sand:   #f3e9dc;
  --paper:  #faf4ec;
  --ink:    #2c1a12;
  --brown:  #4a2c19;
  --bronze: #7c4f2e;
  --muted:  #5c4537;
  --plum:   #2b0e1b;
  --cream:  #f6ecdf;
  --gold:   #e3bd84;
  --bezel:  #1d1210;
  --line:   #c9b59b;
  --field:  #fffdf9;
  --rule:   #d8c7b1;
  --danger: #8e2b2b;
  --display: 'Aref Ruqaa', 'Times New Roman', serif;
  --body:    'IBM Plex Sans Arabic', Tahoma, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body {
  min-height: 100%;
  background: var(--sand);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.6;
}
a { color: var(--bronze); }
:focus-visible { outline: 2px solid var(--bronze); outline-offset: 2px; }

/* --- topbar -------------------------------------------------------------- */
.cx-topbar {
  max-width: 1240px;
  margin: 0 auto;
  padding: 18px 24px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.cx-brand img { display: block; width: 50px; height: 50px; border-radius: 50%; object-fit: cover; }
.cx-admin-link {
  display: inline-flex; align-items: center; min-height: 44px;
  color: var(--ink); font-weight: 500; text-decoration: none;
}
.cx-admin-link:hover { color: var(--bronze); }

/* --- shell + editor layout ---------------------------------------------- */
.cx-shell { max-width: 1240px; margin: 0 auto; padding: 22px 24px 72px; }

.cx-editor {
  display: flex;
  flex-direction: column;
  gap: 28px;
  margin-top: 28px;
}
.cx-form { order: 2; min-width: 0; display: grid; gap: 18px; }
.cx-preview { order: 1; }
@media (min-width: 980px) {
  .cx-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: start;
    gap: 48px;
  }
  .cx-form { order: 0; }
  .cx-preview { order: 0; position: sticky; top: 16px; }
}

.cx-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(42px, 5vw, 66px);
  line-height: 1.25;
  color: var(--brown);
}
.cx-lede { margin-top: 4px; max-width: 56ch; color: var(--muted); }
#draft-note { margin-top: 10px; }
#draft-note .cx-btn { margin-inline-start: 8px; }

/* --- cards ---------------------------------------------------------------- */
.cx-cards { display: grid; gap: 18px; }
.cx-card { background: var(--paper); border-radius: 14px; padding: 22px; }
.cx-section {
  margin-bottom: 14px;
  font-family: var(--display);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.3;
  color: var(--brown);
}
.cx-section + .cx-hint { display: block; margin: -12px 0 14px; }

/* Optional sections stay folded until the host wants them. */
.cx-optional { border-top: 1px solid var(--rule); }
.cx-optional > summary {
  display: flex; align-items: center; justify-content: space-between;
  min-height: 52px;
  font-weight: 500;
  color: var(--brown);
  cursor: pointer;
  list-style: none;
}
.cx-optional > summary::-webkit-details-marker { display: none; }
.cx-optional > summary::after {
  content: "+"; font-size: 24px; line-height: 1; color: var(--bronze);
}
.cx-optional[open] > summary::after { content: "−"; }
.cx-optional[open] { padding-bottom: 18px; }
.cx-optional > .cx-hint { display: block; margin-bottom: 12px; }

/* --- fields --------------------------------------------------------------- */
.cx-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.cx-field:last-child { margin-bottom: 0; }
.cx-field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.cx-field-row:last-child { margin-bottom: 0; }
.cx-field-row > .cx-field { margin-bottom: 0; }
#burgundy-group:not(:last-child) { margin-bottom: 14px; }

.cx-field label, .cx-label { font-weight: 500; }
.cx-field input[type="text"],
.cx-field input[type="url"],
.cx-field input[type="email"],
.cx-field input[type="datetime-local"],
.cx-field input[type="file"],
.cx-field textarea,
.q-text, .q-option-row input[type="text"],
.sched-row input, .contact-row input {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
  font: 17px var(--body);
}
.cx-field textarea, .q-text { line-height: 1.5; resize: vertical; }
.cx-field input[type="file"] { padding: 6px; font-size: 15px; }
.cx-field input[type="file"]::file-selector-button {
  min-height: 34px;
  margin-inline-end: 10px;
  padding: 0 14px;
  border: 1px dashed var(--bronze);
  border-radius: 8px;
  background: transparent;
  color: var(--brown);
  font: 500 15px var(--body);
  cursor: pointer;
}
.cx-field input:focus, .cx-field textarea:focus,
.q-text:focus, .q-option-row input:focus,
.sched-row input:focus, .contact-row input:focus {
  outline: 2px solid var(--bronze);
  outline-offset: 1px;
  border-color: var(--bronze);
}
.cx-field input.invalid { border-color: var(--danger); }
.cx-hint { color: var(--muted); font-size: 15px; }
.cx-error { color: var(--danger); font-size: 15px; }
.cx-error:empty { display: none; }

/* Inline "Remove" button that appears next to a file input once a file
   is picked. Small, aligned under the input, hidden by [hidden]. */
.cx-clear { align-self: flex-start; }

/* Dress-code colour picker row. Each swatch is a native color input
   stripped of its OS chrome so the row reads as a line of coloured
   chips the host clicks to open the system picker. */
.cx-colors { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 4px; }
.cx-color {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  overflow: hidden;
}
.cx-color::-webkit-color-swatch-wrapper { padding: 0; }
.cx-color::-webkit-color-swatch { border: 0; border-radius: 9px; }
.cx-color::-moz-color-swatch     { border: 0; border-radius: 9px; }

/* Template-switcher pills — a row above the form so the host can flip
   template mid-session without reloading. */
.cx-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.cx-pill {
  appearance: none;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--bronze);
  border-radius: 999px;
  background: transparent;
  color: var(--brown);
  font: 500 16px var(--body);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s ease, color .15s ease;
}
.cx-pill:hover { background: rgba(124, 79, 46, .1); }
.cx-pill.is-active { background: var(--bronze); color: #fffaf3; }

/* Program / schedule row builder — one row per timeline item: time
   picker (compact), free-text label (grows), × remove. */
#schedule-builder { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
#schedule-builder:empty, #contacts-builder:empty,
#quiz-builder:empty, #memories-builder:empty, #gallery-builder:empty { display: none; }
.sched-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
}
.sched-row .sched-time { direction: ltr; font-variant-numeric: tabular-nums; }
/* Wedding · Wizard's plan cards have a line under the title. */
.sched-row .sched-detail { display: none; grid-column: 2 / 3; }
#schedule-builder.with-detail .sched-detail { display: block; }

/* Contacts builder — name / role / phone / remove. On narrow screens
   collapse to 2 columns + the phone wraps underneath. */
#contacts-builder { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.contact-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 170px 44px;
  gap: 8px;
  align-items: center;
}
@media (max-width: 640px) {
  .contact-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; }
  .contact-row .c-phone { grid-column: 1 / 4; }
}
.contact-row .c-phone { font-variant-numeric: tabular-nums; }

.sched-remove, .c-remove, .mem-remove {
  width: 44px; height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--field);
  color: var(--brown);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sched-remove:hover, .c-remove:hover, .mem-remove:hover { border-color: var(--danger); color: var(--danger); }

/* --- radio pills --------------------------------------------------------- */
fieldset.cx-field { border: none; }
.cx-radio-row { display: flex; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.cx-radio {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--bronze);
  cursor: pointer;
}
.cx-radio input { accent-color: var(--bronze); }
.cx-radio:has(input:checked) { background: var(--bronze); color: #fffaf3; }

/* --- buttons ------------------------------------------------------------- */
.cx-btn {
  appearance: none;
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: 500 16px var(--body);
  text-decoration: none;
  cursor: pointer;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.cx-btn-primary { background: var(--plum); color: var(--cream); }
.cx-btn-primary:hover:not(:disabled) { background: #431a2d; }
.cx-btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.cx-btn-ghost { background: transparent; color: var(--brown); border-color: var(--bronze); }
.cx-btn-ghost:hover { background: rgba(124, 79, 46, .1); }
.cx-btn-add {
  min-height: 48px;
  padding: 0 20px;
  border: 1px dashed var(--bronze);
  border-radius: 10px;
  background: transparent;
  color: var(--brown);
}
.cx-btn-add:hover { background: rgba(124, 79, 46, .1); }
.cx-btn-plain {
  min-height: 44px; padding: 0;
  background: none; color: var(--brown);
  text-decoration: underline;
}

/* --- quiz + memory rows -------------------------------------------------- */
.q-row, .mem-row {
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}
.q-row-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.q-num { font-weight: 600; color: var(--brown); }
.q-options { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 4px; }
.q-option-row { display: flex; align-items: center; gap: 10px; }
.q-option-row input[type="radio"] { accent-color: var(--bronze); width: 20px; height: 20px; flex-shrink: 0; }
.q-opt-remove { padding: 4px 10px; color: var(--muted); background: transparent; border: none; cursor: pointer; font-size: 16px; }

.mem-row { display: flex; gap: 12px; align-items: flex-start; }
.mem-thumb {
  width: 70px; height: 70px; border-radius: 10px; overflow: hidden; flex-shrink: 0;
  background: var(--sand);
  display: flex; align-items: center; justify-content: center;
}
.mem-thumb img { width: 100%; height: 100%; object-fit: cover; }
.mem-thumb-num { font-family: var(--display); color: var(--brown); font-size: 20px; }
.mem-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.mem-fields .cx-field { margin: 0; }
@media (max-width: 480px) {
  .mem-thumb { width: 52px; height: 52px; }
}
#media-card #gallery-group { margin-bottom: 18px; }

/* --- publish card -------------------------------------------------------- */
.cx-publish-card { padding: 24px; background: var(--plum); color: var(--cream); border-radius: 14px; }
.cx-publish-card .cx-section { margin-bottom: 2px; font-size: 34px; color: var(--gold); }
.cx-publish-card > .cx-hint { display: block; margin: 0 0 16px; font-size: 17px; }
.cx-publish-card .cx-hint { color: #e0d2c2; }
.cx-publish-card .cx-field input { border-color: #8d6f7d; }
.cx-publish-card .cx-field input:focus { outline-color: var(--gold); border-color: var(--gold); }
.cx-publish-card .cx-error { color: #f3b7a8; }
.cx-publish-card :focus-visible { outline-color: var(--gold); }
.cx-link-hint { font-size: 14px; text-align: right; overflow-wrap: anywhere; }
.cx-publish-card #publish-btn {
  min-height: 54px;
  margin-top: 18px;
  padding: 0 40px;
  background: var(--cream);
  color: var(--plum);
  font-size: 19px;
  font-weight: 600;
}
.cx-publish-card #publish-btn:hover:not(:disabled) { background: #fff; }
#publish-hint { margin-top: 10px; font-size: 15px; }

.cx-progress { margin: 14px 0 0; }
.cx-progress-bar { width: 100%; height: 6px; background: rgba(246, 236, 223, .22); border-radius: 999px; overflow: hidden; }
.cx-progress-bar > div { height: 100%; background: var(--gold); width: 0%; transition: width .3s; }
.cx-progress-text { margin-top: 6px; font-size: 15px; color: #e0d2c2; }

/* --- preview panel ------------------------------------------------------- */
.cx-preview { display: grid; justify-items: center; gap: 6px; }
.cx-preview-head {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 0 14px;
  font-size: 15px; color: var(--muted);
}
/* The invitation renders at a real phone width and is scaled down, so it
   looks the same as on a guest's phone whatever size the frame is. */
.cx-preview-stage {
  --s: .5;
  position: relative;
  width: calc(390px * var(--s) + 12px);
  height: calc(760px * var(--s) + 12px);
  border: 6px solid var(--bezel);
  border-radius: 28px;
  background: var(--bezel);
  box-shadow: 0 26px 50px -20px rgba(44, 26, 18, .6);
  overflow: hidden;
  direction: ltr;
}
.cx-preview-stage iframe {
  display: block;
  border: 0;
  width: 390px;
  height: 760px;
  background: var(--paper);
  transform: scale(var(--s));
  transform-origin: top left;
}
@media (min-width: 980px) {
  .cx-preview-stage { --s: .82; }
}
@media (min-width: 980px) and (max-height: 760px) {
  .cx-preview-stage { --s: .68; }
}
/* The next preview loads here, hidden on top of the current one, and is
   swapped in once it has rendered — no blank flash, no jump to the top. */
.cx-preview-stage iframe.is-loading {
  position: absolute; top: 0; left: 0;
  visibility: hidden;
}

/* --- success screen ------------------------------------------------------ */
body.is-published { background: var(--plum); }
body.is-published .cx-topbar { display: none; }
.cx-success {
  min-height: calc(100vh - 94px);
  max-width: 1040px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 36px 72px;
  color: var(--cream);
}
.cx-success-copy { flex: 1 1 420px; min-width: 0; }
.cx-success a { color: var(--cream); }
.cx-success .cx-title { font-size: clamp(50px, 6.6vw, 88px); line-height: 1.22; color: var(--gold); }
.cx-success .cx-lede { margin-top: 18px; color: var(--cream); font-size: 18px; }
.cx-success-url {
  display: block;
  margin-top: 10px;
  padding: 14px 18px;
  border: 1px solid #8d6f7d;
  border-radius: 10px;
  overflow-wrap: anywhere;
  text-align: left;
}
.cx-success-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.cx-success-buttons .cx-btn { min-height: 54px; padding: 0 28px; font-size: 18px; }
.cx-success .cx-btn-primary { background: var(--cream); color: var(--plum); font-weight: 600; }
.cx-success .cx-btn-primary:hover { background: #fff; }
.cx-success .cx-btn-ghost { border-color: var(--gold); color: var(--cream); }
.cx-success .cx-btn-ghost:hover { background: rgba(227, 189, 132, .14); }
.cx-success :focus-visible { outline-color: var(--gold); }
.cx-success-links { display: flex; flex-wrap: wrap; gap: 0 22px; margin-top: 14px; }
.cx-success-links a { display: inline-flex; align-items: center; min-height: 44px; }
.cx-success-phone {
  flex: 0 1 300px;
  width: 300px;
  max-width: 70%;
  aspect-ratio: 390 / 844;
  object-fit: cover;
  border: 6px solid #0f060a;
  border-radius: 28px;
}
#claim-block { margin-top: 24px; padding-top: 18px; border-top: 1px solid #8d6f7d; }
.cx-claim-url { margin: 10px 0; overflow-wrap: anywhere; }

/* --- sign-in gate (shown at Publish when not signed in) ------------------ */
.cx-signin {
  margin-top: 16px;
  padding: 14px 16px;
  border: 1px solid #8d6f7d;
  border-radius: 12px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.cx-signin p { flex-basis: 100%; margin-bottom: 4px; }
.cx-signin .cx-btn-primary { background: var(--cream); color: var(--plum); }
.cx-signin .cx-btn-ghost { border-color: var(--gold); color: var(--cream); }

@media (max-width: 560px) {
  .cx-topbar { padding-inline: 16px; }
  .cx-shell { padding-inline: 16px; }
  .cx-card { padding: 18px 16px; }
  .cx-publish-card { padding: 20px 16px; }
  .cx-publish-card #publish-btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.cx-credit { text-align: center; padding: 24px 16px 32px; font-size: 14px; }
.cx-credit a { display: inline-flex; align-items: center; min-height: 44px; color: inherit; opacity: .75; text-underline-offset: 4px; }
