/* 
 * MortgageGuidelines Chat Embed Styles
 * Version: 1.0.0
 */

/* Container Styles */
.mg-chat-embed-container {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  border: 1px solid #e1e5e9;
  /* transition: all 0.3s ease; */
}

.mg-chat-embed-container:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

/* Fullscreen mode */
.mg-chat-embed-container.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 999999;
  border-radius: 0;
  border: none;
  box-shadow: none;
}

/* Full page mode - overrides site design */
.mg-chat-embed-full-page {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  z-index: 2147483647 !important; /* Maximum z-index value */
  background: white !important;
  border: none !important;
  border-radius: 0 !important;
  box-shadow: none !important;
  margin: 0 !important;
  padding: 0 !important;
  max-width: none !important;
}

/* Body and HTML modifications for full page mode */
html.mg-chat-full-page-active,
body.mg-chat-full-page-active {
  overflow: hidden !important;
  position: fixed !important;
  width: 100% !important;
  height: 100% !important;
  /* Disable smooth scrolling */
  scroll-behavior: auto !important;
  /* Prevent margin collapse issues */
  margin: 0 !important;
  padding: 0 !important;
  /* Ensure no scrollbar space is reserved */
  scrollbar-width: none !important;
  -ms-overflow-style: none !important;
}

/* Hide webkit scrollbars in full page mode */
html.mg-chat-full-page-active::-webkit-scrollbar,
body.mg-chat-full-page-active::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
}

/* Hide WordPress admin bar in full page mode */
body.mg-chat-full-page-active #wpadminbar {
  display: none !important;
}

/* Ensure no scrollbars on common WordPress wrapper elements */
.mg-chat-full-page-active .site,
.mg-chat-full-page-active .site-container,
.mg-chat-full-page-active #page,
.mg-chat-full-page-active #main,
.mg-chat-full-page-active .wrapper,
.mg-chat-full-page-active .ast-container,
.mg-chat-full-page-active .et-main-content,
.mg-chat-full-page-active .content-area {
  overflow: hidden !important;
}

/* Close button for full page mode */
.mg-chat-full-page-close {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000000;
  background: #333;
  color: white;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.mg-chat-full-page-close:hover {
  background: #555;
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.mg-chat-full-page-close:active {
  transform: scale(0.95);
}

/* Fullscreen toggle button */
.mg-fullscreen-toggle {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 100;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px;
  cursor: pointer;
  transition: all 0.3s;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  opacity: 0.8;
}

.mg-fullscreen-toggle:hover {
  background: #f5f5f5;
  opacity: 1;
  transform: scale(1.05);
}

.mg-fullscreen-toggle .dashicons {
  font-size: 16px;
  width: 16px;
  height: 16px;
}

/* Loading state */
.mg-chat-embed-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: #f9f9f9;
  color: #666;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* transition: none; */
}

.mg-chat-embed-loading p {
  margin: 16px 0 0 0;
  font-size: 16px;
  font-weight: 500;
}

/* Loading spinner */
.mg-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid #0073aa;
  border-radius: 50%;
  animation: mg-spin 1s linear infinite;
}

@keyframes mg-spin {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Error state */
.mg-chat-embed-error {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  background: #fff3cd;
  color: #856404;
  padding: 20px;
  text-align: center;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  border: 1px solid #ffeaa7;
  border-radius: 8px;
  margin: 20px;
}

.mg-error {
  color: #d63638;
  font-weight: 500;
  padding: 16px;
  background: #ffebee;
  border: 1px solid #ffcdd2;
  border-radius: 4px;
  margin: 16px;
}

/* iframe styles */
.mg-chat-embed-container iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .mg-chat-embed-container {
    height: calc(100vh - 100px);
    border-radius: 0;
    box-shadow: none;
    border-left: none;
    border-right: none;
  }

  .mg-fullscreen-toggle {
    top: 5px;
    right: 5px;
    padding: 6px;
  }

  .mg-chat-embed-loading p {
    font-size: 14px;
  }

  /* Full page close button on mobile */
  .mg-chat-full-page-close {
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    font-size: 20px;
  }
}

