/* Canvas Chat - Excalidraw-inspired aesthetic */

/* CSS Reset and Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Colors - Light mode */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-canvas: #f5f5f5;
    --text-primary: #1e1e1e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    /* Node colors */
    --node-human: #e3f2fd;
    --node-human-border: #90caf9;
    --node-ai: #f3e5f5;
    --node-ai-border: #ce93d8;
    --node-note: #fff9c4;
    --node-note-border: #fff176;
    --node-summary: #e8f5e9;
    --node-summary-border: #a5d6a7;
    --node-reference: #fff3e0;
    --node-reference-border: #ffcc80;
    --node-search: #e0f7fa;
    --node-search-border: #4dd0e1;
    --node-research: #ede7f6;
    --node-research-border: #b39ddb;
    --node-highlight: #fffde7;
    --node-highlight-border: #ffd54f;
    --node-opinion: #e8eaf6;
    --node-opinion-border: #7986cb;
    --node-synthesis: #fce4ec;
    --node-synthesis-border: #f06292;
    --node-review: #fff8e1;
    --node-review-border: #ffb74d;
    --node-pdf: #e8f4f8;
    --node-pdf-border: #4db6ac;
    --node-image: #fce4ec;
    --node-image-border: #f48fb1;

    /* UI colors */
    --edge-color: #495057;
    --edge-color-light: #adb5bd;
    --selection-color: #228be6;
    --selection-bg: rgba(34, 139, 230, 0.1);
    --context-highlight: rgba(34, 139, 230, 0.2);
    --accent: #228be6;
    --accent-hover: #1c7ed6;
    --danger: #fa5252;
    --success: #40c057;
    --warning: #fab005;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);

    /* Spacing */
    --toolbar-height: 48px;
    --input-height: 60px;

    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", Monaco, "Cascadia Code", "Roboto Mono", Consolas, monospace;

    /* Border radius - slightly rounded for hand-drawn feel */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a1a;
        --bg-secondary: #2d2d2d;
        --bg-canvas: #121212;
        --text-primary: #e4e4e7;
        --text-secondary: #a1a1aa;
        --text-muted: #71717a;

        --node-human: #1e3a5f;
        --node-human-border: #2563eb;
        --node-ai: #3b2d4a;
        --node-ai-border: #9333ea;
        --node-note: #3d3520;
        --node-note-border: #ca8a04;
        --node-summary: #1a3d27;
        --node-summary-border: #16a34a;
        --node-reference: #3d2e1f;
        --node-reference-border: #ea580c;
        --node-search: #1a3d3d;
        --node-search-border: #0891b2;
        --node-research: #2d2445;
        --node-research-border: #7c3aed;
        --node-highlight: #3d3a20;
        --node-highlight-border: #fbc02d;
        --node-opinion: #2d2d45;
        --node-opinion-border: #5c6bc0;
        --node-synthesis: #3d2d35;
        --node-synthesis-border: #ec407a;
        --node-review: #3d3520;
        --node-review-border: #ffa726;
        --node-pdf: #1a3d3d;
        --node-pdf-border: #26a69a;
        --node-image: #3d2d35;
        --node-image-border: #f06292;

        --edge-color: #9ca3af;
        --edge-color-light: #4b5563;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
    }
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-canvas);
}

/* Toolbar */
#toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--toolbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    overflow-x: auto;
    overflow-y: hidden;
}

/* Hide scrollbar but keep functionality */
#toolbar::-webkit-scrollbar {
    height: 4px;
}

#toolbar::-webkit-scrollbar-track {
    background: transparent;
}

#toolbar::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 2px;
}

#toolbar::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.toolbar-left, .toolbar-center, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.logo {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.session-name {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.session-name:hover {
    background: var(--bg-secondary);
}

.auto-title-btn {
    font-size: 14px;
    padding: 4px 6px;
    opacity: 0.6;
    transition: opacity 0.15s, transform 0.15s;
}

.auto-title-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

.auto-title-btn:disabled {
    cursor: wait;
    opacity: 0.4;
}

/* Context Budget Bar */
.context-budget {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.budget-bar {
    width: 120px;
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.budget-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
}

.budget-fill.warning {
    background: var(--warning);
}

.budget-fill.danger {
    background: var(--danger);
}

.budget-text {
    min-width: 80px;
    font-family: var(--font-mono);
    font-size: 11px;
}

/* Model Picker */
.model-picker {
    padding: 6px 10px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

.model-picker:hover {
    border-color: var(--accent);
}

.model-picker:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--selection-bg);
}

.model-picker.no-keys {
    border-color: var(--warning, #f59e0b);
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning, #f59e0b);
    font-style: italic;
}

/* Layout Controls */
.layout-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.layout-picker {
    padding: 6px 8px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    outline: none;
}

.layout-picker:hover {
    border-color: var(--accent);
}

.layout-picker:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--selection-bg);
}

/* Icon Buttons */
.icon-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 16px;
    transition: background 0.15s, opacity 0.15s;
}

.icon-btn:hover:not(:disabled) {
    background: var(--bg-secondary);
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Undo/Redo controls */
.undo-redo-controls {
    display: flex;
    gap: 2px;
    margin-right: 8px;
    padding-right: 12px;
    border-right: 1px solid var(--bg-secondary);
}

/* Canvas Container */
#canvas-container {
    position: fixed;
    top: var(--toolbar-height);
    left: 0;
    right: 0;
    bottom: var(--input-height);
    overflow: hidden;
    cursor: grab;
}

