/* ===================================================================
   Editor de personalización — grabado láser sobre la virola.

   En el celular la página scrollea como cualquier otra: arriba la virola,
   abajo las capas y los ajustes, y la barra de compra fija al pie. Sólo el
   lienzo corta el scroll, y sólo cuando el dedo apoya sobre una capa: ahí
   va a arrastrar. En escritorio son dos columnas: la virola y el panel de trabajo.
   =================================================================== */

/* Varios bloques declaran display:flex/grid y se ocultan con `hidden`: sin
   esta regla la declaración de display le gana y quedarían todos a la vista. */
[hidden] { display: none !important; }

.ed {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ---------- Barra superior ---------- */
.ed-top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .6rem;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-body);
}
.ed-title { flex: 1; min-width: 0; }
.ed-name-input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--c-text);
  font-size: 15px;
  font-weight: 600;
  padding: 0;
}
.ed-name-input:focus { outline: none; }
.ed-saved { display: block; font-size: 11px; color: var(--c-muted); }
.ed-top-actions { display: flex; gap: .25rem; }

.ed-icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  color: var(--c-text);
  flex: none;
}
.ed-icon-btn:active { background: var(--c-surface); }
.ed-icon-btn:disabled { opacity: .3; }

/* ---------- Cuerpo ---------- */
.ed-main { flex: 1; display: flex; flex-direction: column; }

.ed-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .6rem;
  padding: .9rem 1rem 1rem;
  background: var(--c-surface);
}
.ed-ring-wrap {
  width: 100%;
  max-width: 520px;
  aspect-ratio: 1 / 1;
  line-height: 0;
}
/* En un área recta (no virola) la proporción la pone el JavaScript */
.ed-ring-wrap[data-flat] { aspect-ratio: auto; max-width: 760px; }
.ed-ring-wrap canvas {
  width: 100%;
  height: 100%;
  /* El scroll se corta desde el JavaScript sólo al tocar una capa */
  touch-action: manipulation;
  cursor: default;
}
.ed-ring-wrap canvas[data-cursor="grab"] { cursor: grab; }
.ed-ring-wrap canvas[data-cursor="grabbing"] { cursor: grabbing; }

/* Mover uno / Girar todo */
.ed-modes {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  border: 1.5px solid var(--c-border);
  border-radius: 999px;
  background: var(--c-body);
}
.ed-mode {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  min-height: 36px;
  padding: 0 .9rem;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: none;
  color: var(--c-muted);
}
.ed-mode[aria-pressed="true"] { background: var(--c-button); color: var(--c-button-text, #fff); }

.ed-hint {
  font-size: 12px;
  line-height: 1.45;
  color: var(--c-muted);
  text-align: center;
  max-width: 30rem;
  margin: 0;
}

/* Vista previa sobre la foto del producto. El canvas se ubica en porcentajes
   de la foto, así que acompaña cualquier tamaño sin recalcular. */
.ed-preview { margin: 0; padding: 0 1rem 1rem; text-align: center; background: var(--c-surface); }
.ed-preview figcaption { font-size: 11px; color: var(--c-muted); margin-top: .3rem; }
.ed-preview-photo {
  position: relative;
  display: inline-block;
  line-height: 0;
}
.ed-preview-photo img {
  display: block;
  max-height: 180px;
  width: auto;
  border-radius: var(--radius);
}
.ed-preview-canvas { position: absolute; pointer-events: none; }
.ed-preview-zoom {
  position: absolute;
  right: .3rem;
  bottom: .3rem;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: rgb(255 255 255 / .92);
  color: #111;
  box-shadow: 0 2px 8px rgb(0 0 0 / .3);
}
.ed-preview-backdrop {
  position: fixed;
  inset: 0;
  z-index: 55;
  background: rgb(0 0 0 / .72);
}
.ed-preview-photo.ed-preview-big {
  position: fixed;
  z-index: 56;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.ed-preview-photo.ed-preview-big img { max-height: 88dvh; max-width: 94vw; }

/* ---------- Columna de trabajo ---------- */
.ed-side {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 1rem 1.25rem;
  background: var(--c-body);
}
.ed-block { padding: 1rem 0; border-bottom: 1px solid var(--c-border); }
.ed-block:last-of-type { border-bottom: 0; }
.ed-block-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.ed-block-head .ed-block-title { margin: 0; }
.ed-block-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--c-muted);
  margin: 0 0 .6rem;
}

.ed-add { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.ed-add-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .25rem;
  min-height: 64px;
  border: 1.5px dashed var(--c-border);
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
  cursor: pointer;
  background: transparent;
}
.ed-add-btn:hover { border-style: solid; border-color: var(--c-button); }
.ed-add-btn:active { background: var(--c-surface); }
.ed-add-btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }

