/*
 * Editor sobre la tarjeta (static/js/index/card-editor.js).
 * Todo cuelga de body.ce-active. En ≤980px la hoja sube desde abajo; en más ancho el
 * script añade body.ce-wide y la hoja pasa a ser un panel a la derecha de la tarjeta
 * (reglas al final de este archivo).
 */
:root {
  --ce-focus: #2f6bff;
  --ce-sheet-shadow: 0 -12px 40px rgba(29, 29, 31, 0.18);
  --ce-ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

.ce-top,
.ce-tools,
.ce-add-row,
.ce-sheet,
.ce-cta,
.ce-side,
.ce-back-to-card {
  display: none;
}

/* ── Qué se ve en cada momento ── */
body.ce-active .wizard-steps-wrap,
body.ce-active .wizard-nav,
body.ce-active .mini-card-bar,
body.ce-active .preview-header-mobile {
  display: none !important;
}

body.ce-active:not(.ce-pay) .form-stack,
body.ce-active.ce-pay .preview-panel {
  display: none;
}

body.ce-active .preview-panel {
  padding-bottom: 136px;
}

body.ce-active.ce-pay .preview-panel {
  padding-bottom: 0;
}

/* ── Encima de la tarjeta: tipo de Dicard y pista ── */
body.ce-active .ce-top {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.ce-type-slot .card-type-eyebrow,
.ce-type-slot .card-type-hint {
  display: none;
}

.ce-hint {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-secondary);
}

/* ── Zonas tocables de la tarjeta ── */
body.ce-active .card-preview [data-ce-section],
body.ce-active .card-preview [data-ce-field] {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: outline-color 0.15s ease, background-color 0.15s ease;
  outline: 2px solid transparent;
  outline-offset: 3px;
}

body.ce-active .card-preview [data-ce-section]:active,
body.ce-active .card-preview [data-ce-field]:active {
  background-color: rgba(127, 127, 127, 0.12);
}

body.ce-active .card-preview [data-ce-section]:focus-visible,
body.ce-active .card-preview [data-ce-field]:focus-visible,
body.ce-active .card-preview .ce-zone-active {
  outline: 2px solid var(--ce-focus);
  outline-color: var(--ce-focus);
}

body.ce-active .card-preview .cp-identity,
body.ce-active .card-preview .cp-logo-wrap {
  border-radius: 12px;
}

body.ce-active .card-preview .cp-logo-wrap,
body.ce-active .card-preview .cp-role,
body.ce-active .card-preview .cp-name,
body.ce-active .card-preview .cp-site {
  width: fit-content;
  max-width: 100%;
}

body.ce-active .card-preview .cp-role,
body.ce-active .card-preview .cp-name,
body.ce-active .card-preview .cp-contact-phone,
body.ce-active .card-preview .cp-contact-email,
body.ce-active .card-preview .cp-site {
  border-radius: 8px;
}

body.ce-active:not(.ce-final) .ce-add-row {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 6px 0 16px;
}

.ce-add {
  min-height: 36px;
  padding: 0 14px;
  border: 1.5px dashed rgba(127, 127, 127, 0.55);
  border-color: color-mix(in srgb, currentColor 35%, transparent);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
}

/* Vista final: sin textos de ejemplo ni espacios vacíos */
body.ce-final .card-preview .is-ghost:not(.cp-name),
body.ce-final .card-preview .cp-meta-card.ce-empty {
  display: none !important;
}

/* ── Debajo de la tarjeta: vista final y colores ── */
body.ce-active:not(.ce-pay) .ce-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.ce-tool {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg-soft);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}

.ce-tool[aria-pressed="true"] {
  border-color: transparent;
  background: var(--accent);
  color: #fff;
}

/* Acción destructiva: rojo legible (AA sobre blanco) pero sin relleno, para no competir con el resto. */
.ce-tool--reset {
  border-color: rgba(192, 54, 44, 0.32);
  color: #c0362c;
}

.ce-tool[hidden] {
  display: none;
}

/* ── Edición: la tarjeta queda arriba a tamaño real y la hoja abajo ── */
body.ce-editing {
  overflow: hidden;
}

body.ce-editing .preview-card-wrap {
  position: fixed;
  z-index: 40;
  top: var(--ce-vv-top, 0px);
  left: 50%;
  translate: -50% 0;
  width: min(100%, 560px);
  height: calc(var(--ce-vv-h, 100vh) - var(--ce-sheet-h, 50vh));
  margin: 0;
  padding: 14px 16px 24px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--bg);
  transition: top 0.25s var(--ce-ease), height 0.25s var(--ce-ease);
  /* Al pasar a edición la tarjeta queda fija arriba: una entrada breve disimula el cambio de posición. */
  animation: ce-stage-in 0.22s var(--ce-ease);
}

@keyframes ce-stage-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  body.ce-editing .preview-card-wrap {
    animation: none;
  }
}

body.ce-editing .ce-top,
body.ce-editing .ce-tools,
body.ce-editing .preview-qr-note {
  display: none;
}

