/* Network Graph Visualization Styles */

.network-graph-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--color-surface-primary);
    /* NO padding-bottom here. Unlike the scrollable match/document viewers
       (where footer-height padding is just clearance below the last card),
       the graph is a flex-fill canvas — `.app-main` already reserves the fixed
       footer's height (margin-bottom), so any padding here shrinks the canvas
       and leaves a blank strip of page background above the footer. */
    padding-bottom: 0;
}

/* Search container for ego mode */
.network-search-container {
    padding: 1rem 1.5rem;
    background: var(--color-sand-footer);
    border-bottom: 2px solid var(--color-primary);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.network-search-container .search-label {
    font-family: var(--font-primary);
    font-size: 1rem;
    font-weight: var(--font-weight-medium);
    color: var(--color-text-primary);
    white-space: nowrap;
}

.network-search-container .document-search-box {
    flex: 1;
    max-width: 500px;
}

/* The suggestions dropdown must beat the config overlay (--z-panel: 200,
   later in the DOM) and the footer (--z-nav: 1000) — otherwise picking a
   center book while the settings panel is open shows a covered/clipped list */
.network-search-container .search-suggestions {
    z-index: 1100;
}

/* Graph container */
.network-graph-container {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.graph-canvas-wrapper {
    width: 100%;
    height: 100%;
    position: relative;
}

.graph-canvas-wrapper canvas {
    display: block;
}

.graph-canvas-wrapper svg {
    position: absolute;
    top: 0;
    left: 0;
}

/* Loading overlay */
.network-loading-overlay {
    position: absolute;
    top: 0;
    inset-inline: 0;
    bottom: 0;
    background: var(--color-surface-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    z-index: 100;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-gray-light);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    font-family: var(--font-primary);
    color: var(--color-text-secondary);
}

/* Computing state: server-side layout over the full filtered graph */
.network-computing-overlay .computing-text {
    direction: rtl;
    text-align: center;
    max-width: 480px;
    padding: 0 1.5rem;
    line-height: 1.8;
    color: var(--color-text-primary);
}

/* ============================================================================
   FULL-GRAPH NODE STATS PANEL
   Shows degree / weighted_degree from the server layout (complete filtered
   graph), regardless of the drawn top-edges subset.
   ============================================================================ */

.network-node-stats {
    position: absolute;
    bottom: 1rem;
    inset-inline-start: 1rem;
    background: var(--color-surface-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 0.75rem 1rem;
    z-index: 60;
    direction: rtl;
    min-width: 220px;
    max-width: 320px;
    font-family: var(--font-primary);
}

.network-node-stats .node-stats-close {
    position: absolute;
    top: 0.35rem;
    inset-inline-end: 0.5rem;
    background: none;
    border: none;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 0.15rem;
}

.network-node-stats .node-stats-close:hover {
    color: var(--color-text-primary);
}

.network-node-stats .node-stats-title {
    font-size: 0.95rem;
    font-weight: var(--font-weight-bold);
    color: var(--color-text-primary);
    margin-bottom: 0.25rem;
    padding-inline-end: 1.25rem;
}

.network-node-stats .node-stats-author {
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.4rem;
}

.network-node-stats .node-stats-metrics {
    font-size: 0.9rem;
    font-weight: var(--font-weight-medium);
    color: var(--color-primary);
    margin-bottom: 0.3rem;
}

.network-node-stats .node-stats-note {
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-style: italic;
}

/* Error message */
.network-error {
    position: absolute;
    top: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-danger-bg);
    color: var(--color-danger);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: var(--shadow-sm);
    z-index: 50;
    font-family: var(--font-primary);
}

.error-icon {
    font-size: 1.25rem;
}

/* ============================================================================
   NETWORK GRAPH FOOTER (Fixed at Bottom)
   Matches the styling of document-viewer and match-viewer footers
   ============================================================================ */

.network-graph-footer {
    position: fixed;
    bottom: 0;
    inset-inline: 0;
    width: 100%;
    height: var(--footer-height);
    z-index: var(--z-nav);
    background: var(--color-sand-footer);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    border-top: 2px solid var(--color-primary);
}

/* Full-width bar with the controls DISTRIBUTED across it: each section takes
   an equal third and spreads its items evenly, so the buttons span the whole
   footer instead of clumping at the edges of a centered box. */
.network-graph-footer .footer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    width: 100%;
    height: 100%;
    gap: 1rem;
}

.network-graph-footer .footer-left,
.network-graph-footer .footer-right {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    flex: 1 1 0;
    min-width: 0;
    gap: 0.75rem;
}

.network-graph-footer .footer-center {
    display: flex;
    align-items: center;
    justify-content: space-evenly;
    flex: 1 1 0;
    min-width: 0;
    gap: 1rem;
}

/* Control groups (dropdowns with labels) */
.network-graph-footer .control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.network-graph-footer .control-group label {
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-family: var(--font-primary);
    white-space: nowrap;
}

.network-graph-footer .control-group select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    font-size: 0.9rem;
    font-family: var(--font-primary);
    cursor: pointer;
    min-width: 100px;
}

