/* ==============================
   Overlay Editor – Panel flotante
   ============================== */


/* Header del panel: título + X en la misma línea */
.properties-float .prop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.7rem;
}

.properties-float .prop-header span {
  font-size: 0.85rem;
  font-weight: 600;
}

/* Botón X pegado a la derecha */
.properties-float .prop-header .btn-icon {
  margin-left: auto;
  flex-shrink: 0;
}

/* Ancho del panel (un poco más cómodo) */
#propertiesPanel.properties-float {
  width: 260px;
}


/* ==============================
   Inputs de posición (X / Y)
   ============================== */

/* Forzamos ancho decente solo en el panel, por encima del CSS viejo */
#propertiesPanel .prop-row input#propX,
#propertiesPanel .prop-row input#propY {
  width: 100px !important;
}

#propertiesPanel .prop-row input[type="number"] {
  width: 90px !important;
}

#propertiesPanel .prop-row #propX,
#propertiesPanel .prop-row #propY {
  width: 100px !important;
}

#propertiesPanel #propBorderWidth {
  width: 70px !important;
}


/* ==============================
   Fondo / borde / animación UI
   ============================== */

#propertiesPanel #propBgColor {
  width: 60px;
  padding: 0;
}

#propertiesPanel #propBgAlpha {
  flex: 1;
  min-width: 0;
}

#propertiesPanel #propBorderColor {
  width: 60px;
  padding: 0;
}

#propertiesPanel #propBorderWidth {
  width: 60px;
}

/* Texto */
#propertiesPanel #textEditorSection textarea {
  resize: vertical;
}

/* Select de fuente ocupa bien el espacio */
#propertiesPanel #textEditorSection select#propFontFamily {
  min-width: 0;
}

/* Animación y trigger */
#propertiesPanel select#propAnimation,
#propertiesPanel select#propTrigger {
  width: 100%;
}

#propertiesPanel input#propAnimDuration {
  width: 80px;
}

/* ==============================
   Layout específico del panel de propiedades
   (label arriba, inputs abajo en la misma fila)
   ============================== */

#propertiesPanel .prop-row {
  display: flex;
  flex-wrap: wrap;          /* Permite que label e inputs salten de línea */
  align-items: center;
  gap: 0.5rem;
}

/* El label ocupa toda la fila superior */
#propertiesPanel .prop-row > label {
  flex: 0 0 100%;
  min-width: 0;
  font-size: 0.75rem;
}

/* Inputs / selects se reparten el ancho en la fila inferior */
#propertiesPanel .prop-row > input,
#propertiesPanel .prop-row > select,
#propertiesPanel .prop-row > textarea {
  flex: 1 1 0;
  min-width: 0;
  width: auto;             /* Anula widths fijos anteriores dentro del panel */
}

/* Posición X/Y: quepan bien uno al lado del otro */
#propertiesPanel #propX,
#propertiesPanel #propY {
  flex: 1 1 0;
  max-width: 90px;
}

/* Colores pequeños, para no comer todo el ancho */
#propertiesPanel #propBgColor,
#propertiesPanel #propBorderColor,
#propertiesPanel #propTextColor {
  flex: 0 0 40px;
}

/* Slider de alpha de fondo / borde que se estire */
#propertiesPanel #propBgAlpha,
#propertiesPanel #propBorderAlpha,
#propertiesPanel #propTextAlpha {
  flex: 1 1 0;
  min-width: 0;
}

/* Grosor de borde: numérico compacto */
#propertiesPanel #propBorderWidth {
  flex: 0 0 60px;
  max-width: 60px;
}

/* ==================== OVERLAY EDITOR PHOTOPEA ==================== */
.overlay-photopea {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 4rem);
  background: #0b1120;
  overflow: hidden;
}

.photopea-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: rgba(15, 23, 42, 0.98);
  border-bottom: 1px solid var(--border-glass);
  z-index: 100;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border-glass);
  margin: 0 0.25rem;
}

