/* =========================================================
   ADMINISTRADOR DE BOOK
   Interfaz interna del nuevo popup
   ========================================================= */

.book-edit-popup-content {
  width: 90%;
  max-width: 90%;
  height: 90%;
  max-height: 90%;
  background: var(--white);
  padding: 22px;
  border-radius: 12px;
  position: fixed;
  display: flex;
  flex-direction: column;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  overflow: hidden;
}

.book-editor-header {
  text-align: center;
  margin-bottom: 25px;
}

.book-editor-header h2 {
  margin: 0 0 8px;
  font-size: 24px;
  font-weight: 700;
}

#book-editor-popup-close {
  position: absolute;
  z-index: 9;
  background: var(--white);
  border-radius: 3px;
  top: 12px;
  right: 12px;
  cursor: pointer;
}

#book-editor-popup-close svg {
  width: 32px;
  height: 32px;
  cursor: pointer;
}


/* ---------------------------------------------------------
   CONTENIDO
   --------------------------------------------------------- */

.book-editor-body {
  padding: 0 5px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.book-editor-help {
  margin: 0 0 18px;
  font-size: 13px;
  line-height: 13px;
  opacity: .7;
  width: 100%;
}


/* ---------------------------------------------------------
   BOTÓN SUBIR FOTOS
   --------------------------------------------------------- */

.book-upload-button {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 8px;
  background: #222;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s ease, transform .2s ease;
  margin-bottom: 22px;
}

.book-upload-button:hover {
  opacity: .9;
}

.book-upload-button:active {
  transform: scale(.98);
}


/* ---------------------------------------------------------
   ÁREA DE GALERÍA
   --------------------------------------------------------- */

.book-gallery-editor {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 10px;
}


/* Placeholder temporal */

.book-gallery-placeholder {
  grid-column: 1 / -1;
  padding: 35px 20px;
  text-align: center;
  border: 1px dashed #ccc;
  border-radius: 8px;
  font-size: 13px;
  opacity: .6;
}

/* ---------------------------------------------------------
   Galeria
   --------------------------------------------------------- */

.book-editor-item {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 8px;
  background: #eee;
}

.book-editor-item img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.book-editor-item video {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  object-fit: cover;
  height: 100%;
}

/* =========================================================
   SELECTOR DE ARCHIVOS
   ========================================================= */

.book-upload-status {
  margin-top: 15px;
  margin-bottom: 20px;
  padding: 15px;
  border-radius: 10px;
  background: #f5f5f7;
}

.book-upload-status__title {
  margin-bottom: 10px;
  font-size: 14px;
  font-weight: 700;
}


/* Lista de archivos seleccionados */

.book-upload-file-list {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}


/* Cada archivo */

.book-upload-file {
  position: relative;
  aspect-ratio: 1 / 1;
  overflow: hidden;
  border-radius: 7px;
  background: #ddd;
}

.book-upload-file img,
.book-upload-file video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}


/* Indicador para videos */

.book-upload-file--video::after {
  content: "▶";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);

  width: 34px;
  height: 34px;

  display: flex;
  align-items: center;
  justify-content: center;

  border-radius: 50%;

  background: rgba(0, 0, 0, .7);
  color: #fff;

  font-size: 13px;
}


/* Nombre del archivo */

.book-upload-file__name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;

  padding: 5px 6px;

  background: rgba(0, 0, 0, .65);
  color: #fff;

  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#book-file-input {
  display: none !important;
}

.book-upload-errors {
  grid-column: 1 / -1;

  margin-bottom: 12px;
  padding: 12px 14px;

  border-radius: 8px;

  background: #fff1f1;
  border: 1px solid #f0b5b5;

  color: #9b2226;

  font-size: 13px;
  line-height: 1.5;
}

.book-upload-errors strong {
  display: block;
  margin-bottom: 5px;
}

.book-upload-errors ul {
  margin: 5px 0 0 18px;
  padding: 0;
}


/* =========================================================
   PROGRESO DE SUBIDA
   ========================================================= */

.book-upload-progress {
  width: 100%;
  height: 8px;
  margin-top: 12px;

  overflow: hidden;

  border-radius: 10px;
  background: #ddd;
}

.book-upload-progress__bar {
  width: 0;
  height: 100%;

  border-radius: 10px;

  background: #222;

  transition: width .2s ease;
}

.book-upload-status__detail {
  margin-top: 8px;

  font-size: 12px;
  opacity: .65;
}

/* ---------------------------------------------------------
   MOBILE
   --------------------------------------------------------- */

