/* Session Graph view — n8n-style canvas for the Session Detail tab.
 *
 * Structure: a clipping viewport contains one transformed <div class="sg-world">
 * holding both the SVG edge layer and the absolutely-positioned HTML node layer,
 * so pan/zoom is a single transform on a single element and nodes keep normal
 * HTML text rendering (no foreignObject).
 *
 * All colors come from v2.css custom properties so the graph tracks the app theme.
 */

/* ------------------------------------------------------------- viewport -- */

.sg-viewport {
    position: relative;
    width: 100%;
    height: 640px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--r-3, 12px);
    background:
        radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.055) 1px, transparent 0)
        0 0 / 22px 22px,
        linear-gradient(180deg, var(--bg-2), var(--bg-1));
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.sg-viewport.is-panning {
    cursor: grabbing;
}

.sg-world {
    position: absolute;
    top: 0;
    left: 0;
    transform-origin: 0 0;
    will-change: transform;
}

/* No transition while dragging — only when fitting/zooming by button. */
.sg-world.is-animated {
    transition: transform 220ms cubic-bezier(0.32, 0.72, 0, 1);
}

.sg-edges {
    position: absolute;
    top: 0;
    left: 0;
    overflow: visible;
    pointer-events: none;
}

.sg-edge {
    fill: none;
    stroke: var(--line-strong);
    stroke-width: 1.5;
}

.sg-edge.is-turn {
    stroke: var(--brand-line);
    stroke-dasharray: 5 4;
}

.sg-edge.is-active {
    stroke: var(--brand);
    stroke-width: 2.25;
}

.sg-edge-dot {
    fill: var(--line-strong);
}

.sg-edge-dot.is-active {
    fill: var(--brand);
}

/* ---------------------------------------------------------------- nodes -- */

.sg-node {
    position: absolute;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid var(--line-strong);
    border-left-width: 3px;
    border-radius: var(--r-2, 8px);
    background: var(--bg-3);
    cursor: pointer;
    overflow: hidden;
    transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.sg-node:hover {
    border-color: var(--text-dim);
    transform: translateY(-1px);
}

.sg-node.is-selected {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px var(--brand-line), 0 8px 26px var(--brand-glow-2);
}

.sg-node-head {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.sg-node-title {
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sg-node-kind {
    margin-left: auto;
    flex-shrink: 0;
    font-size: 9px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.sg-node-body {
    font-size: 11px;
    line-height: 1.45;
    color: var(--text-mute);
    /* Two-line clamp — the drawer carries the full content. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.sg-node-foot {
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 9.5px;
    color: var(--text-faint);
}

/* Per-type accents. */
.sg-node.sg-prompt { border-left-color: var(--brand); }
.sg-node.sg-prompt .sg-node-icon { color: var(--brand); }

.sg-node.sg-tool { border-left-color: var(--warn); }
.sg-node.sg-tool .sg-node-icon { color: var(--warn); }
.sg-node.sg-tool .sg-node-body { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 10px; }

.sg-node.sg-answer { border-left-color: var(--safe); }
.sg-node.sg-answer .sg-node-icon { color: var(--safe); }

.sg-node.is-missing,
.sg-node.is-synthetic {
    border-style: dashed;
    border-left-color: var(--text-faint);
    background: rgba(14, 15, 32, 0.4);
}

.sg-node.is-missing .sg-node-icon,
.sg-node.is-synthetic .sg-node-icon {
    color: var(--text-dim);
}

.sg-node.is-missing .sg-node-title,
.sg-node.is-synthetic .sg-node-title {
    color: var(--text-dim);
}

.sg-node-score {
    flex-shrink: 0;
    font-weight: 700;
}

.sg-node-icon {
    flex-shrink: 0;
    width: 13px;
    height: 13px;
}

/* -------------------------------------------------------------- controls -- */

.sg-controls {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 4;
    display: flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--line);
    border-radius: var(--r-2, 8px);
    background: rgba(18, 20, 26, 0.9);
    backdrop-filter: blur(8px);
}

.sg-ctrl {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-mute);
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 11px;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}

.sg-ctrl:hover {
    background: var(--bg-5);
    color: var(--text);
}

.sg-zoom-label {
    display: inline-flex;
    align-items: center;
    padding: 0 6px;
    font-family: 'JetBrains Mono', ui-monospace, monospace;
    font-size: 10.5px;
    color: var(--text-dim);
    min-width: 42px;
    justify-content: center;
}

.sg-legend {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 4;
    display: flex;
    gap: 12px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--r-2, 8px);
    background: rgba(18, 20, 26, 0.9);
    backdrop-filter: blur(8px);
    font-size: 10px;
    color: var(--text-dim);
}

.sg-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.sg-legend-swatch {
    width: 8px;
    height: 8px;
    border-radius: 2px;
}

.sg-empty {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-dim);
    font-size: 12px;
}

/* ---------------------------------------------------------------- drawer -- */

.sg-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(6, 7, 10, 0.5);
    backdrop-filter: blur(2px);
}

.sg-drawer {
    position: fixed;
    top: 0;
    right: 0;
    z-index: 61;
    display: flex;
    flex-direction: column;
    width: min(440px, 100vw);
    height: 100vh;
    border-left: 1px solid var(--line-strong);
    background: var(--bg-2);
    box-shadow: -18px 0 48px rgba(0, 0, 0, 0.45);
    animation: sg-slide-in 240ms cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes sg-slide-in {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}

.sg-drawer-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.sg-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sg-field-label {
    font-size: 9.5px;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 5px;
}

.sg-drawer pre.code {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 11px;
    max-height: 320px;
    overflow: auto;
    margin: 0;
}

.sg-meta-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.sg-note {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 8px 10px;
    border: 1px dashed var(--line-strong);
    border-radius: 6px;
    font-size: 10.5px;
    color: var(--text-dim);
    line-height: 1.5;
}

@media (max-width: 900px) {
    .sg-viewport { height: 480px; }
    .sg-drawer { width: 100vw; }
}
