/**
 * Nexus Node Panel Styles
 * =======================
 * Floating slide-in panel for Nexus Pathway graph interactions.
 * Positioned within the canvas with proper spacing from edges.
 */

/* ========================================
   BACKDROP
   ======================================== */

.nexus-panel-backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    pointer-events: none; /* Allow clicks through to canvas */
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.nexus-panel-backdrop.active {
    opacity: 1;
    visibility: visible;
    /* Keep pointer-events: none so graph remains interactive */
}

/* ========================================
   PANEL CONTAINER - Floating within canvas
   ======================================== */

.nexus-panel {
    position: fixed;
    top: var(--space-6);
    right: var(--space-4);
    bottom: var(--space-6);
    width: 400px;
    max-width: calc(100vw - var(--space-8));
    background: var(--color-background-primary);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-2xl);
    z-index: 9999;
    transform: translateX(calc(100% + var(--space-4)));
    transition: transform var(--transition-normal);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    pointer-events: auto; /* Panel captures events even though backdrop doesn't */
}

.nexus-panel.active {
    transform: translateX(0);
}

/* ========================================
   PANEL HEADER - Identity Section
   ======================================== */

.nexus-panel-header {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-5);
    padding-right: var(--space-12);
    background: var(--color-background-secondary);
    border-bottom: 1px solid var(--color-border-primary);
}

.nexus-header-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3);
}

.nexus-header-identity {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    flex: 1;
    min-width: 0;
}

.nexus-company-name-large {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    margin: 0;
    line-height: var(--line-height-tight);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nexus-header-subtitle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
}

.nexus-ticker-badge {
    font-family: var(--font-mono);
    font-weight: var(--font-weight-semibold);
    color: var(--color-interactive-primary);
}

.nexus-subtitle-separator {
    color: var(--color-text-muted);
}

.nexus-industry-text {
    color: var(--color-text-muted);
}

.nexus-header-price {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: var(--space-1);
    flex-shrink: 0;
}

.nexus-price-value {
    font-size: var(--font-size-xl);
    font-weight: var(--font-weight-bold);
    font-family: var(--font-mono);
    color: var(--color-text-primary);
    line-height: 1;
}

.nexus-price-change {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    font-family: var(--font-mono);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
}

.nexus-price-change.positive {
    color: var(--color-signal-success);
    background: var(--color-signal-success-subtle);
}

.nexus-price-change.negative {
    color: var(--color-signal-danger);
    background: var(--color-signal-danger-subtle);
}

.nexus-price-change.neutral {
    color: var(--color-text-muted);
    background: var(--color-background-tertiary);
}

/* Trend icon inside price change badge */
.nexus-trend-icon {
    width: 14px;
    height: 14px;
    stroke-width: 2.5;
}

.nexus-price-change.positive .nexus-trend-icon {
    color: var(--color-signal-success);
}

.nexus-price-change.negative .nexus-trend-icon {
    color: var(--color-signal-danger);
}

.nexus-price-change.neutral .nexus-trend-icon {
    color: var(--color-text-muted);
}

/* ========================================
   CLOSE BUTTON
   ======================================== */

.nexus-panel-close {
    position: absolute;
    top: var(--space-4);
    right: var(--space-4);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-background-primary);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    z-index: 10;
    transition: all var(--transition-fast);
}

.nexus-panel-close:hover {
    background: var(--color-background-tertiary);
    border-color: var(--color-border-secondary);
}

.nexus-panel-close svg {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
}

/* ========================================
   LOADING STATE
   ======================================== */

.nexus-panel-loading {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    padding: var(--space-6);
}

.nexus-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--color-border-primary);
    border-top-color: var(--color-interactive-primary);
    border-radius: 50%;
    animation: nexus-spin 0.8s linear infinite;
}

.nexus-loading-spinner-small {
    width: 18px;
    height: 18px;
    border: 2px solid var(--color-border-primary);
    border-top-color: var(--color-interactive-primary);
    border-radius: 50%;
    animation: nexus-spin 0.8s linear infinite;
}

@keyframes nexus-spin {
    to { transform: rotate(360deg); }
}

.nexus-panel-loading p {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin: 0;
}

/* ========================================
   CONTENT CONTAINER
   ======================================== */

.nexus-panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
}

/* ========================================
   CONTENT SECTIONS
   ======================================== */

.nexus-section {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-primary);
}

.nexus-section:last-of-type {
    border-bottom: none;
}

.nexus-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
}

.nexus-section-icon {
    width: 16px;
    height: 16px;
    color: var(--color-text-muted);
}

.nexus-section-icon.nexus-icon-accent {
    color: var(--color-interactive-primary);
}

.nexus-section-title {
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

/* ========================================
   RIPPLI INSIGHT SECTION
   ======================================== */

.nexus-insight-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.nexus-insight-generate-prompt {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--color-background-secondary);
    border-radius: var(--radius-md);
    border: 1px dashed var(--color-border-secondary);
    text-align: center;
}