.ed-link {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text);
  text-decoration: underline;
  text-underline-offset: 2px;
  background: none;
  padding: .25rem 0;
}
.ed-link-danger { color: #dc2626; }

/* Capas */
.ed-layers { display: flex; flex-direction: column; gap: .4rem; margin: 0; padding: 0; list-style: none; }
.ed-layer {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 48px;
  padding: .25rem .25rem .25rem .6rem;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-body);
}
.ed-layer[data-on="1"] { border-color: var(--c-button); background: var(--c-surface); }
.ed-order { display: flex; flex-direction: column; flex: none; margin-left: -.35rem; }
.ed-order[hidden] { display: none; }
.ed-order-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 22px;
  background: none;
  color: var(--c-text);
  border-radius: 6px;
}
.ed-order-btn:disabled { opacity: .2; cursor: default; }
.ed-order-btn:not(:disabled):hover { background: var(--c-border); }
.ed-layer-icon { display: grid; place-items: center; color: var(--c-muted); flex: none; }
.ed-layer-name {
  flex: 1;
  min-width: 0;
  text-align: left;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  color: var(--c-text);
  min-height: 40px;
}
.ed-layer .ed-copy { color: var(--c-text); }
.ed-layer .ed-icon-btn { width: 38px; height: 38px; }
.ed-layer .ed-pin { color: var(--c-muted); opacity: .35; }
.ed-layer .ed-pin[data-on="1"] { color: var(--c-text); opacity: 1; }
.ed-layer .ed-del { color: #dc2626; }

.ed-meter { margin-top: .75rem; }

.ed-spin {
  display: flex;
  align-items: center;
  gap: .25rem;
  margin-top: .75rem;
  font-size: 12px;
  color: var(--c-muted);
}
.ed-spin[hidden] { display: none; }
.ed-spin span { flex: 1; }
.ed-spin .ed-icon-btn { width: 40px; height: 40px; border: 1.5px solid var(--c-border); border-radius: var(--radius); color: var(--c-text); }
.ed-front-btn { width: 100%; margin-top: .75rem; }
.ed-front-btn[hidden] { display: none; }
.ed-meter-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--c-muted); margin-bottom: .3rem; }
.ed-meter-bar { height: 3px; background: var(--c-border); border-radius: 3px; overflow: hidden; }
.ed-meter-bar i { display: block; height: 100%; background: var(--c-button); transition: width .15s ease; }

/* Ajustes */
.ed-range-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: .72rem;
  font-weight: 600;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: .9rem;
}
.ed-range-label b { font-weight: 600; color: var(--c-text); text-transform: none; letter-spacing: 0; font-variant-numeric: tabular-nums; }
.ed-range { width: 100%; height: 36px; accent-color: var(--c-button); }
.label.mt { margin-top: .9rem; }

.ed-font-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  padding: .5rem .8rem;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-body);
  color: var(--c-text);
  font-size: 18px;
}
.ed-fonts {
  max-height: 260px;
  overflow-y: auto;
  margin-top: .4rem;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
}
.ed-font-group {
  position: sticky;
  top: 0;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--c-muted);
  background: var(--c-surface);
  padding: .45rem .8rem;
  margin: 0;
}
.ed-font {
  display: block;
  width: 100%;
  text-align: left;
  padding: .5rem .8rem;
  font-size: 19px;
  line-height: 1.3;
  color: var(--c-text);
  background: var(--c-body);
  border-top: 1px solid var(--c-border);
}
.ed-font[data-on="1"] { background: var(--c-button); color: var(--c-button-text); }

