/* ============================================================
   Editor Canvas — v4 Hyper-Premium Figma/Canva Style
   ============================================================ */

.cp-stage-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.75rem;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  background:
    radial-gradient(800px 380px at 50% -5%, rgba(37, 99, 235, 0.07), transparent 75%),
    linear-gradient(90deg, rgba(28, 36, 48, 0.022) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(rgba(28, 36, 48, 0.022) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(180deg, #F4F0E9 0%, #E9E2D6 100%);
}

.cp-stage-scroll.is-single-page:not(.needs-scroll) {
  overflow: hidden;
}

.cp-canvas-frame {
  /* Evita fit-content + width:100% del hijo (colapso ~0px → CLS) */
  width: min(540px, 100%);
  max-width: 100%;
  margin: 0 auto;
  flex: 0 0 auto;
  transform-origin: top center;
  /* Sin transition: el zoom/fit no debe “animar” la plantilla */
  filter: drop-shadow(0 24px 48px rgba(15, 23, 42, 0.16));
}

.cp-canvas {
  position: relative;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  background: #fff;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 0 0 1px rgba(28, 36, 48, 0.08);
  border-radius: 4px;
  /* Nunca dejar que elementos (ni rotados) sobresalgan del lienzo */
  overflow: hidden;
  touch-action: none;
}

/* Reserva de espacio según data-w/data-h del boot (anti-CLS) */
.cp-canvas.cp-ar-1080x1920 { aspect-ratio: 1080 / 1920; }
.cp-canvas.cp-ar-1080x1350 { aspect-ratio: 1080 / 1350; }
.cp-canvas.cp-ar-1080x1080 { aspect-ratio: 1 / 1; }
.cp-canvas.cp-ar-1080x3240 { aspect-ratio: 1080 / 3240; }
.cp-canvas.cp-ar-1200x628 { aspect-ratio: 1200 / 628; }
.cp-canvas.cp-ar-1920x1080 { aspect-ratio: 1920 / 1080; }
.cp-canvas.cp-ar-1080x566 { aspect-ratio: 1080 / 566; }

/* Hojas apiladas: misma fórmula que computeDisplaySize (hoja ~88% viewport) */
.cp-canvas-frame.is-multipage {
  width: max(160px, calc((100vh - var(--cp-topbar-h) - 7.5rem) * 0.88));
  max-width: 100%;
  padding-bottom: 1.25rem;
}

/* LCP SSR: pinta la foto principal antes del JS del editor */
.cp-boot-lcp {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: calc(100% / var(--cp-page-count, 1));
  object-fit: cover;
  object-position: center 42%;
  z-index: 1;
  pointer-events: none;
}

.cp-canvas[data-pages="2"] { --cp-page-count: 2; }
.cp-canvas[data-pages="3"] { --cp-page-count: 3; }
.cp-canvas[data-pages="4"] { --cp-page-count: 4; }
.cp-canvas[data-pages="5"] { --cp-page-count: 5; }
.cp-canvas[data-pages="6"] { --cp-page-count: 6; }

.cp-canvas.is-multipage {
  border-radius: 2px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.9) inset,
    0 0 0 1px rgba(28, 36, 48, 0.1),
    0 18px 40px rgba(15, 23, 42, 0.14);
}

.cp-page-sheet {
  position: absolute;
  left: 0;
  right: 0;
  pointer-events: none;
  z-index: 0;
  box-sizing: border-box;
  border-bottom: 1px solid rgba(28, 36, 48, 0.1);
}

.cp-page-sheet.is-active-sheet {
  box-shadow: inset 0 0 0 2px rgba(37, 99, 235, 0.22);
}

.cp-page-gap {
  position: absolute;
  left: -10px;
  right: -10px;
  height: 12px;
  transform: translateY(-6px);
  background:
    linear-gradient(180deg, rgba(233, 226, 214, 0.2) 0%, #E9E2D6 35%, #E9E2D6 65%, rgba(233, 226, 214, 0.2) 100%);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    0 1px 0 rgba(28, 36, 48, 0.06);
  pointer-events: none;
  z-index: 0;
}

.cp-page-label {
  position: absolute;
  left: 10px;
  transform: translateY(8px);
  z-index: 4;
  pointer-events: none;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(28, 36, 48, 0.38);
  background: rgba(255, 252, 248, 0.88);
  border: 1px solid rgba(28, 36, 48, 0.08);
  border-radius: 999px;
  padding: 0.12rem 0.45rem;
}

/* ============================================================
   Canvas Elements & Selection Handles
   ============================================================ */

.cp-el {
  position: absolute;
  box-sizing: border-box;
  cursor: move;
  user-select: none;
  min-width: 8px;
  min-height: 8px;
  overflow: visible;
}

.cp-el.is-selected {
  z-index: 5;
  box-shadow: none;
  overflow: visible !important; /* handles de resize/giro fuera del box */
}

.cp-el.is-multi-selected {
  box-shadow: none;
}

/* Guías de alineación (bordes / centros) al arrastrar */
.cp-align-guide {
  position: absolute;
  z-index: 55;
  pointer-events: none;
}

.cp-align-guide-v {
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed rgba(255, 45, 85, 0.92);
  transform: translateX(-0.5px);
}

.cp-align-guide-h {
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px dashed rgba(255, 45, 85, 0.92);
  transform: translateY(-0.5px);
}

.cp-canvas.has-multi-selection .cp-el.is-selected {
  z-index: 6;
}

/* Marco de selección múltiple (arrastrar en vacío) */
.cp-marquee {
  position: absolute;
  z-index: 40;
  pointer-events: none;
  border: 1.5px solid rgba(37, 99, 235, 0.85);
  background: rgba(37, 99, 235, 0.12);
  border-radius: 2px;
  box-sizing: border-box;
}

.cp-marquee[hidden] {
  display: none !important;
}

/* Capa visual: fondo/clip; los handles viven fuera y no se recortan */
.cp-el-visual {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  pointer-events: none;
  overflow: hidden;
}

.cp-el-visual.is-text {
  position: relative;
  inset: auto;
  display: flex;
  width: 100%;
  height: auto;
  min-height: 100%;
  align-items: flex-start;
  padding: 0.05rem 0.15rem;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.2;
  overflow: visible;
}

.cp-el-visual::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  clip-path: inherit;
  pointer-events: none;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity 120ms var(--cp-ease);
}

.cp-el.is-selected > .cp-el-visual::after {
  opacity: 1;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.92);
}

