/**
 * @file
 * Glossary tooltip styles.
 */

/* Glossary links */
:root {
  --glossary-link-style: dotted;
  --glossary-link-color: #0073e6;
  --glossary-link-hover-color: #004494;
  --glossary-max-width: 320px;
}

.glossary-link {
  color: inherit;
  text-decoration: underline;
  text-decoration-style: var(--glossary-link-style);
  text-decoration-color: var(--glossary-link-color);
  text-underline-offset: 2px;
  cursor: help;
  transition: text-decoration-color 0.2s ease, background-color 0.2s ease;
}

/* Dotted style (default) */
.glossary-link.link-style-dotted {
  text-decoration-style: dotted;
  background: none;
}

/* Solid style */
.glossary-link.link-style-solid {
  text-decoration-style: solid;
  background: none;
}

/* Dashed style */
.glossary-link.link-style-dashed {
  text-decoration-style: dashed;
  background: none;
}

/* Highlight style */
.glossary-link.link-style-highlight {
  text-decoration: none;
  background: linear-gradient(120deg, #ffeb3b 0%, #ffeb3b 100%);
  background-repeat: no-repeat;
  background-size: 100% 30%;
  background-position: 0 85%;
  transition: background-size 0.2s ease;
}

.glossary-link:hover,
.glossary-link:focus {
  text-decoration-color: var(--glossary-link-hover-color);
}

.glossary-link.link-style-dotted:hover,
.glossary-link.link-style-dotted:focus {
  text-decoration-style: solid;
}

.glossary-link.link-style-highlight:hover,
.glossary-link.link-style-highlight:focus {
  background-size: 100% 100%;
  background-position: 0 0;
}

.glossary-link:focus {
  outline: 2px solid #0073e6;
  outline-offset: 2px;
  border-radius: 2px;
}

/* Glossary tooltip */
.glossary-tooltip {
  position: absolute;
  z-index: 9999;
  max-width: var(--glossary-max-width, 320px);
  padding: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.glossary-tooltip.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.glossary-tooltip.is-above {
  transform: translateY(4px);
}

.glossary-tooltip.is-above.is-visible {
  transform: translateY(0);
}

/* Tooltip arrow */
.glossary-tooltip::before,
.glossary-tooltip::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-style: solid;
}

.glossary-tooltip::before {
  top: -9px;
  border-width: 0 9px 9px 9px;
  border-color: transparent transparent #ddd transparent;
}

.glossary-tooltip::after {
  top: -8px;
  border-width: 0 8px 8px 8px;
  border-color: transparent transparent #fff transparent;
}

.glossary-tooltip.is-above::before {
  top: auto;
  bottom: -9px;
  border-width: 9px 9px 0 9px;
  border-color: #ddd transparent transparent transparent;
}

.glossary-tooltip.is-above::after {
  top: auto;
  bottom: -8px;
  border-width: 8px 8px 0 8px;
  border-color: #fff transparent transparent transparent;
}

/* Tooltip content */
.glossary-tooltip__title {
  padding: 12px 16px 8px;
  font-weight: 600;
  font-size: 16px;
  color: #333;
  border-bottom: 1px solid #eee;
}

/* Add extra padding to title when close button is present */
.glossary-tooltip:has(.glossary-tooltip__close) .glossary-tooltip__title {
  padding-right: 40px;
}

.glossary-tooltip__close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  border-radius: 50%;
  font-size: 18px;
  font-weight: bold;
  line-height: 1;
  color: #666;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.glossary-tooltip__close:hover,
.glossary-tooltip__close:focus {
  background-color: #f5f5f5;
  color: #333;
  outline: none;
}

.glossary-tooltip__close:active {
  background-color: #e0e0e0;
}

.glossary-tooltip__description {
  padding: 12px 16px 16px;
  font-size: 14px;
  line-height: 1.5;
  color: #555;
}

.glossary-tooltip__description p {
  margin: 0 0 8px;
}

.glossary-tooltip__description p:last-child {
  margin-bottom: 0;
}

/* CKEditor 5 autocomplete styles */
.ck-glossary-form {
  min-width: 300px;
}

.ck-glossary-autocomplete {
  max-height: 200px;
  overflow-y: auto;
  margin-top: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
}

.ck-glossary-autocomplete:empty {
  display: none;
}

.ck-glossary-autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid #eee;
  transition: background-color 0.1s ease;
}

.ck-glossary-autocomplete-item:last-child {
  border-bottom: none;
}

.ck-glossary-autocomplete-item:hover,
.ck-glossary-autocomplete-item.selected {
  background-color: #f0f0f0;
}

.ck-glossary-autocomplete-label {
  font-weight: 500;
  color: #333;
  margin-bottom: 2px;
}

.ck-glossary-autocomplete-description {
  font-size: 12px;
  color: #666;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ck-glossary-no-results {
  padding: 12px;
  text-align: center;
  color: #666;
  font-style: italic;
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .glossary-tooltip {
    max-width: calc(100vw - 32px);
  }

  .glossary-link {
    text-decoration-thickness: 2px;
  }
}
