/* Interactive D3.js Network Diagram Styling */
.d3-graph-container {
    width: 100%;
    height: 600px;
    background: #080a14;
    border: 1px solid var(--color-border-dark);
    position: relative;
    overflow: hidden;
    margin-top: var(--space-4);
    border-radius: 4px;
}

/* Diagram section header: title left, full-screen button right. */
.diagram-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.diagram-fullscreen-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: var(--color-bg-canvas-raised);
    border: 1px solid var(--color-border-dark);
    color: var(--color-text-on-dark-muted);
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.diagram-fullscreen-btn:hover {
    border-color: var(--accent-blue-400);
    color: #FFFFFF;
    background: var(--color-bg-surface-dark);
}

.diagram-fullscreen-btn .material-icons {
    font-size: 18px;
}

/* Full-screen mode: fill the whole viewport, drop the card chrome. */
.d3-graph-container:fullscreen {
    width: 100%;
    height: 100%;
    margin-top: 0;
    border: none;
    border-radius: 0;
}

#d3-graph-viewport {
    width: 100%;
    height: 100%;
    cursor: grab;
}

#d3-graph-viewport:active {
    cursor: grabbing;
}

/* Subgraph/Group Styling */
.d3-subgraph-group rect {
    fill: rgba(255, 255, 255, 0.015);
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 1.5px;
    stroke-dasharray: 4 4;
    rx: 8;
    ry: 8;
    transition: all 0.3s ease;
}

.d3-subgraph-label {
    font-size: 11px;
    font-weight: 700;
    fill: var(--color-text-on-dark-faint);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    pointer-events: none;
}

/* Node Styling */
.d3-node {
    cursor: pointer;
}

.d3-node rect {
    fill: var(--color-bg-canvas-raised);
    stroke: var(--color-border-dark);
    stroke-width: 1.5px;
    rx: 4;
    ry: 4;
    transition: fill 0.2s ease, stroke-color 0.2s ease, filter 0.2s ease;
}

.d3-node:hover rect {
    fill: var(--color-bg-surface-dark);
    stroke: var(--accent-blue-400);
    filter: drop-shadow(0 0 8px rgba(45, 111, 232, 0.25));
}

.d3-node-label {
    font-size: 12px;
    font-weight: 600;
    fill: #FFFFFF;
    pointer-events: none;
    user-select: none;
}

/* Link Styling */
.d3-link {
    fill: none;
    stroke: rgba(255, 255, 255, 0.15);
    stroke-width: 1.5px;
    transition: stroke 0.2s ease;
}

.d3-link-hover {
    stroke-width: 8px;
    stroke: transparent;
    cursor: pointer;
    fill: none;
}

.d3-link-group:hover .d3-link {
    stroke: var(--accent-blue-400);
}

/* Link Labels */
.d3-link-label-bg {
    fill: #080a14;
    rx: 2;
    ry: 2;
}

.d3-link-label-text {
    font-size: 9px;
    font-weight: 600;
    fill: var(--color-text-on-dark-muted);
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
}

/* Arrowhead Markers */
.d3-arrow {
    fill: rgba(255, 255, 255, 0.15);
    transition: fill 0.2s ease;
}

.d3-link-group:hover .d3-arrow {
    fill: var(--accent-blue-400);
}

/* Interactive Overlay Panel */
.d3-controls-overlay {
    position: absolute;
    bottom: var(--space-4);
    right: var(--space-4);
    display: flex;
    gap: var(--space-2);
    z-index: 10;
}

.d3-control-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--color-bg-canvas-raised);
    border: 1px solid var(--color-border-dark);
    color: var(--color-text-on-dark-muted);
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.d3-control-btn:hover {
    border-color: var(--accent-blue-400);
    color: #FFFFFF;
    background: var(--color-bg-surface-dark);
}

.d3-control-btn span {
    font-size: 18px;
}

/* Curated Color Themes for Subgraphs & Nodes */

/* Theme 1: Blue */
.theme-blue rect {
    stroke: rgba(45, 111, 232, 0.4);
}
.d3-subgraph-group.theme-blue rect {
    fill: rgba(45, 111, 232, 0.012);
    stroke: rgba(45, 111, 232, 0.25);
}
.theme-blue .d3-node-label {
    fill: #e0f2fe;
}
.theme-blue:hover rect {
    stroke: #2d6fe8;
}

/* Theme 2: Violet */
.theme-violet rect {
    stroke: rgba(168, 85, 247, 0.4);
}
.d3-subgraph-group.theme-violet rect {
    fill: rgba(168, 85, 247, 0.012);
    stroke: rgba(168, 85, 247, 0.25);
}
.theme-violet .d3-node-label {
    fill: #f5f3ff;
}
.theme-violet:hover rect {
    stroke: #a855f7;
}

/* Theme 3: Teal */
.theme-teal rect {
    stroke: rgba(20, 184, 166, 0.4);
}
.d3-subgraph-group.theme-teal rect {
    fill: rgba(20, 184, 166, 0.012);
    stroke: rgba(20, 184, 166, 0.25);
}
.theme-teal .d3-node-label {
    fill: #f0fdfa;
}
.theme-teal:hover rect {
    stroke: #14b8a6;
}

/* Theme 4: Amber */
.theme-amber rect {
    stroke: rgba(245, 158, 11, 0.4);
}
.d3-subgraph-group.theme-amber rect {
    fill: rgba(245, 158, 11, 0.012);
    stroke: rgba(245, 158, 11, 0.25);
}
.theme-amber .d3-node-label {
    fill: #fffbeb;
}
.theme-amber:hover rect {
    stroke: #f59e0b;
}

/* Default / Uncategorized: Grey */
.theme-grey rect {
    stroke: rgba(59, 66, 97, 0.4);
}
.d3-subgraph-group.theme-grey rect {
    fill: rgba(59, 66, 97, 0.012);
    stroke: rgba(59, 66, 97, 0.2);
}

/* Themed Connection Lines */
.d3-link-group.theme-blue .d3-link { stroke: rgba(45, 111, 232, 0.45); }
.d3-link-group.theme-violet .d3-link { stroke: rgba(168, 85, 247, 0.45); }
.d3-link-group.theme-teal .d3-link { stroke: rgba(20, 184, 166, 0.45); }
.d3-link-group.theme-amber .d3-link { stroke: rgba(245, 158, 11, 0.45); }
.d3-link-group.theme-grey .d3-link { stroke: rgba(59, 66, 97, 0.4); }

/* Hover states */
.d3-link-group.theme-blue:hover .d3-link { stroke: #2d6fe8; }
.d3-link-group.theme-violet:hover .d3-link { stroke: #a855f7; }
.d3-link-group.theme-teal:hover .d3-link { stroke: #14b8a6; }
.d3-link-group.theme-amber:hover .d3-link { stroke: #f59e0b; }