.ed-shape-row { display: flex; align-items: center; gap: .75rem; }
.ed-shape-thumb {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  flex: none;
}
.ed-shape-thumb img { max-width: 80%; max-height: 80%; }
.ed-shape-row .btn { flex: 1; }

.ed-note { font-size: 12px; line-height: 1.45; color: var(--c-muted); margin: .6rem 0 0; }

.ed-toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: .7rem 1rem;
  border-radius: var(--radius);
  background: #1f2326;
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgb(0 0 0 / .25);
}

/* ---------- Barra de compra ---------- */
.ed-bottom {
  position: sticky;
  bottom: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .6rem .8rem calc(.6rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--c-border);
  background: var(--c-body);
}
.ed-price { display: flex; flex-direction: column; min-width: 0; }
.ed-price-value { font-size: 18px; font-weight: 700; }
.ed-price-note { font-size: 11px; color: var(--c-muted); }

/* ---------- Biblioteca de figuras ---------- */
.ed-sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgb(0 0 0 / .45);
}
.ed-sheet-box {
  display: flex;
  flex-direction: column;
  gap: .6rem;
  width: 100%;
  max-width: 560px;
  max-height: 82dvh;
  padding: .75rem 1rem calc(1rem + env(safe-area-inset-bottom));
  border-radius: 16px 16px 0 0;
  background: var(--c-body);
}
.ed-sheet-head { display: flex; align-items: center; justify-content: space-between; }
.ed-sheet-head h2 { font-size: 16px; font-weight: 700; margin: 0; }

.ed-search { position: relative; }
.ed-search svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--c-muted); }
.ed-search .field { padding-left: 2.2rem; }

.ed-cats { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; flex: none; }
.ed-chip {
  flex: none;
  padding: .4rem .8rem;
  border: 1.5px solid var(--c-border);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--c-text);
}
.ed-chip[data-on="1"] { background: var(--c-button); color: var(--c-button-text); border-color: var(--c-button); }

.ed-assets {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: .5rem;
  overflow-y: auto;
  min-height: 160px;
  padding: .1rem;
}
.ed-asset {
  display: grid;
  place-items: center;
  aspect-ratio: 1 / 1;
  border: 1.5px solid var(--c-border);
  border-radius: var(--radius);
  background: var(--c-body);
  padding: .6rem;
}
.ed-asset:hover, .ed-asset:active { border-color: var(--c-button); }
.ed-asset img { max-width: 100%; max-height: 100%; }
.ed-empty { font-size: 13px; color: var(--c-muted); text-align: center; padding: .75rem 0; margin: 0; }

/* ---------- Ocupado ---------- */
.ed-busy {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgb(255 255 255 / .75);
}
.ed-busy-box {
  padding: 1rem 1.4rem;
  border-radius: var(--radius);
  background: var(--c-body);
  box-shadow: 0 10px 30px rgb(0 0 0 / .15);
  font-weight: 600;
}

/* ---------- Escritorio: dos columnas ---------- */
@media (min-width: 900px) {
  .ed { height: 100dvh; min-height: 0; overflow: hidden; }
  /* La foto del mate sube a la columna derecha: así la virola entra entera
     en el alto de la pantalla, con sus marcas de grados. */
  .ed-main {
    display: grid;
    grid-template-columns: 1fr 380px;
    grid-template-rows: auto 1fr;
    grid-template-areas: "stage preview" "stage side";
    min-height: 0;
  }
  .ed-stage {
    grid-area: stage;
    justify-content: center;
    justify-content: safe center;   /* si no entra, que no se corte arriba */
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
  }
  .ed-ring-wrap { max-width: min(620px, calc(100dvh - 210px)); }
  .ed-preview {
    grid-area: preview;
    padding: 1rem 1.25rem .75rem;
    border-left: 1px solid var(--c-border);
    border-bottom: 1px solid var(--c-border);
  }
  .ed-preview-photo img { max-height: 150px; }
  .ed-side { grid-area: side; overflow-y: auto; border-left: 1px solid var(--c-border); padding: 0 1.25rem 1.5rem; }
  .ed-sheet { align-items: center; }
  .ed-sheet-box { border-radius: 16px; max-height: 76dvh; }
  .ed-toast { bottom: 90px; }
}
