/**
 * Ravenore — reusable “i” help popover (hover, focus-within, click toggle).
 * Pair with static/js/rn-info-tip.js for click + outside close + Escape.
 *
 * UI Phase 7: calmer icon + popover (token borders, single shadow tier); keyboard
 * focus-visible on trigger; no loud gold ring on mouse focus.
 */

.rn-info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  vertical-align: middle;
}

.rn-info-tip__trigger {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
  cursor: help;
  line-height: 0;
  border-radius: 50%;
  outline: none;
}

.rn-info-tip__trigger:focus-visible {
  outline: 2px solid rgba(201, 166, 74, 0.38);
  outline-offset: 2px;
  border-radius: 50%;
}

.rn-info-tip__trigger:focus:not(:focus-visible) {
  outline: none;
}

.rn-info-tip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 1px solid var(--rn-chrome-gold-muted, rgba(201, 166, 74, 0.22));
  font-size: 0.58rem;
  font-weight: 700;
  font-style: italic;
  line-height: 1;
  color: var(--rn-text-muted, #7d8792);
  background: rgba(0, 0, 0, 0.28);
  user-select: none;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.rn-info-tip__trigger:hover .rn-info-tip-icon {
  border-color: var(--rn-chrome-gold-faint, rgba(201, 166, 74, 0.35));
  color: var(--rn-gold-300, #f0d78a);
  background: rgba(0, 0, 0, 0.38);
}

.rn-info-tip__trigger:focus-visible .rn-info-tip-icon {
  border-color: rgba(201, 166, 74, 0.42);
  color: var(--rn-gold-300, #f0d78a);
}

.rn-info-tip-body {
  display: none;
  box-sizing: border-box;
  /* Fallback when JS off: above trigger (may clip inside overflow containers) */
  position: absolute;
  z-index: 200;
  left: 0;
  bottom: calc(100% + 5px);
  width: min(17rem, calc(100vw - 2rem));
  padding: 0.45rem 0.6rem;
  border-radius: var(--rn-radius-md, 10px);
  border: 1px solid var(--rn-divider-strong, rgba(255, 255, 255, 0.08));
  background: var(--rn-bg-elevated, #12151a);
  box-shadow: var(--rn-surface-panel-shadow, 0 2px 12px rgba(0, 0, 0, 0.35));
  font-size: 0.72rem;
  font-weight: 400;
  font-style: normal;
  line-height: 1.42;
  letter-spacing: 0.01em;
  text-transform: none;
  color: var(--rn-text-secondary, #b4bcc6);
  text-align: left;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--rn-scrollbar-thumb) var(--rn-scrollbar-track);
}

.rn-info-tip-body::-webkit-scrollbar {
  width: var(--rn-scrollbar-size, 8px);
  height: var(--rn-scrollbar-size, 8px);
}

.rn-info-tip-body::-webkit-scrollbar-track {
  background: var(--rn-scrollbar-track);
  border-radius: 4px;
}

.rn-info-tip-body::-webkit-scrollbar-thumb {
  background: var(--rn-scrollbar-thumb);
  border-radius: 4px;
}

.rn-info-tip-body::-webkit-scrollbar-thumb:hover {
  background: var(--rn-scrollbar-thumb-hover);
}

/* JS pins popover to viewport — avoids sidebar/panel overflow clipping */
.rn-info-tip-body.rn-info-tip-body--fixed {
  position: fixed !important;
  z-index: 10050 !important;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.14s ease, transform 0.14s ease;
  will-change: opacity, transform;
}

.rn-info-tip-body.rn-info-tip-body--fixed.rn-info-tip-body--shown {
  opacity: 1;
  transform: translateY(0);
  will-change: auto;
}

.rn-info-tip-body p {
  margin: 0 0 0.38rem;
}

.rn-info-tip-body p:last-child {
  margin-bottom: 0;
}

.rn-info-tip-body code {
  font-size: 0.88em;
}

.rn-info-tip--wide .rn-info-tip-body {
  width: min(32rem, calc(100vw - 2rem));
  max-height: min(70vh, 22rem);
}

/* Pop below (toolbar / tight top) */
.rn-info-tip--below .rn-info-tip-body {
  top: calc(100% + 6px);
  bottom: auto;
}

.rn-info-tip:hover .rn-info-tip-body,
.rn-info-tip:focus-within .rn-info-tip-body,
.rn-info-tip.rn-info-tip--open .rn-info-tip-body {
  display: block;
}

/* Escape control-panel overflow so popover isn’t clipped */
.control-panel:has(.rn-info-tip:hover),
.control-panel:has(.rn-info-tip:focus-within),
.control-panel:has(.rn-info-tip--open) {
  overflow: visible;
  position: relative;
  z-index: 30;
}

.digest-main-toolbar:has(.rn-info-tip:hover),
.digest-main-toolbar:has(.rn-info-tip:focus-within),
.digest-main-toolbar:has(.rn-info-tip--open) {
  overflow: visible;
  position: relative;
  z-index: 35;
}

@media (max-width: 1100px) {
  .rn-info-tip-body {
    left: auto;
    right: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .rn-info-tip-icon {
    transition: none;
  }

  .rn-info-tip-body.rn-info-tip-body--fixed {
    transition: none;
    transform: none;
    opacity: 1;
  }

  .rn-info-tip__trigger:focus-visible {
    outline-width: 1px;
  }
}

.rn-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
