/* ── BASE ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
  background: #fafaf7;
  color: #111;
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

.logo {
  font-family: 'Unbounded', sans-serif;
  font-weight: 900;
  font-size: 22px;
  color: #111;
  text-decoration: none;
  letter-spacing: 0.02em;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: #111;
  text-decoration: underline;
  cursor: pointer;
}
.link:hover { color: #000; }

/* ── STEP 1: PICKER ───────────────────────────────────────────────────── */
.picker {
  min-height: 100%;
  padding: 32px 24px 64px;
  max-width: 920px;
  margin: 0 auto;
}
.picker__head { text-align: center; margin-bottom: 32px; }
.picker__head .logo { display: inline-block; margin-bottom: 24px; }
.picker__title {
  font-family: 'Unbounded', sans-serif;
  font-weight: 900;
  font-size: clamp(28px, 5vw, 44px);
  margin: 0 0 8px;
  line-height: 1.1;
  text-wrap: balance;
}
.picker__sub {
  margin: 0;
  color: #666;
  font-size: 16px;
  text-wrap: pretty;
}
.picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
.pick-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 16px;
  min-height: 160px;
  background: #fff;
  border: 3px solid #111;
  border-radius: 4px;
  box-shadow: 4px 4px 0 #111;
  cursor: pointer;
  text-decoration: none;
  color: #111;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.pick-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #111;
}
.pick-card:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 #111;
}
.pick-card__icon {
  font-size: 40px;
  line-height: 1;
}
.pick-card__name {
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-align: center;
}
.pick-card__swatch {
  width: 56px; height: 56px; border-radius: 50%;
  border: 3px solid #111;
}

/* ── STEP 2: SERVICES ─────────────────────────────────────────────────── */
.services {
  min-height: 100%;
  padding: 32px 24px 64px;
  max-width: 820px;
  margin: 0 auto;
}
.services__head { text-align: center; margin-bottom: 28px; }
.services__head .logo { display: inline-block; margin-bottom: 24px; }
.services__title {
  font-family: 'Unbounded', sans-serif;
  font-weight: 900;
  font-size: clamp(26px, 5vw, 40px);
  margin: 0 0 8px;
  line-height: 1.1;
  text-wrap: balance;
}
.services__sub {
  margin: 0;
  color: #666;
  font-size: 15px;
  text-wrap: pretty;
}
.services__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.svc-card {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: #fff;
  border: 3px solid #111;
  border-radius: 4px;
  box-shadow: 4px 4px 0 #111;
  cursor: pointer;
  user-select: none;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
.svc-card:hover {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #111;
}
.svc-card:active {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 #111;
}
.svc-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.svc-card__box {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  margin-top: -2px;          /* lift to sit centred on the label's first line */
  display: grid;
  place-items: center;       /* centres the SVG tick exactly */
  border: 3px solid #111;
  border-radius: 3px;
  background: #fff;
  color: transparent;        /* tick hidden until checked (stroke = currentColor) */
}
.svc-card__tick {
  width: 16px;
  height: 16px;
  display: block;
}
.svc-card input:checked ~ .svc-card__box {
  background: var(--accent, #FFE600);
  color: #111;
}
.svc-card input:focus-visible ~ .svc-card__box {
  outline: 3px solid #111;
  outline-offset: 2px;
}
.svc-card--disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.svc-card--disabled:hover {
  transform: none;
  box-shadow: 4px 4px 0 #111;
}
.svc-card__label {
  font-weight: 800;
  font-size: 14px;
  line-height: 1.35;
  display: block;
}
.svc-card__desc {
  font-size: 12px;
  color: #666;
  display: block;
  margin-top: 2px;
}

/* custom service add */
.services__custom { margin-top: 22px; }
.services__custom-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}
.services__custom-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 10px 12px;
  border: 2px solid #111;
  border-radius: 2px;
  background: #fff;
}
.services__custom-row input:focus {
  outline: 3px solid #FFE600;
  outline-offset: 1px;
}
.services__add {
  font: inherit;
  font-weight: 800;
  font-size: 14px;
  padding: 0 16px;
  border: 2px solid #111;
  border-radius: 2px;
  background: #111;
  color: #fff;
  cursor: pointer;
}
.services__add:hover:not(:disabled) { background: #000; }
.services__add:disabled { opacity: 0.5; cursor: not-allowed; }
.services__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}
.svc-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--accent, #FFE600);
  border: 2px solid #111;
  border-radius: 2px;
  box-shadow: 2px 2px 0 #111;
  font-weight: 700;
  font-size: 13px;
}
.svc-chip__remove {
  position: relative;
  font: inherit;
  font-weight: 800;
  background: none;
  border: 0;
  padding: 0 2px;
  cursor: pointer;
  line-height: 1;
}
/* visible × is ~15px — extend the touch target invisibly. Vertical is capped
   at the half-gap (chips wrap with 8px gap) so two stacked remove buttons
   never claim overlapping hit areas. */
.svc-chip__remove::after { content: ''; position: absolute; inset: -4px -12px; }
.svc-chip__remove:hover { color: #b00020; }

/* services footer */
.services__cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  margin-top: 28px;
  padding-top: 20px;
  border-top: 2px solid #111;
}
.services__cta .cta { width: 100%; max-width: 380px; }
.services__count {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: #666;
}