#canvas-container:active {
    cursor: grabbing;
}

#canvas {
    width: 100%;
    height: 100%;
    background: var(--bg-canvas);
}

/* Grid pattern for canvas (subtle) */
#canvas {
    background-image:
        radial-gradient(circle, var(--edge-color-light) 1px, transparent 1px);
    background-size: 24px 24px;
    background-position: center center;
}

/* Hint overlay when no nodes visible */
.no-nodes-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease-in;
}

.no-nodes-hint.visible {
    opacity: 1;
}

.no-nodes-hint .hint-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 32px;
    background: var(--bg-primary);
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.no-nodes-hint .hint-icon {
    font-size: 32px;
}

.no-nodes-hint .hint-text {
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

/* Drop zone overlay for PDF drag & drop */
.drop-zone-overlay {
    position: absolute;
    inset: 0;
    background: rgba(34, 139, 230, 0.1);
    border: 3px dashed var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    pointer-events: none;
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 24px 48px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.drop-zone-icon {
    font-size: 48px;
}

.drop-zone-text {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Canvas hint notification */
#canvas-hint {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    padding: 12px 24px;
    background: var(--bg-primary);
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 14px;
    color: var(--text-primary);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#canvas-hint.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Edges */
.edge {
    fill: none;
    stroke: var(--edge-color);
    stroke-width: 2;
    stroke-linecap: round;
}

.edge.highlight {
    stroke: var(--node-highlight-border);
    stroke-width: 2;
    stroke-dasharray: 8, 4;
}

.edge.context-highlight {
    stroke: var(--selection-color);
    stroke-width: 3;
}

.edge-arrow {
    fill: var(--edge-color);
}

/* Nodes */
.node-wrapper {
    overflow: visible;
}

.node {
    position: relative;
    width: 100%;
    min-width: 200px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    border: 2px solid transparent;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    cursor: pointer;
    overflow: visible;
}

.node:hover {
    box-shadow: var(--shadow-lg);
}

.node.selected {
    border-color: var(--selection-color);
    border-width: 3px;
    box-shadow: var(--shadow-lg), 0 0 0 4px rgba(34, 139, 230, 0.3);
    outline: 2px dashed var(--selection-color);
    outline-offset: 4px;
}

.node.copy-flash {
    animation: copy-flash 0.3s ease;
}

@keyframes copy-flash {
    0%, 100% { background-color: inherit; }
    50% { background-color: var(--success); opacity: 0.8; }
}

.node.faded {
    opacity: 0.4;
    transition: opacity 0.2s ease;
}

.node.context-ancestor {
    border-color: var(--selection-color);
    background: var(--context-highlight);
}

/* Ancestors should be less faded than non-ancestors */
.node.faded.context-ancestor {
    opacity: 0.85;
}

.node.dragging {
    opacity: 0.8;
    transform: scale(1.02);
    box-shadow: var(--shadow-lg);
}

/* Node Types */
.node.human {
    background: var(--node-human);
    border-color: var(--node-human-border);
}

.node.ai {
    background: var(--node-ai);
    border-color: var(--node-ai-border);
}

.node.note {
    background: var(--node-note);
    border-color: var(--node-note-border);
}

.node.summary {
    background: var(--node-summary);
    border-color: var(--node-summary-border);
}

.node.reference {
    background: var(--node-reference);
    border-color: var(--node-reference-border);
}

.node.search {
    background: var(--node-search);
    border-color: var(--node-search-border);
}

.node.research {
    background: var(--node-research);
    border-color: var(--node-research-border);
}

.node.highlight {
    background: var(--node-highlight);
    border-color: var(--node-highlight-border);
    border-style: dashed;
}

.node.opinion {
    background: var(--node-opinion);
    border-color: var(--node-opinion-border);
}

.node.synthesis {
    background: var(--node-synthesis);
    border-color: var(--node-synthesis-border);
}

.node.review {
    background: var(--node-review);
    border-color: var(--node-review-border);
}

.node.pdf {
    background: var(--node-pdf);
    border-color: var(--node-pdf-border);
}

.node.image {
    background: var(--node-image);
    border-color: var(--node-image-border);
}

/* Source text highlight - shown in parent node when a highlight excerpt is selected */
.source-highlight {
    background: var(--node-highlight);
    color: inherit;
    padding: 2px 0;
    /* Use box-decoration-break to make multi-element highlights appear contiguous */
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
    animation: sourceHighlightPulse 2s ease-in-out infinite;
}

/* Apply border-radius and padding only to first/last marks for seamless look */
.node-content .source-highlight:first-of-type {
    padding-left: 4px;
    border-top-left-radius: 3px;
    border-bottom-left-radius: 3px;
}

.node-content .source-highlight:last-of-type {
    padding-right: 4px;
    border-top-right-radius: 3px;
    border-bottom-right-radius: 3px;
}

/* When there's only one highlight, it gets both rounded ends */
.node-content .source-highlight:only-of-type {
    padding: 2px 4px;
    border-radius: 3px;
}

@keyframes sourceHighlightPulse {
    0%, 100% {
        background: var(--node-highlight);
    }
    50% {
        background: color-mix(in srgb, var(--node-highlight) 70%, var(--node-highlight-border));
    }
}

/* Node Summary Overlay (for semantic zoom) */
.node-summary {
    display: flex;
    position: absolute;
    inset: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 16px;
    text-align: center;
    background: inherit;
    border-radius: inherit;
    gap: 8px;
    cursor: pointer;
    overflow: hidden;
    /* Start hidden - smooth transitions */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Custom tooltip for node summary - progressive disclosure */
.node-summary::after {
    content: "Double-click to edit title";
    position: absolute;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 400;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.node-summary:hover::after {
    opacity: 1;
}

.node-type-icon {
    font-size: 28px;
    line-height: 1;
    transition: font-size 0.3s ease;
}

.summary-text {
    font-size: 18px;
    font-weight: 500;
    line-height: 1.3;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    transition: font-size 0.3s ease, text-align 0.3s ease;
}

/* Smooth transitions for node content elements */
.node-header,
.node-content,
.node-actions,
.resize-handle,
.node-tags {
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

/* Semantic Zoom Levels */

/* Full zoom (scale > 0.6) - normal view */
.zoom-full .node-summary {
    opacity: 0;
    visibility: hidden;
}

.zoom-full .node-header,
.zoom-full .node-content,
.zoom-full .node-actions,
.zoom-full .resize-handle,
.zoom-full .node-tags {
    opacity: 1;
    visibility: visible;
}

/* Summary zoom (scale 0.35-0.6) - show summary, hide details */
.zoom-summary .node-summary {
    opacity: 1;
    visibility: visible;
}

.zoom-summary .node-summary .node-type-icon {
    font-size: 32px;
}

.zoom-summary .node-summary .summary-text {
    font-size: 22px;
}

.zoom-summary .node-header,
.zoom-summary .node-content,
.zoom-summary .node-actions,
.zoom-summary .resize-handle {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Tags remain visible when zoomed out */
.zoom-summary .node-tags {
    opacity: 1;
    visibility: visible;
}

/* Mini zoom (scale < 0.35) - minimal view */
.zoom-mini .node-summary {
    opacity: 1;
    visibility: visible;
    flex-direction: row;
    gap: 12px;
    padding: 20px;
}

.zoom-mini .node-summary .node-type-icon {
    font-size: 48px;
}

.zoom-mini .node-summary .summary-text {
    font-size: 32px;
    text-align: left;
}

.zoom-mini .node-header,
.zoom-mini .node-content,
.zoom-mini .node-actions,
.zoom-mini .resize-handle {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Tags remain visible even at mini zoom */
.zoom-mini .node-tags {
    opacity: 1;
    visibility: visible;
}

/* Reply Tooltip - floating tooltip with input on text selection */
.reply-tooltip {
    position: fixed;
    z-index: 10000;
    background: var(--bg-primary);
    border: 1px solid var(--edge-color-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    min-width: 280px;
    max-width: 400px;
    animation: tooltipFadeIn 0.15s ease-out;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reply-tooltip-selection {
    margin-bottom: 8px;
    padding: 6px 8px;
    background: var(--node-highlight);
    border-left: 3px solid var(--node-highlight-border);
    border-radius: var(--radius-sm);
}

.reply-tooltip-selection-text {
    font-size: 12px;
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.4;
    display: block;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.reply-tooltip-input-row {
    display: flex;
    gap: 6px;
}

.reply-tooltip-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    transition: border-color 0.15s;
}

.reply-tooltip-input:focus {
    border-color: var(--accent);
}

.reply-tooltip-input::placeholder {
    color: var(--text-muted);
}

.reply-tooltip-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.reply-tooltip-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.reply-tooltip-btn:active {
    transform: scale(0.98);
}

/* Image Action Tooltip */
.image-tooltip {
    position: fixed;
    z-index: 10000;
    background: var(--bg-primary);
    border: 1px solid var(--edge-color-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    width: 200px;
    animation: tooltipFadeIn 0.15s ease-out;
}

.image-tooltip-preview {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.image-tooltip-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.image-tooltip-actions {
    display: flex;
    gap: 6px;
}

.image-tooltip-btn {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.image-tooltip-btn:hover {
    background: var(--accent);
    color: white;
}

.image-tooltip-btn:active {
    transform: scale(0.98);
}

/* Slash Command Menu */
.slash-command-menu {
    position: fixed;
    z-index: 10001;
    background: var(--bg-primary);
    border: 1px solid var(--edge-color-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    min-width: 200px;
    max-width: 320px;
    animation: tooltipFadeIn 0.1s ease-out;
}

.slash-command-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.1s;
}

.slash-command-item:hover,
.slash-command-item.selected {
    background: var(--selection-bg);
}

.slash-command-name {
    font-size: 13px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--accent);
}

.slash-command-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.slash-command-hint {
    padding: 6px 12px;
    border-top: 1px solid var(--bg-secondary);
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

.slash-command-hint kbd {
    display: inline-block;
    padding: 1px 4px;
    font-family: var(--font-mono);
    font-size: 10px;
    background: var(--bg-secondary);
    border-radius: 3px;
    border: 1px solid var(--edge-color-light);
    margin: 0 1px;
}

/* Node Header */
.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    font-size: 11px;
    color: var(--text-muted);
}

/* Drag Handle */
.drag-handle {
    display: grid;
    grid-template-columns: repeat(2, 5px);
    grid-template-rows: repeat(3, 5px);
    gap: 2px;
    padding: 4px;
    margin: -4px;
    margin-right: 4px;
    cursor: grab;
    border-radius: var(--radius-sm);
    transition: background 0.15s;
}

.drag-handle:hover {
    background: rgba(0, 0, 0, 0.08);
}

.drag-handle:active {
    cursor: grabbing;
    background: rgba(0, 0, 0, 0.12);
}

.grip-dot {
    width: 3px;
    height: 3px;
    background: var(--text-muted);
    border-radius: 50%;
    opacity: 0.6;
}

.drag-handle:hover .grip-dot {
    opacity: 1;
}

.node-type {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.node-model {
    font-family: var(--font-mono);
}

.node-header .delete-btn {
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
    background: transparent;
    border: none;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
}

.node:hover .node-header .delete-btn {
    opacity: 0.6;
}

.node-header .delete-btn:hover {
    opacity: 1;
    background: rgba(250, 82, 82, 0.15);
    color: var(--danger);
}

/* Node Content */
.node-content {
    padding: 12px;
    padding-right: 18px;  /* Make room for resize-e handle */
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

.node-content::selection {
    background: var(--selection-bg);
}

/* Streaming indicator */
.node-content.streaming::after {
    content: "▋";
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Header buttons (stop/continue) - in node header next to delete */
.header-btn {
    padding: 4px 8px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    display: none;
}

.header-btn.stop-btn {
    background: var(--danger);
    color: white;
}

.header-btn.stop-btn:hover {
    background: #e03131;
}

.header-btn.continue-btn {
    background: var(--success);
    color: white;
}

.header-btn.continue-btn:hover {
    background: #2f9e44;
}

.header-btn.fit-viewport-btn,
.header-btn.reset-size-btn {
    display: inline-flex;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.node:hover .header-btn.fit-viewport-btn,
.node:hover .header-btn.reset-size-btn {
    opacity: 0.6;
}

.header-btn.fit-viewport-btn:hover,
.header-btn.reset-size-btn:hover {
    opacity: 1;
    background: var(--accent);
    color: white;
}

/* Navigation buttons */
.header-btn.nav-parent-btn,
.header-btn.nav-child-btn {
    display: inline-flex;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
    font-size: 14px;
    font-weight: bold;
    min-width: 24px;
    justify-content: center;
}

.node:hover .header-btn.nav-parent-btn,
.node:hover .header-btn.nav-child-btn {
    opacity: 0.6;
}

.header-btn.nav-parent-btn:hover,
.header-btn.nav-child-btn:hover {
    opacity: 1;
    background: var(--accent);
    color: white;
}

/* Disabled state for nav buttons (no parent/child) */
.header-btn.nav-parent-btn.disabled,
.header-btn.nav-child-btn.disabled {
    opacity: 0.2 !important;
    cursor: not-allowed;
    pointer-events: none;
}

.node:hover .header-btn.nav-parent-btn.disabled,
.node:hover .header-btn.nav-child-btn.disabled {
    opacity: 0.2 !important;
}

/* Navigation Popover */
.nav-popover {
    position: fixed;
    z-index: 1001;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    min-width: 200px;
    max-width: 320px;
    max-height: 300px;
    overflow-y: auto;
}

.nav-popover-title {
    padding: 8px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-tertiary);
    border-bottom: 1px solid var(--border);
}

.nav-popover-list {
    padding: 4px;
}

.nav-popover-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.nav-popover-item:hover {
    background: var(--selection-bg);
}

.nav-popover-item.selected {
    background: var(--selection-bg);
    outline: 2px solid var(--border);
    outline-offset: -2px;
}

/* Navigation toast message */
.nav-toast {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: var(--radius-md);
    font-size: 13px;
    box-shadow: var(--shadow-md);
    pointer-events: none;
    z-index: 1002;
    animation: nav-toast-fade 2s ease-in-out forwards;
}

@keyframes nav-toast-fade {
    0% { opacity: 0; transform: translateY(8px); }
    12% { opacity: 1; transform: translateY(0); }
    88% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-8px); }
}

.nav-popover-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.nav-popover-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.nav-popover-summary {
    font-size: 12px;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

/* Viewport-fitted nodes have scrollable content */
.node.viewport-fitted {
    display: flex;
    flex-direction: column;
    /* Note: overflow is NOT set here so tags (positioned outside) aren't clipped */
    /* The .node-content child handles its own overflow:auto */
}

.node.viewport-fitted .node-content {
    flex: 1;
    overflow: auto;
    min-height: 0;
    /* Prevent scroll chaining - don't pan canvas when reaching scroll boundaries */
    overscroll-behavior: contain;
}

/* Node Actions */
.node-actions {
    display: flex;
    gap: 4px;
    padding: 8px 12px;
    padding-bottom: 16px;  /* Make room for resize-s handle */
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    opacity: 0;
    transition: opacity 0.15s;
    position: relative;
    z-index: 1;
}

.node:hover .node-actions {
    opacity: 1;
}

.node-action {
    padding: 4px 8px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.node-action:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Error node styling */
.node.error-node {
    border-color: var(--danger);
    background: #fff5f5;
}

@media (prefers-color-scheme: dark) {
    .node.error-node {
        background: #2d1f1f;
    }
}

.error-content {
    text-align: center;
    padding: 20px 16px;
}

.error-icon {
    font-size: 32px;
    margin-bottom: 8px;
}

.error-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--danger);
    margin-bottom: 8px;
}

.error-description {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.4;
}

.error-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.error-retry-btn,
.error-dismiss-btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

.error-retry-btn {
    background: var(--accent);
    color: white;
}

.error-retry-btn:hover {
    background: var(--accent-hover);
}

.error-dismiss-btn {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.error-dismiss-btn:hover {
    background: var(--border);
}

/* Resize Handles */
.resize-handle {
    position: absolute;
    background: transparent;
    z-index: 10;
    pointer-events: auto;
}

.resize-handle:hover {
    background: var(--accent);
    opacity: 0.3;
}

.resize-e {
    right: 0;
    top: 0;
    width: 8px;
    height: 100%;
    cursor: ew-resize;
    border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.resize-s {
    bottom: 0;
    left: 0;
    width: 100%;
    height: 8px;
    cursor: ns-resize;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.resize-se {
    right: 0;
    bottom: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    border-radius: 0 0 var(--radius-lg) 0;
}

.resize-se::after {
    content: "";
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 8px;
    height: 8px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    opacity: 0.5;
}

.node:hover .resize-se::after {
    opacity: 1;
}

/* Markdown Content Styles */
.node-content h1,
.node-content h2,
.node-content h3,
.node-content h4,
.node-content h5,
.node-content h6 {
    margin-top: 0.5em;
    margin-bottom: 0.25em;
    font-weight: 600;
    line-height: 1.3;
}

.node-content h1 { font-size: 1.4em; }
.node-content h2 { font-size: 1.25em; }
.node-content h3 { font-size: 1.1em; }
.node-content h4,
.node-content h5,
.node-content h6 { font-size: 1em; }

.node-content p {
    margin: 0.5em 0;
}

.node-content ul,
.node-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

.node-content li {
    margin: 0.25em 0;
}

.node-content code {
    background: rgba(0, 0, 0, 0.08);
    padding: 0.15em 0.4em;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.node-content pre {
    background: rgba(0, 0, 0, 0.08);
    padding: 0.75em 1em;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0.5em 0;
}

.node-content pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
}

.node-content blockquote {
    border-left: 3px solid var(--accent);
    margin: 0.5em 0;
    padding-left: 1em;
    color: var(--text-secondary);
}

.node-content a {
    color: var(--accent);
    text-decoration: none;
}

.node-content a:hover {
    text-decoration: underline;
}

.node-content table {
    border-collapse: collapse;
    margin: 0.5em 0;
    width: 100%;
}

.node-content th,
.node-content td {
    border: 1px solid var(--bg-secondary);
    padding: 0.4em 0.6em;
    text-align: left;
}

.node-content th {
    background: var(--bg-secondary);
    font-weight: 600;
}

.node-content hr {
    border: none;
    border-top: 1px solid var(--bg-secondary);
    margin: 1em 0;
}

.node-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

/* Image node content (for IMAGE type nodes) */
.image-node-content {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    height: 100%;
    min-height: 150px;
}

.node-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: transform 0.15s ease;
}

.node-image:hover {
    transform: scale(1.02);
}

/* Dark mode adjustments for markdown */
@media (prefers-color-scheme: dark) {
    .node-content code {
        background: rgba(255, 255, 255, 0.1);
    }

    .node-content pre {
        background: rgba(255, 255, 255, 0.08);
    }
}

/* Math rendering adjustments */
.node-content .katex-display {
    margin: 0.5em 0;
    overflow-x: auto;
}

.node-content .katex {
    font-size: 1em;
}

/* Chat Input */
#chat-input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-primary);
    border-top: 1px solid var(--bg-secondary);
    padding: 10px 20px;
    z-index: 100;
}

.selected-nodes-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 6px 12px;
    background: var(--selection-bg);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--accent);
}

.selected-nodes-indicator button {
    margin-left: auto;
    border: none;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    font-size: 14px;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
}

#chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--bg-secondary);
    border-radius: var(--radius-lg);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    resize: none;
    outline: none;
    max-height: 150px;
    transition: border-color 0.15s;
}

#chat-input:focus {
    border-color: var(--accent);
}

#chat-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: var(--accent);
    color: white;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.attach-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.attach-btn:hover {
    color: var(--accent);
    background: var(--bg-secondary);
}

.attach-btn:active {
    transform: scale(0.95);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 480px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--bg-secondary);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    font-size: 24px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Settings Modal */
.settings-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.api-key-group {
    margin-bottom: 16px;
}

.api-key-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.api-key-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
    outline: none;
}

.api-key-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--selection-bg);
}

.api-key-group .key-hint {
    display: block;
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-muted);
}

.api-key-group .key-hint code {
    background: var(--bg-secondary);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
}

.api-key-group .key-hint a {
    color: var(--accent);
    text-decoration: none;
}

.api-key-group .key-hint a:hover {
    text-decoration: underline;
}

.api-key-group.copilot-note {
    background: var(--node-highlight);
    border: 1px solid var(--node-highlight-border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-top: 8px;
}

.api-key-group.copilot-note strong {
    display: block;
    font-size: 12px;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.api-key-group.copilot-note .key-hint {
    margin-top: 0;
}

.primary-btn {
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: var(--accent);
    color: white;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s;
}

.primary-btn:hover {
    background: var(--accent-hover);
}

/* Session List */
.session-list {
    margin-top: 16px;
}

.session-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.15s;
}

.session-item:hover {
    background: var(--bg-secondary);
}

.session-item-name {
    font-weight: 500;
}

.session-item-date {
    font-size: 12px;
    color: var(--text-muted);
}

.session-item-delete {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--danger);
    cursor: pointer;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity 0.15s, background 0.15s;
}

.session-item:hover .session-item-delete {
    opacity: 1;
}

.session-item-delete:hover {
    background: rgba(250, 82, 82, 0.1);
}

/* Tooltip styles for context menu could go here */

/* Loading state for nodes */
.node.loading .node-content::after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty state */
.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
}

.empty-state a {
    color: var(--accent-color);
    text-decoration: underline;
    cursor: pointer;
}

.empty-state a:hover {
    color: var(--accent-hover);
}

/* Keyboard shortcut hints */
kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    background: var(--bg-secondary);
    border-radius: 3px;
    border: 1px solid var(--edge-color-light);
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--edge-color-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--edge-color);
}

/* Modal wide variant */
.modal-wide {
    max-width: 700px;
}

/* Modal narrow variant (for simple text input) */
.modal-narrow {
    max-width: 400px;
}

/* Modal text input */
.modal-text-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.modal-text-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

/* Modal extra-wide variant (for editing large content) */
.modal-extra-wide {
    max-width: 90vw;
    width: 90vw;
    height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-extra-wide .modal-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 12px 20px;
}

/* Split-pane editor layout */
.edit-content-body {
    flex-direction: row !important;
    gap: 16px;
}

.edit-content-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.pane-header {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--bg-secondary);
}

#edit-content-textarea {
    flex: 1;
    width: 100%;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    padding: 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: none;
    outline: none;
}

#edit-content-textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--selection-bg);
}

