/* ============================================
   MODAL SYSTEM - EXTRACTED FROM UI CONSISTENCY
   All modal-related styles for consistent UI
   ============================================ */

/* ============================================
   MODAL WIDTH SYSTEM (ONE STANDARD)
   ============================================ */

/* Default modal - All modals use this base */
.modal,
.modal-premium {
  position: fixed;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  z-index: 9999;
  padding: 2rem 1rem;
  box-sizing: border-box;
  flex-direction: column;
  /* Ensure modal is always on top of everything */
  transform: none !important;
}

@media (min-width: 1024px) {
  .modal,
  .modal-premium {
    padding: 2rem;
  }
}

.modal.hidden,
.modal-premium.hidden {
  display: none !important;
}

/* Modal backdrop - consistent across all */
.modal-overlay,
.modal-premium::before {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 9998;
  pointer-events: auto;
  cursor: pointer;
}

/* ============================================
   SIMPLIFIED MODAL STYLING - CLEAN APPROACH
   ============================================ */

/* Base: All modal containers */
.modal-container,
.modal-card-premium {
  background: white;
  border-radius: 1rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.16);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  z-index: 10000;
  animation: modalSlideUp 0.3s ease-out;
  box-sizing: border-box !important;
  /* Center the modal container */
  margin: auto !important;
  padding: 0 !important;
  /* Mobile-first: 90vw with safe padding */
  width: calc(100vw - 32px) !important;
  max-width: 90vw !important;
  /* Ensure proper positioning */
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
  transform: none !important;
}

/* Tablet: 95% width (641px - 1023px) */
@media (min-width: 641px) and (max-width: 1023px) {
  .modal-container,
  .modal-card-premium {
    width: 95vw !important;
    max-width: 95vw !important;
    max-height: 75vh !important; /* Reduced to avoid navbar overlap */
  }
}

/* Desktop: Fixed widths by size class (1024px+) */
@media (min-width: 1024px) {
  .modal-container,
  .modal-card-premium {
    width: 600px !important; /* Default medium modal */
    max-width: 600px !important;
    max-height: 80vh !important;
  }

  /* Size variants */
  .modal-container.modal-sm,
  .modal-card-premium.modal-sm {
    width: 400px !important;
    max-width: 400px !important;
  }

  .modal-container.modal-lg,
  .modal-card-premium.modal-lg {
    width: 800px !important;
    max-width: 800px !important;
  }

  .modal-container.modal-xl,
  .modal-card-premium.modal-xl {
    width: 1000px !important;
    max-width: 1000px !important;
  }

  .modal-container.modal-full,
  .modal-card-premium.modal-full {
    width: 90vw !important;
    max-width: 90vw !important;
  }
}

/* ============================================
   MODAL ANIMATIONS
   ============================================ */

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   MODAL STRUCTURE COMPONENTS
   ============================================ */

/* Header section - consistent padding and styling */
.modal-header {
  padding: 1.5rem 2rem 1rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.modal-header h2,
.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #1f2937;
}

.modal-header .modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #6b7280;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 0.375rem;
  transition: all 0.2s;
}

.modal-header .modal-close:hover {
  background-color: #f3f4f6;
  color: #374151;
}

/* Body section - scrollable content area */
.modal-body {
  padding: 1.5rem 2rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0; /* Allow flex shrinking */
}

/* Footer section - action buttons */
.modal-footer {
  padding: 1rem 2rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-shrink: 0;
}

/* ============================================
   MODAL RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 640px) {
  .modal-header,
  .modal-body,
  .modal-footer {
    padding-left: 1.5rem;
    padding-right: 1.5rem;
  }

  .modal-header {
    padding-top: 1.25rem;
    padding-bottom: 0.75rem;
  }

  .modal-body {
    padding-top: 1.25rem;
    padding-bottom: 1.25rem;
  }

  .modal-footer {
    padding-top: 0.75rem;
    padding-bottom: 1.25rem;
    flex-direction: column;
  }

  .modal-footer button {
    width: 100%;
  }
}

/* ============================================
   MODAL ACCESSIBILITY
   ============================================ */

.modal[aria-hidden='true'] {
  display: none !important;
}

.modal[aria-hidden='false'] {
  display: flex;
}

/* Focus management for modals */
.modal:focus-within .modal-container {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* ============================================
   SPECIAL MODAL VARIANTS
   ============================================ */

/* Confirmation modals - smaller and centered */
.modal-confirmation .modal-container {
  max-width: 400px !important;
}

.modal-confirmation .modal-body {
  text-align: center;
  padding: 2rem 1.5rem;
}

.modal-confirmation .modal-footer {
  justify-content: center;
}

/* Form modals - wider for form content */
.modal-form .modal-container {
  max-width: 700px !important;
}

/* Data table modals - full width for tables */
.modal-table .modal-container {
  max-width: 90vw !important;
}

@media (min-width: 1024px) {
  .modal-table .modal-container {
    max-width: 1200px !important;
  }
}
