/* Bootstrap Modal CSS - Fully Converted from SCSS with Modern Features */

/* ========================================
   MODAL COMPONENT
   ======================================== */

/* Container that the modal scrolls within */
.modal {
  /* CSS Custom Properties (Variables) */
  --bs-modal-zindex: 1055;
  --bs-modal-width: 500px;
  --bs-modal-padding: 1rem;
  --bs-modal-margin: 0.5rem;
  --bs-modal-color: var(--text-primary);
  --bs-modal-bg: var(--white);
  --bs-modal-border-color: var(--card-stroke);
  --bs-modal-border-width: 1px;
  --bs-modal-border-radius: 0.375rem;
  --bs-modal-box-shadow: var(--shadow-modal);
  --bs-modal-inner-border-radius: calc(0.375rem - 1px);
  --bs-modal-header-padding-x: 1rem;
  --bs-modal-header-padding-y: 1rem;
  --bs-modal-header-padding: 1rem 1rem;
  --bs-modal-header-border-color: var(--card-stroke);
  --bs-modal-header-border-width: 1px;
  --bs-modal-title-line-height: 1.5;
  --bs-modal-footer-gap: 0.5rem;
  --bs-modal-footer-bg: transparent;
  --bs-modal-footer-border-color: var(--card-stroke);
  --bs-modal-footer-border-width: 1px;

  /* Layout Properties */
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--bs-modal-zindex);
  display: none;
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  outline: 0;

  /* Modern scrolling behavior */
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

/* Show state */
.modal.show {
  display: block;
}

/* Shell div to position the modal with bottom padding */
.modal-dialog {
  position: relative;
  width: auto;
  margin: var(--bs-modal-margin);
  pointer-events: none;

  /* Modern transform-origin for better animations */
  transform-origin: center center;
}

/* Fade animations with modern CSS */
.modal.fade .modal-dialog {
  transform: translate(0, -50px);
  transition: transform 0.3s ease-out;
}

.modal.show .modal-dialog {
  transform: translate(0, 0);
}

/* Static modal animation (when backdrop is static) */
.modal.modal-static .modal-dialog {
  transform: scale(1.02);
  animation: modal-static-animation 0.3s ease-out;
}

@keyframes modal-static-animation {
  0% {
    transform: scale(1);
  }

  50% {
    transform: scale(1.02);
  }

  100% {
    transform: scale(1);
  }
}

/* Scrollable modal */
.modal-dialog-scrollable {
  height: calc(100% - var(--bs-modal-margin) * 2);
}

.modal-dialog-scrollable .modal-content {
  max-height: 100%;
  overflow: hidden;
}

.modal-dialog-scrollable .modal-body {
  overflow-y: auto;
  /* Modern scrollbar styling */
  scrollbar-width: thin;
  scrollbar-color: var(--text-medium-emphasis) transparent;
}

.modal-dialog-scrollable .modal-body::-webkit-scrollbar {
  width: 6px;
}

.modal-dialog-scrollable .modal-body::-webkit-scrollbar-track {
  background: transparent;
}

.modal-dialog-scrollable .modal-body::-webkit-scrollbar-thumb {
  background-color: var(--text-medium-emphasis);
  border-radius: 3px;
}

/* Centered modal */
.modal-dialog-centered {
  display: flex;
  align-items: center;
  min-height: calc(100% - var(--bs-modal-margin) * 2);
}

/* Actual modal content */
.modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  color: var(--bs-modal-color);
  pointer-events: auto;
  background-color: var(--bs-modal-bg);
  background-clip: padding-box;
  border: var(--bs-modal-border-width) solid var(--bs-modal-border-color);
  border-radius: var(--bs-modal-border-radius);
  box-shadow: var(--bs-modal-box-shadow);
  outline: 0;

  /* Modern backdrop-filter for glass effect */
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