#edit-content-preview {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
}

.modal-extra-wide .modal-actions {
    padding: 12px 20px 20px;
}

/* Help Modal */
.help-content {
    max-height: 70vh;
    overflow-y: auto;
}

.help-section {
    margin-bottom: 24px;
}

.help-section:last-child {
    margin-bottom: 0;
}

.help-section h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.help-section ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.help-section ul li {
    padding: 6px 0;
    color: var(--text-secondary);
    line-height: 1.5;
}

.help-section ul li strong {
    color: var(--text-primary);
}

.shortcuts-table {
    width: 100%;
    border-collapse: collapse;
}

.shortcuts-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--bg-secondary);
}

.shortcuts-table td:first-child {
    width: 50%;
    white-space: nowrap;
}

.shortcuts-table td:last-child {
    color: var(--text-secondary);
}

.shortcuts-table code {
    background: var(--bg-secondary);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 12px;
    color: var(--accent);
}

.shortcuts-table em {
    color: var(--text-muted);
    font-style: italic;
}

/* Keyboard key styling */
kbd {
    display: inline-block;
    padding: 3px 6px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 11px;
    line-height: 1;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 1px 0 var(--border);
}

/* Matrix Modal */

.matrix-context-group {
    margin-bottom: 20px;
}

.matrix-context-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.matrix-context-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
}