.cp-el.is-multi-selected > .cp-el-visual::after {
  opacity: 1;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.82);
}

.cp-el.is-selected > img {
  border-radius: inherit;
}

/* Handles de esquina y borde — discretos para no tapar el diseño */
.cp-handle {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #FFFFFF;
  border: 1.5px solid #2563EB;
  border-radius: 50%;
  z-index: 10;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  pointer-events: auto;
  touch-action: none;
}

/* Zona de clic más grande que el círculo visible */
.cp-handle::before {
  content: "";
  position: absolute;
  inset: -7px;
}

.cp-handle-tl { top: -4px; left: -4px; cursor: nwse-resize; }
.cp-handle-tr { top: -4px; right: -4px; cursor: nesw-resize; }
.cp-handle-bl { bottom: -4px; left: -4px; cursor: nesw-resize; }
.cp-handle-br { bottom: -4px; right: -4px; cursor: nwse-resize; }
.cp-handle-t { top: -4px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.cp-handle-b { bottom: -4px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.cp-handle-l { left: -4px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.cp-handle-r { right: -4px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

.cp-rotate-handle {
  position: absolute;
  top: -40px;
  bottom: auto;
  left: 50%;
  width: 24px;
  height: 24px;
  transform: translateX(-50%);
  border: 2px solid #2563EB;
  border-radius: 999px;
  background: #FFFFFF;
  color: #2563EB;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.22);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  z-index: 12;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cp-rotate-handle::before {
  content: "";
  position: absolute;
  inset: -10px;
}

.cp-rotate-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 2px;
  height: 14px;
  background: #2563EB;
  transform: translateX(-50%);
}

.cp-rotate-handle svg {
  pointer-events: none;
  display: block;
  position: relative;
  z-index: 1;
}

.cp-rotate-handle:active {
  cursor: grabbing;
  background: #EFF6FF;
}

.cp-el.is-rotating {
  cursor: grabbing;
}

.cp-el.is-resizing {
  cursor: default;
}

/* Capas bloqueadas: sin contorno permanente (parecía “recorte” en el lienzo).
   Solo al seleccionar: outline punteado para indicar que no se mueven. */
.cp-el.is-locked {
  cursor: not-allowed;
}

.cp-el.is-locked.is-selected {
  outline: 1px dashed #94A3B8;
  box-shadow: none;
}

/* Foto/fondo a pantalla completa: sin “agarre” hasta elegir la capa */
.cp-el.is-backdrop-layer:not(.is-selected) {
  pointer-events: none;
  cursor: default;
}

.cp-el.is-backdrop-layer.is-selected:not(.is-locked) {
  cursor: move;
}

.cp-el.is-hidden {
  opacity: 0.25;
}

.cp-el-text,
.cp-el-variable {
  overflow: visible;
  box-sizing: border-box;
}

.cp-el-variable > .cp-el-visual {
  border: 1px dashed rgba(37, 99, 235, 0.5);
  background: rgba(37, 99, 235, 0.08);
  border-radius: 4px;
}

.cp-el-image > .cp-el-visual {
  overflow: hidden;
  background: #E8EEF7;
}

/* PNG/JPG con alpha: fondo transparente; los iconos sí pueden llevar placa editable */
.cp-el-image.has-src:not(.is-empty):not([data-role="icon"]) > .cp-el-visual {
  background: transparent !important;
  box-shadow: none;
}

.cp-el-image[data-role="icon"] > .cp-el-visual {
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 30% 24%, rgba(255,255,255,0.12), transparent 48%),
    linear-gradient(180deg, rgba(14,23,42,0.96), rgba(9,16,31,0.98));
  border: 1px solid rgba(148,163,184,0.22);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.08),
    0 12px 28px rgba(2,6,23,0.22);
}

.cp-el-image[data-role="icon"] img {
  object-fit: contain !important;
  background: transparent !important;
  width: 66%;
  height: 66%;
  filter: drop-shadow(0 4px 12px rgba(15, 23, 42, 0.22));
}

.cp-el-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

.cp-el-image.is-empty > .cp-el-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px dashed rgba(37, 99, 235, 0.45);
  background:
    linear-gradient(180deg, #F5F8FF 0%, #E8EEF7 100%);
}

.cp-el-image.is-map-fallback > .cp-el-visual {
  border-style: solid;
  background:
    radial-gradient(circle at 50% 46%, rgba(239, 68, 68, 0.95) 0 7px, rgba(255, 255, 255, 0.95) 7px 10px, transparent 10px),
    linear-gradient(32deg, transparent 0 42%, rgba(58, 82, 72, 0.18) 42% 44%, transparent 44% 100%),
    linear-gradient(148deg, transparent 0 38%, rgba(58, 82, 72, 0.16) 38% 40%, transparent 40% 100%),
    linear-gradient(90deg, transparent 0 31%, rgba(58, 82, 72, 0.12) 31% 32%, transparent 32% 64%, rgba(58, 82, 72, 0.12) 64% 65%, transparent 65%),
    linear-gradient(180deg, #EEF4EC 0%, #DCE9E1 100%);
}

.cp-el-image-ph {
  font-size: 0.72rem;
  font-weight: 700;
  color: #2563EB;
  letter-spacing: 0.01em;
  pointer-events: none;
  text-align: center;
  padding: 0.4rem;
}

.cp-el-rect > .cp-el-visual,
.cp-el-background > .cp-el-visual {
  border-radius: 2px;
}

.cp-el-rect.has-label > .cp-el-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.cp-rect-label {
  line-height: 1;
  font-weight: 700;
  letter-spacing: inherit;
  pointer-events: none;
}

.cp-el-circle > .cp-el-visual {
  border-radius: 999px;
}

.cp-el-triangle > .cp-el-visual,
.cp-el-diamond > .cp-el-visual,
.cp-el-ribbon > .cp-el-visual {
  border-radius: 0;
  overflow: hidden;
}

.cp-el-line {
  height: 0 !important;
  min-height: 0;
  background: transparent !important;
}

.cp-el-line > .cp-el-visual {
  height: 0 !important;
  min-height: 0;
  background: transparent !important;
  border-top-width: 4px;
  border-top-style: solid;
  overflow: visible;
}

/* ============================================================
   Layers List
   ============================================================ */

.cp-layers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.25rem;
}

.cp-layers li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  border: 1px solid var(--cp-line);
  border-radius: 8px;
  padding: 0.35rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 550;
  cursor: grab;
  background: rgba(255, 255, 255, 0.75);
  transition: border-color 140ms var(--cp-ease), background 140ms var(--cp-ease), box-shadow 140ms var(--cp-ease), opacity 140ms var(--cp-ease);
  user-select: none;
}

