/* ── Nexus Tab ────────────────────────────────────────────────────────────── */

#nexus-workspace {
    display: none;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    position: relative;
    z-index: 0;
}
#nexus-workspace.active { display: flex; }

/* ── Three-panel layout ── */

.nexus-questions-panel {
    width: 180px;
    flex-shrink: 0;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.nexus-graph-panel {
    flex: 1;
    background-color: var(--bg-primary);
    overflow: hidden;
    position: relative;
    cursor: grab;
    min-width: 0;
}

.nexus-graph-panel.panning { cursor: grabbing; }

.nexus-metrics-panel {
    width: 280px;
    flex-shrink: 0;
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.nexus-questions-panel.collapsed,
.nexus-metrics-panel.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    overflow: hidden;
}

/* ── Graph stage ── */

.nexus-graph-stage {
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
}

.nexus-graph-svg {
    width: 100%;
    height: 100%;
    display: block;
}

/* ── Panel resize handles (same pattern as lineage) ── */

.nexus-panel-resize {
    position: absolute;
    top: 0;
    right: 0;
    width: 6px;
    height: 100%;
    cursor: ew-resize;
    z-index: 10;
    background: transparent;
}

.nexus-panel-resize:hover,
.nexus-panel-resize.active {
    background-color: var(--accent-color);
    opacity: 0.5;
}

.nexus-panel-resize.left {
    right: auto;
    left: 0;
}

/* ── Panel toggle pills (same pattern as lineage) ── */

.nexus-panel-toggle {
    flex-shrink: 0;
    align-self: center;
    width: 20px;
    height: 60px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: none;
    border-radius: 0 6px 6px 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11;
    transition: background-color 0.15s ease;
    padding: 0;
    color: var(--text-muted);
}

.nexus-panel-toggle:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.nexus-panel-toggle-right {
    border-left: 1px solid var(--border-color);
    border-right: none;
    border-radius: 6px 0 0 6px;
}

.nexus-panel-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.nexus-panel-toggle.collapsed .nexus-panel-toggle-icon {
    transform: rotate(180deg);
}

/* ── Questions panel ── */

.nexus-questions-header {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.nexus-questions-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.nexus-q-item {
    padding: 6px 8px;
    border-radius: 4px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 4px;
    transition: border-color 0.1s;
}

.nexus-q-item:hover { border-color: var(--border-hover, var(--accent-color)); }

.nexus-q-item.active {
    background-color: var(--accent-color-alpha);
    border-color: var(--accent-color);
}

.nexus-q-text {
    flex: 1;
    font-size: 1rem;
    color: var(--text-primary);
    outline: none;
    min-width: 0;
    word-break: break-word;
    line-height: 1.4;
}

.nexus-q-delete {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    opacity: 0;
    transition: opacity 0.1s;
    display: flex;
    align-items: center;
}

.nexus-q-item:hover .nexus-q-delete { opacity: 1; }
.nexus-q-delete:hover { color: var(--danger-color); }

/* ── Metrics panel ── */

.nexus-metrics-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
}

.nexus-metrics-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.nexus-metric-row {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 6px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    transition: box-shadow 0.2s;
}
.nexus-metric-highlight {
    animation: nexus-metric-flash 1.4s ease-out;
}
@keyframes nexus-metric-flash {
    0%   { box-shadow: 0 0 0 3px var(--highlight-border); }
    60%  { box-shadow: 0 0 0 3px var(--highlight-border); }
    100% { box-shadow: none; }
}

.nexus-metric-row-header {
    display: flex;
    align-items: center;
    gap: 6px;
}

.nexus-metric-name {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    padding: 2px 0;
    outline: none;
    font-family: inherit;
    min-width: 0;
}

.nexus-metric-name:focus { border-bottom-color: var(--accent-color); }

.nexus-metric-delete {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    display: flex;
    align-items: center;
}
.nexus-metric-delete:hover { color: var(--danger-color); }

.nexus-metric-calc {
    font-size: 1rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 6px;
    width: 100%;
    resize: vertical;
    min-height: 36px;
    font-family: var(--font-mono, monospace);
    outline: none;
    box-sizing: border-box;
}

.nexus-metric-calc:focus { border-color: var(--accent-color); }

.nexus-field-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nexus-field-pick-btn {
    font-size: 1rem;
    padding: 3px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-muted);
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    font-family: inherit;
    transition: border-color 0.1s, color 0.1s;
}

.nexus-field-pick-btn:hover {
    border-color: var(--accent-color);
    color: var(--text-primary);
}

.nexus-field-pick-btn.has-value {
    color: var(--success-color);
    border-color: var(--success-color);
}

.nexus-source-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.nexus-source-tag {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 1rem;
    padding: 2px 5px;
    border-radius: 3px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid var(--warning-color);
    color: var(--warning-color);
    font-family: var(--font-mono, monospace);
}

.nexus-source-tag-remove {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1;
    font-family: sans-serif;
}

.nexus-source-tag-remove:hover { color: var(--danger-color); }

