/* Simple, clean tooltip implementation */
.tooltip-wrapper {
  position: relative;
  display: inline-block;
}

.tooltip-trigger {
  background: #2563eb;
  border: none;
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  margin-left: 6px;
  font-weight: bold;
  line-height: 1;
  padding: 0;
  box-sizing: border-box;
}

/* Ensure SVG icons are properly sized and visible */
.tooltip-trigger svg {
  width: 1em !important;
  height: 1em !important;
  min-width: 1em;
  min-height: 1em;
  flex-shrink: 0;
}

.tooltip-trigger.small {
  width: 24px;
  height: 24px;
  font-size: 14px;
}

.tooltip-trigger.medium {
  width: 26px;
  height: 26px;
  font-size: 16px;
}

.tooltip-trigger.large {
  width: 30px;
  height: 30px;
  font-size: 18px;
}

.tooltip-trigger:hover {
  background: #1d4ed8;
  transform: scale(1.1);
}

/* Mobile-specific styles */
.tooltip-trigger.mobile {
  min-width: 44px; /* Apple's recommended minimum touch target */
  min-height: 44px;
  padding: 0;
  position: relative;
}

.tooltip-trigger.mobile.small {
  width: 44px;
  height: 44px;
  font-size: 14px;
}

.tooltip-trigger.mobile.medium {
  width: 48px;
  height: 48px;
  font-size: 16px;
}

.tooltip-trigger.mobile.large {
  width: 52px;
  height: 52px;
  font-size: 18px;
}

/* Remove hover effects on mobile */
@media (hover: none) and (pointer: coarse) {
  .tooltip-trigger:hover {
    background: #2563eb;
    transform: none;
  }
  
  .tooltip-trigger:active {
    background: #1d4ed8;
    transform: scale(0.95);
  }
}

.tooltip-content {
  position: absolute;
  z-index: 10000;
  background: #1f2937;
  color: white;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.4;
  max-width: 250px;
  white-space: normal;
  word-wrap: break-word;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  animation: fadeIn 0.15s ease-in;
}

.tooltip-portal {
  pointer-events: auto; /* allow hovering into tooltip on desktop */
}

/* Allow pointer events on mobile for better interaction */
@media (max-width: 768px) {
  .tooltip-portal {
    pointer-events: auto;
  }
}

.tooltip-content-portal {
  background: #1f2937;
  color: white;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.5;
  max-width: 250px;
  white-space: normal;
  word-wrap: break-word;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.1);
  animation: tooltipFadeIn 0.2s ease-out;
  pointer-events: auto; /* Allow interaction with tooltip content on mobile */
  z-index: 10000; /* Ensure above charts/canvases */
}

/* Mobile-specific tooltip content */
@media (max-width: 768px) {
  .tooltip-content-portal {
    max-width: 220px;
    font-size: 15px; /* Slightly larger for mobile readability */
    padding: 14px 18px;
    line-height: 1.6;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.25);
  }
}

.tooltip-top {
  bottom: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
}

.tooltip-bottom {
  top: calc(100% + 5px);
  left: 50%;
  transform: translateX(-50%);
}

.tooltip-left {
  right: calc(100% + 5px);
  top: 50%;
  transform: translateY(-50%);
}

.tooltip-right {
  left: calc(100% + 5px);
  top: 50%;
  transform: translateY(-50%);
}

/* Ensure tooltips don't get cut off at screen edges */
@media (max-width: 768px) {
  .tooltip-content {
    max-width: 200px;
    font-size: 14px; /* Larger for better mobile readability */
    padding: 10px 14px;
    line-height: 1.5;
  }
  
  .tooltip-top,
  .tooltip-bottom {
    left: 50%;
    transform: translateX(-50%);
    /* Ensure it doesn't go off-screen */
    max-width: calc(100vw - 32px);
  }
  
  .tooltip-left,
  .tooltip-right {
    /* Convert to bottom position on mobile */
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    right: auto;
    max-width: calc(100vw - 32px);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateX(-50%) scale(0.9);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) scale(1);
  }
}

@keyframes tooltipFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-5px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Improved mobile animations */
@media (max-width: 768px) {
  @keyframes tooltipFadeIn {
    from {
      opacity: 0;
      transform: scale(0.9) translateY(-8px);
    }
    to {
      opacity: 1;
      transform: scale(1) translateY(0);
    }
  }
  
  @keyframes fadeIn {
    from {
      opacity: 0;
      transform: translateX(-50%) scale(0.9) translateY(-5px);
    }
    to {
      opacity: 1;
      transform: translateX(-50%) scale(1) translateY(0);
    }
  }
}