/* @section:tooltip - General Purpose Tooltip System with Edge Detection */

/* ============================================
   BASE TOOLTIP CONTAINER
   ============================================ */

[data-tooltip] {
  position: relative;
  cursor: help;
}

/* ============================================
   TOOLTIP POPUP - Core Styles
   ============================================ */

.tooltip {
  position: absolute;
  width: max-content;
  max-width: 280px;
  padding: 8px 12px;
  background: #1e293b;
  color: #94a3b8;
  font-size: var(--t-sm);
  line-height: 1.5;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
  white-space: normal;
  text-transform: none;
  font-weight: 400;
}

/* Arrow base */
.tooltip::before {
  content: '';
  position: absolute;
  border: 6px solid transparent;
}

/* Active state */
.tooltip.active,
[data-tooltip]:hover .tooltip,
[data-tooltip]:focus .tooltip {
  opacity: 1;
  visibility: visible;
}

/* Interactive tooltip (can be hovered/clicked) */
.tooltip.interactive {
  pointer-events: auto;
}

/* ============================================
   TOOLTIP SIZES
   ============================================ */

.tooltip.tooltip-sm {
  max-width: 180px;
  padding: 6px 10px;
  font-size: var(--t-xs);
}

.tooltip.tooltip-lg {
  max-width: 360px;
  padding: 12px 16px;
  font-size: var(--t-base);
}

.tooltip.tooltip-xl {
  max-width: 440px;
  padding: 14px 18px;
}

/* ============================================
   POSITION: BOTTOM (Default)
   Arrow points up, tooltip below trigger
   ============================================ */

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

.tooltip::before,
.tooltip.tooltip-bottom::before {
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-color: #1e293b;
}

/* ============================================
   POSITION: TOP
   Arrow points down, tooltip above trigger
   ============================================ */

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

.tooltip.tooltip-top::before {
  top: 100%;
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-color: transparent;
  border-top-color: #1e293b;
}

/* ============================================
   POSITION: LEFT
   Arrow points right, tooltip left of trigger
   ============================================ */

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

.tooltip.tooltip-left::before {
  left: 100%;
  right: auto;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-left-color: #1e293b;
}

/* ============================================
   POSITION: RIGHT
   Arrow points left, tooltip right of trigger
   ============================================ */

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

.tooltip.tooltip-right::before {
  right: 100%;
  left: auto;
  top: 50%;
  bottom: auto;
  transform: translateY(-50%);
  border-bottom-color: transparent;
  border-right-color: #1e293b;
}

/* ============================================
   ALIGNMENT MODIFIERS
   Fine-tune horizontal/vertical alignment
   ============================================ */

/* Bottom/Top - align left */
.tooltip.tooltip-align-start {
  left: 0;
  transform: none;
}

.tooltip.tooltip-align-start::before {
  left: 16px;
  transform: none;
}

/* Bottom/Top - align right */
.tooltip.tooltip-align-end {
  left: auto;
  right: 0;
  transform: none;
}

.tooltip.tooltip-align-end::before {
  left: auto;
  right: 16px;
  transform: none;
}

/* Left/Right - align top */
.tooltip.tooltip-left.tooltip-align-start,
.tooltip.tooltip-right.tooltip-align-start {
  top: 0;
  transform: none;
}

.tooltip.tooltip-left.tooltip-align-start::before,
.tooltip.tooltip-right.tooltip-align-start::before {
  top: 12px;
  transform: none;
}

/* Left/Right - align bottom */
.tooltip.tooltip-left.tooltip-align-end,
.tooltip.tooltip-right.tooltip-align-end {
  top: auto;
  bottom: 0;
  transform: none;
}

.tooltip.tooltip-left.tooltip-align-end::before,
.tooltip.tooltip-right.tooltip-align-end::before {
  top: auto;
  bottom: 12px;
  transform: none;
}

/* ============================================
   CORNER POSITIONS
   For elements near viewport corners
   ============================================ */

/* Bottom-left corner: tooltip goes right */
.tooltip.tooltip-bottom-start {
  top: calc(100% + 8px);
  left: 0;
  transform: none;
}

.tooltip.tooltip-bottom-start::before {
  bottom: 100%;
  left: 12px;
  transform: none;
  border-bottom-color: #1e293b;
}

/* Bottom-right corner: tooltip goes left */
.tooltip.tooltip-bottom-end {
  top: calc(100% + 8px);
  left: auto;
  right: 0;
  transform: none;
}

.tooltip.tooltip-bottom-end::before {
  bottom: 100%;
  left: auto;
  right: 12px;
  transform: none;
  border-bottom-color: #1e293b;
}

/* Top-left corner */
.tooltip.tooltip-top-start {
  bottom: calc(100% + 8px);
  top: auto;
  left: 0;
  transform: none;
}

.tooltip.tooltip-top-start::before {
  top: 100%;
  bottom: auto;
  left: 12px;
  transform: none;
  border-top-color: #1e293b;
  border-bottom-color: transparent;
}

