/**
 * Regulation Tooltip Styles
 * Custom styling for Bootstrap tooltips used in regulation content
 * Provides modern, responsive design with dark mode support
 */

/* Custom Bootstrap Tooltip Styling */
.regulation-tooltip-custom {
  --tooltip-border-radius: 8px;
  --tooltip-padding-top-bottom: 8px;
  --tooltip-padding-right-left: 8px;
  --tooltip-max-width: 400px;
  --tooltip-max-height: 300px;
  --tooltip-arrow-size: 8px;
  --tooltip-z-index: 9999;

  /* Animation */
  --tooltip-fade-duration: 0.2s;
}

/* Main tooltip container */
.regulation-tooltip-custom {
  position: absolute;
  z-index: var(--tooltip-z-index);
  color: var(--bs-black);
  background-color: var(--bs-white);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--tooltip-border-radius);
  padding: calc(2 * var(--tooltip-padding-top-bottom)) calc(2 * var(--tooltip-padding-right-left));
  max-width: var(--tooltip-max-width);
  max-height: calc(var(--tooltip-max-height) + calc(4 * var(--tooltip-padding-top-bottom)));
  word-wrap: break-word;
  white-space: normal;
  scrollbar-color: var(--bs-gray-300) var(--bs-gray-100);

  /* Smooth fade animation only */
  opacity: 0;
  transition: opacity var(--tooltip-fade-duration) ease-out;
}

/* Tooltip inner content with scroll */
.regulation-tooltip-custom .tooltip-inner {
  background: none;
  padding: 0;
  padding-right: var(--tooltip-padding-right-left);
  border: none;
  border-radius: 0;
  box-shadow: none;
  max-width: none;
  color: inherit;
  text-align: left;
  max-height: var(--tooltip-max-height);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Paragraph tooltip specific styling */
.regulation-tooltip-paragraph .tooltip-inner {
  /* Add blockquote styling for paragraph content */
  border-left: calc(var(--tooltip-padding-right-left) / 2) solid var(--bs-primary);
  padding-left: calc(1.5 * var(--tooltip-padding-right-left));
  border-radius: 0;
}

/* Show state */
.regulation-tooltip-custom.show {
  opacity: 1;
}

/* Tooltip arrow */
.regulation-tooltip-custom .regulation-tooltip-arrow {
  position: absolute;
  width: 0;
  height: 0;
  z-index: 10000;
}

/* Default arrow styling (bottom placement - tooltip appears above, arrow at bottom) */
.regulation-tooltip-custom .regulation-tooltip-arrow {
  bottom: calc(-2 * var(--tooltip-arrow-size)); /* Position exactly on the bottom border, outside the tooltip */
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-top-color: var(--bs-border-color);
}

.regulation-tooltip-custom .regulation-tooltip-arrow .arrow {
  position: absolute;
  bottom: 1px;
  left: calc(-2 * var(--tooltip-arrow-size));
  border: 8px solid transparent;
}

/* Left placement - tooltip appears to the right, arrow at left */
.regulation-tooltip-custom[data-popper-placement='left'] .regulation-tooltip-arrow,
.regulation-tooltip-custom.bs-tooltip-start .regulation-tooltip-arrow {
  top: 50%;
  right: calc(-2 * var(--tooltip-arrow-size)); /* Position exactly on the right border, outside the tooltip */
  left: auto;
  transform: translateY(-50%);
  border: 8px solid transparent;
  border-left-color: var(--bs-border-color);
}

.regulation-tooltip-custom[data-popper-placement='left'] .regulation-tooltip-arrow .arrow,
.regulation-tooltip-custom.bs-tooltip-start .regulation-tooltip-arrow .arrow {
  top: calc(-2 * var(--tooltip-arrow-size));
  left: 1px;
  right: auto;
  border: 8px solid transparent;
}

/* Right placement - tooltip appears to the left, arrow at right */
.regulation-tooltip-custom[data-popper-placement='right'] .regulation-tooltip-arrow,
.regulation-tooltip-custom.bs-tooltip-end .regulation-tooltip-arrow {
  top: 50%;
  left: calc(-2 * var(--tooltip-arrow-size)); /* Position exactly on the left border, outside the tooltip */
  right: auto;
  transform: translateY(-50%);
  border: 8px solid transparent;
  border-right-color: var(--bs-border-color);
}

.regulation-tooltip-custom[data-popper-placement='right'] .regulation-tooltip-arrow .arrow,
.regulation-tooltip-custom.bs-tooltip-end .regulation-tooltip-arrow .arrow {
  top: calc(-2 * var(--tooltip-arrow-size));
  right: 1px;
  left: auto;
  border: 8px solid transparent;
}

/* Top placement - tooltip appears below, arrow at top */
.regulation-tooltip-custom[data-popper-placement='bottom'] .regulation-tooltip-arrow,
.regulation-tooltip-custom.bs-tooltip-top .regulation-tooltip-arrow {
  bottom: 50%;
  top: calc(-2 * var(--tooltip-arrow-size)); /* Position exactly on the top border, outside the tooltip */
  left: 50%;
  transform: translateX(-50%);
  border: 8px solid transparent;
  border-bottom-color: var(--bs-border-color);
}

.regulation-tooltip-custom[data-popper-placement='bottom'] .regulation-tooltip-arrow .arrow,
.regulation-tooltip-custom.bs-tooltip-top .regulation-tooltip-arrow .arrow {
  bottom: 1px;
  left: calc(-2 * var(--tooltip-arrow-size));
  border: 8px solid transparent;
}

/* Responsive design */
@media (max-width: 768px) {
  .regulation-tooltip-custom {
    --tooltip-max-width: 300px;
    --tooltip-max-height: 250px;
  }
}

@media (max-width: 480px) {
  .regulation-tooltip-custom {
    --tooltip-max-width: 280px;
    --tooltip-max-height: 200px;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .regulation-tooltip-custom {
    --tooltip-fade-duration: 0.1s;
  }
}

/* Print styles */
@media print {
  .regulation-tooltip-custom {
    display: none !important;
  }
}

/* Mobile touch feedback for regulation links */
@media (hover: none) and (pointer: coarse) {
  /* Long press feedback for mobile devices */
  .xref:active {
    background-color: var(--bs-primary);
    color: var(--bs-white);
    border-radius: 4px;
    transition: all 0.2s ease;
  }

  /* Prevent text selection during long press */
  .xref {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
  }

  /* Add subtle visual hint for long press */
  .xref::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: transparent;
    border-radius: 4px;
    transition: background-color 0.3s ease;
    pointer-events: none;
  }

  .xref:active::after {
    background-color: rgba(var(--bs-primary-rgb), 0.1);
  }
}
