/* datagrid graph/network view — spec: docs/specs/datagrid-graph-view.
   Structural rules only: node/edge colors come per element from the consumer's
   ColorToken via style.setProperty('--fill'/'--stroke', 'var(<token>, …)') —
   this file declares NO per-type or per-kind selector (U8). All values are
   --dg-* tokens from modules/theme.css; the @media print block at the bottom
   is the single inherited literal-color exception. */

.dg-graph {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    font-family: var(--dg-font);
    color: var(--dg-text-main);
}

/* ── toolbar ─────────────────────────────────────────────────────────────── */
.dg-graph-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.dg-graph-group { display: inline-flex; align-items: center; gap: 4px; }
.dg-graph-group + .dg-graph-group { margin-left: 10px; }
.dg-graph-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: var(--dg-card-bg);
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    color: var(--dg-text-mute);
    font-size: 15px;
    cursor: pointer;
}
.dg-graph-btn:hover { border-color: var(--dg-accent); color: var(--dg-accent); }
.dg-graph-search-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--dg-text-mute);
}
.dg-graph-search {
    width: 280px;
    background: var(--dg-input-bg);
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    color: var(--dg-text-main);
    font: inherit;
    font-size: 12px;
    padding: 6px 10px;
}
.dg-graph-edge-filter {
    background: var(--dg-input-bg);
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    color: var(--dg-text-main);
    font: inherit;
    font-size: 12px;
    padding: 6px 8px;
}
.dg-graph-status { font-size: 11px; color: var(--dg-text-mute); }

.dg-graph-print-title { display: none; }

/* ── body: optional panel + canvas ───────────────────────────────────────── */
.dg-graph-body {
    display: flex;
    gap: 10px;
    margin-top: 10px;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
}
.dg-graph-canvas {
    position: relative;
    /* basis 0, not auto: with `auto` the canvas's intrinsic (SVG) width joins the flex
       basis sum, the row overflows, and the shrink pass claws width back off the PANEL —
       so a dragged panel silently rendered narrower than it was set to. */
    flex: 1 1 0;
    min-width: 0;
    min-height: 400px;
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    background: var(--dg-card-bg);
    overflow: hidden;
    user-select: none;
}
/* Shrink-wraps to its content's natural width (e.g. a wide detail table) instead of forcing an
   internal horizontal scrollbar at a fixed 240px — clamped between --dg-graph-panel-min/-max so
   it never starves the canvas. Consumers override the two tokens, never this selector (theming
   contract). */
.dg-graph-panel {
    /* No shrink: the panel's width is a decision (a token default, or the reader's drag),
       not a budget the layout may raid. The canvas is the flexible one. */
    flex: 0 0 auto;
    /* border-box so the width the drag WRITES is the width the drag MEASURES. Content-box
       makes them differ by padding+border: the pane lands ~22px off the cursor and grows
       by that much on every reload, because the stored border-box number comes back as a
       content-box width. It also makes --dg-graph-panel-min/-max mean "the pane is this
       wide", which is what a consumer setting them means. */
    box-sizing: border-box;
    /* --dg-graph-panel-w is set by the drag handle; unset, the panel keeps shrink-wrapping. */
    width: var(--dg-graph-panel-w, fit-content);
    min-width: var(--dg-graph-panel-min, 240px);
    max-width: var(--dg-graph-panel-max, 45%);
    overflow-y: auto;
    scrollbar-width: none;
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    background: var(--dg-card-bg);
    padding: 10px;
    font-size: 12px;
}
.dg-graph-panel::-webkit-scrollbar { display: none; }

/* Drag handle. Sits in the 10px body gap, so it costs no layout width of its own. */
.dg-graph-panel-resize {
    flex: none;
    width: 6px;
    margin: 0 -8px;          /* overlap the gap: a grabbable target, no visual gutter */
    cursor: col-resize;
    border-radius: var(--dg-radius);
    background: transparent;
    transition: background 0.12s ease;
}
.dg-graph-panel-resize:hover,
.dg-graph-panel-resize:focus-visible,
.dg-graph-panel-resize.is-resizing { background: var(--dg-accent); opacity: 0.45; }
.dg-graph-panel-resize:focus-visible { outline: none; }
body.dg-graph-resizing { user-select: none; cursor: col-resize; }