.nexus-insight-prompt-text {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    margin: 0;
    line-height: var(--line-height-relaxed);
}

.nexus-btn-generate {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: white;
    background: var(--color-interactive-primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.nexus-btn-generate:hover {
    background: var(--color-interactive-primary-hover);
}

.nexus-btn-generate svg {
    width: 16px;
    height: 16px;
}

.nexus-insight-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-6);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

.nexus-insight-auth-required {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-6);
    text-align: center;
    background: var(--color-surface-alt);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
}

.nexus-auth-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-accent);
    border-radius: var(--radius-full);
}

.nexus-auth-icon svg {
    width: 24px;
    height: 24px;
    color: var(--color-accent-contrast);
}

.nexus-auth-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text);
    margin: 0;
}

.nexus-auth-description {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    line-height: var(--lh-body);
    margin: 0;
    max-width: 280px;
}

.nexus-auth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: var(--btn-accent-gradient);
    color: var(--color-accent-contrast);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    border-radius: var(--button-radius);
    text-decoration: none;
    transition: var(--transition-base);
    margin-top: var(--space-2);
}

.nexus-auth-btn:hover {
    background: var(--color-accent-hover);
    transform: translateY(-1px);
    color: var(--color-accent-contrast);
}

.nexus-auth-btn svg {
    width: 16px;
    height: 16px;
}

/* Insight Content Blocks */
.nexus-insight-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.nexus-insight-block {
    padding: var(--space-4);
    background: var(--color-background-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-primary);
}

.nexus-insight-block-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-secondary);
    margin: 0 0 var(--space-2) 0;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.nexus-insight-block-title svg {
    width: 14px;
    height: 14px;
    color: var(--color-text-muted);
}

.nexus-insight-block-text {
    font-size: var(--font-size-sm);
    line-height: 1.7;
    color: var(--color-text-primary);
    margin: 0;
    letter-spacing: 0.01em;
}

/* Improved paragraph spacing within insight text */
.nexus-insight-block-text p {
    margin: 0 0 var(--space-3) 0;
}

.nexus-insight-block-text p:last-child {
    margin-bottom: 0;
}

/* Better visual separation for financial metrics inline */
.nexus-insight-block-text strong {
    color: var(--color-text-primary);
    font-weight: var(--font-weight-semibold);
    background: var(--color-background-tertiary);
    padding: 0.1em 0.3em;
    border-radius: var(--radius-xs);
}

.nexus-insight-list {
    margin: 0;
    padding-left: var(--space-4);
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
    color: var(--color-text-secondary);
}

.nexus-insight-list li {
    margin-bottom: var(--space-1);
}

.nexus-insight-list li:last-child {
    margin-bottom: 0;
}

.nexus-insight-empty {
    color: var(--color-text-muted);
    font-style: italic;
    list-style: none;
    margin-left: calc(-1 * var(--space-4));
}

/* Relationship Analysis Section */
.nexus-relationship-analysis {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.nexus-connected-tickers {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.nexus-connected-ticker-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    font-family: var(--font-mono);
    font-weight: var(--font-weight-medium);
    color: var(--color-interactive-primary);
    background: var(--color-interactive-primary-subtle);
    border-radius: var(--radius-sm);
}

.nexus-connected-ticker-badge svg {
    width: 12px;
    height: 12px;
}

.nexus-connected-ticker-badge.high-confidence {
    background: var(--color-interactive-primary);
    color: white;
    border: 1px solid var(--color-interactive-primary-hover);
}

.nexus-connected-ticker-badge.high-confidence svg {
    stroke: white;
}

/* Relationship narrative styling */
.nexus-insight-block-text em {
    display: block;
    margin-top: var(--space-2);
    padding-top: var(--space-2);
    border-top: 1px solid var(--color-border-secondary);
    color: var(--color-text-muted);
    font-style: italic;
}

/* Loading text animation */
.nexus-loading-text {
    color: var(--color-text-muted);
    font-style: italic;
}

.nexus-loading-text::after {
    content: '';
    animation: nexus-loading-dots 1.5s infinite;
}

@keyframes nexus-loading-dots {
    0%, 20% { content: ''; }
    40% { content: '.'; }
    60% { content: '..'; }
    80%, 100% { content: '...'; }
}

/* Risk Factors styling */
.nexus-insight-risks .nexus-insight-block-title svg {
    color: var(--color-signal-warning);
}

/* Opportunities styling */
.nexus-insight-opportunities .nexus-insight-block-title svg {
    color: var(--color-signal-success);
}

/* Recommended Actions - special styling */
.nexus-insight-actions-list {
    list-style: none;
    padding-left: 0;
}

.nexus-insight-actions-list li {
    position: relative;
    padding-left: var(--space-5);
}

.nexus-insight-actions-list li::before {
    content: "→";
    position: absolute;
    left: 0;
    color: var(--color-interactive-primary);
    font-weight: var(--font-weight-bold);
}

/* Sentiment Display */
.nexus-sentiment-display {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.nexus-sentiment-label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-semibold);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    text-transform: capitalize;
}