.network-graph-footer .control-group select:hover {
    border-color: var(--color-primary-dark);
}

/* Live simulation toggle */
.network-graph-footer .live-sim-toggle .live-sim-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--color-text-secondary);
    font-family: var(--font-primary);
    white-space: nowrap;
    cursor: pointer;
}

.network-graph-footer .live-sim-toggle input[type="checkbox"] {
    cursor: pointer;
    accent-color: var(--color-primary);
}

.network-graph-footer .live-sim-toggle input[type="checkbox"]:disabled {
    cursor: not-allowed;
}

.network-graph-footer .live-sim-toggle input[type="checkbox"]:disabled + span {
    opacity: 0.5;
}

/* Footer buttons */
.network-graph-footer .footer-button {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: var(--font-weight-medium);
    font-family: var(--font-primary);
    transition: var(--transition-bg);
}

.network-graph-footer .footer-button:hover {
    background: var(--color-primary-dark);
}

/* حفظ sits at the far-left edge (RTL), set off from the utility buttons
   (تنزيل / إعادة التوسيط / الإعدادات / دليل) by a thin divider — same edge
   position it holds in the match browser and document-viewer footers. */
.network-graph-footer .footer-save-edge {
    margin-inline-start: 0.5rem;
    padding-inline-start: 0.75rem;
    border-inline-start: 1px solid var(--color-gray-border);
}

/* GEXF export link styled like a footer button */
.network-graph-footer a.gexf-export-button {
    text-decoration: none;
    background: var(--color-white);
    color: var(--color-primary);
    border: 1px solid var(--color-primary);
}

.network-graph-footer a.gexf-export-button:hover {
    background: var(--color-sand-light);
    color: var(--color-primary-dark);
}

.network-graph-footer .footer-button.has-filters {
    background: var(--color-primary-dark);
    box-shadow: 0 0 0 2px var(--color-primary-light);
}

.network-graph-footer .filter-badge {
    background: var(--color-white);
    color: var(--color-primary);
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    min-width: 1.25rem;
    text-align: center;
    font-weight: var(--font-weight-bold);
}

/* Stats display */
.network-graph-footer .network-stats {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-family: var(--font-primary);
}

.network-graph-footer .stat-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.network-graph-footer .stat-value {
    font-size: 1rem;
    font-weight: var(--font-weight-bold);
    color: var(--color-primary);
}

.network-graph-footer .stat-label {
    font-size: 0.85rem;
    color: var(--color-text-secondary);
}

.network-graph-footer .stat-separator {
    color: var(--color-gray-medium);
    font-size: 0.85rem;
}

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

@media (max-width: 768px) {
    .network-graph-footer {
        height: auto;
        padding: 0.5rem 0;
    }

    .network-graph-footer .footer-controls {
        flex-direction: column;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
    }

    .network-graph-footer .footer-left,
    .network-graph-footer .footer-center,
    .network-graph-footer .footer-right {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .network-graph-footer .control-group {
        flex: 1;
        min-width: 120px;
    }

    .network-graph-footer .control-group select {
        flex: 1;
    }
}

@media (max-width: 480px) {
    .network-graph-footer .footer-button {
        padding: 0.4rem 0.75rem;
        font-size: 0.85rem;
    }

    .network-graph-footer .control-group label {
        font-size: 0.8rem;
    }

    .network-graph-footer .control-group select {
        font-size: 0.85rem;
        min-width: 80px;
    }

    .network-graph-footer .stat-value {
        font-size: 0.9rem;
    }

    .network-graph-footer .stat-label {
        font-size: 0.75rem;
    }
}

/* Document search box */
.document-search-box {
    position: relative;
    max-width: 400px;
}

.document-search-box .search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: var(--font-primary);
    direction: rtl;
}

.document-search-box .search-input:focus {
    outline: none;
    border-color: var(--color-primary-dark);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.search-suggestions {
    position: absolute;
    top: 100%;
    inset-inline: 0;
    background: var(--color-white);
    border: 1px solid var(--color-gray-light);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 300px;
    overflow-y: auto;
    z-index: 200;
    margin-top: 4px;
}

.suggestion-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    font-family: var(--font-primary);
    direction: rtl;
    border-bottom: 1px solid var(--color-gray-light);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover {
    background: var(--color-gray-light);
}

/* Graph settings modal */
.graph-settings-modal {
    width: 500px;
    max-width: 90vw;
    max-height: 80vh;
    overflow-y: auto;
}

.graph-settings-modal .modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--color-gray-light);
}

.graph-settings-modal .modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-family: var(--font-primary);
    color: var(--color-text-primary);
}

