/**
 * Bengal SSG - Contextual Graph Minimap Component Styles
 *
 * Styles for the contextual graph minimap shown in the sidebar above TOC.
 * Shows only connections to the current page (like Obsidian's contextual graph).
 *
 * Loading Strategy (v3):
 * - Reserve a fixed square (200px) immediately so layout does not grow later
 * - JS adds .graph-has-data when valid graph data is found
 * - Graph contents fade in instead of resizing the container
 * - JS still hides the component entirely when data is missing
 */

/* Contextual Minimap Container */
.graph-contextual {
    width: 100%;
    height: 200px;
    min-height: 200px;
    overflow: hidden;
    position: relative;
    /* Breathing room from parent's scrollbar (docs-toc overflow-y: auto) */
    padding-inline-end: 0.5rem;
    box-sizing: border-box;
    margin-bottom: var(--space-6);
    flex-shrink: 0;
}

/* Loading state - reserve space so layout doesn't collapse before JS loads */
.graph-contextual-container.graph-loading {
    display: flex;
    opacity: 0.5;
    /* Explicit min-height - height:100% can fail when parent is in flex/scroll context */
    min-height: 200px;
}

.graph-contextual-container {
    position: relative;
    width: 100%;
    height: 100%; /* Takes full height of parent (200px) */
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden; /* Changed from auto to hidden - zoom handles panning */
    background: var(--color-bg-secondary);
    opacity: 0; /* Keep frame in place but fade in contents when ready */
    transition:
        opacity 0.2s ease,
        border-color 0.2s ease,
        background-color 0.2s ease,
        box-shadow 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    /* Prevent layout shifts during animation */
    contain: layout style paint;
    /* Fixed height prevents jitter */
    min-height: 0; /* Allow flex shrinking if needed */
}

.graph-contextual-container:hover {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Section Header (matches action bar style) */
.graph-contextual-section-header {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-primary);
    background: var(--color-bg-secondary);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    position: relative;
    overflow: hidden;
}

/* Subtle blob background effect (like action bar) */
.graph-contextual-section-header::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    transform: translateY(-50%);
    width: 80px;
    height: 80px;
    background: radial-gradient(circle,
        color-mix(in srgb, var(--blob-color-1, var(--color-primary)) 8%, transparent) 0%,
        color-mix(in srgb, var(--blob-color-2, var(--color-secondary)) 5%, transparent) 40%,
        transparent 70%);
    border-radius: 50%;
    filter: blur(15px);
    opacity: 0.4;
    pointer-events: none;
    z-index: 0;
    transition: opacity 0.3s ease;
}

.graph-contextual-section-header:hover::before {
    opacity: 0.6;
}

.graph-contextual-section-header > * {
    position: relative;
    z-index: 1;
}

.graph-contextual-section-header-icon {
    display: flex;
    align-items: center;
    color: var(--color-text-secondary, #757575);
}

.graph-contextual-section-header-icon svg {
    width: 18px;
    height: 18px;
}

/* Contextual Minimap SVG */
.graph-contextual-container svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* Container visibility controlled by parent .graph-has-data class */
.graph-contextual.graph-has-data .graph-contextual-container {
    opacity: 1;
    visibility: visible;
}

/* Reuse graph.css styles - contextual graph uses same classes */
/* Links and nodes inherit from graph.css (.graph-link, .graph-node) */

/* Contextual-specific overrides */
.graph-contextual-container .graph-link {
    stroke-width: 0.5px; /* Thinner for contextual view */
    opacity: 0.6;
}

.graph-contextual-container .graph-node {
    /* Smaller sizes handled in JS */
    stroke-width: 0.5px;
    opacity: 0.8;
}

/* Current page node (highlighted) */
.graph-contextual-container .graph-node-current {
    stroke: var(--color-primary, #2196f3) !important;
    stroke-width: 1.5px !important;
    opacity: 1 !important;
    filter: drop-shadow(0 0 3px var(--color-primary, #2196f3));
}

.graph-contextual-container .graph-node-current:hover {
    stroke-width: 2px !important;
}

/* Previous page node (last page visited before current) */
.graph-contextual-container .graph-node-previous {
    stroke: var(--color-primary-active, #1976d2) !important;
    stroke-width: 1px !important;
    opacity: 0.9 !important;
    filter: drop-shadow(0 0 2px var(--color-primary-active, #1976d2));
}

.graph-contextual-container .graph-node-previous:hover {
    stroke-width: 1.5px !important;
    opacity: 1 !important;
}

/* Tooltip */
.graph-contextual-tooltip {
    position: absolute;
    background: var(--color-bg-elevated, var(--color-bg-secondary, #f5f5f5));
    border: 1px solid var(--color-border, #e0e0e0);
    border-radius: 4px;
    padding: 6px 10px;
    pointer-events: none;
    font-size: 11px;
    max-width: 180px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.graph-contextual-tooltip-title {
    font-weight: 500;
    color: var(--color-text-primary, #212121);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Expand Button (matches action bar button style) */
.graph-contextual-expand {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--color-text-secondary);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 10;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.graph-contextual-expand:hover {
    background: var(--color-bg-tertiary);
    border-color: var(--color-primary);
    color: var(--color-primary);
    transform: scale(1.05);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.graph-contextual-expand:active {
    transform: scale(0.98);
}

.graph-contextual-expand svg {
    width: 16px;
    height: 16px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .graph-contextual {
        height: 180px; /* Fixed height for mobile */
    }

    .graph-contextual-container.graph-loading {
        min-height: 180px;
    }

    .graph-contextual-expand {
        width: 24px;
        height: 24px;
    }

    .graph-contextual-expand svg {
        width: 14px;
        height: 14px;
    }
}

/* Hide if no connections or explicitly hidden */
.graph-contextual:empty,
.graph-contextual[style*="display: none"],
.graph-contextual.graph-hidden,
.graph-contextual-container.graph-hidden {
    display: none !important;
}