/* Top-right corner */
.tooltip.tooltip-top-end {
  bottom: calc(100% + 8px);
  top: auto;
  left: auto;
  right: 0;
  transform: none;
}

.tooltip.tooltip-top-end::before {
  top: 100%;
  bottom: auto;
  left: auto;
  right: 12px;
  transform: none;
  border-top-color: #1e293b;
  border-bottom-color: transparent;
}

/* ============================================
   TOOLTIP CONTENT STYLING
   ============================================ */

.tooltip-title {
  font-weight: 600;
  color: #e2e8f0;
  margin-bottom: 4px;
  font-size: 1.1em;
}

.tooltip-text {
  color: #94a3b8;
}

.tooltip-text strong {
  color: #cbd5e1;
  font-weight: 600;
}

.tooltip-divider {
  height: 1px;
  background: #334155;
  margin: 8px 0;
}

.tooltip-footer {
  font-size: 0.9em;
  color: #64748b;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid #334155;
}

/* ============================================
   COLOR VARIANTS
   ============================================ */

/* Info - Blue */
.tooltip.tooltip-info {
  background: #1e3a5f;
  border: 1px solid #3b82f6;
}

.tooltip.tooltip-info::before {
  border-bottom-color: #1e3a5f;
}

.tooltip.tooltip-info.tooltip-top::before {
  border-top-color: #1e3a5f;
  border-bottom-color: transparent;
}

.tooltip.tooltip-info.tooltip-left::before {
  border-left-color: #1e3a5f;
  border-bottom-color: transparent;
}

.tooltip.tooltip-info.tooltip-right::before {
  border-right-color: #1e3a5f;
  border-bottom-color: transparent;
}

/* Success - Green */
.tooltip.tooltip-success {
  background: #14532d;
  border: 1px solid #10b981;
}

.tooltip.tooltip-success::before {
  border-bottom-color: #14532d;
}

.tooltip.tooltip-success.tooltip-top::before {
  border-top-color: #14532d;
  border-bottom-color: transparent;
}

/* Warning - Yellow */
.tooltip.tooltip-warning {
  background: #713f12;
  border: 1px solid #f59e0b;
}

.tooltip.tooltip-warning::before {
  border-bottom-color: #713f12;
}

.tooltip.tooltip-warning.tooltip-top::before {
  border-top-color: #713f12;
  border-bottom-color: transparent;
}

/* Danger - Red */
.tooltip.tooltip-danger {
  background: #7f1d1d;
  border: 1px solid #ef4444;
}

.tooltip.tooltip-danger::before {
  border-bottom-color: #7f1d1d;
}

.tooltip.tooltip-danger.tooltip-top::before {
  border-top-color: #7f1d1d;
  border-bottom-color: transparent;
}

/* ============================================
   TRIGGER ICON STYLES
   ============================================ */

.tooltip-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  background: #475569;
  color: #fff;
  border-radius: 50%;
  font-size: var(--t-2xs);
  font-weight: 700;
  cursor: help;
  opacity: 0.5;
  transition: opacity 0.15s ease;
  vertical-align: middle;
  margin-left: 4px;
}

.tooltip-trigger:hover {
  opacity: 0.8;
}

/* Smaller trigger */
.tooltip-trigger.tooltip-trigger-sm {
  width: 11px;
  height: 11px;
  font-size: var(--t-3xs);
  margin-left: 3px;
}

/* ============================================
   ANIMATION VARIANTS
   ============================================ */

/* Fade + scale */
.tooltip.tooltip-animate {
  transform-origin: center top;
  opacity: 0;
  transform: translateX(-50%) scale(0.95);
}

.tooltip.tooltip-animate.active,
[data-tooltip]:hover .tooltip.tooltip-animate {
  transform: translateX(-50%) scale(1);
}

.tooltip.tooltip-top.tooltip-animate {
  transform-origin: center bottom;
}

.tooltip.tooltip-left.tooltip-animate {
  transform-origin: right center;
  transform: translateY(-50%) scale(0.95);
}

.tooltip.tooltip-left.tooltip-animate.active,
[data-tooltip]:hover .tooltip.tooltip-left.tooltip-animate {
  transform: translateY(-50%) scale(1);
}

.tooltip.tooltip-right.tooltip-animate {
  transform-origin: left center;
  transform: translateY(-50%) scale(0.95);
}

.tooltip.tooltip-right.tooltip-animate.active,
[data-tooltip]:hover .tooltip.tooltip-right.tooltip-animate {
  transform: translateY(-50%) scale(1);
}

/* ============================================
   DELAY VARIANTS
   ============================================ */

.tooltip.tooltip-delay {
  transition-delay: 0.3s;
}

.tooltip.tooltip-delay-long {
  transition-delay: 0.5s;
}

/* ============================================
   NO ARROW VARIANT
   ============================================ */

.tooltip.tooltip-no-arrow::before {
  display: none;
}