.graph-settings-modal .close-button {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-text-secondary);
    padding: 0.25rem;
    line-height: 1;
}

.graph-settings-modal .close-button:hover {
    color: var(--color-text-primary);
}

.graph-settings-modal .modal-body {
    padding: 1.5rem;
}

.settings-section {
    margin-bottom: 1.5rem;
}

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

.settings-section h4 {
    margin: 0 0 1rem 0;
    font-size: 1rem;
    font-family: var(--font-primary);
    color: var(--color-text-primary);
    border-bottom: 1px solid var(--color-gray-light);
    padding-bottom: 0.5rem;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

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

.setting-row label {
    font-size: 0.875rem;
    font-family: var(--font-primary);
    color: var(--color-text-secondary);
}

.setting-row select,
.setting-row input[type="number"] {
    padding: 0.5rem;
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-family: var(--font-primary);
    min-width: 150px;
}

.setting-row input[type="range"] {
    flex: 1;
    margin-inline-end: 1rem;
    max-width: 200px;
}

.graph-settings-modal .modal-footer {
    display: flex;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-gray-light);
}

.reset-button {
    padding: 0.5rem 1rem;
    background: var(--color-white);
    border: 1px solid var(--color-gray-medium);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-family: var(--font-primary);
    transition: var(--transition-bg);
}

.reset-button:hover {
    background: var(--color-gray-light);
}

.apply-button {
    padding: 0.5rem 1.5rem;
    background: var(--color-primary);
    color: var(--color-white);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    font-family: var(--font-primary);
    font-weight: var(--font-weight-medium);
    transition: var(--transition-bg);
}

.apply-button:hover {
    background: var(--color-primary-dark);
}

/* Modal overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    inset-inline: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

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

/* ============================================================================
   NETWORK LEGEND (Collapsible)
   ============================================================================ */

.network-legend {
    position: absolute;
    top: 1rem;
    inset-inline-start: 1rem;
    background: var(--color-surface-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: 50;
    direction: rtl;
    min-width: 180px;
    max-width: 250px;
    transition: all 0.2s ease;
}

.network-legend .legend-toggle {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--color-sand-light);
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-family: var(--font-primary);
    font-size: 0.85rem;
    color: var(--color-text-secondary);
    text-align: start;
    transition: background 0.2s ease;
}

.network-legend.expanded .legend-toggle {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: 1px solid var(--color-gray-light);
}

.network-legend .legend-toggle:hover {
    background: var(--color-sand);
}

.network-legend .legend-content {
    padding: 0.75rem 1rem;
}

.network-legend .legend-section {
    margin-bottom: 1rem;
}

.network-legend .legend-section:last-child {
    margin-bottom: 0;
}

.network-legend .legend-section h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.8rem;
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    font-family: var(--font-primary);
}

.network-legend .legend-items {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

/* Color legend items */
.network-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    font-family: var(--font-primary);
}

.network-legend .legend-item.more {
    color: var(--color-text-muted);
    font-style: italic;
    padding-inline-start: 1.25rem;
}

.network-legend .color-swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.network-legend .legend-note {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-style: italic;
    font-family: var(--font-primary);
}

/* Size legend */
.network-legend .size-scale {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    padding: 0.25rem 0;
}

.network-legend .size-node {
    border-radius: 50%;
    background: var(--color-primary);
    opacity: 0.7;
}

.network-legend .size-node.small {
    width: 10px;
    height: 10px;
}

.network-legend .size-node.large {
    width: 24px;
    height: 24px;
}

.network-legend .size-arrow {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.network-legend .size-labels,
.network-legend .edge-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--color-text-muted);
    font-family: var(--font-primary);
}

/* Edge legend */
.network-legend .edge-scale {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.25rem 0;
}

.network-legend .edge-line {
    height: 2px;
    background: var(--color-text-secondary);
    border-radius: 1px;
}

.network-legend .edge-line.thin {
    width: 60%;
    opacity: 0.4;
}

.network-legend .edge-line.thick {
    width: 100%;
    height: 4px;
    opacity: 0.8;
}

/* --- Edge hover tooltip -------------------------------------------------- */

.network-edge-tooltip {
    position: absolute;
    z-index: 50;
    pointer-events: none;
    direction: rtl;
    max-width: 320px;
    background: var(--color-surface-primary);
    border: 1px solid var(--color-border-primary);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
    padding: 10px 12px;
    font-size: 0.83rem;
    line-height: 1.5;
}

.network-edge-tooltip .edge-tt-doc {
    padding: 2px 0;
}

.network-edge-tooltip .edge-tt-title {
    font-weight: 700;
}

.network-edge-tooltip .edge-tt-sub {
    color: var(--color-text-secondary, #6b5d4f);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

.network-edge-tooltip .edge-tt-link {
    margin: 6px 0;
    padding: 5px 8px;
    background: rgba(184, 148, 106, 0.14);
    border-radius: 5px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