.cp-layers li:hover {
  border-color: rgba(37, 99, 235, 0.28);
  background: #F8FAFC;
}

.cp-layers li.is-active {
  border-color: transparent;
  background: var(--cp-blue-soft);
  color: var(--cp-blue);
}

.cp-layers li.is-dragging {
  opacity: 0.45;
  cursor: grabbing;
}

.cp-layers li.is-drag-over {
  box-shadow: inset 0 2px 0 0 var(--cp-blue);
}

.cp-layers li.is-drag-over-after {
  box-shadow: inset 0 -2px 0 0 var(--cp-blue);
}

.cp-layers .layer-grip {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--cp-muted);
  opacity: 0.7;
}

.cp-layers .layer-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cp-layers .layer-meta {
  flex-shrink: 0;
  color: var(--cp-muted);
  font-size: 0.62rem;
  font-weight: 500;
}

/* ============================================================
   Properties Empty State
   ============================================================ */

#propsEmpty {
  padding: 0.85rem 0.75rem;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.6), rgba(241, 245, 249, 0.8));
  border: 1px dashed rgba(30, 41, 59, 0.15);
  font-size: 0.76rem;
  line-height: 1.45;
  text-align: center;
  color: var(--cp-muted);
}

/* ============================================================
   Right panel — Capas + Propiedades (sin solape)
   ============================================================ */

