/* ===================================================
   SHARED HELP SYSTEM
   Reusable help popover component for all pages
   Created: December 2024
   =================================================== */

/* CSS Custom Properties - Override these per page if needed
   
   Example: To customize on a specific page, add to your page's CSS:
   
   :root {
     --help-popover-max-width: 400px;
     --help-popover-max-height: 80vh;
     --help-popover-min-width: 250px;
   }
   
   Or target specific screen sizes:
   @media (max-width: 768px) {
     :root {
       --help-popover-max-width: 90vw;
       --help-popover-max-height: 50vh;
     }
   }
*/
:root {
  --help-popover-max-width: 320px;
  --help-popover-max-height: 60vh; /* 60% of viewport height */
  --help-popover-min-width: 200px;
}

/* Help Icon Trigger */
/* Help Icon - MUST have consistent blue circle background everywhere */
span.help-icon,
.help-icon {
  cursor: pointer !important;
  color: #2196F3 !important;
  font-style: normal !important;
  font-weight: bold !important;
  margin-left: 4px !important;
  font-size: 14px !important;
  display: inline-block !important;
  width: 18px !important;
  height: 18px !important;
  line-height: 18px !important;
  text-align: center !important;
  border-radius: 50% !important;
  background-color: rgba(33, 150, 243, 0.15) !important;
  background: rgba(33, 150, 243, 0.15) !important;
  border: 1px solid rgba(33, 150, 243, 0.3) !important;
  box-sizing: border-box !important;
  transition: all 0.2s !important;
  user-select: none !important;
  flex-shrink: 0 !important;
  vertical-align: middle !important;
  position: relative !important;
  top: -1px !important;
}

span.help-icon:hover,
.help-icon:hover {
  background-color: rgba(33, 150, 243, 0.25) !important;
  background: rgba(33, 150, 243, 0.25) !important;
  border-color: rgba(33, 150, 243, 0.5) !important;
  transform: scale(1.15) !important;
}

/* Popover Container */
.help-popover {
  position: fixed; /* Changed from absolute to fixed for better positioning */
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  padding: 16px;
  width: 500px; /* Fixed width for consistency */
  max-width: calc(100vw - 40px); /* Don't exceed viewport width minus margins */
  max-height: var(--help-popover-max-height);
  overflow-y: auto; /* Enable scrolling when content exceeds max-height */
  overflow-x: hidden;
  z-index: 10000;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  /* Smooth scrolling for better UX */
  scroll-behavior: smooth;
}

/* Custom scrollbar styling for modern browsers */
.help-popover::-webkit-scrollbar {
  width: 8px;
}

.help-popover::-webkit-scrollbar-track {
  background: #f5f5f5;
  border-radius: 4px;
}

.help-popover::-webkit-scrollbar-thumb {
  background: #c0c0c0;
  border-radius: 4px;
  transition: background 0.2s;
}

.help-popover::-webkit-scrollbar-thumb:hover {
  background: #2196F3;
}

/* Firefox scrollbar styling */
.help-popover {
  scrollbar-width: thin;
  scrollbar-color: #c0c0c0 #f5f5f5;
}

.help-popover.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: all;
}

/* Popover Arrows (default: below) */
.help-popover::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 8px solid transparent;
  border-bottom-color: white;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
}

.help-popover::after {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border: 9px solid transparent;
  border-bottom-color: #e0e0e0;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: -1;
}

/* Arrow positioning when popover appears above */
.help-popover.above::before {
  top: auto;
  bottom: -16px;
  border-bottom-color: transparent;
  border-top-color: white;
}

.help-popover.above::after {
  top: auto;
  bottom: -18px;
  border-bottom-color: transparent;
  border-top-color: #e0e0e0;
}

/* Arrow positioning when popover appears to the right */
.help-popover.right::before {
  top: 50%;
  left: -16px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-right-color: white;
}

.help-popover.right::after {
  top: 50%;
  left: -18px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-right-color: #e0e0e0;
}

/* Arrow positioning when popover appears to the left */
.help-popover.left::before {
  top: 50%;
  left: auto;
  right: -16px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-left-color: white;
}

.help-popover.left::after {
  top: 50%;
  left: auto;
  right: -18px;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-left-color: #e0e0e0;
}

/* No arrow when centered */
.help-popover.center::before,
.help-popover.center::after {
  display: none;
}

/* Popover Header */
.help-popover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e0e0e0;
}

.help-popover-title {
  font-weight: 600;
  font-size: 14px;
  color: #333;
  display: flex;
  align-items: center;
  gap: 6px;
}

.help-popover-close {
  background: none;
  border: none;
  font-size: 20px;
  color: #999;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.2s;
}

.help-popover-close:hover {
  background: #f5f5f5;
  color: #333;
}

/* Popover Content */
.help-popover-content {
  font-size: 13px;
  line-height: 1.6;
  color: #555;
  /* Ensure content doesn't break scrolling */
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.help-popover-content p {
  margin: 0 0 8px 0;
}

.help-popover-content p:last-child {
  margin-bottom: 0;
}

.help-popover-content strong {
  color: #333;
  font-weight: 600;
}

.help-popover-content code {
  background: #f5f5f5;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: #e91e63;
}

.help-popover-content ul {
  margin: 8px 0;
  padding-left: 20px;
}

.help-popover-content li {
  margin: 4px 0;
}

.help-popover-section {
  margin: 12px 0;
}

.help-popover-section-title {
  font-weight: 600;
  font-size: 12px;
  color: #2196F3;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============================================ */
/* EXAMPLES SECTION */
/* ============================================ */

.help-examples {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #e0e0e0;
}

.help-examples h5 {
  font-size: 14px;
  font-weight: 600;
  color: #2196F3;
  margin: 0 0 12px 0;
}

.help-examples-list {
  max-height: 400px;
  overflow-y: auto;
  padding-right: 8px;
}

.help-example-item {
  margin-bottom: 16px;
  background: #f8f9fa;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  overflow: hidden;
  transition: all 0.2s ease;
}

.help-example-item:hover {
  border-color: #2196F3;
  box-shadow: 0 2px 8px rgba(33, 150, 243, 0.1);
}

.help-example-title {
  font-size: 12px;
  font-weight: 600;
  color: #333;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}

.help-example-code {
  margin: 0;
  padding: 12px;
  background: #f8f9fa;
  border: none;
  border-radius: 0;
  font-family: 'Monaco', 'Menlo', 'Courier New', monospace;
  font-size: 11px;
  line-height: 1.5;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow-x: auto;
}

.help-example-code:hover {
  background: #e8f4f8;
  color: #2196F3;
}

.help-example-code:active {
  background: #4CAF50;
  color: white;
}

/* Scrollbar for examples list */
.help-examples-list::-webkit-scrollbar {
  width: 6px;
}

.help-examples-list::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 3px;
}

.help-examples-list::-webkit-scrollbar-thumb {
  background: #c0c0c0;
  border-radius: 3px;
}

.help-examples-list::-webkit-scrollbar-thumb:hover {
  background: #a0a0a0;
}