/* Modal backdrop */
.modal-backdrop {
  --bs-backdrop-zindex: 1050;
  --bs-backdrop-bg: var(--backdrop-overlay);
  --bs-backdrop-opacity: 0.5;

  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--bs-backdrop-zindex);
  width: 100vw;
  height: 100vh;
  background-color: var(--bs-backdrop-bg);
  opacity: var(--bs-backdrop-opacity);

  /* Modern backdrop animation */
  transition: opacity 0.15s linear;
}

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

.modal-backdrop.show {
  opacity: var(--bs-backdrop-opacity);
}

/* Modal header */
.modal-header {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  padding: var(--bs-modal-header-padding);
  border-bottom: var(--bs-modal-header-border-width) solid var(--bs-modal-header-border-color);
  border-top-left-radius: var(--bs-modal-inner-border-radius);
  border-top-right-radius: var(--bs-modal-inner-border-radius);

  /* Modern gap for spacing */
  gap: 1rem;
}

.modal-header .btn-close {
  padding: calc(var(--bs-modal-header-padding-y) * 0.5) calc(var(--bs-modal-header-padding-x) * 0.5);
  margin-top: calc(-0.5 * var(--bs-modal-header-padding-y));
  margin-right: calc(-0.5 * var(--bs-modal-header-padding-x));
  margin-bottom: calc(-0.5 * var(--bs-modal-header-padding-y));
  margin-left: auto;

  /* Modern focus styles */
  border: none;
  background: transparent;
  opacity: 0.5;
  transition: opacity 0.15s ease-in-out;
}

.modal-header .btn-close:hover,
.modal-header .btn-close:focus {
  opacity: 1;
}

/* Title text within header */
.modal-title {
  margin-bottom: 0;
  line-height: var(--bs-modal-title-line-height);
  font-weight: 500;
  flex-grow: 1;
}

/* Modal body */
.modal-body {
  position: relative;
  flex: 1 1 auto;
  padding: var(--bs-modal-padding);
}

/* Footer for actions */
.modal-footer {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  padding: calc(var(--bs-modal-padding) - var(--bs-modal-footer-gap) * 0.5);
  background-color: var(--bs-modal-footer-bg);
  border-top: var(--bs-modal-footer-border-width) solid var(--bs-modal-footer-border-color);
  border-bottom-left-radius: var(--bs-modal-inner-border-radius);
  border-bottom-right-radius: var(--bs-modal-inner-border-radius);

  /* Modern gap instead of margins */
  gap: var(--bs-modal-footer-gap);
}

/* Legacy support for margin-based spacing */
.modal-footer>* {
  margin: calc(var(--bs-modal-footer-gap) * 0.5);
}

/* ========================================
     RESPONSIVE BREAKPOINTS
     ======================================== */

/* Small and up (≥576px) */
@media (min-width: 1024px) {
  .modal {
    --bs-modal-margin: 1.75rem;
    --bs-modal-box-shadow: var(--shadow-modal);
  }

  .modal-dialog {
    max-width: var(--bs-modal-width);
    margin-right: auto;
    margin-left: auto;
  }

  .modal-sm {
    --bs-modal-width: 300px;
  }
}

/* Large and up (≥992px) */
@media (min-width: 1024px) {

  .modal-lg,
  .modal-xl {
    --bs-modal-width: 800px;
  }
}

/* Extra large and up (≥1200px) */
@media (min-width: 1200px) {
  .modal-xl {
    --bs-modal-width: 1140px;
  }
}

/* ========================================
     FULLSCREEN MODALS
     ======================================== */

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

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

.modal-fullscreen .modal-header,
.modal-fullscreen .modal-footer {
  border-radius: 0;
}

.modal-fullscreen .modal-body {
  overflow-y: auto;
}

/* Responsive fullscreen variants */
@media (max-width: 1023px) {
  .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;
  }

  .modal-fullscreen-sm-down .modal-header,
  .modal-fullscreen-sm-down .modal-footer {
    border-radius: 0;
  }

  .modal-fullscreen-sm-down .modal-body {
    overflow-y: auto;
  }
}

