/**
 * Bootstrap 5 Compatibility & Modal Fix
 * Ensures all modals work correctly after removing Bootstrap 3
 * Date: November 5, 2025
 */

/* ==================== MODAL FIXES ==================== */

/* Ensure modals are visible and properly layered */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1055 !important;
  display: none;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  outline: 0;
}

.modal.show {
  display: block !important;
}

.modal-dialog {
  position: relative;
  width: auto;
  margin: 1.75rem auto;
  pointer-events: none;
  z-index: 1056 !important;
}

.modal.fade .modal-dialog {
  transition: transform 0.3s ease-out;
  transform: translate(0, -50px);
}

.modal.show .modal-dialog {
  transform: none;
}

.modal-dialog-centered {
  display: flex;
  align-items: center;
  min-height: calc(100% - 3.5rem);
}

.modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  pointer-events: auto;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 0.5rem;
  outline: 0;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
}

.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1050 !important;
  width: 100vw;
  height: 100vh;
  background-color: #000;
}

.modal-backdrop.fade {
  opacity: 0 !important;
}

.modal-backdrop.show {
  opacity: 0.5 !important;
}

/* Modal Header */
.modal-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem;
  border-bottom: 1px solid #dee2e6;
  border-top-left-radius: calc(0.5rem - 1px);
  border-top-right-radius: calc(0.5rem - 1px);
}

.modal-header .btn-close {
  padding: 0.5rem 0.5rem;
  margin: -0.5rem -0.5rem -0.5rem auto;
}

/* Modal Title */
.modal-title {
  margin-bottom: 0;
  line-height: 1.5;
  font-size: 1.25rem;
  font-weight: 500;
}

/* Modal Body */
.modal-body {
  position: relative;
  flex: 1 1 auto;
  padding: 1rem;
}

/* Modal Footer */
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  flex-shrink: 0;
  align-items: center;
  justify-content: flex-end;
  padding: 0.75rem;
  border-top: 1px solid #dee2e6;
  border-bottom-right-radius: calc(0.5rem - 1px);
  border-bottom-left-radius: calc(0.5rem - 1px);
}

.modal-footer > * {
  margin: 0.25rem;
}

/* Modal Sizes */
.modal-sm {
  max-width: 300px;
}

.modal-lg {
  max-width: 800px;
}

.modal-xl {
  max-width: 1140px;
}

.modal-fullscreen {
  width: 100vw;
  max-width: none;
  height: 100%;
  margin: 0;
}

/* ==================== BOOTSTRAP 3 TO 5 COMPATIBILITY ==================== */

/* Panel → Card Migration */
.panel {
  border: 1px solid rgba(0, 0, 0, 0.125);
  border-radius: 0.375rem;
  background-color: #fff;
  margin-bottom: 1rem;
}

.panel-heading {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.125);
  border-top-left-radius: calc(0.375rem - 1px);
  border-top-right-radius: calc(0.375rem - 1px);
}

.panel-body {
  padding: 1.25rem;
}

.panel-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(0, 0, 0, 0.125);
  border-bottom-left-radius: calc(0.375rem - 1px);
  border-bottom-right-radius: calc(0.375rem - 1px);
}

/* Panel Variants */
.panel-default {
  border-color: #dee2e6;
}

.panel-primary {
  border-color: #0d6efd;
}

.panel-primary > .panel-heading {
  background-color: #0d6efd;
  border-color: #0d6efd;
  color: #fff;
}

.panel-success {
  border-color: #198754;
}

.panel-success > .panel-heading {
  background-color: #198754;
  border-color: #198754;
  color: #fff;
}

.panel-info {
  border-color: #0dcaf0;
}

.panel-info > .panel-heading {
  background-color: #0dcaf0;
  border-color: #0dcaf0;
  color: #000;
}

.panel-warning {
  border-color: #ffc107;
}

