/* ============================================================
   Builder UI — layout, components, form elements
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display:none !important; }

:root {
  --blue:         #2563eb;
  --blue-hover:   #1d4ed8;
  --blue-light:   #eff6ff;
  --green:        #16a34a;
  --green-light:  #f0fdf4;
  --red:          #dc2626;
  --red-light:    #fef2f2;
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --border-focus: #93c5fd;
  --text:         #1e293b;
  --text-muted:   #64748b;
  --text-faint:   #94a3b8;
  --radius:       8px;
  --radius-lg:    12px;
  --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:    0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --header-h:     60px;
  --left-w:       440px;
  --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.builder-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  box-shadow: var(--shadow);
}
.builder-header-inner {
  max-width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
}
.builder-brand-name {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--blue);
  white-space: nowrap;
}
.builder-header-title {
  flex: 1;
  overflow: hidden;
}
.builder-header-title h1 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.builder-help-link {
  font-size: .875rem;
  color: var(--blue);
  text-decoration: none;
  white-space: nowrap;
  padding: .375rem .75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: background .15s;
}
.builder-help-link:hover { background: var(--blue-light); }

/* ── Main layout ── */
.builder-layout {
  display: flex;
  height: 100vh;
  padding-top: var(--header-h);
}

/* ── Left panel ── */
.builder-left {
  width: var(--left-w);
  min-width: 320px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Progress bar ── */
.progress-bar {
  padding: 1.25rem 1.5rem .75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.progress-step {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 0;
}
.progress-step:last-child { flex: 0 0 auto; }
.progress-step-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  background: var(--surface);
  color: var(--text-faint);
  flex-shrink: 0;
  transition: all .2s ease;
  cursor: default;
}
.progress-step.active .progress-step-circle {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
}
.progress-step.done .progress-step-circle {
  border-color: var(--green);
  background: var(--green);
  color: #fff;
}
.progress-step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  transition: background .2s;
}
.progress-step.done .progress-step-line { background: var(--green); }
.progress-step-label {
  display: none;
}

