/**
 * DRAG-AND-DROP STYLES
 * Cyber-themed drag-and-drop visual feedback with accessibility support
 */

/* Container when drag is enabled */
.drag-enabled {
  position: relative;
  user-select: none;
}

/* Draggable items */
.drag-item {
  position: relative;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.drag-item[draggable="true"] {
  cursor: move;
  cursor: grab;
}

.drag-item[draggable="true"]:active {
  cursor: grabbing;
}

/* Drag handle */
.drag-handle {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 32px;
  height: 32px;
  background: rgba(0, 255, 65, 0.1);
  border: 1px solid #00ff41;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #00ff41;
  cursor: grab;
  opacity: 0;
  transition: opacity 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  z-index: 10;
}

.drag-item:hover .drag-handle,
.drag-item:focus-within .drag-handle {
  opacity: 1;
}

.drag-handle:hover,
.drag-handle:focus {
  opacity: 1 !important;
  background: rgba(0, 255, 65, 0.2);
  box-shadow: 0 0 10px rgba(0, 255, 65, 0.3);
  outline: 2px solid #00ff41;
  outline-offset: 2px;
}

.drag-handle:active {
  cursor: grabbing;
  background: rgba(0, 255, 65, 0.3);
  box-shadow: 0 0 15px rgba(0, 255, 65, 0.5);
}

/* Dragging state */
.dragging {
  opacity: 0.4;
  transform: scale(1.02);
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.5);
  z-index: 1000;
}

.dragging .drag-handle {
  opacity: 1;
  background: rgba(0, 255, 65, 0.3);
  box-shadow: 0 0 15px rgba(0, 255, 65, 0.5);
}

/* Drag over state */
.drag-over {
  border: 2px dashed #00ff41;
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.3), inset 0 0 20px rgba(0, 255, 65, 0.1);
  transform: scale(1.02);
}

/* Placeholder */
.drag-placeholder {
  background: rgba(0, 255, 65, 0.05);
  border: 2px dashed #00ff41;
  border-radius: 8px;
  margin: 10px 0;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.3;
    box-shadow: 0 0 5px rgba(0, 255, 65, 0.2);
  }
  50% {
    opacity: 0.6;
    box-shadow: 0 0 15px rgba(0, 255, 65, 0.4);
  }
}

/* Drop indicator */
.drag-enabled::before {
  content: '';
  position: absolute;
  top: -5px;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, transparent, #00ff41, transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.drag-enabled.drag-active::before {
  opacity: 1;
}

/* Keyboard focus styles */
.drag-item:focus {
  outline: 2px solid #00ff41;
  outline-offset: 4px;
  box-shadow: 0 0 15px rgba(0, 255, 65, 0.3);
}

.drag-item:focus-visible {
  outline: 2px solid #00ff41;
  outline-offset: 4px;
}

/* Drag disabled state */
.drag-disabled {
  opacity: 0.6;
  pointer-events: none;
}

.drag-disabled .drag-handle {
  display: none;
}

/* Accessibility - Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .drag-item,
  .drag-handle,
  .dragging,
  .drag-over {
    transition: none;
    animation: none;
  }

  .drag-placeholder {
    animation: none;
  }
}

/* Mobile touch optimizations */
@media (max-width: 768px) {
  .drag-handle {
    width: 40px;
    height: 40px;
    top: 5px;
    left: 5px;
  }

  .drag-handle svg {
    width: 24px;
    height: 24px;
  }

  .drag-item:active .drag-handle {
    opacity: 1;
  }

  .dragging {
    transform: scale(1.01);
  }

  .drag-over {
    transform: scale(1.01);
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .drag-handle {
    border-width: 2px;
    background: #000;
  }

  .dragging {
    opacity: 0.5;
  }

  .drag-over {
    border-width: 3px;
  }

  .drag-placeholder {
    border-width: 3px;
  }
}

/* Dark mode specific adjustments */
@media (prefers-color-scheme: dark) {
  .drag-handle {
    background: rgba(0, 255, 65, 0.15);
  }

  .drag-placeholder {
    background: rgba(0, 255, 65, 0.08);
  }
}

/* Light mode support */
@media (prefers-color-scheme: light) {
  .drag-handle {
    background: rgba(0, 200, 50, 0.1);
    border-color: #00cc33;
    color: #00cc33;
  }

  .dragging {
    box-shadow: 0 0 20px rgba(0, 200, 50, 0.4);
  }

  .drag-over {
    border-color: #00cc33;
    box-shadow: 0 0 20px rgba(0, 200, 50, 0.3), inset 0 0 20px rgba(0, 200, 50, 0.1);
  }

  .drag-placeholder {
    background: rgba(0, 200, 50, 0.05);
    border-color: #00cc33;
  }
}

/* Screen reader only content */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Loading indicator */
.drag-loading {
  position: relative;
  pointer-events: none;
}

.drag-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  margin: -20px 0 0 -20px;
  border: 3px solid rgba(0, 255, 65, 0.3);
  border-top-color: #00ff41;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Success indicator */
.drag-success {
  animation: successFlash 0.5s ease;
}

@keyframes successFlash {
  0%, 100% {
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.3);
  }
  50% {
    box-shadow: 0 0 30px rgba(0, 255, 65, 0.8), inset 0 0 20px rgba(0, 255, 65, 0.2);
  }
}

/* Error indicator */
.drag-error {
  animation: errorShake 0.5s ease;
  border-color: #ff0055 !important;
}

@keyframes errorShake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Tooltip for drag handle */
.drag-handle::after {
  content: attr(aria-label);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  border-radius: 4px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  margin-bottom: 5px;
}

.drag-handle:hover::after,
.drag-handle:focus::after {
  opacity: 1;
}

/* Drag hint text */
.drag-hint {
  position: absolute;
  top: -30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 255, 65, 0.9);
  color: #000;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: 1000;
}

.drag-item:first-child .drag-hint {
  top: auto;
  bottom: -30px;
}

/* Print styles */
@media print {
  .drag-handle,
  .drag-placeholder,
  .drag-hint {
    display: none;
  }

  .drag-item {
    break-inside: avoid;
  }
}

/* Animation for order change */
@keyframes orderChange {
  0% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
  100% {
    transform: translateY(0);
  }
}

.order-changed {
  animation: orderChange 0.3s ease;
}

/* Custom scrollbar for drag container */
.drag-enabled::-webkit-scrollbar {
  width: 8px;
}

.drag-enabled::-webkit-scrollbar-track {
  background: rgba(0, 255, 65, 0.05);
  border-radius: 4px;
}

.drag-enabled::-webkit-scrollbar-thumb {
  background: rgba(0, 255, 65, 0.3);
  border-radius: 4px;
}

.drag-enabled::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 255, 65, 0.5);
}

/* Focus trap for keyboard navigation */
.keyboard-trap {
  outline: 2px solid #00ff41;
  box-shadow: 0 0 20px rgba(0, 255, 65, 0.5);
}

/* ARIA live region for announcements */
.drag-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Smooth transitions for grid items */
.article-grid.drag-enabled .article-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

/* Prevent text selection during drag */
.drag-enabled {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

/* Touch device specific styles */
@media (hover: none) and (pointer: coarse) {
  .drag-handle {
    opacity: 0.7;
  }

  .drag-item:active .drag-handle {
    opacity: 1;
  }
}

/* Performance optimization - GPU acceleration */
.dragging,
.drag-over,
.order-changed {
  will-change: transform;
}

/* Remove will-change after animation */
.dragging:not(.dragging),
.drag-over:not(.drag-over),
.order-changed:not(.order-changed) {
  will-change: auto;
}