.panel-warning > .panel-heading {
  background-color: #ffc107;
  border-color: #ffc107;
  color: #000;
}

.panel-danger {
  border-color: #dc3545;
}

.panel-danger > .panel-heading {
  background-color: #dc3545;
  border-color: #dc3545;
  color: #fff;
}

/* Close Button (Bootstrap 3 style) */
.close {
  float: right;
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1;
  color: #000;
  text-shadow: 0 1px 0 #fff;
  opacity: 0.5;
  background: transparent;
  border: 0;
  cursor: pointer;
  padding: 0;
}

.close:hover {
  color: #000;
  text-decoration: none;
  opacity: 0.75;
}

/* Glyphicons Fallback (use Bootstrap Icons instead) */
.glyphicon {
  font-family: 'bootstrap-icons' !important;
  font-style: normal;
  font-weight: normal;
  line-height: 1;
}

/* Form Control Fixes */
.form-control {
  display: block;
  width: 100%;
  padding: 0.375rem 0.75rem;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.5;
  color: #212529;
  background-color: #fff;
  background-clip: padding-box;
  border: 1px solid #ced4da;
  appearance: none;
  border-radius: 0.375rem;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
  color: #212529;
  background-color: #fff;
  border-color: #86b7fe;
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.form-control:disabled,
.form-control[readonly] {
  background-color: #e9ecef;
  opacity: 1;
}

/* Button Block (Bootstrap 3 compatibility) */
.btn-block {
  display: block;
  width: 100%;
}

.btn-block + .btn-block {
  margin-top: 0.5rem;
}

/* ==================== DARK MODE SUPPORT ==================== */

@media (prefers-color-scheme: dark) {
  .modal-content {
    background-color: #1f2937;
    border-color: #374151;
    color: #f3f4f6;
  }

  .modal-header {
    border-bottom-color: #374151;
  }

  .modal-footer {
    border-top-color: #374151;
  }

  .panel {
    background-color: #1f2937;
    border-color: #374151;
    color: #f3f4f6;
  }

  .panel-heading {
    border-bottom-color: #374151;
  }

  .panel-footer {
    border-top-color: #374151;
  }

  .form-control {
    background-color: #374151;
    border-color: #4b5563;
    color: #f3f4f6;
  }

  .form-control:focus {
    background-color: #374151;
    border-color: #3b82f6;
    color: #f3f4f6;
  }

  .form-control:disabled,
  .form-control[readonly] {
    background-color: #1f2937;
    color: #9ca3af;
  }

  .close {
    color: #f3f4f6;
    text-shadow: none;
  }
}

/* ==================== RESPONSIVE FIXES ==================== */

@media (max-width: 576px) {
  .modal-dialog {
    margin: 0.5rem;
    max-width: calc(100% - 1rem);
  }

  .modal-dialog-centered {
    min-height: calc(100% - 1rem);
  }

  .modal-fullscreen-sm-down {
    width: 100vw;
    max-width: none;
    height: 100%;
    margin: 0;
  }

  .modal-fullscreen-sm-down .modal-content {
    height: 100%;
    border: 0;
    border-radius: 0;
  }
}

/* ==================== UTILITY FIXES ==================== */

/* Ensure proper stacking context */
body.modal-open {
  overflow: hidden;
  padding-right: 0 !important;
}

/* Remove scrollbar jump */
body.modal-open .fixed-top,
body.modal-open .fixed-bottom,
body.modal-open .sticky-top {
  padding-right: 0 !important;
}

/* Smooth scrolling for modals */
.modal {
  -webkit-overflow-scrolling: touch;
}

/* Fix for nested modals */
.modal.fade.show {
  z-index: 1055;
}

.modal-backdrop.show ~ .modal-backdrop.show {
  z-index: 1052;
}

/* Accessibility */
.modal:focus {
  outline: 0;
}

/* Print */
@media print {
  .modal {
    display: none !important;
  }
}
