/* === MODAL & OVERLAY SYSTEM === */
/* Base overlay for all modal-like components */
/* Base modal and overlay system */
.modal-base {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
}

/* Modal types */
.modal-base.modal--standard {
  background: var(--overlay-transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: var(--z-modal);
}

/* Separate overlay element - covers full screen */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: var(--z-modal); /* Base layer */
  display: none;
}

.modal-overlay.u-flex {
  display: flex !important;
}

/* Modal content container - separate from overlay */
.modal-content-container {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: calc(var(--z-modal) + 1); /* Above overlay */
  pointer-events: none; /* Allow clicks to pass through except on content */
}

.modal-content-container.u-flex {
  display: flex !important;
}

.modal-content-container .modal-content {
  pointer-events: auto; /* Re-enable clicks on actual content */
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-radius: var(--border-radius-2xl);
  overflow-y: auto;
  box-shadow: 0 var(--spacing-sm) var(--spacing-xl) var(--shadow-color);
  border: 1px solid rgba(255, 255, 255, 0.15);
  /* Mobile first - full screen approach */
  width: 98%;
  max-height: 98vh;
  margin: var(--spacing-2xs);
}

.modal-content-container .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  /* Mobile first - compact padding */
  padding: var(--spacing-xs) var(--spacing-sm);
}

.modal-content-container .modal-header h3 {
  margin: 0;
  color: var(--accent-color);
  font-family: var(--alt-heading-font-family);
  font-size: 1.7rem;
  font-weight: 600;
  margin-left: var(--spacing-sm);
  padding: var(--spacing-sm);
}

.modal-content-container .modal-close {
  background: none;
  border: none;
  font-size: var(--spacing-lg);
  cursor: pointer;
  color: var(--text-color);
  padding: 0;
  width: var(--spacing-xl);
  height: var(--spacing-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  margin-right: var(--spacing-sm);
}

.modal-content-container .modal-close:hover {
  background: color-mix(in srgb, var(--gray-400) 30%, transparent);
}

.modal-content-container .modal-body {
  padding: var(--spacing-md);
  /* Mobile first - constrained height */
  max-height: calc(98vh - 70px);
}

.modal-base.modal-loading {
  background: var(--overlay-light);
  z-index: var(--z-modal);
}

.modal-base.modal-recipe-loader {
  background: var(--overlay-medium);
  z-index: var(--z-modal);
  flex-direction: column;
}

/* Confirmation modal specific styling */
.modal-base.modal-confirmation .modal-content {
  max-width: 480px;
}

.modal-confirmation .modal-body {
  padding: var(--spacing-lg);
  text-align: center;
}

.modal-confirmation .confirmation-message {
  margin-bottom: var(--spacing-lg);
  line-height: 1.5;
  white-space: pre-line;
}

.modal-confirmation .modal-buttons {
  display: flex;
  gap: var(--spacing-md);
  justify-content: center;
}

/* Action type indicators */
.modal-confirmation.confirmation--danger .modal-header {
  border-bottom-color: var(--error-color);
}

.modal-confirmation.confirmation--warning .modal-header {
  border-bottom-color: var(--warning-color);
}

.modal-confirmation.confirmation--info .modal-header {
  border-bottom-color: var(--accent-color);
}

/* Legacy modal classes - use .modal-base instead */
.duplicate-recipe-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  background: var(--overlay-medium);
  z-index: var(--z-modal);
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  background: var(--overlay-light);
  z-index: var(--z-modal);
}

.recipe-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: none;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
  background: var(--overlay-medium);
  z-index: var(--z-modal);
  flex-direction: column;
}

/* Modal visibility states */
.modal-visible, .modal--visible { display: flex !important; }
.modal-hidden, .modal--hidden { display: none !important; }
.modal-base .modal-content {
  position: relative;
  background: rgba(0, 0, 0, 0.4);
  border-radius: var(--border-radius-2xl);
  overflow-y: auto;
  box-shadow: 0 var(--spacing-sm) var(--spacing-xl) var(--shadow-color);
  border: 1px solid rgba(255, 255, 255, 0.15);
  /* Mobile first - full screen approach */
  width: 98%;
  max-height: 98vh;
  margin: var(--spacing-2xs);
}