body.ce-active .ce-sheet {
  display: block;
  position: fixed;
  z-index: 45;
  top: calc(var(--ce-vv-top, 0px) + var(--ce-vv-h, 100vh) - var(--ce-sheet-h, 50vh));
  left: 50%;
  translate: -50% 0;
  width: min(100%, 560px);
  height: var(--ce-sheet-h, 50vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: 22px 22px 0 0;
  background: var(--bg-soft);
  box-shadow: var(--ce-sheet-shadow);
  transform: translateY(105%);
  visibility: hidden;
  transition: transform 0.28s var(--ce-ease), visibility 0s linear 0.28s;
}

/* top y height también se animan: cuando sube el teclado la hoja acompaña el movimiento
   en vez de saltar de golpe a su nueva posición. */
body.ce-active .ce-sheet.is-open {
  transform: none;
  visibility: visible;
  transition: transform 0.28s var(--ce-ease), top 0.25s var(--ce-ease), height 0.25s var(--ce-ease);
}

/* La hoja se desplaza por dentro, pero el título y los botones quedan siempre a la vista.
   Con el teclado abierto la hoja se achica y antes "Siguiente" quedaba debajo del teclado. */
body.ce-active:not(.ce-wide) .ce-sheet-head,
body.ce-active:not(.ce-wide) .ce-sheet-nav {
  z-index: 1;
  margin-inline: -18px;
  padding-inline: 18px;
  background: var(--bg-soft);
}

body.ce-active:not(.ce-wide) .ce-sheet-head {
  position: sticky;
  top: 0;
  padding-block: 6px;
}

body.ce-active:not(.ce-wide) .ce-sheet-nav {
  position: sticky;
  bottom: 0;
  margin-bottom: calc(-18px - env(safe-area-inset-bottom, 0px));
  padding-block: 10px calc(12px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -1px 0 var(--border);
}

.ce-sheet-inner {
  display: grid;
  gap: 14px;
  padding: 8px 18px calc(18px + env(safe-area-inset-bottom, 0px));
}

.ce-grab {
  justify-self: center;
  width: 40px;
  height: 5px;
  margin-top: 2px;
  padding: 0;
  border: 0;
  border-radius: 3px;
  background: var(--border-strong);
}

.ce-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ce-sheet-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.ce-sheet-count {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ce-sheet-body {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.ce-sheet-body .field {
  margin-bottom: 0;
}

.ce-sheet-nav {
  display: flex;
  gap: 10px;
}

.ce-sheet-nav #ce-next {
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1.2;
}

/* Doble clase: .ce-btn (más abajo) trae padding lateral que descentraba la flecha */
.ce-btn.ce-btn-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  padding: 0;
}

.ce-btn.ce-btn-icon[hidden] {
  display: none;
}

.ce-btn {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
}

.ce-btn-ghost {
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
}

/* ── Barra inferior: progreso y continuar ── */
body.ce-active.ce-cta-visible .ce-cta {
  display: grid;
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  gap: 8px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  background: rgba(245, 245, 247, 0.94);
  -webkit-backdrop-filter: saturate(1.8) blur(20px);
  backdrop-filter: saturate(1.8) blur(20px);
}

.ce-progress {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.ce-bar {
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--border);
}

.ce-bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.ce-cta .ce-btn {
  width: 100%;
}

/* ── Paso de pago ── */
body.ce-active .ce-back-to-card {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  margin-bottom: 12px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
}

body.is-paid-flow .ce-back-to-card {
  display: none;
}

/* ── Escritorio: tarjeta a la izquierda, editor fijo a la derecha ── */
body.ce-wide .layout {
  grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
  gap: 28px;
  align-items: start;
}

body.ce-wide .preview-panel {
  grid-column: 1;
  grid-row: 1;
  padding-bottom: 0;
}

body.ce-wide .ce-side,
body.ce-wide .form-stack {
  grid-column: 2;
  grid-row: 1;
}

/* En el pago la tarjeta sigue a la vista, junto al resumen y el plan */
body.ce-wide.ce-pay .preview-panel {
  display: block;
}

body.ce-wide:not(.ce-pay) .ce-side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

body.ce-wide .preview-card-wrap {
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}

/* Misma tarjeta que en móvil: ancho de teléfono, centrada en su columna */
body.ce-wide .preview-wrap {
  max-width: 400px;
  margin-inline: auto;
}

body.ce-wide .ce-sheet {
  display: block;
  position: static;
  translate: none;
  top: auto;
  left: auto;
  width: auto;
  height: auto;
  overflow: visible;
  transform: none;
  visibility: visible;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-soft);
  box-shadow: none;
}

body.ce-wide .ce-sheet-inner {
  padding: 20px;
}

body.ce-wide .ce-grab,
body.ce-wide #ce-done {
  display: none;
}

body.ce-wide.ce-cta-visible .ce-cta {
  position: static;
  right: auto;
  bottom: auto;
  left: auto;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-soft);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

@media (prefers-reduced-motion: reduce) {
  body.ce-active .ce-sheet,
  body.ce-active .ce-sheet.is-open,
  .ce-bar span {
    transition: none;
  }
}
