/* ==============================================
   Template Blocks Controller Styles
   ============================================== */

/* Sortable.js - Drag and Drop */
.sortable-ghost {
  opacity: 0.4;
  background: #f3f4f6;
  border: 2px dashed #d1d5db;
}

.sortable-drag {
  opacity: 1;
  cursor: grabbing !important;
  z-index: 9999;
}

.dragging {
  transform: scale(1.02);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.drag-handle {
  cursor: grab;
  color: #9ca3af;
  transition: color 0.2s;
}

.drag-handle:hover {
  color: #6b7280;
}

.drag-handle:active {
  cursor: grabbing;
}

/* Block Item */
.block-item {
  position: relative;
  transition: all 0.2s ease;
}

.block-item:hover {
  background-color: #f9fafb;
}

/* Flash Messages */
.flash-message {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  font-weight: 500;
  transition: opacity 0.3s ease, transform 0.3s ease;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.flash-message.hidden {
  opacity: 0;
  transform: translateX(100%);
  pointer-events: none;
}

.flash-success {
  background: #10b981;
  color: white;
}

.flash-error {
  background: #ef4444;
  color: white;
}

.flash-info {
  background: #3b82f6;
  color: white;
}

.flash-warning {
  background: #f59e0b;
  color: white;
}

/* Toast (fallback si pas de flashMessage target) */
.toast {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  padding: 1rem 1.5rem;
  border-radius: 0.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  font-weight: 500;
  animation: slideIn 0.3s ease;
}

/* Animation de succès pour les blocks */
.flash-success-animation {
  animation: flash-pulse 0.6s ease;
  background: #d1fae5 !important;
}

@keyframes flash-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.01);
  }
}

/* Validation Errors */
.border-red-500 {
  border-color: #ef4444 !important;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.validation-error,
.json-error {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.validation-error::before,
.json-error::before {
  content: "⚠️";
  font-size: 1rem;
}

/* Highlight des changements après suggestion IA */
.highlight-change {
  animation: highlight 1.5s ease;
  transition: background 0.3s ease;
}

@keyframes highlight {
  0%, 100% {
    background: transparent;
  }
  25%, 75% {
    background: #fef3c7;
  }
  50% {
    background: #fde68a;
  }
}

/* Fade out pour la suppression */
.fade-out {
  opacity: 0;
  transform: translateX(-20px);
  transition: all 0.3s ease;
}

.fade-in {
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Loading State */
button.loading {
  opacity: 0.6;
  cursor: wait !important;
  pointer-events: none;
  position: relative;
}

button.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 0.75rem;
  width: 1rem;
  height: 1rem;
  margin-top: -0.5rem;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Modal Backdrop */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9998;
  animation: fadeIn 0.2s ease;
}

/* Block Actions Hover */
.block-actions {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.block-item:hover .block-actions {
  opacity: 1;
}

/* Responsive - Mobile */
@media (max-width: 768px) {
  .block-actions {
    opacity: 1; /* Toujours visible sur mobile */
  }

  .flash-message,
  .toast {
    left: 1rem;
    right: 1rem;
    width: auto;
  }

  .drag-handle {
    /* Plus gros sur mobile pour faciliter le touch */
    font-size: 1.5rem;
    padding: 0.5rem;
  }
}

/* États de validation - Success */
.border-green-500 {
  border-color: #10b981 !important;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.validation-success {
  color: #10b981;
  font-size: 0.875rem;
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.validation-success::before {
  content: "✓";
  font-size: 1rem;
  font-weight: bold;
}

/* Form Fields avec validation */
textarea[data-validate-prompt],
textarea[data-validate-json] {
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

textarea[data-validate-prompt]:focus,
textarea[data-validate-json]:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Bouton de suggestion IA */
button[data-action*="suggestPrompt"] {
  position: relative;
  overflow: hidden;
}

button[data-action*="suggestPrompt"]::before {
  content: "✨";
  margin-right: 0.5rem;
}

button[data-action*="suggestPrompt"]:hover {
  transform: scale(1.05);
  transition: transform 0.2s ease;
}

/* Animation de génération IA */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

button.loading[data-action*="suggestPrompt"] {
  background: linear-gradient(
    90deg,
    #3b82f6 0%,
    #8b5cf6 25%,
    #ec4899 50%,
    #8b5cf6 75%,
    #3b82f6 100%
  );
  background-size: 200% 100%;
  animation: shimmer 2s linear infinite;
  color: white;
}

/* Empty State */
.blocks-empty-state {
  padding: 3rem 1rem;
  text-align: center;
  color: #9ca3af;
}

.blocks-empty-state svg {
  width: 4rem;
  height: 4rem;
  margin: 0 auto 1rem;
  opacity: 0.5;
}

/* Block Counter */
.block-counter {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  background: #f3f4f6;
  border-radius: 9999px;
  font-size: 0.875rem;
  color: #6b7280;
}

.block-counter::before {
  content: "📦";
}
