/**
 * Drag and Drop Accessibility Styles
 * Ensures WCAG 2.2 AA 2.5.7 compliance
 * All drag movements must have keyboard/pointer alternatives
 */

/* ==========================================================================
   Draggable Element Keyboard Controls
   ========================================================================== */

.draggable-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.draggable-keyboard-controls {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-left: auto;
}

.draggable-keyboard-controls .move-up,
.draggable-keyboard-controls .move-down {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #dee2e6;
  background: #fff;
  cursor: pointer;
  transition: all 0.2s ease;
}

.draggable-keyboard-controls .move-up:hover,
.draggable-keyboard-controls .move-down:hover {
  background: #e9ecef;
  border-color: #adb5bd;
}

.draggable-keyboard-controls .move-up:focus,
.draggable-keyboard-controls .move-down:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
  border-color: #0d6efd;
}

.draggable-keyboard-controls .move-up:disabled,
.draggable-keyboard-controls .move-down:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ==========================================================================
   File Upload Accessibility
   ========================================================================== */

.file-upload,
[data-file-drop] {
  position: relative;
  border: 2px dashed #dee2e6;
  border-radius: 0;
  padding: 2rem;
  text-align: center;
  transition: all 0.3s ease;
}

.file-upload:hover,
[data-file-drop]:hover {
  border-color: #0d6efd;
  background-color: #f8f9fa;
}

.file-upload.drag-over,
[data-file-drop].drag-over {
  border-color: #0d6efd;
  background-color: #e7f1ff;
}

.file-browse-button {
  min-height: 44px;
  min-width: 120px;
  padding: 0.75rem 1.5rem;
  margin: 1rem auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.file-browse-button:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

.upload-instructions {
  margin-bottom: 1rem;
  color: #6c757d;
}

.upload-instructions p {
  margin: 0;
  font-size: 0.875rem;
}

/* ==========================================================================
   Tabledrag Accessibility Enhancements
   ========================================================================== */

/* Make tabledrag handles more visible and accessible */
.tabledrag-handle {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: move;
}

.tabledrag-handle:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
  background-color: #e7f1ff;
}

/* Enhance "Show row weights" button visibility */
.tabledrag-toggle-weight {
  min-height: 44px;
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 0;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tabledrag-toggle-weight:hover {
  background-color: #e9ecef;
  border-color: #adb5bd;
}

.tabledrag-toggle-weight:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
  border-color: #0d6efd;
}

/* Style for weight select dropdowns when shown */
table.tabledrag-processed select.form-select {
  min-height: 44px;
  padding: 0.5rem;
}

table.tabledrag-processed select.form-select:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

/* ==========================================================================
   Carousel Accessibility Hints
   ========================================================================== */

/* Ensure carousel controls meet minimum target size */
.carousel-control-prev,
.carousel-control-next,
.slick-prev,
.slick-next {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Enhanced focus states for carousel controls */
.carousel-control-prev:focus,
.carousel-control-next:focus,
.slick-prev:focus,
.slick-next:focus {
  outline: 3px solid #0d6efd;
  outline-offset: 2px;
}

/* Carousel indicators should be large enough */
.carousel-indicators button {
  min-width: 44px;
  min-height: 8px;
  margin: 0 4px;
}

.carousel-indicators button:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
}

/* ==========================================================================
   Sortable List Accessibility
   ========================================================================== */

.sortable-item {
  position: relative;
  padding-left: 3rem; /* Space for drag handle */
}

.sortable-handle {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: move;
  color: #6c757d;
}

.sortable-handle:focus {
  outline: 2px solid #0d6efd;
  outline-offset: 2px;
  background-color: #e7f1ff;
  border-radius: 0;
}

.sortable-handle:hover {
  color: #212529;
  background-color: #f8f9fa;
  border-radius: 0;
}

/* Keyboard move buttons for sortable items */
.sortable-keyboard-nav {
  display: flex;
  gap: 0.25rem;
  margin-left: 0.5rem;
}

.sortable-keyboard-nav button {
  min-width: 44px;
  min-height: 44px;
  padding: 0.5rem;
}

/* ==========================================================================
   Accessibility Notifications
   ========================================================================== */

.drag-accessibility-notification {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  background: #0d6efd;
  color: white;
  padding: 1rem 1.5rem;
  border-radius: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 9999;
  animation: slideInUp 0.3s ease;
}

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

/* ==========================================================================
   High Contrast Mode Support
   ========================================================================== */

@media (prefers-contrast: high) {
  .draggable-keyboard-controls .move-up,
  .draggable-keyboard-controls .move-down,
  .file-browse-button,
  .tabledrag-toggle-weight {
    border-width: 2px;
  }

  .tabledrag-handle:focus,
  .sortable-handle:focus,
  .carousel-control-prev:focus,
  .carousel-control-next:focus {
    outline-width: 3px;
  }
}

/* ==========================================================================
   Reduced Motion Support
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .file-upload,
  [data-file-drop],
  .draggable-keyboard-controls button,
  .tabledrag-toggle-weight,
  .sortable-handle {
    transition: none;
  }

  .drag-accessibility-notification {
    animation: none;
  }
}

/* ==========================================================================
   Mobile/Touch Enhancements
   ========================================================================== */

@media (max-width: 768px) {
  /* Increase touch targets on mobile */
  .draggable-keyboard-controls .move-up,
  .draggable-keyboard-controls .move-down,
  .file-browse-button,
  .tabledrag-handle,
  .sortable-handle,
  .carousel-control-prev,
  .carousel-control-next {
    min-width: 48px;
    min-height: 48px;
  }

  /* Stack keyboard controls vertically on mobile */
  .sortable-keyboard-nav {
    flex-direction: column;
  }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
  .draggable-keyboard-controls,
  .file-browse-button,
  .tabledrag-toggle-weight,
  .tabledrag-handle,
  .sortable-handle,
  .sortable-keyboard-nav,
  .carousel-control-prev,
  .carousel-control-next,
  .carousel-indicators {
    display: none;
  }
}