.nexus-add-source-btn {
    font-size: 1rem;
    padding: 2px 7px;
    border-radius: 3px;
    border: 1px dashed var(--border-color);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.1s, color 0.1s;
}

.nexus-add-source-btn:hover {
    border-color: var(--warning-color);
    color: var(--warning-color);
}

.nexus-add-metric-btn {
    width: 100%;
    padding: 7px;
    border-radius: 4px;
    border: 1px dashed var(--border-color);
    background: transparent;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.1s, color 0.1s;
}

.nexus-add-metric-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* ── Empty states ── */

.nexus-empty-state {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 1rem;
    line-height: 1.5;
}

/* ── Mind map SVG node labels ── */

.nexus-node-label {
    font-family: var(--font-sans, sans-serif);
    pointer-events: none;
    user-select: none;
}

/* ── Field picker popup ── */

.nfp-popup {
    position: fixed;
    z-index: 9000;
    width: 320px;
    max-height: 380px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 8px 24px var(--shadow-color, rgba(0,0,0,0.25));
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.nfp-hidden { display: none !important; }

.nfp-search-row {
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.nfp-search-input {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 1rem;
    outline: none;
    box-sizing: border-box;
    font-family: inherit;
}

.nfp-search-input:focus { border-color: var(--accent-color); }

.nfp-results {
    flex: 1;
    overflow-y: auto;
    padding: 4px;
}

.nfp-group { margin-bottom: 2px; }

.nfp-group-label {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-muted);
    padding: 4px 8px 2px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.nfp-item {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    gap: 4px;
}

.nfp-item:hover { background: var(--bg-hover, var(--bg-tertiary)); }

.nfp-item-selected { background: var(--accent-color-alpha); }

.nfp-item-check {
    width: 14px;
    font-size: 1rem;
    color: var(--accent-color);
    flex-shrink: 0;
    text-align: center;
}

.nfp-item-name {
    flex: 1;
    font-size: 1rem;
    color: var(--text-primary);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nfp-item-type {
    font-size: 1rem;
    color: var(--text-muted);
    font-family: var(--font-mono, monospace);
    flex-shrink: 0;
}

.nfp-empty {
    padding: 12px 8px;
    text-align: center;
    color: var(--text-muted);
    font-size: 1rem;
}

.nfp-footer {
    padding: 6px 8px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.nfp-done-btn {
    padding: 3px 14px;
    border-radius: 4px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    font-family: inherit;
}

.nfp-done-btn:hover { background: var(--accent-hover, var(--accent-color)); opacity: 0.9; }

/* ── MathQuill formula editor — dark theme overrides ── */

.nexus-metric-calc-wrap {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 2px;
}

.nexus-metric-calc-wrap .mq-editable-field {
    width: 100%;
    min-height: 38px;
    box-sizing: border-box;
    padding: 5px 8px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
    cursor: text;
    line-height: 1.6;
}

.nexus-metric-calc-wrap .mq-editable-field.mq-focused {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: none;
}

.nexus-metric-calc-wrap .mq-cursor {
    border-left-color: var(--text-primary) !important;
}

.nexus-metric-calc-wrap .mq-selection .mq-matrixed-container,
.nexus-metric-calc-wrap .mq-selection .mq-scaled,
.nexus-metric-calc-wrap .mq-selection {
    background: var(--accent-color-alpha) !important;
    color: var(--text-primary) !important;
}

.nexus-metric-calc-wrap var,
.nexus-metric-calc-wrap .mq-root-block {
    color: var(--text-primary);
}

.nexus-metric-calc-wrap .mq-operator-name,
.nexus-metric-calc-wrap .mq-binary-operator {
    color: var(--text-primary);
}

/* ── Definition textarea ── */

.nexus-metric-def {
    font-size: 1rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 6px;
    width: 100%;
    resize: vertical;
    min-height: 36px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    line-height: 1.45;
}

.nexus-metric-def:focus { border-color: var(--accent-color); }

/* ── KPI hover tooltip ── */

.nexus-node-tooltip {
    position: fixed;
    z-index: 9100;
    width: 320px;
    max-width: calc(100vw - 16px);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 6px 22px var(--shadow-color, rgba(0,0,0,0.35));
    padding: 10px 12px;
    pointer-events: none;
}

.nexus-node-tooltip.nnt-hidden { display: none; }

.nnt-section { margin-bottom: 8px; }
.nnt-section:last-child { margin-bottom: 0; }

.nnt-label {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 3px;
}

.nnt-text {
    font-size: 1rem;
    color: var(--text-primary);
    line-height: 1.45;
    white-space: pre-wrap;
    word-break: break-word;
}

.nnt-mono {
    font-family: var(--font-mono, monospace);
    font-size: 1rem;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-all;
}

.nnt-calc-render {
    display: block;
    color: var(--text-primary);
    padding: 2px 0;
    max-width: 100%;
    overflow-x: auto;
}

.nexus-node-tooltip .mq-static-math {
    display: block !important;
    max-width: 100%;
}

/* MathQuill static math in tooltip — dark theme */
.nexus-node-tooltip .mq-math-mode,
.nexus-node-tooltip .mq-static-math {
    background: transparent !important;
    color: var(--text-primary) !important;
    border: none !important;
    padding: 0 !important;
}

.nexus-node-tooltip var,
.nexus-node-tooltip .mq-root-block,
.nexus-node-tooltip .mq-operator-name,
.nexus-node-tooltip .mq-binary-operator,
.nexus-node-tooltip .mq-math-mode * {
    color: var(--text-primary) !important;
    background: transparent !important;
}

/* ── D3 Traceability Graph ─────────────────────────────────────────────────── */

#nexus-graph-svg {
    width: 100%;
    height: 100%;
    overflow: visible;
}

/* Edges */
.tg-edge {
    stroke: var(--border-color);
    stroke-opacity: 0.35;
    stroke-width: 1.5;
    fill: none;
    pointer-events: none;
}
.tg-edge.tg-dimmed { stroke-opacity: 0.08; }

/* Affinity lines — dotted, shown only when a metric is selected */
.tg-affinity {
    stroke-dasharray: 5 4;
    stroke-width: 1.5;
    stroke-opacity: 0.55;
    fill: none;
    pointer-events: none;
}

.tg-affinity-label {
    font-size: 14px;
    fill: var(--text-secondary);
    text-anchor: middle;
    dominant-baseline: central;
    pointer-events: none;
    user-select: none;
    opacity: 0.75;
}

/* Nodes — common */
.tg-node { cursor: pointer; }
.tg-node.tg-dimmed { opacity: 0.18; }

/* Question nodes */
.tg-node-question rect {
    fill: var(--accent-color);
}
.tg-node-question text {
    fill: #ffffff;
    font-size: 14px;
    font-weight: 600;
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
}
.tg-node-question.tg-selected rect {
    stroke: var(--highlight-border);
    stroke-width: 2.5;
}

/* Metric nodes */
.tg-node-metric circle {
    fill: var(--success-color);
}
.tg-node-metric text {
    fill: var(--text-secondary);
    font-size: 14px;
    text-anchor: middle;
    pointer-events: none;
    user-select: none;
}
.tg-node-metric.tg-selected circle {
    stroke: var(--highlight-border);
    stroke-width: 2.5;
}
.tg-node-metric:hover circle { opacity: 0.85; }

/* Inline node name editor overlay */
#nexus-inline-editor {
    position: fixed;
    z-index: 2000;
    box-sizing: border-box;
    padding: 2px 6px;
    border: 2px solid var(--accent-color);
    border-radius: 4px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    text-align: center;
    font-family: inherit;
    font-weight: 600;
    outline: none;
    pointer-events: auto;
}
#nexus-inline-editor.hidden { display: none; }

/* Cut KPI — pending clipboard cut visual */
.tg-node-cut circle {
    opacity: 0.4 !important;
    stroke-dasharray: 5 3 !important;
    stroke: var(--accent-color) !important;
    stroke-width: 2px !important;
}
.tg-node-cut text { opacity: 0.4; }

/* ── Segmented toggle (Settings modal) ── */
.btn-toggle-group {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.btn-toggle {
    padding: 5px 14px;
    font-size: 1rem;
    background: var(--bg-primary);
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-toggle + .btn-toggle {
    border-left: 1px solid var(--border-color);
}

.btn-toggle.active {
    background: var(--accent-color);
    color: #fff;
}

/* ── Nexus search badge ── */
.search-nexus-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: var(--accent-color);
    color: #fff;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
}

/* ── Graph search dimming ── */
.tg-node.tg-search-dim { opacity: 0.2; transition: opacity 0.15s; }
.tg-node:not(.tg-search-dim) { transition: opacity 0.15s; }
.tg-edge.tg-search-dim { stroke-opacity: 0.05; transition: stroke-opacity 0.15s; }
.tg-edge:not(.tg-search-dim) { transition: stroke-opacity 0.15s; }

/* ── Collapsed metric rows ── */
.nexus-metric-collapsed-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
    background: var(--bg-secondary);
    user-select: none;
}

.nexus-metric-collapsed-row:hover {
    border-color: var(--accent-color);
}

.nexus-metric-collapsed-row .ncr-name {
    font-size: 1rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.nexus-metric-collapsed-row .ncr-chevron {
    font-size: 1rem;
    color: var(--text-muted);
    margin-left: 8px;
    flex-shrink: 0;
    transition: transform 0.15s;
}

.nexus-metric-collapsed-row.open .ncr-chevron {
    transform: rotate(90deg);
}

.nexus-metric-expanded-body {
    border-left: 2px solid var(--accent-color);
    margin-left: 8px;
    margin-bottom: 6px;
    padding: 8px 0 8px 10px;
}

/* ── Question list search dimming ── */
.nexus-q-item.nexus-q-search-dim {
    opacity: 0.4;
    transition: opacity 0.15s;
}
.nexus-q-item:not(.nexus-q-search-dim) {
    transition: opacity 0.15s;
}