@media (max-width: 768px) {

  .book-gallery-editor {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .book-upload-file-list {
    grid-template-columns: repeat(4, 1fr);
  }

}

/* =========================================================
   MOBILE
   ========================================================= */

@media (max-width: 600px) {

  /* -------------------------------------------------------
     POPUP FULL SCREEN
     ------------------------------------------------------- */

  .edit-popup-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
  }

  .book-edit-popup-content {
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    padding: 12px;
    max-height: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }

  /* -------------------------------------------------------
     BODY SCROLLEABLE
     ------------------------------------------------------- */

  .book-editor-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding:
      0 14px calc(30px + env(safe-area-inset-bottom));
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }


  /* -------------------------------------------------------
     GALERÍA — 3 COLUMNAS
     ------------------------------------------------------- */

  .book-gallery-editor {
    grid-template-columns:
      repeat(3, minmax(0, 1fr));
    gap: 8px;
  }


  /* -------------------------------------------------------
     HEADER
     ------------------------------------------------------- */

  .book-editor-header {
    flex: 0 0 auto;
    padding:
      18px 45px 14px;
  }


  .book-editor-header h2 {
    font-size: 21px;
  }


  /* -------------------------------------------------------
     BOTÓN SUBIR
     ------------------------------------------------------- */

  .book-upload-button {
    min-height: 52px;
    margin-bottom: 18px;
  }
}


/* =========================================================
   ELIMINACIÓN DE FOTO
   ========================================================= */

/*
 * Estado mientras WordPress elimina el archivo.
 *
 * La tarjeta queda visible pero atenuada y bloqueada.
 */
.book-editor-item.is-deleting {
  opacity: .45;
  pointer-events: none;
}


/*
 * Botón eliminar.
 */
.book-editor-delete {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .75);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 5;
  transition: background .15s ease, transform .15s ease;
}

.book-editor-delete svg {
  width: 20px;
  height: 20px;
}


/*
 * Estado activo durante la eliminación.
 */
.book-editor-delete.is-loading {
  background: #d63031;
  color: #fff;
  cursor: default;
}


/*
 * Pequeño loader circular.
 */
.book-editor-delete.is-loading::after {
  content: "";
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  border-radius: 50%;
  animation:
    cksBookDeleteSpin .7s linear infinite;
}


@keyframes cksBookDeleteSpin {

  to {
    transform: rotate(360deg);
  }

}


/* =========================================================
   ORDENAMIENTO DEL BOOK — SORTABLEJS
   ========================================================= */


/*
 * ---------------------------------------------------------
 * ELEMENTO SELECCIONADO
 * ---------------------------------------------------------
 *
 * Se aplica mientras Sortable ha seleccionado
 * la tarjeta para iniciar el drag.
 */

.book-sortable-chosen {

  outline:
    3px solid #8e44ad;

  outline-offset:
    -3px;

  box-shadow:
    0 8px 22px rgba(142, 68, 173, .35);

  z-index:
    90;
}


/*
 * ---------------------------------------------------------
 * ELEMENTO DURANTE DRAG
 * ---------------------------------------------------------
 */

.book-sortable-drag {

  opacity:
    .55;

  box-shadow:
    0 12px 30px rgba(0, 0, 0, .22);

  transform:
    scale(.97);

  z-index:
    100;
}


/*
 * ---------------------------------------------------------
 * GHOST / ESPACIO DE DESTINO
 * ---------------------------------------------------------
 *
 * SortableJS utiliza esta clase para representar
 * visualmente dónde quedará el elemento.
 */

.book-sortable-ghost {

  aspect-ratio:
    1 / 1;

  border-radius:
    8px;

  border:
    2px dashed #8e44ad;

  background:
    rgba(142, 68, 173, .10);

  box-sizing:
    border-box;

  opacity:
    1;
}


/*
 * ---------------------------------------------------------
 * PREVENIR INTERACCIONES NATIVAS
 * ---------------------------------------------------------
 *
 * Evitamos selección y drag nativo de imágenes/videos.
 */

.book-editor-item img,
.book-editor-item video {

  user-select:
    none;

  -webkit-user-select:
    none;

  -webkit-user-drag:
    none;

  -webkit-touch-callout:
    none;

  pointer-events:
    none;
}


/*
 * La tarjeta sigue siendo el elemento interactivo
 * para SortableJS.
 */

.book-editor-item {

  -webkit-touch-callout:
    none;

  user-select:
    none;
}