/* Responsive Modal Styles */

/* Mobile-first approach for modals */
@media screen and (max-width: 768px) {
  /* Modal dialog adjustments for mobile */
  .modal-dialog {
    max-width: 100%;
    max-height: 100dvh;
    height: 100dvh; /* Force full height */
    width: 100%;
    margin: 0;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    position: fixed;
    bottom: 0; /* Anchor to bottom */
    top: auto; /* Override default center positioning */
  }
  
  /* Full-screen modals on mobile */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0; /* Remove any padding that might push content */
  }
  
  /* Modal slides up from bottom on mobile */
  .modal-dialog {
    width: 100%; /* Ensure full width */
    animation: modalSlideUp 0.3s ease-out forwards;
  }
  
  @keyframes modalSlideUp {
    from {
      transform: translateY(100%);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
  
  /* Sticky header on mobile */
  .modal-header {
    position: sticky;
    top: 0;
    z-index: 10;
    background-color: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  }
  
  /* Modal body takes remaining space */
  .modal-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
    padding: 1rem;
  }
  
  /* Larger touch targets for mobile */
  .modal-close-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Modal sizes on mobile are ignored - always full screen */
  .modal-dialog.modal-sm,
  .modal-dialog.modal-lg,
  .modal-dialog.modal-xl {
    max-width: 100%;
  }
  
  /* Reorder modal specific adjustments */
  .modal-dialog-wide {
    max-width: 100%;
    width: 100%;
  }
  
  .sortable-workouts-list {
    max-height: calc(100vh - 200px); /* Account for header and buttons */
  }
  
  /* Workout occurrence modal adjustments */
  .workout-occurrence-modal-content {
    padding: 0;
  }
  
  .workout-occurrence-modal-actions {
    position: sticky;
    bottom: 0;
    background-color: white;
    padding: 1rem;
    box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
    margin: 0 -1rem -1rem -1rem; /* Negative margins to counteract body padding */
  }
  
  /* Stack buttons vertically on very small screens */
  @media screen and (max-width: 400px) {
    .workout-occurrence-modal-actions {
      flex-direction: column;
    }
    
    .workout-occurrence-modal-actions .btn {
      width: 100%;
      justify-content: center;
    }
    
    .modal-actions {
      flex-direction: column;
    }
    
    .modal-actions .btn {
      width: 100%;
    }
  }
  
  /* Modal options stack better on mobile */
  .modal-options {
    gap: 0.75rem;
  }
  
  /* Workout description responsive */
  .workout-description pre {
    font-size: 0.875rem;
    padding: 0.75rem;
  }
  
  /* Badge responsive sizing */
  .badge {
    font-size: 0.75rem;
    padding: 0.2rem 0.4rem;
  }
  
  /* Elements list responsive */
  .workout-elements .flex-wrap {
    gap: 0.5rem;
  }
}

/* Tablet adjustments */
@media screen and (min-width: 769px) and (max-width: 1024px) {
  .modal-dialog {
    max-width: 90%;
    margin: 2rem auto;
  }

  .modal-dialog.modal-lg {
    max-width: 80%;
  }

  .modal-dialog-wide {
    max-width: 80%;
  }
}

/* Desktop - wider modals */
@media screen and (min-width: 1025px) {
  .modal-dialog {
    max-width: 40rem;
  }

  .modal-dialog.modal-lg {
    max-width: 75%;
  }

  .modal-dialog.modal-xl {
    max-width: 90%;
  }
}

/* Ensure proper touch scrolling */
.modal-body {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Prevent body scroll when modal is open */
body.modal-open {
  overflow: hidden;
  /* Don't use position: fixed as it causes scroll-to-top issues */
  /* The modal-backdrop uses position: fixed to stay in viewport */
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
  .modal-dialog {
    animation: none;
    transform: none;
    opacity: 1;
  }
  
  @media screen and (max-width: 768px) {
    .modal-dialog {
      animation: none;
    }
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .modal-dialog {
    border: 2px solid currentColor;
  }
  
  .modal-header {
    border-bottom-width: 2px;
  }
}