.cp-panel-right .cp-panel-inner {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0.75rem;
}

.cp-panel-right #secCapas {
  flex: 1 1 0;
  min-height: 6rem;
  max-height: 55%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cp-panel-right #secCapas.is-collapsed {
  flex: 0 0 auto;
  min-height: 0;
  max-height: none;
}

.cp-panel-right #secCapas.is-collapsed .cp-section-body.cp-layers-body {
  flex: 0 0 0;
  min-height: 0;
  max-height: 0;
  overflow: hidden;
  display: none;
}

.cp-panel-right #secCapas .cp-section-body.cp-layers-body {
  flex: 1 1 auto;
  min-height: 0;
  height: auto;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
}

.cp-panel-right #secPropiedades {
  flex: 1 1 0;
  min-height: 8rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.cp-panel-right #secPropiedades.is-collapsed {
  flex: 0 0 auto;
  min-height: 0;
}

.cp-panel-right #secPropiedades.is-collapsed > .cp-section-body {
  flex: 0 0 0;
  min-height: 0;
  max-height: 0;
  overflow: hidden;
  display: none;
}

.cp-panel-right #secCapas.is-collapsed ~ #secPropiedades:not(.is-collapsed) {
  flex: 1 1 auto;
  min-height: 0;
}

.cp-panel-right #secPropiedades > .cp-section-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

/* Restaura scroll anulado por .cp-panel-block:not(.is-collapsed) .cp-section-body { overflow: visible } */
.cp-panel-right .cp-panel-block:not(.is-collapsed) .cp-section-body.cp-layers-body,
.cp-panel-right .cp-panel-block:not(.is-collapsed) #secPropiedades > .cp-section-body {
  overflow-x: hidden;
  overflow-y: auto;
}

.cp-props-effects {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid rgba(28, 36, 48, 0.08);
}

.cp-props-grid.cp-props-grid-effects {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cp-props-effects input[type="range"] {
  width: 100%;
}