.dg-graph-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--dg-text-mute);
    font-size: 12px;
}
.dg-graph-empty i { font-size: 28px; }

.dg-graph-svg { display: block; cursor: grab; }
.dg-graph-svg.panning { cursor: grabbing; }

/* ── nodes (colors injected per element — no type selectors here) ────────── */
.gnode { cursor: pointer; }
.gnode circle {
    fill: var(--fill, var(--dg-graph-edge-default));
    fill-opacity: var(--dg-graph-node-fill-alpha);
    /* stroke reads the same ColorToken as the fill; darken it via color-mix so the ring reads
       as a deliberate frame instead of a flat duplicate of the fill hue (owner feedback,
       datagrid-graph-migration, 2026-07-16). */
    stroke: color-mix(in srgb, var(--stroke, var(--dg-graph-edge-default)) 70%, black);
    stroke-width: 1.5;
}
.gnode__label {
    font-size: 10px;
    fill: var(--dg-text-mute);
    pointer-events: none;
}
.gnode--focus circle { stroke-width: var(--dg-graph-focus-ring-width); }
.gnode--pending { opacity: var(--dg-graph-pending-opacity); }
.gnode.hl circle { stroke-width: 2.5; }
.gnode.hl .gnode__label { fill: var(--dg-text-main); }
/* label_color:"node" (opt-in): a label takes its node's own type colour. --stroke is set on
   the node <g> by the engine and inherited by the label. On hover the label keeps that
   colour and gains weight, rather than switching to the neutral text colour and losing the
   type it was just showing. The default rules above are untouched. */
.dg-graph-svg--label-by-type .gnode__label { fill: var(--stroke); }
.dg-graph-svg--label-by-type .gnode.hl .gnode__label { fill: var(--stroke); font-weight: 600; }
/* label_halo (opt-in): an outline in the canvas colour, painted BENEATH the fill (paint-order),
   masks any edge that crosses the label, so the line passes under the letters instead of
   through them. The halo is the canvas colour, so it is invisible except where it hides a line.
   0.7em, not a hairline: a 3px halo only hugged each glyph, and a crossing edge still showed in
   the gaps between letters and around a hyphen. At 0.7em the glyph outlines merge into one
   solid band. In em, so it scales with the label size. */
.dg-graph-svg--label-halo .gnode__label {
    paint-order: stroke;
    stroke: var(--dg-card-bg);
    stroke-width: 0.7em;
    stroke-linejoin: round;
}
.gnode.dim { opacity: 0.25; }
.gnode.dragging { cursor: grabbing; }
/* A node the user has dragged is PINNED — it keeps the place they put it while the
   simulation keeps arranging everything around it. Without a cue the new behaviour is
   invisible until something refuses to move, so the ring is dashed: same geometry, no size
   or colour change, readable in all three themes because it inherits the node's own stroke.
   Re-layout clears every pin. */
.gnode.pinned circle { stroke-dasharray: 3 2; }

/* ── edges (stroke/dash/width injected per element from config) ──────────── */
.gedge { stroke: var(--stroke, var(--dg-graph-edge-default)); stroke-width: 1; }
.gedge.hl  { stroke-width: 2.5; }
.gedge.dim { opacity: 0.12; }

/* ── 3D modes (solar + sphere) ───────────────────────────────────────────── */
.gorbit { fill: none; stroke: var(--dg-graph-orbit-stroke); stroke-dasharray: 2 4; }
.gnode--hub circle { stroke-width: var(--dg-graph-focus-ring-width); }
.gnode--distant circle { stroke-dasharray: 3 2; }
.gnode--moon .gnode__label { display: none; }
.gnode--moon:hover .gnode__label { display: block; }
.gnode__label.lbl--hid { display: none; }