@media (max-width: 1023px) {
  .modal-fullscreen-md-down {
    width: 100vw;
    max-width: none;
    height: 100%;
    margin: 0;
  }

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

  .modal-fullscreen-md-down .modal-header,
  .modal-fullscreen-md-down .modal-footer {
    border-radius: 0;
  }

  .modal-fullscreen-md-down .modal-body {
    overflow-y: auto;
  }
}

@media (max-width: 1023px) {
  .modal-fullscreen-lg-down {
    width: 100vw;
    max-width: none;
    height: 100%;
    margin: 0;
  }

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

  .modal-fullscreen-lg-down .modal-header,
  .modal-fullscreen-lg-down .modal-footer {
    border-radius: 0;
  }

  .modal-fullscreen-lg-down .modal-body {
    overflow-y: auto;
  }
}

@media (max-width: 1023px) {
  .modal-fullscreen-xl-down {
    width: 100vw;
    max-width: none;
    height: 100%;
    margin: 0;
  }

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

  .modal-fullscreen-xl-down .modal-header,
  .modal-fullscreen-xl-down .modal-footer {
    border-radius: 0;
  }

  .modal-fullscreen-xl-down .modal-body {
    overflow-y: auto;
  }
}

@media (max-width: 1199px) {
  .modal-fullscreen-xxl-down {
    width: 100vw;
    max-width: none;
    height: 100%;
    margin: 0;
  }

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

  .modal-fullscreen-xxl-down .modal-header,
  .modal-fullscreen-xxl-down .modal-footer {
    border-radius: 0;
  }

  .modal-fullscreen-xxl-down .modal-body {
    overflow-y: auto;
  }
}

/* ========================================
     MODERN ENHANCEMENTS
     ======================================== */

/* Improved accessibility */
.modal {
  /* Better focus management */
  focus-trap: true;
}

.modal[aria-hidden="true"] {
  display: none;
}

/* Dark theme support */
/* @media (prefers-color-scheme: dark) {
  .modal {
    --bs-modal-color: var(--text-inverted-high);
    --bs-modal-bg: var(--card-fill);
    --bs-modal-border-color: var(--card-stroke);
    --bs-modal-header-border-color: var(--card-stroke);
    --bs-modal-footer-border-color: var(--card-stroke);
  }
} */

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .modal.fade .modal-dialog {
    transition: none;
  }

  .modal-backdrop {
    transition: none;
  }

  .modal-static .modal-dialog {
    animation: none;
  }
}

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

.siu-modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.siu-modal-body {
  overflow-y: auto;
  overflow-x: hidden;
  max-height: calc(90vh - 100px); /* Account for header and padding */
}

.siu-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--card-stroke);
  margin-bottom: 16px;
}

.siu-modal.show {
  display: flex;
}

.siu-modal-box {
  width: 95vw;
  max-width: 660px;
  max-height: 90vh;
  overflow-y: auto;
  overflow-x: hidden;

  margin: auto;
  border-radius: 8px;
  padding: 16px;

  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--white);
  box-shadow: var(--shadow-modal);
}

@media (min-width: 1024px) {
  .siu-modal-box {
    width: 660px;
  }
}

.siu-modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: background 0.12s;
  flex-shrink: 0;
  font-size: 0;
  color: transparent;
  overflow: hidden;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
}

.siu-modal-close:hover {
  background-color: #f3f4f6;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%231a1a1a' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='M18 6L6 18M6 6l12 12'/%3E%3C/svg%3E");
}

.siu-modal-close:focus {
  outline: none;
  background-color: #f3f4f6;
}

.siu-modal-box--xl {
  width: 95vw;
  max-width: var(--container-width-desktop-md);
}

.siu-modal-box--medium {
  width: 95vw;
  max-width: 520px;
}

.siu-modal-box--narrow {
  width: 95vw;
  max-width: 400px;
}

.siu-modal-box--xxl {
  width: 95vw;
  max-width: var(--container-width-desktop-lg);
}