.matrix-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px;
    color: var(--text-secondary);
    font-size: 14px;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--bg-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.matrix-axes {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.matrix-axis {
    flex: 1;
    min-width: 0;
}

.axis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.axis-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.axis-count {
    font-size: 12px;
    color: var(--text-muted);
}

.axis-items {
    list-style: none;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-md);
    max-height: 300px;
    overflow-y: auto;
}

.axis-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid var(--bg-secondary);
    gap: 8px;
}

.axis-item:last-child {
    border-bottom: none;
}

.axis-item-text {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.axis-item-input {
    flex: 1;
    font-size: 13px;
    padding: 4px 8px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    min-width: 0;
}

.axis-item-input:hover {
    border-color: var(--bg-secondary);
    background: var(--bg-primary);
}

.axis-item-input:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--bg-primary);
}

.axis-add-btn {
    width: 100%;
    padding: 8px;
    margin-top: 8px;
    border: 1px dashed var(--text-muted);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.axis-add-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--selection-bg);
}

.axis-item-remove {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.15s;
}

.axis-item:hover .axis-item-remove {
    opacity: 1;
}

.axis-item-remove:hover {
    color: var(--danger);
    background: rgba(250, 82, 82, 0.1);
}

.matrix-swap {
    display: flex;
    align-items: center;
    padding-top: 30px;
}