/* ── legend (fixed overlay; items are filters) ───────────────────────────── */
.dg-graph-legend {
    position: absolute;
    bottom: 12px;
    right: 12px;
    background: var(--dg-card-bg);
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    padding: 7px 10px;
    font-size: 11px;
    z-index: 10;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-height: 45%;
    overflow-y: auto;
    /* thin (not hidden) scrollbar: a long vocabulary must stay discoverable —
       "more below" has no other affordance in this compact overlay */
    scrollbar-width: thin;
}
.dg-graph-legend-hdr {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--dg-text-mute);
    margin: 2px 0 4px;
}
.dg-graph-legend-item {
    display: flex;
    align-items: center;
    gap: 7px;
    background: none;
    border: none;
    color: var(--dg-text-main);
    font: inherit;
    font-size: 11px;
    padding: 1px 0;
    cursor: pointer;
}
.dg-graph-legend-item.is-off { opacity: 0.35; text-decoration: line-through; }
.dg-graph-legend-item.is-active { color: var(--dg-select, var(--dg-accent)); font-weight: 600; }
.dg-graph-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 1.5px solid var(--stroke, var(--dg-graph-edge-default));
    background: var(--fill, transparent);
}
.dg-graph-legend-line {
    display: inline-block;
    width: 18px;
    border-top: 2px var(--dash-style, solid) var(--stroke, var(--dg-graph-edge-default));
    flex: 0 0 auto;
}
/* solar shows all edge kinds — the edge filter is inert there */
.dg-graph[data-mode="solar"] .dg-graph-legend-edge { opacity: 0.4; pointer-events: none; }

/* ── tooltip ─────────────────────────────────────────────────────────────── */
.dg-graph-tooltip {
    position: fixed;
    display: none;
    flex-direction: column;
    gap: 2px;
    background: var(--dg-card-bg);
    border: 1px solid var(--dg-border);
    border-radius: var(--dg-radius);
    padding: 6px 9px;
    font-size: 11px;
    color: var(--dg-text-main);
    pointer-events: none;
    z-index: 700;
    max-width: 320px;
    word-break: break-all;
}
.dg-graph-tooltip.show { display: flex; }
.dg-graph-tooltip span { color: var(--dg-text-mute); }

/* ── print — A3 landscape, chrome hidden, print-legible remap ────────────── */
/* Inherited exception (pf-ui graph.css / dag.css idiom), carried over
   verbatim in spirit: print re-declares the tokens with literal values in
   this one block, and every rule above stays var()-driven so nodes, edges
   and legend remap through the cascade. This is the single place literal
   colors are allowed in library CSS (spec audit finding 4 — inherited,
   not newly introduced). */
@media print {
    @page { size: A3 landscape; margin: 15mm 20mm; }

    :root {
        --dg-bg: white;
        --dg-card-bg: white;
        --dg-input-bg: white;
        --dg-border: #333;
        --dg-text-main: #111;
        --dg-text-mute: #444;
        --dg-accent: #111;
        --dg-graph-edge-default: #666;
        --dg-graph-orbit-stroke: #ccc;
        --dg-graph-node-fill-alpha: 0;
        --dg-graph-cat-1: #333;
        --dg-graph-cat-2: #333;
        --dg-graph-cat-3: #333;
        --dg-graph-cat-4: #333;
        --dg-graph-cat-5: #333;
        --dg-graph-cat-6: #333;
        --dg-graph-cat-7: #333;
        --dg-graph-cat-8: #333;
    }

    .dg-graph-toolbar,
    .dg-graph-panel,
    .dg-graph-tooltip,
    .dg-graph-legend-item.is-off { display: none !important; }

    .dg-graph { display: block; }
    .dg-graph-print-title {
        display: block;
        margin: 0 0 4mm;
        font-size: 14pt;
        color: var(--dg-text-main);
    }
    .dg-graph-body { margin: 0; display: block; }
    .dg-graph-canvas {
        height: auto;
        min-height: 0;
        border: none;
        overflow: visible;
    }

    /* uniform white-fill nodes on paper (fills stay tinted on screen only) */
    .gnode circle { --fill: white; --stroke: #333; }

    .dg-graph-legend {
        position: static;
        width: max-content;
        max-height: none;
        margin-top: 4mm;
    }
}
