/* =========================================
   Agent Workflow Trace Panel — Graph UI
   Dark theme SVG-based LangGraph visualiser
   ========================================= */

/* ── Panel shell ──────────────────────────── */
.trace-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 480px;
    background: #0a0d14;
    border-left: 1px solid #1e2a42;
    box-shadow: -12px 0 48px rgba(0, 0, 0, 0.6);
    z-index: 8500;
    display: flex;
    flex-direction: column;
    /* calc(100% + 20px), not a bare 100% — subpixel rounding on some
       viewport widths otherwise leaves a 1px sliver of this dark panel
       visible at the right edge even while "closed". */
    transform: translateX(calc(100% + 20px));
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

.trace-panel.open {
    transform: translateX(0);
}

/* ── Header ──────────────────────────────── */
.trace-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 60%, #0f172a 100%);
    border-bottom: 1px solid #1e2a42;
    flex-shrink: 0;
}

.trace-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.trace-panel-title .trace-logo {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, #4f8ef7, #8b5cf6);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}

.trace-panel-title h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #e2e8f0;
    letter-spacing: 0.01em;
}

.trace-panel-title p {
    margin: 0;
    font-size: 11px;
    color: #64748b;
    margin-top: 1px;
}

.trace-panel-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.trace-panel-actions button {
    background: none;
    border: 1px solid transparent;
    cursor: pointer;
    color: #64748b;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.trace-panel-actions button:hover {
    background: #1e2a42;
    border-color: #334155;
    color: #94a3b8;
}

.trace-panel-actions button i {
    width: 16px;
    height: 16px;
}

/* ── Legend bar ───────────────────────────── */
.trace-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 16px;
    padding: 10px 18px;
    background: #10141f;
    border-bottom: 1px solid #1e2a42;
    flex-shrink: 0;
}

.trace-legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #64748b;
}

.trace-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ── Scrollable graph body ────────────────── */
.trace-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    background: #0a0d14;
    scrollbar-width: thin;
    scrollbar-color: #1e2a42 transparent;
}

.trace-list::-webkit-scrollbar {
    width: 5px;
}

.trace-list::-webkit-scrollbar-track {
    background: transparent;
}

.trace-list::-webkit-scrollbar-thumb {
    background: #1e2a42;
    border-radius: 3px;
}

/* ── Empty / loading states ───────────────── */
.trace-panel-empty,
.trace-panel-loading {
    padding: 48px 24px;
    font-size: 13px;
    color: #475569;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.trace-panel-empty::before {
    content: '🧠';
    font-size: 36px;
    display: block;
    margin-bottom: 4px;
}

/* ── SVG graph container ──────────────────── */
.trace-graph-wrap {
    padding: 20px 16px 0;
    min-height: 200px;
}

.trace-graph-wrap svg {
    display: block;
    width: 100%;
    overflow: visible;
}

/* ── Node hover / active effects ─────────── */
.tg-node {
    cursor: pointer;
    transition: opacity 0.2s;
}

.tg-node:hover rect,
.tg-node:hover circle {
    filter: brightness(1.25);
}

.tg-node.tg-active rect {
    stroke-width: 2.5;
}

/* ── Detail drawer (below SVG) ────────────── */
.trace-detail-drawer {
    margin: 12px 16px 20px;
    background: #10141f;
    border: 1px solid #1e2a42;
    border-radius: 12px;
    overflow: hidden;
    display: none;
    animation: traceDrawerIn 0.2s ease;
}

.trace-detail-drawer.open {
    display: block;
}

@keyframes traceDrawerIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.trace-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid #1e2a42;
    background: #161b2e;
}

.trace-drawer-title {
    font-size: 13px;
    font-weight: 700;
    color: #93c5fd;
    display: flex;
    align-items: center;
    gap: 8px;
}

.trace-drawer-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.trace-drawer-close {
    background: none;
    border: none;
    cursor: pointer;
    color: #475569;
    padding: 2px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s;
}

.trace-drawer-close:hover {
    color: #94a3b8;
}

.trace-drawer-body {
    padding: 0;
    max-height: 280px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: #1e2a42 transparent;
}

.trace-drawer-section {
    padding: 10px 14px;
    border-bottom: 1px solid #1e2a42;
}

.trace-drawer-section:last-child {
    border-bottom: none;
}

.trace-drawer-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #475569;
    margin-bottom: 6px;
}

.trace-drawer-value {
    font-size: 12px;
    color: #cbd5e1;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Fira Code', 'SFMono-Regular', Consolas, monospace;
    line-height: 1.55;
    background: #0a0d14;
    border-radius: 6px;
    padding: 8px 10px;
    border: 1px solid #1e2a42;
}

/* ── Step counter pill ────────────────────── */
.trace-step-counter {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 18px 0;
    flex-shrink: 0;
}

.trace-step-counter span {
    font-size: 11px;
    color: #475569;
}

.trace-step-counter strong {
    color: #4f8ef7;
}

/* ── Animated edge pulse ──────────────────── */
@keyframes edgePulse {
    0%   { stroke-dashoffset: 20; }
    100% { stroke-dashoffset: 0; }
}

.tg-edge-animated {
    animation: edgePulse 0.8s linear infinite;
}

/* ── Node type badge colours ──────────────── */
.badge-core    { background: #1e3a5f; color: #60a5fa; }
.badge-sql     { background: #064e3b; color: #6ee7b7; }
.badge-safety  { background: #450a0a; color: #fca5a5; }
.badge-qdrant  { background: #2e1065; color: #a78bfa; }
.badge-pdf     { background: #451a03; color: #fcd34d; }
.badge-merge   { background: #1e293b; color: #bfdbfe; }
.badge-unknown { background: #1e2a42; color: #94a3b8; }

/* ── Tooltip ──────────────────────────────── */
.trace-tooltip {
    position: fixed;
    background: #1e2540;
    border: 1px solid #334155;
    border-radius: 10px;
    padding: 12px 16px;
    max-width: 300px;
    font-size: 12.5px;
    line-height: 1.55;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 9999;
    color: #e2e8f0;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.7);
}

.trace-tooltip.show {
    opacity: 1;
}

.trace-tooltip strong {
    color: #93c5fd;
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
}

/* ── Responsive ───────────────────────────── */
