/* Graph pane — top-down hierarchical view of the wiki vault, paired
   with the Context tab in the same drawer. Scoped under .chat-container
   to inherit the existing pane/drawer-tab plumbing without leaking. */

.chat-container .graph-canvas {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--bs-body-bg);
}

.chat-container .graph-svg {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    /* Claim touch gestures for d3.zoom instead of letting the browser
       treat vertical drags as page scrolls. Without this, pan/zoom is
       unusable on phones — the drawer or page scrolls first. */
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.chat-container .graph-svg:active {
    cursor: grabbing;
}

.chat-container .graph-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--bs-border-color);
    flex-shrink: 0;
    font-size: 11px;
    font-family: "SF Mono", "Fira Code", monospace;
    color: var(--bs-secondary-color);
}

.chat-container .graph-btn {
    background: var(--bs-tertiary-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 11px;
    font-family: "SF Mono", "Fira Code", monospace;
    color: var(--bs-body-color);
    cursor: pointer;
}

.chat-container .graph-btn:hover {
    background: var(--bs-secondary-bg);
}

.chat-container .graph-legend {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-container .graph-legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

.chat-container .graph-legend-visited {
    background: var(--bs-primary);
}

.chat-container .graph-legend-current {
    background: var(--bs-warning);
    box-shadow: 0 0 0 2px rgba(255, 193, 7, 0.35);
}

.chat-container .graph-visited-count {
    font-weight: 400;
    font-size: 11px;
    color: var(--bs-primary);
    text-transform: none;
    letter-spacing: 0;
    font-family: "SF Mono", "Fira Code", monospace;
}

/* ─── SVG layers ────────────────────────────────────────────────── */

.chat-container .tree-link {
    fill: none;
    stroke: var(--bs-border-color);
    stroke-width: 1px;
    opacity: 0.5;
    transition: stroke 0.2s ease, stroke-width 0.2s ease, opacity 0.2s ease;
}

.chat-container .tree-link.traversed {
    stroke: var(--bs-primary);
    stroke-width: 2px;
    opacity: 0.9;
}

.chat-container .tree-link.traversed.turn-current {
    stroke: var(--bs-warning);
    stroke-width: 2.5px;
    opacity: 1;
    filter: drop-shadow(0 0 2px rgba(255, 193, 7, 0.55));
}

.chat-container .tree-link.traversed.turn-past {
    stroke: var(--bs-primary);
    stroke-width: 1.5px;
    opacity: 0.7;
}

.chat-container .cross-link {
    fill: none;
    stroke: var(--bs-info);
    stroke-width: 1px;
    opacity: 0.55;
    pointer-events: none;
}

/* ─── Nodes ─────────────────────────────────────────────────────── */

.chat-container .node circle {
    opacity: 0.4;
    stroke: var(--bs-body-bg);
    stroke-width: 1px;
    transition: opacity 0.15s ease;
}

.chat-container .node-root circle,
.chat-container .node-section circle {
    opacity: 0.95;
}

.chat-container .node-entity {
    cursor: pointer;
}

.chat-container .node.visited circle {
    opacity: 1;
    stroke: var(--bs-primary);
    stroke-width: 1.5px;
}

.chat-container .node.current-turn circle {
    stroke: var(--bs-warning);
    stroke-width: 2px;
    filter: drop-shadow(0 0 3px rgba(255, 193, 7, 0.55));
}

.chat-container .node.dim circle {
    opacity: 0.08;
}

.chat-container .node.dim text {
    opacity: 0.2;
}

.chat-container .root-label {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 12px;
    font-weight: 700;
    fill: var(--bs-body-color);
}

.chat-container .section-label {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 11px;
    font-weight: 600;
    fill: var(--bs-body-color);
    cursor: pointer;
}

.chat-container .node-section {
    cursor: pointer;
}

.chat-container .graph-canvas {
    position: relative;  /* anchor for absolute-positioned popup */
}

.chat-container .graph-popup {
    position: absolute;
    z-index: 10;
    max-width: 260px;
    min-width: 200px;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.15);
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.4;
    pointer-events: auto;
}

.chat-container .graph-popup-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.chat-container .graph-popup-label {
    font-family: "SF Mono", "Fira Code", monospace;
    font-weight: 700;
    font-size: 13px;
    color: var(--bs-body-color);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-container .graph-popup-close {
    background: none;
    border: none;
    color: var(--bs-secondary-color);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 4px 6px;
    min-width: 28px;
    min-height: 28px;
    border-radius: 4px;
}

.chat-container .graph-popup-close:hover {
    background: var(--bs-secondary-bg);
    color: var(--bs-body-color);
}

.chat-container .graph-popup-meta {
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--bs-secondary-color);
    margin-bottom: 6px;
}

.chat-container .graph-popup-title {
    margin: 0 0 10px 0;
    color: var(--bs-body-color);
}

.chat-container .graph-popup-link {
    display: block;
    text-align: center;
    background: var(--bs-primary);
    color: #fff;
    border-radius: 4px;
    padding: 8px 12px;
    text-decoration: none;
    font-weight: 600;
    min-height: 36px;
    line-height: 20px;
}

.chat-container .graph-popup-link:hover {
    background: var(--bs-primary);
    filter: brightness(1.1);
    color: #fff;
    text-decoration: none;
}

@media (max-width: 991.98px) {
    .chat-container .graph-popup-close {
        min-width: 44px;
        min-height: 44px;
    }
    .chat-container .graph-popup-link {
        min-height: 44px;
        line-height: 28px;
    }
}