.siu-modal-box--fullscreen {
  width: calc(100vw - 48px);
  max-width: calc(100vw - 48px);
  height: calc(100vh - 48px);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
}

.siu-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--card-stroke, #e5e7eb);
}

.siu-modal-box--fullscreen .siu-modal-body {
  flex: 1 1 auto;
  max-height: none;
  overflow-y: auto;
  overflow-x: hidden;
}

/* Modal Styles - Light Theme */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--backdrop-overlay);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: var(--z-index-modal);
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--white);
  border: 1px solid var(--card-stroke);
  border-radius: var(--border-radius-s);
  max-width: 90vw;
  max-height: 90vh;
  overflow: auto;
  position: relative;
  box-shadow: var(--shadow-modal);
}

.modal-header {
  padding: var(--spacing-m);
  border-bottom: 1px solid var(--card-stroke);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface-field-passive);
  border-radius: var(--border-radius-s) var(--border-radius-s) 0 0;
}

.modal-title {
  font-family: var(--font-family-title);
  font-weight: var(--font-weights-headers-h4);
  font-size: var(--font-size-headers-h4);
  line-height: var(--font-line-height-headers-h4);
  letter-spacing: var(--font-letter-spacing-headers-h4);
  color: var(--text-primary);
  margin: 0;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-medium-emphasis);
  padding: 4px 8px;
  border-radius: var(--border-radius-xs);
  transition: var(--transition-fast);
}

.modal-close:hover {
  background: var(--surface-field-passive);
  color: var(--text-primary);
}

.modal-body {
  padding: var(--spacing-m);
}

.modal-footer {
  padding: var(--spacing-m);
  border-top: 1px solid var(--card-stroke);
  display: flex;
  justify-content: flex-end;
  gap: var(--spacing-s);
  background: var(--surface-field-passive);
  border-radius: 0 0 var(--border-radius-s) var(--border-radius-s);
}

/* Supplier Modal Specific Styles */
.supplier-modal {
  min-width: 400px;
}

.supplier-list {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-s);
}

.supplier-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--spacing-s);
  background: var(--surface-field-passive);
  border: 1px solid var(--card-stroke);
  border-radius: var(--border-radius-xs);
  transition: var(--transition-fast);
}

.supplier-item:hover {
  background: var(--surface-field-active);
  border-color: var(--card-stroke);
}

.supplier-info {
  color: var(--text-medium-emphasis);
}

.supplier-name {
  font-weight: var(--font-weights-body-bold);
  font-size: var(--font-size-body-default);
  color: var(--text-primary);
}

.supplier-details {
  color: var(--text-medium-emphasis);
}

.supplier-price {
  font-weight: var(--font-weights-body-bold);
  font-size: var(--font-size-body-default);
  color: var(--text-medium-emphasis);
}

.supplier-select-btn {
  background: var(--brand-green);
  color: var(--text-on-dark-color-1);
  padding: 8px 16px;
  border: none;
  border-radius: var(--border-radius-xs);
  cursor: pointer;
  font-family: var(--font-family-body);
  font-weight: var(--font-weights-other-button);
  font-size: var(--font-size-body-fine-print);
  transition: var(--transition-fast);
}

.supplier-select-btn:hover {
  background: var(--brand-green-hover);
}

/* Animation */
.modal-overlay.fade-in {
  animation: fadeIn var(--transition-normal);
}

.modal.slide-in {
  animation: slideIn var(--transition-normal);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Responsive Design */
@media (max-width: 1023px) {
  .modal {
    max-width: 95vw;
    margin: var(--spacing-s);
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: var(--spacing-s);
  }

  .supplier-modal {
    min-width: auto;
  }

  .supplier-item {
    flex-direction: column;
    align-items: flex-start;
    gap: var(--spacing-xs);
  }
}

/* Focus Management */
.modal-overlay:focus-within .modal {
  outline: 2px solid var(--brand-green);
  outline-offset: -2px;
}