.matrix-swap .icon-btn {
    font-size: 20px;
}

.matrix-warning {
    margin-top: 16px;
    padding: 8px 12px;
    background: rgba(250, 176, 5, 0.1);
    border: 1px solid var(--warning);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--warning);
}

/* Committee Modal */
.committee-question-group {
    margin-bottom: 20px;
}

.committee-question-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.committee-question-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    resize: none;
}

.committee-models-group {
    margin-bottom: 20px;
}

.committee-models-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.committee-models-header label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.committee-models-count {
    font-size: 12px;
    color: var(--text-muted);
}

.committee-models-count.valid {
    color: var(--success);
}

.committee-models-count.invalid {
    color: var(--danger);
}

.committee-models-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}

.committee-model-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    cursor: pointer;
    transition: all 0.15s;
    border: 1px solid transparent;
}

.committee-model-item:hover {
    border-color: var(--accent);
}

.committee-model-item.selected {
    border-color: var(--accent);
    background: var(--selection-bg);
}

.committee-model-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--accent);
}

.committee-model-item .model-name {
    font-size: 12px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.committee-chairman-group {
    margin-bottom: 20px;
}

.committee-chairman-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.committee-chairman-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

.committee-chairman-select:focus {
    outline: none;
    border-color: var(--accent);
}

.committee-options-group {
    margin-bottom: 8px;
}

.committee-checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--bg-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s;
}