/* ── Step container ── */
.step-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}
.step-header { margin-bottom: 1.5rem; }
.step-header h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .35rem;
}
.step-header p {
  font-size: .875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* ── Section headings within a step ── */
.form-section-heading {
  margin: 1.75rem 0 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}
.form-section-heading:first-child { margin-top: 0; }
.form-section-heading h3 {
  font-size: .9rem;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-section-heading .optional-tag {
  font-size: .7rem;
  background: #f1f5f9;
  color: var(--text-muted);
  padding: .1rem .45rem;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: .35rem;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
}
.form-section-heading p {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: .25rem;
}

/* ── Form fields ── */
.form-field {
  margin-bottom: 1.1rem;
}
.form-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: .35rem;
}
.form-label .required-star { color: var(--red); margin-left: 2px; }
.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: .6rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  line-height: 1.5;
}
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.form-input.error,
.form-textarea.error { border-color: var(--red); }
.form-textarea { resize: vertical; min-height: 90px; }
.form-help {
  font-size: .775rem;
  color: var(--text-muted);
  margin-top: .3rem;
  line-height: 1.4;
}
.form-error {
  font-size: .775rem;
  color: var(--red);
  margin-top: .3rem;
  display: none;
}
.form-error.visible { display: block; }
.char-count {
  font-size: .7rem;
  color: var(--text-faint);
  text-align: right;
  margin-top: .2rem;
}
.char-count.warning { color: #f59e0b; }
.char-count.over    { color: var(--red); }

/* ── Color field ── */
.color-field-row {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.color-swatch-input {
  width: 44px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  background: none;
  flex-shrink: 0;
}
.color-swatch-input:focus { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.color-hex-input {
  flex: 1;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: .85rem;
}

/* ── Two-column row ── */
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

/* ── Repeating sections ── */
.repeating-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem;
  margin-bottom: .85rem;
  background: #fafbfc;
  position: relative;
}
.repeating-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .85rem;
}
.repeating-item-label {
  font-size: .8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.btn-remove-item {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .25rem .6rem;
  font-size: .75rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.btn-remove-item:hover { border-color: var(--red); color: var(--red); background: var(--red-light); }
.btn-add-item {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: none;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: .5rem 1rem;
  font-size: .85rem;
  color: var(--blue);
  cursor: pointer;
  width: 100%;
  justify-content: center;
  transition: all .15s;
  margin-top: .25rem;
}
.btn-add-item:hover { border-color: var(--blue); background: var(--blue-light); }
.btn-add-item svg { flex-shrink: 0; }

/* ── Items list (tags/bullet input) ── */
.items-list-container { }
.items-list-tags {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-bottom: .5rem;
  min-height: 28px;
}
.items-list-tag {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 20px;
  padding: .2rem .65rem .2rem .75rem;
  font-size: .8rem;
  font-weight: 500;
}
.items-list-tag button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--blue);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  opacity: .7;
}
.items-list-tag button:hover { opacity: 1; }
.items-list-input-row {
  display: flex;
  gap: .5rem;
}
.items-list-input-row .form-input { flex: 1; }
.btn-add-tag {
  flex-shrink: 0;
  padding: .6rem .85rem;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-add-tag:hover { background: var(--blue-hover); }

/* ── Template selector ── */
.template-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}
.template-card {
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
  background: var(--surface);
}
.template-card:hover { border-color: #93c5fd; box-shadow: var(--shadow-md); }
.template-card.selected { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.template-thumbnail {
  width: 100%;
  aspect-ratio: 16/10;
  object-fit: cover;
  background: var(--bg);
  display: block;
}
.template-thumb-placeholder {
  width: 100%;
  aspect-ratio: 16/10;
  background: linear-gradient(135deg, #e2e8f0 0%, #f1f5f9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: .75rem;
}
.template-card-body {
  padding: .65rem .75rem;
}
.template-card-name {
  font-size: .85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: .15rem;
}
.template-card-desc {
  font-size: .75rem;
  color: var(--text-muted);
  line-height: 1.4;
}
.template-selected-check {
  display: none;
  position: absolute;
  top: .5rem;
  right: .5rem;
  background: var(--blue);
  color: white;
  border-radius: 50%;
  width: 22px;
  height: 22px;
  align-items: center;
  justify-content: center;
  font-size: .7rem;
}
.template-card.selected .template-selected-check { display: flex; }
.template-card { position: relative; }

/* ── Image fields ── */
.image-field-box {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
  transition: border-color .15s;
  background: #fafbfc;
}
.image-field-box:hover { border-color: #93c5fd; }
.image-field-box.has-image { border-style: solid; border-color: var(--blue); background: var(--blue-light); }
.image-field-preview {
  max-width: 100%;
  max-height: 80px;
  object-fit: contain;
  border-radius: 4px;
  margin-bottom: .75rem;
  display: none;
}
.image-field-preview.visible { display: block; margin: 0 auto .75rem; }
.image-field-label-text {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: .75rem;
}
.image-field-spec {
  font-size: .73rem;
  color: var(--text-faint);
  margin-bottom: .75rem;
  line-height: 1.4;
}
.image-field-actions { display: flex; gap: .5rem; justify-content: center; flex-wrap: wrap; }
.btn-upload {
  padding: .5rem 1rem;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-upload:hover { background: var(--blue-hover); }
.btn-remove-image {
  padding: .5rem 1rem;
  background: none;
  color: var(--red);
  border: 1px solid var(--red);
  border-radius: var(--radius);
  font-size: .85rem;
  cursor: pointer;
  transition: background .15s;
  display: none;
}
.btn-remove-image:hover { background: var(--red-light); }
.btn-remove-image.visible { display: block; }
.upload-hidden-input { display: none; }

/* Hero image options */
.hero-options { display: flex; flex-direction: column; gap: .85rem; }
.hero-option {
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color .15s;
}
.hero-option.active { border-color: var(--blue); }
.hero-option-header {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .75rem 1rem;
  cursor: pointer;
  background: var(--surface);
}
.hero-option-header input[type=radio] { accent-color: var(--blue); }
.hero-option-title { font-size: .875rem; font-weight: 600; color: var(--text); }
.hero-option-body { padding: 0 1rem 1rem; display: none; }
.hero-option.active .hero-option-body { display: block; }

.stock-image-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .4rem;
}
.stock-image-thumb {
  aspect-ratio: 16/10;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s, opacity .15s;
  width: 100%;
}
.stock-image-thumb:hover { border-color: #93c5fd; opacity: .9; }
.stock-image-thumb.selected { border-color: var(--blue); }
.stock-image-label {
  font-size: .7rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: .2rem;
}

.upload-preview-wrap { text-align: center; }
.upload-preview-img {
  max-width: 100%;
  max-height: 110px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: .5rem;
  display: none;
}
.upload-preview-img.visible { display: block; margin: 0 auto .5rem; }
.upload-progress { font-size: .8rem; color: var(--text-muted); }

/* ── Step nav ── */
.step-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}
.btn-primary {
  padding: .65rem 1.6rem;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--blue-hover); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { background: var(--text-faint); cursor: not-allowed; }
.btn-secondary {
  padding: .65rem 1.2rem;
  background: none;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.btn-secondary:hover { border-color: #94a3b8; color: var(--text); }
.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }

/* Submit button (shown on last step in place of Next) */
.btn-submit {
  padding: .65rem 1.6rem;
  background: var(--green);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s;
}
.btn-submit:hover { background: #15803d; }

/* ── Review step ── */
.review-summary {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.review-row {
  display: flex;
  gap: .75rem;
  font-size: .875rem;
  padding: .35rem 0;
  border-bottom: 1px solid var(--border);
}
.review-row:last-child { border-bottom: none; }
.review-key { color: var(--text-muted); flex: 0 0 120px; }
.review-val { color: var(--text); font-weight: 500; flex: 1; word-break: break-word; }
.review-disclaimer {
  font-size: .8rem;
  color: var(--text-muted);
  line-height: 1.5;
  text-align: center;
  padding: .75rem;
  background: var(--bg);
  border-radius: var(--radius);
}

/* ── Right panel ── */
.builder-right {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #e8edf2;
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.preview-label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.preview-close-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0 .25rem;
}
.preview-scaler-wrapper {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.preview-scaler {
  position: absolute;
  top: 0; left: 0;
  transform-origin: top left;
}
.preview-frame {
  display: block;
  width: 1440px;
  height: 900px;
  border: none;
  background: white;
}

/* ── Mobile preview FAB ── */
.preview-fab {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 50px;
  padding: .65rem 1.1rem;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(37,99,235,.4);
  align-items: center;
  gap: .4rem;
}

/* ── Overlays ── */
.submit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  z-index: 500;
  font-size: 1rem;
  color: var(--text-muted);
}
.submit-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.success-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 600;
  padding: 2rem;
}
.success-inner {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 3rem 2.5rem;
  max-width: 520px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-md);
}
.success-icon { margin-bottom: 1.25rem; }
.success-inner h2 {
  font-size: 1.6rem;
  font-weight: 800;
  margin-bottom: 1rem;
  color: var(--text);
}
.success-inner p {
  font-size: .95rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: .75rem;
}
.success-email-note { color: var(--text); }
.success-inner a { color: var(--blue); }

/* ── Validation message area ── */
.step-validation-error {
  background: var(--red-light);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: .65rem 1rem;
  font-size: .85rem;
  color: var(--red);
  margin-bottom: 1rem;
  display: none;
}
.step-validation-error.visible { display: block; }

/* ── Responsive ── */
@media (max-width: 1023px) {
  :root { --left-w: 380px; }
}

@media (max-width: 767px) {
  .builder-layout { flex-direction: column; }
  .builder-left {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    height: calc(100vh - var(--header-h));
    flex: 1;
  }
  .builder-right {
    position: fixed;
    inset: 0;
    z-index: 300;
    transform: translateX(100%);
    transition: transform .25s ease;
  }
  .builder-right.mobile-open {
    transform: translateX(0);
  }
  .preview-close-btn { display: block; }
  .preview-fab { display: flex; }
  .template-grid { grid-template-columns: 1fr; }
  .stock-image-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .step-container { padding: 1rem; }
  .step-nav { padding: .75rem 1rem; }
  .progress-bar { padding: 1rem; }
  .success-inner { padding: 2rem 1.5rem; }
}