/* ============================================
   FIXED/PORTAL TOOLTIP
   For JS-controlled positioning
   ============================================ */

.tooltip.tooltip-fixed {
  position: fixed;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  transform: none;
}

/* JS will set data-position for arrow direction */
.tooltip.tooltip-fixed[data-position="top"]::before {
  top: 100%;
  bottom: auto;
  left: 50%;
  transform: translateX(-50%);
  border-top-color: #1e293b;
  border-bottom-color: transparent;
  border-left-color: transparent;
  border-right-color: transparent;
}

.tooltip.tooltip-fixed[data-position="bottom"]::before {
  bottom: 100%;
  top: auto;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-color: #1e293b;
  border-top-color: transparent;
  border-left-color: transparent;
  border-right-color: transparent;
}

.tooltip.tooltip-fixed[data-position="left"]::before {
  left: 100%;
  right: auto;
  top: 50%;
  transform: translateY(-50%);
  border-left-color: #1e293b;
  border-right-color: transparent;
  border-top-color: transparent;
  border-bottom-color: transparent;
}

.tooltip.tooltip-fixed[data-position="right"]::before {
  right: 100%;
  left: auto;
  top: 50%;
  transform: translateY(-50%);
  border-right-color: #1e293b;
  border-left-color: transparent;
  border-top-color: transparent;
  border-bottom-color: transparent;
}

/* ============================================
   PORTAL TOOLTIP SYSTEM
   Used by tooltip-position.js for dynamic positioning
   ============================================ */

/* Hide original tooltip when JS portal is active */
.tooltip-hidden,
.tooltip-active .tip-popup,
.tooltip-active .tooltip-content,
.tooltip-active .tooltip,
.tooltip-active:hover .tip-popup,
.tooltip-active:hover .tooltip-content,
.tooltip-active:hover .tooltip,
.macro-tooltip.tooltip-active:hover .tooltip-content,
.teaching-tooltip.tooltip-active:hover .tip-popup,
.opt-stat.tooltip-active:hover .tip-popup {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

/* ============================================
   PORTAL TOOLTIP ARROW CLASSES
   ============================================ */

/* Ensure portal tooltips have proper styling */
#tooltip-portal .tip-popup,
#tooltip-portal .tooltip-content,
#tooltip-portal .tooltip {
  background: #1e293b !important;
  color: #94a3b8 !important;
  padding: 10px 12px !important;
  border-radius: 6px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3) !important;
  font-size: var(--t-xs) !important;
  line-height: 1.5 !important;
}

#tooltip-portal .tip-title,
#tooltip-portal .tooltip-title {
  font-weight: 600 !important;
  color: #e2e8f0 !important;
  margin-bottom: 4px !important;
  font-size: var(--t-sm) !important;
}

#tooltip-portal .tip-text,
#tooltip-portal .tooltip-text,
#tooltip-portal .tip-detail {
  color: #94a3b8 !important;
}

/* Ensure arrow exists on portal tooltips */
#tooltip-portal .tip-popup::before,
#tooltip-portal .tooltip-content::before,
#tooltip-portal .tooltip::before {
  content: '';
  position: absolute;
  border: 6px solid transparent;
}

/* Arrow pointing up (tooltip below trigger) */
.arrow-bottom::before,
.tip-popup.arrow-bottom::before,
.tooltip-content.arrow-bottom::before,
.tooltip.arrow-bottom::before {
  bottom: 100% !important;
  top: auto !important;
  left: var(--arrow-left, 50%) !important;
  right: auto !important;
  transform: translateX(-50%) !important;
  border-bottom-color: #1e293b !important;
  border-top-color: transparent !important;
  border-left-color: transparent !important;
  border-right-color: transparent !important;
}

/* Arrow pointing down (tooltip above trigger) */
.arrow-top::before,
.tip-popup.arrow-top::before,
.tooltip-content.arrow-top::before,
.tooltip.arrow-top::before {
  top: 100% !important;
  bottom: auto !important;
  left: var(--arrow-left, 50%) !important;
  right: auto !important;
  transform: translateX(-50%) !important;
  border-top-color: #1e293b !important;
  border-bottom-color: transparent !important;
  border-left-color: transparent !important;
  border-right-color: transparent !important;
}

/* ============================================
   RESPONSIVE / MOBILE - Force full width tooltips
   ============================================ */

/* Force ALL tooltips to be properly contained - centered */
#tooltip-portal > * {
  position: fixed !important;
  left: 50% !important;
  right: auto !important;
  transform: translateX(-50%) !important;
  width: max-content !important;
  max-width: min(400px, calc(100vw - 20px)) !important;
  margin: 0 !important;
  box-sizing: border-box !important;
}

@media (max-width: 768px) {
  /* On mobile - full width centered with padding */
  #tooltip-portal > * {
    left: 50% !important;
    right: auto !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 20px) !important;
    max-width: calc(100vw - 20px) !important;
    box-sizing: border-box !important;
  }
}