.photopea-workspace {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* Bibliotecas laterales */
.library-sidebar {
  background: rgba(15, 23, 42, 0.6);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.library-sidebar[data-side="right"] {
  width: 240px !important;
  border-right: none;
  border-left: 1px solid var(--border-glass);
}

.panel-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.panel-header span {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.search-box-small input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
}

.library-grid {
  overflow-y: auto;
  padding: 0.5rem;
  display: grid;
  grid-template-columns: repeat(1, 1fr);
  gap: 0.5rem;
}

.library-item {
  aspect-ratio: 1;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  padding: 0.5rem;
  cursor: grab;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.library-item:hover {
  background: rgba(6, 182, 212, 0.1);
  border-color: var(--accent-mc);
  transform: translateY(-2px);
}

.library-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.library-item .item-label {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0,0,0,0.8);
  padding: 0.2rem;
  font-size: 0.65rem;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-item .item-cost {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(244, 63, 94, 0.9);
  color: white;
  font-size: 0.65rem;
  padding: 0.1rem 0.3rem;
  border-radius: 10px;
  font-weight: 600;
}

/* Viewport central del editor (ventana) */
.canvas-area {
  flex: 1;
  display: block;               
  position: relative;
  background: #1a1a2e;
  border-radius: 12px;
  border: 1px solid var(--border-glass);
  min-height: 400px;
  padding: 1rem 0;
  overflow: hidden;             
}

.canvas-world {
  position: relative;
  margin: 0 auto;                 
  background:
    linear-gradient(45deg, #2a2a3a 25%, transparent 25%),
    linear-gradient(-45deg, #2a2a3a 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #2a2a3a 75%),
    linear-gradient(-45deg, transparent 75%, #2a2a3a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  box-shadow: 0 0 50px rgba(0,0,0,0.8);
  border: 2px solid var(--border-glass);
  overflow: hidden;
  transform-origin: center center;  /* zoom/pan alrededor del centro */
}

/* Panel de Capas */
.layers-panel {
  height: 160px;
  background: rgba(15, 23, 42, 0.98);
  border-top: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
}

.layers-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border-glass);
  background: rgba(0,0,0,0.2);
}

.layers-actions {
  display: flex;
  gap: 0.5rem;
}

.layers-tree {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.layer-indent {
  width: 20px;
}

.layer-visibility {
  opacity: 0.5;
  cursor: pointer;
  width: 16px;
  text-align: center;
}

.layer-visibility:hover {
  opacity: 1;
}

.properties-float .prop-header {
  cursor: grab;
  user-select: none;
  background: rgba(255,255,255,0.03);
}

.properties-float .prop-header:active {
  cursor: grabbing;
}

.prop-content {
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 70vh;
  overflow-y: auto;
}

.prop-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.prop-row label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  min-width: 50px;
}

.prop-row input[type="number"] {
  width: 60px;
  padding: 0.3rem;
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border-glass);
  border-radius: 4px;
  color: white;
  font-size: 0.8rem;
}

.prop-section {
  border-top: 1px solid var(--border-glass);
  padding-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.prop-section label {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.prop-section select,
.prop-section textarea {
  background: rgba(0,0,0,0.3);
  border: 1px solid var(--border-glass);
  border-radius: 4px;
  color: white;
  padding: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

/* Overlay Manager (Vista Lista) */
.overlay-manager {
  padding: 1rem 0;
}

.overlay-preview-card {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  height: 240px; /* Altura fija */
}

.overlay-preview-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent-mc);
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}

.overlay-thumb {
  aspect-ratio: 9/16; /* Ratio vertical para TikTok */
  background: #1a1a2e;
  position: relative;
  overflow: hidden;
  height: 160px; /* Altura fija */
}

.overlay-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0.5rem;
}

.overlay-info {
  padding: 1rem;
}

.overlay-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.overlay-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.overlay-actions {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  gap: 0.25rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.overlay-preview-card:hover .overlay-actions {
  opacity: 1;
}

/* Animaciones */
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

@keyframes float {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

.animate-breathe { animation: breathe 3s ease-in-out infinite; }
.animate-float { animation: float 3s ease-in-out infinite; }
.animate-spin { animation: spin 10s linear infinite; }

/* Panel de Propiedades Flotante Draggable */
.properties-float {
  position: fixed; /* Cambiado de absolute a fixed */
  top: 100px;
  right: 300px; /* Un poco más a la izquierda para no tapar el panel de capas */
  width: 240px;
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  z-index: 1000;
  backdrop-filter: blur(10px);
  transition: box-shadow 0.2s;
}

.properties-float:hover {
  box-shadow: 0 15px 50px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.1);
}

.properties-float.dragging {
  opacity: 0.9;
  cursor: grabbing !important;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
}

.prop-header:active {
  cursor: grabbing;
}

/* Estilos mejorados para selección múltiple en capas */
.layer-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: all 0.15s;
  margin-bottom: 0.15rem;
  border: 1px solid transparent;
}

.layer-item:hover {
  background: rgba(255,255,255,0.05);
}

/* Selección individual */
.layer-item.selected {
  background: rgba(6, 182, 212, 0.15);
  color: var(--accent-mc);
  border-color: rgba(6, 182, 212, 0.3);
}

/* Selección múltiple */
.layer-item.multi-selected {
  background: rgba(251, 191, 36, 0.15);
  color: var(--accent-gold);
  border-color: rgba(251, 191, 36, 0.3);
}

.layer-item.group {
  font-weight: 600;
  color: var(--accent-gold);
  background: rgba(251, 191, 36, 0.05);
}

.layer-item.child {
  padding-left: 2rem;
  font-size: 0.8rem;
  opacity: 0.9;
  position: relative;
}

/* Arrastrando sobre grupo (para drop) */
.layer-item.drag-over {
  border: 2px dashed var(--accent-mc);
  background: rgba(6, 182, 212, 0.2);
}

/* Contador de selección */
.selection-counter {
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--accent-tt);
  color: white;
  font-size: 0.7rem;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
}

/* Fix para el panel de capas en el aside derecho */
.library-sidebar[data-side="right"] .layers-tree {
  max-height: calc(100vh - 250px);
}

.library-sidebar[data-side="left"] {
  width: 280px !important;    
}

/* Fix grid de 2 columnas para TikTok y Minecraft */
.library-sidebar[data-side="left"] .library-grid {
    flex-direction: column;
    gap: 0.4rem;
    overflow-y: auto;
    padding: 0.4rem;
}

.library-sidebar[data-side="left"] .library-item {
  width: 100%;
  height: 64px; /* Altura fija compacta */
  aspect-ratio: auto;
  flex-direction: row;
  justify-content: flex-start;
  gap: 0.75rem;
  padding: 0.5rem;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.library-sidebar[data-side="left"] .library-item img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 4px;
  background: rgba(0,0,0,0.2); /* Fondo para transparencias */
}

.library-sidebar[data-side="left"] .library-item .item-label {
    position: static;
    flex: 1;
    text-align: left;
    background: none;
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-item .item-cost {
  display: none; /* Se controla vía JS para Minecraft */
}

/* Separador entre TikTok y Minecraft */
.library-sidebar[data-side="left"] > div:first-child {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.library-sidebar[data-side="left"] > div:last-child {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border-top: 1px solid var(--border-glass);
}

/* Item activo en biblioteca */
.library-item:active {
  cursor: grabbing;
}

.layer-item.child::before {
  content: '';
  position: absolute;
  left: 8px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(255,255,255,0.1);
}

#overlaysGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.layer-item input[type="text"] {
  font-family: inherit;
  border-radius: 3px;
}

.layer-item.group .layer-name {
  font-weight: 600;
  color: var(--accent-gold);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-1deg); }
  75% { transform: translateX(5px) rotate(1deg); }
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}
@keyframes glow {
  0%, 100% { filter: drop-shadow(0 0 5px currentColor); }
  50% { filter: drop-shadow(0 0 20px currentColor); }
}
.animate-shake { animation: shake 0.5s ease-in-out infinite; }
.animate-pulse { animation: pulse 1.5s ease-in-out infinite; }
.animate-glow { animation: glow 2s ease-in-out infinite; }

.layers-tree .layer-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.layers-tree .layer-item.selected {
  background: rgba(56, 189, 248, 0.25);
}

/* INDENTACIÓN VISUAL PARA CAPAS EN GRUPO */
.layers-tree .layer-item.in-group {
  margin-left: 1.5rem;
  border-left: 2px solid rgba(148, 163, 184, 0.5);
}

/* FILA DE GRUPO */
.layers-tree .layer-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.4rem;
  margin-top: 0.4rem;
  border-radius: 4px;
  background: rgba(148, 163, 184, 0.12);
  font-weight: 600;
  color: var(--text-muted);
}

/* HANDLE DE DRAG VISUAL */
.layer-drag {
  width: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  color: var(--text-muted);
}

.layer-drag::before {
  content: '⋮⋮';
  font-size: 10px;
  opacity: 0.8;
}

.layer-drag {
  cursor: grab;
  padding: 0 4px;
  opacity: 0.6;
}
.layer-drag:active {
  cursor: grabbing;
  opacity: 1;
}