.nexus-sentiment-label.positive {
    color: var(--color-signal-success);
    background: var(--color-signal-success-subtle);
}

.nexus-sentiment-label.negative {
    color: var(--color-signal-danger);
    background: var(--color-signal-danger-subtle);
}

.nexus-sentiment-label.neutral {
    color: var(--color-text-muted);
    background: var(--color-background-tertiary);
}

.nexus-sentiment-bar {
    flex: 1;
    height: 8px;
    background: var(--color-background-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.nexus-sentiment-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width var(--transition-normal);
    background: var(--color-text-muted);
}

.nexus-sentiment-fill.positive {
    background: var(--color-signal-success);
}

.nexus-sentiment-fill.negative {
    background: var(--color-signal-danger);
}

.nexus-sentiment-fill.neutral {
    background: var(--color-text-muted);
}

/* Error & Retry */
.nexus-insight-error {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-4);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
}

.nexus-retry-btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    color: var(--color-interactive-primary);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast);
}

.nexus-retry-btn:hover {
    background: var(--color-interactive-primary-subtle);
}

.nexus-retry-btn svg {
    width: 12px;
    height: 12px;
}

/* ========================================
   ACTION BUTTONS
   ======================================== */

.nexus-panel-actions {
    display: flex;
    gap: var(--space-2);
    padding: var(--space-4) var(--space-5);
    background: var(--color-background-secondary);
    border-top: 1px solid var(--color-border-primary);
    margin-top: auto;
    flex-shrink: 0;
}

.nexus-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-2);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid var(--color-border-primary);
    background: var(--color-background-primary);
    color: var(--color-text-primary);
}

.nexus-btn svg {
    width: 16px;
    height: 16px;
    color: var(--color-text-secondary);
    flex-shrink: 0;
}

.nexus-btn:hover {
    background: var(--color-background-tertiary);
    border-color: var(--color-border-secondary);
}

.nexus-btn-primary {
    background: var(--color-interactive-primary);
    border-color: var(--color-interactive-primary);
    color: white;
}

.nexus-btn-primary svg {
    color: white;
}

.nexus-btn-primary:hover {
    background: var(--color-interactive-primary-hover);
    border-color: var(--color-interactive-primary-hover);
}

.nexus-btn-watchlist:hover svg {
    color: var(--color-signal-warning);
}

.nexus-btn-explore:hover svg {
    color: var(--color-interactive-primary);
}

.nexus-btn-watchlist.active {
    background: color-mix(in srgb, var(--color-signal-warning) 15%, var(--color-background-primary));
    border-color: var(--color-signal-warning);
}

.nexus-btn-watchlist.active svg {
    color: var(--color-signal-warning);
    fill: var(--color-signal-warning);
}

/* ========================================
   UTILITY
   ======================================== */

.hidden {
    display: none !important;
}

/* ========================================
   RESPONSIVE
   ======================================== */

@media (max-width: 1024px) {
    .nexus-panel {
        width: 360px;
    }
}

@media (max-width: 768px) {
    .nexus-panel {
        width: 320px;
        top: var(--space-4);
        right: var(--space-3);
        bottom: var(--space-4);
    }
    
    .nexus-panel-header {
        padding: var(--space-4);
        padding-right: var(--space-10);
    }
    
    .nexus-company-name-large {
        font-size: var(--font-size-md);
    }
    
    .nexus-price-value {
        font-size: var(--font-size-lg);
    }
    
    .nexus-section {
        padding: var(--space-3) var(--space-4);
    }
    
    .nexus-panel-actions {
        padding: var(--space-3) var(--space-4);
        flex-wrap: wrap;
    }
    
    .nexus-btn {
        padding: var(--space-2);
        font-size: var(--font-size-xs);
    }
}

@media (max-width: 480px) {
    .nexus-panel {
        top: var(--space-4);
        right: var(--space-2);
        bottom: var(--space-4);
        left: var(--space-2);
        width: auto;
        max-width: none;
        transform: translateY(100%);
    }
    
    .nexus-panel.active {
        transform: translateY(0);
    }
    
    .nexus-insight-grid {
        grid-template-columns: 1fr;
    }
    
    .nexus-header-top {
        flex-direction: column;
        gap: var(--space-2);
    }
    
    .nexus-header-price {
        align-items: flex-start;
        flex-direction: row;
        gap: var(--space-3);
    }
}

@media (max-width: 360px) {
    .nexus-panel-header {
        padding: var(--space-3);
        padding-right: var(--space-8);
    }
    
    .nexus-section {
        padding: var(--space-2) var(--space-3);
    }
    
    .nexus-insight-block {
        padding: var(--space-3);
    }
}