@media (max-width: 480px) {
  .mg-chat-embed-container {
    height: calc(100vh - 80px);
  }

  .mg-chat-embed-loading {
    padding: 20px;
  }

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

/* WordPress theme integration */
.wp-dark-mode .mg-chat-embed-container,
body.dark-mode .mg-chat-embed-container {
  background: #1a1a1a;
  border-color: #333;
  box-shadow: 0 2px 10px rgba(255, 255, 255, 0.1);
}

.wp-dark-mode .mg-chat-embed-loading,
body.dark-mode .mg-chat-embed-loading {
  background: #2a2a2a;
  color: #ccc;
}

.wp-dark-mode .mg-fullscreen-toggle,
body.dark-mode .mg-fullscreen-toggle {
  background: #333;
  border-color: #555;
  color: #ccc;
}

.wp-dark-mode .mg-fullscreen-toggle:hover,
body.dark-mode .mg-fullscreen-toggle:hover {
  background: #444;
}

/* Full page mode in dark theme */
.wp-dark-mode .mg-chat-embed-full-page,
body.dark-mode .mg-chat-embed-full-page {
  background: #1a1a1a !important;
}

.wp-dark-mode .mg-chat-full-page-close,
body.dark-mode .mg-chat-full-page-close {
  background: #555;
  color: #fff;
}

.wp-dark-mode .mg-chat-full-page-close:hover,
body.dark-mode .mg-chat-full-page-close:hover {
  background: #777;
}

/* Hide WordPress admin bar in fullscreen */
.mg-chat-embed-container.fullscreen ~ #wpadminbar {
  display: none !important;
}

/* Ensure proper z-index stacking */
.mg-chat-embed-container {
  z-index: 1;
}

.mg-chat-embed-container.fullscreen {
  z-index: 999999;
}

/* Animation for container appearance */
.mg-chat-embed-container {
  /* animation: mg-fade-in 0.5s ease-out; */
}

@keyframes mg-fade-in {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Focus styles for accessibility */
.mg-fullscreen-toggle:focus {
  outline: 2px solid #0073aa;
  outline-offset: 2px;
}

/* Print styles */
@media print {
  .mg-chat-embed-container {
    display: none !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .mg-chat-embed-container {
    border-width: 2px;
    border-color: #000;
  }

  .mg-fullscreen-toggle {
    border-width: 2px;
    border-color: #000;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .mg-chat-embed-container,
  .mg-fullscreen-toggle,
  .mg-chat-embed-container iframe {
    transition: none !important;
    animation: none !important;
  }

  .mg-loading-spinner {
    animation: none !important;
    border-top-color: transparent !important;
  }
}

/* Custom scrollbar for webkit browsers */
.mg-chat-embed-container::-webkit-scrollbar {
  width: 8px;
}

.mg-chat-embed-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.mg-chat-embed-container::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 4px;
}

.mg-chat-embed-container::-webkit-scrollbar-thumb:hover {
  background: #a1a1a1;
}

/* Integration with common WordPress themes */

/* Twenty Twenty-Three */
.wp-site-blocks .mg-chat-embed-container {
  max-width: none;
}

/* Genesis Framework */
.site-container .mg-chat-embed-container {
  max-width: none;
}

/* Astra */
.ast-container .mg-chat-embed-container {
  max-width: none;
}

/* OceanWP */
.oceanwp-row .mg-chat-embed-container {
  max-width: none;
}

/* Elementor */
.elementor-widget-container .mg-chat-embed-container {
  max-width: none;
  width: 100%;
}

/* Gutenberg block editor styles */
.wp-block-group .mg-chat-embed-container,
.wp-block-columns .mg-chat-embed-container {
  max-width: none;
  width: 100%;
}

/* Ensure embed works in various layout contexts */
.mg-chat-embed-container {
  box-sizing: border-box;
}

.mg-chat-embed-container * {
  box-sizing: border-box;
}

/* Utility classes */
.mg-chat-embed-hidden {
  display: none !important;
}

.mg-chat-embed-loading-state .mg-chat-embed-loading {
  display: flex;
}

.mg-chat-embed-loading-state iframe {
  display: none;
}

.mg-chat-embed-ready .mg-chat-embed-loading {
  display: none;
}

.mg-chat-embed-ready iframe {
  display: block;
}
