/* ==========================================================================
   SHARED WIDGET POPUP COMPONENT

   JS-positioned fixed popup with hover/touch activation. Used by the vector
   widget, portfolio heatmap, and info tooltips.

   Usage:
     1. Add class `has-popup` to the trigger element
     2. Inside the trigger, place a .widget-popup element with a direction modifier:
          .widget-popup--top    (popup appears above the trigger)
          .widget-popup--bottom (popup appears below the trigger)
          .widget-popup--left   (popup appears to the left of the trigger)
          .widget-popup--right  (popup appears to the right of the trigger)
     3. Add .widget-popup--compact for small inline tooltips (e.g. info icons)
     4. Popup shows on :hover or when the trigger has class .active (touch/tap)
     5. JS in app.js positions the popup as position:fixed on mouseenter so it
        always renders on top, even inside overflow:hidden containers.
   ========================================================================== */

/* --- Trigger base --- */
.has-popup {
  position: relative;
}

/* --- Base --- */
.widget-popup {
  position: fixed;
  top: -9999px;
  left: -9999px;
  min-width: min(260px, calc(100vw - 32px));
  max-width: min(300px, calc(100vw - 32px));
  background: linear-gradient(135deg, #1e2545 0%, #2a3153 100%);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.1);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease;
  z-index: 9999;
  backdrop-filter: blur(10px);
  text-align: left;
  cursor: default;
  color: rgba(255, 255, 255, 0.9);
}

/* Override the global `* { color: var(--color-dark) }` wildcard in app.css.
   Without this, unclassed elements (strong, span, div, etc.) inside the popup
   receive navy text (#1D3354) on a navy background and become invisible.
   A class selector (0,1,0) beats the wildcard (0,0,0); child-specific
   rules defined below retain their own colors because they follow in source order. */
.widget-popup * {
  color: inherit;
}

/* --- Show when JS adds .is-visible (popup is appended to document.body) --- */
.widget-popup.is-visible {
  opacity: 1;
  pointer-events: auto;
}

/* --- Direction modifier classes are read by JS to determine placement --- */
/* .widget-popup--top | --bottom | --left | --right */

/* ==========================================================================
   POPUP CONTENT STRUCTURE
   ========================================================================== */

.widget-popup-header {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.widget-popup-title {
  font-size: var(--text-base);
  font-weight: bold;
  display: block;
  margin-bottom: 4px;
  color: #fff;
}

.widget-popup-subtitle {
  font-size: var(--text-xs);
  color: var(--color-on-dark-secondary, rgba(255, 255, 255, 0.7));
  display: block;
}

.widget-popup-body {
  font-size: var(--text-sm);
  line-height: 1.6;
  color: #fff;
  max-height: min(400px, calc(100vh - 100px));
  overflow-y: auto;
  /* Prevents the last text line from sitting exactly at the scroll boundary */
  padding-bottom: 4px;
}

.widget-popup-section {
  margin-bottom: 12px;
}

.widget-popup-section:last-child {
  margin-bottom: 0;
}

.widget-popup-label {
  font-size: var(--text-xs);
  color: var(--color-on-dark-muted, rgba(255, 255, 255, 0.6));
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.widget-popup-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.widget-popup-list li {
  padding-left: 16px;
  position: relative;
  margin-bottom: 4px;
  color: rgba(255, 255, 255, 0.9);
}

.widget-popup-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: #4cd7a5;
}

.widget-popup-insight {
  background: rgba(76, 215, 165, 0.1);
  border-left: 3px solid #4cd7a5;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: var(--text-xs);
  margin-top: 10px;
  color: rgba(255, 255, 255, 0.9);
}

.widget-popup-insight::before {
  content: "💡 ";
}

.widget-popup-warning {
  background: rgba(255, 171, 0, 0.1);
  border-left: 3px solid #FFAB00;
  color: #FFAB00;
}

.widget-popup-warning::before {
  content: "⚠️ ";
}

/* Ghost pill button — reveals hidden attention items on click */
.widget-popup-more-toggle {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: var(--text-xs);
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    transition: background 150ms ease, border-color 150ms ease, color 150ms ease, opacity 200ms ease;
    margin-top: 8px;
    font-family: inherit;
}

.widget-popup-more-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.9);
}

.widget-popup-more-chevron {
    display: inline-block;
    transition: transform 200ms ease;
    font-style: normal;
}

.widget-popup-more-toggle:hover .widget-popup-more-chevron {
    transform: rotate(90deg);
}

.widget-popup-more-toggle.is-hidden {
    display: none;
}

/* Close button — top-right corner of the popup */
.widget-popup-close {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.35);
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-base);
    line-height: 1;
    border-radius: 4px;
    transition: color 150ms ease, background 150ms ease;
    font-family: inherit;
}

.widget-popup-close:hover {
    color: rgba(255, 255, 255, 0.9);
    background: rgba(255, 255, 255, 0.08);
}

/* Pull title away from close button */
.widget-popup-title {
    padding-right: 20px;
}


/* Key-value rows — used by the heatmap cell popup */
.widget-popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: var(--text-sm);
}

.widget-popup-row:last-child {
  margin-bottom: 0;
}

.widget-popup-row-label {
  color: rgba(255, 255, 255, 0.65);
}

.widget-popup-row-value {
  color: #fff;
  font-weight: 600;
  text-align: right;
  margin-left: 1rem;
}

.widget-popup-row-value.positive {
  color: var(--color-positive, #36E0A0);
}

.widget-popup-row-value.negative {
  color: var(--color-negative, #EF4444);
}

/* --- Compact modifier: smaller tooltip style for inline info icons --- */
.widget-popup--compact {
  min-width: min(200px, calc(100vw - 32px));
  max-width: min(260px, calc(100vw - 32px));
  padding: 10px 12px;
  border-radius: 8px;
  font-size: var(--text-xs);
  font-weight: 400;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.9);
}

.widget-popup--compact .widget-popup-body {
  font-size: var(--text-xs);
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.9);
}

/* --- Info-tip trigger: inline icon that opens a compact tooltip --- */
.info-tip {
  display: inline-flex;
  align-items: center;
  cursor: help;
  color: var(--bs-secondary);
  font-size: var(--text-xs);
  margin-left: 0.35rem;
  vertical-align: middle;
}