.link--small {
  position: relative;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  color: #666;
  text-align: left;
  align-self: flex-start;
}
/* text link is ~14px tall — extend the touch target invisibly */
.link--small::after { content: ''; position: absolute; inset: -10px 0; }
.link--small:hover { color: #111; }

/* ── STEP 3: BUILDER ──────────────────────────────────────────────────── */
.builder {
  display: grid;
  grid-template-columns: minmax(380px, 460px) 1fr;
  height: 100vh;
  min-height: 0;
}

.builder__pane { min-height: 0; min-width: 0; }
.builder__form {
  background: #fafaf7;
  border-right: 3px solid #111;
  padding: 20px 24px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.builder__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid #111;
}
.builder__preview {
  background: #fff;
  position: relative;
}
.builder__preview iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* ── MOBILE: full-page editor + slide-up preview ─────────────────────── */
@media (max-width: 880px) {
  .builder {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: 100vh;
  }
  .builder__form {
    border-right: 0;
    /* Reserve space at the bottom so the floating button doesn't
       obscure the pay CTA when scrolled to the end. */
    padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }
  .builder__preview {
    position: fixed;
    inset: 0;
    z-index: 20;
    transform: translateY(100%);
    transition: transform 0.25s ease-out;
    border-top: 3px solid #111;
  }
  body.preview-open .builder__preview {
    transform: translateY(0);
  }
  body.preview-open {
    /* Prevent background scroll while the preview is up. */
    overflow: hidden;
  }
}

@media (prefers-reduced-motion: reduce) {
  .builder__preview { transition: none; }
}

/* ── PREVIEW TOGGLE (mobile floating button) ─────────────────────────── */
.preview-toggle { display: none; }

@media (max-width: 880px) {
  .preview-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    z-index: 30;
    padding: 12px 18px;
    background: #111;
    color: #fff;
    font: inherit;
    font-weight: 800;
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    border: 3px solid #111;
    border-radius: 4px;
    box-shadow: 4px 4px 0 #FFE600;
    cursor: pointer;
    transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.12s ease, color 0.12s ease;
  }
  .preview-toggle:active {
    transform: translate(2px, 2px);
    box-shadow: 0 0 0 #FFE600;
  }
  .preview-toggle__icon { display: inline-flex; align-items: center; }
  .preview-toggle__label { display: inline; }
  /* Closed state: show eye + "Anteprima", hide close + "Modifica". */
  .preview-toggle__icon--close,
  .preview-toggle__label--close { display: none; }
  /* Open state: swap. */
  body.preview-open .preview-toggle__icon--eye,
  body.preview-open .preview-toggle__label--open { display: none; }
  body.preview-open .preview-toggle__icon--close { display: inline-flex; }
  body.preview-open .preview-toggle__label--close { display: inline; }
  body.preview-open .preview-toggle {
    background: #FFE600;
    color: #111;
  }
}

/* ── FORM ─────────────────────────────────────────────────────────────── */
.form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field__label {
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.field__hint {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}
.field__row {
  display: flex;
  align-items: stretch;
  border: 2px solid #111;
  background: #fff;
  border-radius: 2px;
  overflow: hidden;
}
.field__row input {
  border: 0 !important;
  background: transparent !important;
  flex: 1;
  min-width: 0;
}
.field__row .field__suffix {
  display: flex;
  align-items: center;
  padding: 0 10px;
  background: #111;
  color: #FFE600;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}
.field__row--color { padding: 4px; gap: 8px; align-items: center; }
.field__row--color input[type="color"] {
  width: 44px;
  height: 32px;
  padding: 0;
  border: 2px solid #111 !important;
  border-radius: 2px;
  cursor: pointer;
}
.field__row--color input[type="text"] {
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  padding: 6px 10px;
}

.field input,
.field textarea {
  font: inherit;
  padding: 10px 12px;
  border: 2px solid #111;
  border-radius: 2px;
  background: #fff;
  width: 100%;
  resize: vertical;
}
.field input:focus,
.field textarea:focus {
  outline: 3px solid #FFE600;
  outline-offset: 1px;
}

.field__status {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  min-height: 16px;
  margin-top: 2px;
}
.field__status--ok    { color: #1a7a3a; }
.field__status--error { color: #b00020; }
.field__status--checking { color: #666; }

/* ── CTA ──────────────────────────────────────────────────────────────── */
.builder__cta {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  border-top: 2px solid #111;
  margin-top: 8px;
}
.cta {
  font: inherit;
  font-weight: 800;
  font-size: 17px;
  padding: 14px 18px;
  border: 3px solid #111;
  border-radius: 4px;
  background: #FFE600;
  color: #111;
  cursor: pointer;
  box-shadow: 4px 4px 0 #111;
  transition: transform 0.06s ease, box-shadow 0.06s ease;
}
/* Pay CTA: two-line layout — action + recurring fee inside the same button. */
.cta--pay {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 12px 18px 14px;
  line-height: 1.15;
  text-align: left;
}
.cta--pay .cta__main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 17px;
  font-weight: 800;
}
.cta--pay .cta__arrow { font-weight: 800; }
.cta--pay .cta__sub {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  opacity: 0.78;
}
.cta:hover:not(:disabled) {
  transform: translate(-2px, -2px);
  box-shadow: 6px 6px 0 #111;
}
.cta:active:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 0 0 0 #111;
}
.cta:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.cta__hint {
  margin: 0;
  font-size: 11px;
  font-family: 'JetBrains Mono', monospace;
  color: #666;
  text-align: center;
}
.cta__consent {
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  text-wrap: pretty;
  font-family: 'JetBrains Mono', monospace;
  color: #888;
  text-align: center;
}
.cta__consent a { color: #111; text-decoration: underline; }
.cta__consent a:hover { color: #000; }
