/**
 * anchor-tooltips.css
 * Sprint 003 Task 2.2: CSS Anchor-Positioned Tooltips
 * 
 * Pure CSS tooltips using CSS anchor positioning
 * No JavaScript positioning calculations
 * 
 * Features:
 * - anchor-name for dynamic markers
 * - position-try-fallbacks for auto-flip
 * - Pure CSS (no layout thrashing on scroll)
 * 
 * @see memory/nodes/CSS_Anchor_Positioning_2026.md
 */

/* ===== Anchor Positioning ===== */
/* Note: Uses Chrome 125+ features with fallbacks */

/* Tooltip container using anchor positioning */
.anchor-tooltip {
  /* Default: hidden until anchor trigger */
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  
  /* Positioning context */
  position: absolute;
  
  /* Anchor reference - set via inline style on marker */
  position-anchor: --marker-anchor;
  
  /* Position above the anchor */
  inset-area: top;
  
  /* Fallback position if no space */
  position-try-fallbacks: flip-block;
  
  /* Z-index */
  z-index: var(--z-tooltip, 700);
  
  /* Prevent layout shifts */
  contain: layout;
}

/* Show tooltip on marker hover */
.marker-anchor:hover + .anchor-tooltip,
.marker-anchor:focus + .anchor-tooltip {
  opacity: 1;
  visibility: visible;
}

.marker-anchor[data-has-tooltip="true"]:hover + .anchor-tooltip,
.marker-anchor[data-has-tooltip="true"]:focus + .anchor-tooltip {
  opacity: 1;
  visibility: visible;
}

/* ===== Tooltip Styles ===== */
.anchor-tooltip__content {
  background: var(--color-bg-overlay, rgba(0,0,0,0.92));
  backdrop-filter: blur(8px);
  border: 1px solid var(--color-border, rgba(255,255,255,0.1));
  border-radius: var(--radius-md, 8px);
  padding: var(--space-3, 12px);
  min-width: 200px;
  max-width: 320px;
  
  /* Shadow */
  box-shadow: var(--shadow-lg, 0 10px 20px rgba(0,0,0,0.5));
  
  /* Typography */
  font-size: var(--text-sm, 14px);
  color: var(--color-text, #f0f0f0);
  line-height: 1.5;
}

/* Arrow pointing to anchor */
.anchor-tooltip__arrow {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--color-bg-overlay);
  border-left: 1px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  transform: rotate(45deg);
  
  /* Position at bottom center */
  bottom: -6px;
  left: 50%;
  margin-left: -6px;
}

/* When flipped to bottom, arrow position changes */
@supports (position-area: bottom) {
  .anchor-tooltip[position-area="bottom"] .anchor-tooltip__arrow {
    bottom: auto;
    top: -6px;
    border: none;
    border-right: 1px solid var(--color-border);
    border-top: 1px solid var(--color-border);
  }
}

/* ===== Tooltip Content Sections ===== */
.anchor-tooltip__header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 8px);
  margin-bottom: var(--space-2, 8px);
  padding-bottom: var(--space-2, 8px);
  border-bottom: 1px solid var(--color-border);
}

.anchor-tooltip__icon {
  width: 24px;
  height: 24px;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.anchor-tooltip__title {
  font-weight: 600;
  font-size: var(--text-base, 16px);
  flex: 1;
}

.anchor-tooltip__badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full, 999px);
  font-size: var(--text-xs, 10px);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.anchor-tooltip__badge--military {
  background: rgba(220, 38, 38, 0.2);
  color: #fca5a5;
  border: 1px solid #dc2626;
}

.anchor-tooltip__badge--aerospace {
  background: rgba(37, 99, 235, 0.2);
  color: #93c5fd;
  border: 1px solid #2563eb;
}

.anchor-tooltip__badge--civilian {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
  border: 1px solid #22c55e;
}

.anchor-tooltip__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-1, 4px);
}

.anchor-tooltip__row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.anchor-tooltip__label {
  color: var(--color-text-muted, #666);
  font-size: var(--text-xs, 12px);
}

.anchor-tooltip__value {
  font-weight: 500;
}

.anchor-tooltip__connections {
  margin-top: var(--space-2, 8px);
  padding-top: var(--space-2, 8px);
  border-top: 1px solid var(--color-border);
}

.anchor-tooltip__connections-title {
  font-size: var(--text-xs, 12px);
  color: var(--color-text-muted);
  margin-bottom: var(--space-1, 4px);
}

.anchor-tooltip__connection-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1, 4px);
}

.anchor-tooltip__connection-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--color-bg-hover);
  border-radius: var(--radius-sm, 4px);
  font-size: var(--text-xs, 12px);
}

/* ===== Marker Anchor Base ===== */
.marker-anchor {
  position: relative;
  cursor: pointer;
  /* Anchor positioning support */
  anchor-name: --marker-anchor;
}

.marker-anchor::after {
  content: '';
  position: absolute;
  inset: -8px;
  /* Larger touch target without visual change */
}

/* ===== Fallback for browsers without anchor positioning ===== */
@supports not (position-anchor: --marker-anchor) {
  /* Use traditional positioned tooltips */
  .anchor-tooltip {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
  }
  
  /* Flip on edge detection would need JS fallback */
  .anchor-tooltip--flipped {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 8px;
  }
}

/* ===== Theme Support ===== */
[data-theme="light"] .anchor-tooltip__content {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.1);
  color: #0f172a;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .anchor-tooltip__label {
  color: #64748b;
}

[data-theme="geek"] .anchor-tooltip__content {
  background: #0a0a0a;
  border: 1px solid #00ff00;
  color: #00ff00;
  font-family: 'JetBrains Mono', monospace;
  box-shadow: 0 0 20px rgba(0, 255, 0, 0.3);
}

/* ===== Animation ===== */
@keyframes tooltip-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.anchor-tooltip--animated {
  animation: tooltip-in 0.2s ease forwards;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .anchor-tooltip__content {
    min-width: 160px;
    max-width: 280px;
    padding: var(--space-2, 8px);
    font-size: var(--text-xs, 12px);
  }
  
  .anchor-tooltip__title {
    font-size: var(--text-sm, 14px);
  }
}

/* ===== Print ===== */
@media print {
  .anchor-tooltip {
    display: none !important;
  }
}
