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

   CSS-anchored popup with hover/touch activation. Used by the vector widget
   and portfolio heatmap.

   Usage:
     1. Add class `has-popup` to the trigger element (must be position: relative)
     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. Popup shows on :hover or when the trigger has class .active (touch/tap)
     4. JS edge-flip helper in app.js adds .widget-popup--flip-v or
        .widget-popup--flip-h when the popup would overflow the viewport.
   ========================================================================== */

/* --- Base --- */
.widget-popup {
    position: absolute;
    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, transform 200ms ease;
    z-index: 1000;
    backdrop-filter: blur(10px);
    text-align: left;
    cursor: default;
}

/* --- Direction: above the trigger --- */
.widget-popup--top {
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-10px);
    margin-bottom: 10px;
}

.has-popup:hover .widget-popup--top,
.has-popup.active .widget-popup--top {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

/* --- Direction: below the trigger --- */
.widget-popup--bottom {
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    margin-top: 10px;
}

.has-popup:hover .widget-popup--bottom,
.has-popup.active .widget-popup--bottom {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

/* --- Direction: left of the trigger --- */
.widget-popup--left {
    top: 50%;
    right: 100%;
    transform: translateY(-50%) translateX(10px);
    margin-right: 10px;
}

.has-popup:hover .widget-popup--left,
.has-popup.active .widget-popup--left {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    pointer-events: auto;
}

/* --- Direction: right of the trigger --- */
.widget-popup--right {
    top: 50%;
    left: 100%;
    transform: translateY(-50%) translateX(-10px);
    margin-left: 10px;
}

.has-popup:hover .widget-popup--right,
.has-popup.active .widget-popup--right {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
    pointer-events: auto;
}

/* --- Edge-flip: --top overflows viewport top → flip to below --- */
.widget-popup--top.widget-popup--flip-v {
    bottom: auto;
    top: 100%;
    transform: translateX(-50%) translateY(10px);
    margin-bottom: 0;
    margin-top: 10px;
}

.has-popup:hover .widget-popup--top.widget-popup--flip-v,
.has-popup.active .widget-popup--top.widget-popup--flip-v {
    transform: translateX(-50%) translateY(0);
}

/* --- Edge-flip: --bottom overflows viewport bottom → flip to above --- */
.widget-popup--bottom.widget-popup--flip-v {
    top: auto;
    bottom: 100%;
    transform: translateX(-50%) translateY(-10px);
    margin-top: 0;
    margin-bottom: 10px;
}

.has-popup:hover .widget-popup--bottom.widget-popup--flip-v,
.has-popup.active .widget-popup--bottom.widget-popup--flip-v {
    transform: translateX(-50%) translateY(0);
}

/* --- Edge-flip: horizontal overflow → right-align popup to trigger edge --- */
.widget-popup--top.widget-popup--flip-h,
.widget-popup--bottom.widget-popup--flip-h {
    left: auto;
    right: 0;
    transform: translateX(0) translateY(-10px);
}

.has-popup:hover .widget-popup--top.widget-popup--flip-h,
.has-popup.active .widget-popup--top.widget-popup--flip-h {
    transform: translateX(0) translateY(0);
}

.has-popup:hover .widget-popup--bottom.widget-popup--flip-h,
.has-popup.active .widget-popup--bottom.widget-popup--flip-h {
    transform: translateX(0) translateY(0);
}

/* ==========================================================================
   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: 1.1em;
    font-weight: bold;
    display: block;
    margin-bottom: 4px;
    color: #fff;
}

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

.widget-popup-body {
    font-size: 0.9em;
    line-height: 1.6;
    color: #fff;
}

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

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

.widget-popup-label {
    font-size: 0.85em;
    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: 0.85em;
    margin-top: 10px;
}

.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: "⚠️ ";
}

.widget-popup-more {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
    font-style: italic;
    margin-top: 0.5rem;
    padding-left: 1rem;
}

/* 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: 0.875em;
}

.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);
}