.committee-checkbox-label:hover {
    background: var(--bg-secondary);
}

.committee-checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    cursor: pointer;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.committee-checkbox-label .checkbox-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
}

.committee-checkbox-label .checkbox-hint {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.modal-actions .secondary-btn,
.modal-actions .primary-btn {
    flex: 1;
    width: auto;
}

.secondary-btn {
    padding: 12px 16px;
    border: 1px solid var(--bg-secondary);
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background 0.15s;
}

.secondary-btn:hover {
    background: var(--bg-secondary);
}

/* Cell Detail Modal */
.cell-detail-row {
    margin-bottom: 16px;
}

.cell-detail-row label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.cell-copy-btn {
    padding: 2px 6px;
    font-size: 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--edge-color-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-transform: none;
}

.cell-copy-btn:hover {
    background: var(--bg-canvas);
}

.cell-detail-content {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.5;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.cell-evaluation {
    min-height: 60px;
}

.slice-content {
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* Matrix Node */
.node.matrix {
    background: var(--bg-primary);
    border-color: var(--accent);
}

.node.matrix .node-content {
    padding: 0;
    overflow: hidden;
    height: calc(100% - 125px); /* Fill available space minus header/summary/context/footer */
    display: flex;
    flex-direction: column;
}

.matrix-context {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-style: italic;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--edge-color-light);
}

.matrix-context-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.matrix-context-copy {
    flex-shrink: 0;
    padding: 2px 6px;
    font-size: 12px;
    font-style: normal;
    background: var(--bg-primary);
    border: 1px solid var(--edge-color-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.matrix-context:hover .matrix-context-copy {
    opacity: 1;
}

.matrix-context-copy:hover {
    background: var(--bg-canvas);
}

.matrix-table-container {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.matrix-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    table-layout: fixed;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.matrix-table thead {
    flex-shrink: 0;
    display: block;
}

.matrix-table thead tr {
    display: flex;
    width: 100%;
}

.matrix-table tbody {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.matrix-table tbody tr {
    display: flex;
    flex: 1;
    min-height: 0;
}

.matrix-table th,
.matrix-table td {
    border: 1px solid var(--bg-secondary);
    padding: 4px 6px;
    text-align: left;
    vertical-align: top;
    overflow: hidden;
    flex: 1;
    min-height: 0;
}

.matrix-table th:first-child,
.matrix-table td:first-child {
    flex: 0 0 25%;
}

.matrix-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    height: auto; /* Headers keep natural height */
}

.matrix-table th:first-child,
.matrix-table td:first-child {
    background: var(--bg-secondary);
    font-weight: 500;
}

.matrix-table td.row-header {
    background: var(--bg-secondary);
    cursor: pointer;
    transition: background 0.15s;
}

.matrix-table td.row-header:hover {
    background: var(--selection-bg);
}

.matrix-table th.col-header {
    cursor: pointer;
    transition: background 0.15s;
}

.matrix-table th.col-header:hover {
    background: var(--selection-bg);
}

.matrix-table .corner-cell {
    background: var(--accent);
    color: white;
}

.matrix-header-text {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Dynamic width - fills available space */
}

.matrix-cell {
    cursor: pointer;
    transition: background 0.15s;
    overflow: hidden;
    position: relative;
}

.matrix-cell:hover {
    background: var(--selection-bg);
}

.matrix-cell-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 16px;
}

.matrix-cell-fill {
    width: 24px;
    height: 24px;
    border: 1px dashed var(--text-muted);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.matrix-cell-fill:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--selection-bg);
}

.matrix-cell-content {
    font-size: 11px;
    line-height: 1.4;
    color: var(--text-primary);
    overflow: hidden;
    word-wrap: break-word;
    /* Fill cell and truncate overflow */
    height: 100%;
    position: relative;
}

/* Fade out effect at the bottom when content is truncated */
.matrix-cell-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1.4em;
    background: linear-gradient(transparent, white);
    pointer-events: none;
}

.matrix-cell.highlighted {
    background: var(--selection-bg);
    box-shadow: inset 0 0 0 2px var(--selection-color);
    animation: cellPulse 1.5s ease-in-out infinite;
}

@keyframes cellPulse {
    0%, 100% { box-shadow: inset 0 0 0 2px var(--selection-color); }
    50% { box-shadow: inset 0 0 0 3px var(--selection-color), 0 0 8px var(--selection-color); }
}

.matrix-cell.loading {
    position: relative;
}

.matrix-cell.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.matrix-actions {
    display: flex;
    gap: 4px;
    padding: 8px;
    border-top: 1px solid var(--bg-secondary);
    background: var(--bg-secondary);
}

.matrix-actions button {
    flex: 1;
    padding: 6px 8px;
    border: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.matrix-actions button:hover {
    background: var(--accent);
    color: white;
}

/* Cell Node */
.node.cell {
    background: var(--bg-primary);
    border-color: var(--accent);
    border-style: dashed;
}

.node.cell .node-header {
    background: var(--selection-bg);
}

/* Matrix Cell Edge */
.edge.matrix_cell {
    stroke: var(--accent);
    stroke-dasharray: 4, 4;
}

/* ===== Tag Drawer ===== */
.tag-drawer {
    position: fixed;
    top: 50px;
    right: -250px;
    width: 240px;
    height: calc(100vh - 50px);
    background: var(--bg-primary);
    border-left: 1px solid var(--bg-secondary);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    transition: right 0.25s ease;
    z-index: 100;
}

.tag-drawer.open {
    right: 0;
}

.tag-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--bg-secondary);
}

.tag-drawer-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.tag-drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.tag-slots {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tag-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.tag-slot:hover {
    background: var(--bg-secondary);
}

.tag-slot.active {
    border-color: var(--accent);
    background: var(--selection-bg);
}

.tag-slot.partial {
    border-style: dashed;
    border-color: var(--accent);
}

.tag-color-dot {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    flex-shrink: 0;
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.tag-slot-content {
    flex: 1;
    min-width: 0;
}

.tag-slot-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-slot-empty {
    font-size: 13px;
    color: var(--text-muted);
}

.tag-slot-input {
    width: 100%;
    padding: 2px 4px;
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 13px;
    outline: none;
    background: var(--bg-primary);
    color: var(--text-primary);
}

.tag-slot-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s;
}

.tag-slot:hover .tag-slot-actions {
    opacity: 1;
}

.tag-slot-btn {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    border-radius: var(--radius-sm);
}

.tag-slot-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.tag-slot-btn.delete:hover {
    background: #ffc9c9;
    color: #c92a2a;
}

.tag-drawer-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--bg-secondary);
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

.tag-drawer-footer.has-selection {
    color: var(--accent);
    font-weight: 500;
}

/* Tags on nodes */
.node-tags {
    position: absolute;
    right: 100%;
    top: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 8px;
}

.node-tag {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: var(--shadow-sm);
    position: relative;
}

.node-tag::after {
    content: '';
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 8px solid currentColor;
}

/* Tag colors - text colors for contrast */
.node-tag[data-color="#ffc9c9"] { background: #ffc9c9; color: #c92a2a; }
.node-tag[data-color="#ffc9c9"]::after { border-left-color: #ffc9c9; }

.node-tag[data-color="#ffd8a8"] { background: #ffd8a8; color: #d9480f; }
.node-tag[data-color="#ffd8a8"]::after { border-left-color: #ffd8a8; }

.node-tag[data-color="#fff3bf"] { background: #fff3bf; color: #e67700; }
.node-tag[data-color="#fff3bf"]::after { border-left-color: #fff3bf; }

.node-tag[data-color="#c0eb75"] { background: #c0eb75; color: #2b8a3e; }
.node-tag[data-color="#c0eb75"]::after { border-left-color: #c0eb75; }

.node-tag[data-color="#a5d8ff"] { background: #a5d8ff; color: #1971c2; }
.node-tag[data-color="#a5d8ff"]::after { border-left-color: #a5d8ff; }

.node-tag[data-color="#d0bfff"] { background: #d0bfff; color: #7048e8; }
.node-tag[data-color="#d0bfff"]::after { border-left-color: #d0bfff; }

.node-tag[data-color="#fcc2d7"] { background: #fcc2d7; color: #c2255c; }
.node-tag[data-color="#fcc2d7"]::after { border-left-color: #fcc2d7; }

.node-tag[data-color="#e9ecef"] { background: #e9ecef; color: #495057; }
.node-tag[data-color="#e9ecef"]::after { border-left-color: #e9ecef; }

/* Tags button active state */
#tags-btn.active {
    background: var(--selection-bg);
    color: var(--accent);
}

/* ===== Search Overlay ===== */
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 15vh;
    z-index: 1000;
    animation: overlayFadeIn 0.15s ease-out;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.search-container {
    width: 90%;
    max-width: 560px;
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    animation: searchSlideIn 0.2s ease-out;
}

@keyframes searchSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.search-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--bg-secondary);
}

.search-icon {
    font-size: 18px;
    opacity: 0.5;
}

.search-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    font-family: var(--font-sans);
    color: var(--text-primary);
    outline: none;
}

.search-input::placeholder {
    color: var(--text-muted);
}

.search-hint {
    padding: 4px 8px;
    font-size: 11px;
    background: var(--bg-secondary);
    border: 1px solid var(--edge-color-light);
    border-radius: 4px;
    color: var(--text-muted);
}

.search-results {
    max-height: 400px;
    overflow-y: auto;
}

.search-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.search-result {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.1s;
    border-bottom: 1px solid var(--bg-secondary);
}

.search-result:last-child {
    border-bottom: none;
}

.search-result:hover,
.search-result.selected {
    background: var(--bg-secondary);
}

.search-result.selected {
    background: var(--selection-bg);
}

.search-result-icon {
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

.search-result-content {
    flex: 1;
    min-width: 0;
}

.search-result-type {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.search-result-snippet {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.search-result-snippet mark {
    background: var(--node-highlight);
    color: inherit;
    padding: 0 2px;
    border-radius: 2px;
}

.search-no-results {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.search-result-nav-hint {
    padding: 8px 20px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-secondary);
    display: flex;
    gap: 16px;
    justify-content: center;
}

.search-result-nav-hint kbd {
    margin: 0 4px;
}