.modal-base .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(10px) saturate(180%);
  -webkit-backdrop-filter: blur(10px) saturate(180%);
  border-radius: var(--border-radius) var(--border-radius) 0 0;
  /* Mobile first - compact padding */
  padding: var(--spacing-xs) var(--spacing-sm);
}
.modal-header h3 { margin: 0; color: var(--accent-color); font-family: var(--alt-heading-font-family); font-size: 1.7rem; font-weight: 600; margin-left: var(--spacing-sm); padding: var(--spacing-sm); }
.modal-title { margin: 0; color: var(--accent-color); font-size: 1.2rem; font-weight: 600; }
.modal-body {
  padding: var(--spacing-md);
  /* Mobile first - constrained height */
  max-height: calc(98vh - 70px);
}
.modal-close { background: none; border: none; font-size: var(--spacing-lg); cursor: pointer; color: var(--text-color); padding: 0; width: calc(var(--spacing-xl) - var(--spacing-2xs)); height: calc(var(--spacing-xl) - var(--spacing-2xs)); display: flex; align-items: center; justify-content: center; border-radius: 50%; }

.modal-close:hover { background: color-mix(in srgb, var(--gray-400) 30%, transparent); }
.loading-spinner { width: var(--floating-button-size); height: var(--floating-button-size); border: var(--spacing-xs) solid var(--gray-400); border-top-color: var(--accent-color); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Modal responsive enhancements - mobile first */
@media (min-width: 481px) {
  .modal-content {
    width: 95%;
    max-height: 90vh;
    margin: var(--spacing-xs);
  }

  .modal-header {
    padding: var(--spacing-sm) var(--spacing-md);
  }

  .modal-body {
    max-height: calc(90vh - 80px);
  }
}

@media (min-width: 769px) {
  .modal-content {
    max-width: var(--modal-max-width);
    width: 90%;
    max-height: 80vh;
    margin: var(--spacing-xl);
  }

  .modal-header {
    padding: var(--spacing-md) var(--spacing-lg);
  }

  .modal-body {
    max-height: calc(80vh - 100px);
  }
}

/* Recipe Loader Component */
.recipe-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--overlay-medium);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  backdrop-filter: blur(3px);
}

.recipe-loader .loading-spinner {
  margin-bottom: var(--spacing-md);
}

.recipe-loader .loading-message {
  color: var(--text-color);
  font-size: var(--spacing-md);
  font-weight: 500;
  text-align: center;
  max-width: 300px;
  line-height: 1.4;
}

/* Modal Extensions */


/* Legacy modal buttons for other uses */
.modal-buttons { display: flex; gap: var(--spacing-md); flex-wrap: wrap; }

/* Mobile User Menu Modal */
.mobile-menu-buttons {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
}

/* Initial Loading State */
.initial-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: var(--spacing-lg);
}

.loading-logo {
    width: 120px;
    height: 120px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.8;
        transform: scale(0.95);
    }
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-300);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Modal responsive enhancements - mobile specific adjustments */
@media screen and (max-width: 480px) {
  /* Modal full-screen approach */
  .modal-base {
    padding: var(--spacing-2xs);
  }

  .modal-close {
    width: 44px;
    height: 44px;
    padding: var(--spacing-xs);
  }

  /* Loading spinner adjustments */
  .loading-spinner {
    width: 40px;
    height: 40px;
  }

  .initial-loading .app-logo {
    width: 200px;
    height: auto;
  }
}

/* Extra small phones (iPhone SE, etc.) */
@media screen and (max-width: 375px) {
  /* Loading screen minimal */
  .initial-loading .app-logo {
    width: 160px;
  }

  .loading-spinner {
    width: 32px;
    height: 32px;
  }
}