/* Tooltip container */
.tooltip {
  position: relative;
  display: inline;
  cursor: default;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-decoration-color: #999;
  white-space: nowrap;
}

/* Remove underline for image tooltips */
.image.avatar.tooltip {
  text-decoration: none;
  cursor: default;
}

/* Tooltip text */
.tooltip .tooltiptext {
  visibility: hidden;
  width: 280px;
  max-width: calc(100vw - 40px);
  background-color: #333;
  color: #fff;
  text-align: left;
  padding: 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-line;
  
  /* Position the tooltip */
  position: absolute;
  z-index: 1000;
  bottom: 125%;
  left: 50%;
  transform: translateX(-50%);
  
  /* Fade in tooltip */
  opacity: 0;
  transition: opacity 0.3s;
  
  /* Box shadow for depth */
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
}

/* Create an invisible bridge between text and tooltip for easier hovering */
.tooltip .tooltiptext::before {
  content: "";
  position: absolute;
  top: 100%;
  left: 25%;
  right: 25%;
  height: 20px;
  background: transparent;
}

/* Adjust bridge when tooltip is below text */
.tooltip .tooltiptext.tooltip-below::before {
  top: auto;
  bottom: 100%;
}

/* Style links inside tooltips */
.tooltip .tooltiptext a {
  color: #66b3ff;
  text-decoration: underline;
}

.tooltip .tooltiptext a:hover {
  color: #99ccff;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .tooltip .tooltiptext {
    width: 240px;
    font-size: 0.85rem;
    padding: 10px;
  }
}

/* Prevent tooltip from going off-screen on mobile */
@media (max-width: 480px) {
  .tooltip .tooltiptext {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    max-width: calc(100vw - 30px);
    width: auto;
    min-width: 200px;
  }
}

/* Tooltip arrow (default: above text) */
.tooltip .tooltiptext::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  margin-left: -5px;
  border-width: 5px;
  border-style: solid;
  border-color: #333 transparent transparent transparent;
}

/* Tooltip arrow when flipped below text */
.tooltip .tooltiptext.tooltip-below::after {
  top: auto;
  bottom: 100%;
  border-color: transparent transparent #333 transparent;
}

/* Photo credit tooltip - smaller and transparent with no arrow */
.image.avatar.tooltip .tooltiptext {
  width: auto;
  max-width: 200px;
  padding: 8px 10px;
  font-size: 0.8rem;
  background-color: rgba(51, 51, 51, 0.85);
  white-space: nowrap;
}

.image.avatar.tooltip .tooltiptext::after {
  display: none;
}

.image.avatar.tooltip .tooltiptext::before {
  display: none;
}

/* Show the tooltip on hover of trigger text OR tooltip itself */
.tooltip:hover .tooltiptext,
.tooltip .tooltiptext:hover {
  visibility: visible;
  opacity: 1;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .tooltip .tooltiptext {
    background-color: #444;
    color: #eee;
  }
  
  .tooltip .tooltiptext::after {
    border-color: #444 transparent transparent transparent;
  }
  
  .tooltip .tooltiptext.tooltip-below::after {
    border-color: transparent transparent #444 transparent;
  }
  
  .image.avatar.tooltip .tooltiptext {
    background-color: rgba(68, 68, 68, 0.85);
  }
}

/* Light mode explicit */
@media (prefers-color-scheme: light) {
  .tooltip .tooltiptext {
    background-color: #2a2a2a;
    color: #f5f5f5;
  }
  
  .tooltip .tooltiptext::after {
    border-color: #2a2a2a transparent transparent transparent;
  }
  
  .tooltip .tooltiptext.tooltip-below::after {
    border-color: transparent transparent #2a2a2a transparent;
  }
  
  .image.avatar.tooltip .tooltiptext {
    background-color: rgba(42, 42, 42, 0.85);
  }
}
