/* Dark theme (default) */
:root, [data-theme="dark"] {
    --color-bg: #1e1e1e;
    --color-surface: #1e293b;
    --color-surface-hover: #334155;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-text-dim: #64748b;
    --color-accent: #3b82f6;
    --color-accent-hover: #60a5fa;
    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.15);
    --color-error: #ef4444;
    --color-error-bg: rgba(239, 68, 68, 0.15);
    --color-warning: #f59e0b;
    --color-stuff: #f59e0b;
    --color-stuff-bg: rgba(245, 158, 11, 0.15);
    --color-stuff-border: #d97706;
    --color-stuff-text: #fef3c7;
    --color-stuff-text-dim: #fcd34d;
    --color-pipe: #3b82f6;
    --color-pipe-bg: rgba(59, 130, 246, 0.1);
    --color-pipe-text: #dbeafe;
    --color-pipe-failed: #ef4444;
    --color-pipe-failed-bg: rgba(239, 68, 68, 0.15);
    --color-edge: #3b82f6;
    --color-batch-item: #a855f7;
    --color-batch-aggregate: #22c55e;
    --color-parallel-combine: #c084fc;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Monaco', 'Menlo', monospace;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-pill: 999px;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
}
/* Light theme */
[data-theme="light"] {
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-surface-hover: #f1f5f9;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-dim: #94a3b8;
    --color-accent: #3b82f6;
    --color-accent-hover: #2563eb;
    --color-success: #10b981;
    --color-success-bg: rgba(16, 185, 129, 0.1);
    --color-error: #ef4444;
    --color-error-bg: rgba(239, 68, 68, 0.1);
    --color-warning: #f59e0b;
    --color-stuff: #f59e0b;
    --color-stuff-bg: rgba(245, 158, 11, 0.1);
    --color-stuff-border: #d97706;
    --color-stuff-text: #78350f;
    --color-stuff-text-dim: #92400e;
    --color-pipe: #3b82f6;
    --color-pipe-bg: rgba(59, 130, 246, 0.08);
    --color-pipe-text: #1e3a8a;
    --color-pipe-failed: #ef4444;
    --color-pipe-failed-bg: rgba(239, 68, 68, 0.1);
    --color-edge: #3b82f6;
    --color-batch-item: #9333ea;
    --color-batch-aggregate: #16a34a;
    --color-parallel-combine: #a855f7;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
}
/* System theme - follows OS preference */
@media (prefers-color-scheme: light) {
    [data-theme="system"] {
        --color-bg: #f8fafc;
        --color-surface: #ffffff;
        --color-surface-hover: #f1f5f9;
        --color-border: #e2e8f0;
        --color-text: #1e293b;
        --color-text-muted: #64748b;
        --color-text-dim: #94a3b8;
        --color-accent: #3b82f6;
        --color-accent-hover: #2563eb;
        --color-success: #10b981;
        --color-success-bg: rgba(16, 185, 129, 0.1);
        --color-error: #ef4444;
        --color-error-bg: rgba(239, 68, 68, 0.1);
        --color-warning: #f59e0b;
        --color-stuff: #f59e0b;
        --color-stuff-bg: rgba(245, 158, 11, 0.1);
        --color-stuff-border: #d97706;
        --color-stuff-text: #78350f;
        --color-stuff-text-dim: #92400e;
        --color-pipe: #3b82f6;
        --color-pipe-bg: rgba(59, 130, 246, 0.08);
        --color-pipe-text: #1e3a8a;
        --color-pipe-failed: #ef4444;
        --color-pipe-failed-bg: rgba(239, 68, 68, 0.1);
        --color-edge: #3b82f6;
        --color-batch-item: #9333ea;
        --color-batch-aggregate: #16a34a;
        --color-parallel-combine: #a855f7;
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
    }
}

/* === PALETTES === */
/* Yellow-Blue palette is the default (uses theme colors) */

/* Dracula palette - vibrant dark theme with high contrast */
[data-palette="dracula"] {
    /* Pipes / Execution Units - Salmon red (matches MTHDS syntax highlighting) */
    --color-pipe: #ff6b6b;
    --color-pipe-bg: rgba(224, 108, 117, 0.18);
    --color-pipe-text: #ffffff;

    /* Stuff / Concepts - Teal border with Pale Green variable names */
    --color-stuff: #4ECDC4;
    --color-stuff-bg: rgba(78, 205, 196, 0.12);
    --color-stuff-border: #9ddcfd;
    --color-stuff-text: #98FB98;          /* Pale Green - flashy for variable names */
    --color-stuff-text-dim: #9ddcfd;      /* Light Cyan - for concept names */

    /* Edges / Data Flow - Super light yellow, almost white */
    --color-edge: #FFFACD;
    --color-batch-item: #bd93f9;
    --color-batch-aggregate: #50fa7b;
    --color-parallel-combine: #d6a4ff;

    /* Status colors */
    --color-success: #50FA7B;             /* Bright Green */
    --color-success-bg: rgba(80, 250, 123, 0.15);
    --color-error: #FF5555;               /* Dracula Red */
    --color-error-bg: rgba(255, 85, 85, 0.15);

    /* Supporting colors */
    --color-accent: #8BE9FD;              /* Light Cyan - control flow */
    --color-warning: #FFB86C;             /* Orange - structural elements */
    --color-template: #FF79C6;            /* Magenta/Pink - template markers */
    --color-metadata: #F1FA8C;            /* Pale Yellow - attributes */
    --color-comment: #6272A4;             /* Slate Blue/Gray - comments */
}

/* Light theme adjustments for Dracula palette */
[data-theme="light"][data-palette="dracula"] {
    --color-pipe-text: #8B0000;
    --color-stuff-text: #006400;          /* Dark green for light mode */
    --color-stuff-text-dim: #006666;
    --color-edge: #B8860B;                /* Darker yellow for light mode */
}

@media (prefers-color-scheme: light) {
    [data-theme="system"][data-palette="dracula"] {
        --color-pipe-text: #8B0000;
        --color-stuff-text: #006400;
        --color-stuff-text-dim: #006666;
        --color-edge: #B8860B;
    }
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body {
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
    background: var(--color-bg);
    color: var(--color-text);
}
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
}
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    z-index: 100;
}
.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}
.header-logo {
    height: 28px;
    width: auto;
}
.header-logo.dark-logo { display: block; }
.header-logo.light-logo { display: none; }
[data-theme="light"] .header-logo.dark-logo { display: none; }
[data-theme="light"] .header-logo.light-logo { display: block; }
@media (prefers-color-scheme: light) {
    [data-theme="system"] .header-logo.dark-logo { display: none; }
    [data-theme="system"] .header-logo.light-logo { display: block; }
}
.header-title {
    font-size: 14px;
    color: var(--color-text-muted);
    font-weight: 500;
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--color-surface-hover);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 16px;
    line-height: 1;
}
.header-btn:hover {
    background: var(--color-accent);
    border-color: var(--color-accent);
}
.theme-icon { display: none; }
.theme-icon.active { display: inline; }
.direction-icon { display: none; color: var(--color-text); }
.direction-icon.active { display: inline-flex; align-items: center; justify-content: center; }
.stat-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--color-text-muted);
}
.stat-value {
    font-weight: 600;
    color: var(--color-text);
}
.stat-icon {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}
#root {
    flex: 1;
    width: 100%;
    overflow: hidden;
}
.react-flow-container {
    width: 100%;
    height: 100%;
    background: var(--color-bg);
}
.react-flow__node {
    font-family: var(--font-sans);
}
.react-flow__background {
    background: var(--color-bg) !important;
}
.react-flow__controls {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    bottom: 57px !important;
    left: 16px !important;
}
.react-flow__controls-button {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    fill: var(--color-text-muted);
}
.react-flow__controls-button:hover {
    background: var(--color-surface-hover);
}
.react-flow__edge-path {
    stroke-width: 2;
}
.react-flow__edge-text {
    font-size: 11px;
    fill: var(--color-text-muted);
}
.react-flow__edge-textbg {
    fill: var(--color-bg);
}
/* Selected node highlight */
.react-flow__node.selected {
    box-shadow: 0 0 0 3px var(--color-accent), var(--shadow-lg) !important;
    z-index: 1000 !important;
}

/* Inspector Sidebar */
.inspector-panel {
    position: fixed;
    top: 57px;
    right: 0;
    width: 40vw;
    min-width: 360px;
    max-width: 80vw;
    height: calc(100vh - 57px - 41px);
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    z-index: 1000;
    display: none;
    transition: none;
}
.inspector-panel.visible {
    display: flex;
    flex-direction: column;
}
.inspector-resize-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 6px;
    height: 100%;
    cursor: ew-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.2s;
}
.inspector-resize-handle:hover,
.inspector-resize-handle.dragging {
    background: var(--color-accent);
}
.inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--color-accent), var(--color-stuff));
    color: white;
}
.inspector-header.stuff {
    background: linear-gradient(135deg, var(--color-stuff), var(--color-stuff-border));
}
.inspector-header.pipe {
    background: linear-gradient(135deg, var(--color-pipe), var(--color-accent));
}
.inspector-title {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.inspector-subtitle {
    font-size: 12px;
    opacity: 0.85;
    margin-top: 2px;
}
.inspector-close {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: rgba(255,255,255,0.2);
    border-radius: var(--radius-sm);
    font-size: 18px;
    line-height: 1;
    transition: background 0.15s;
}
.inspector-close:hover {
    background: rgba(255,255,255,0.3);
}
.inspector-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}
/* Only apply flex behavior to the stuff data section, not all sections */
.inspector-content.stuff-inspector {
    display: flex;
    flex-direction: column;
}
.inspector-content.stuff-inspector > .inspector-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}
#stuff-data-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
#stuff-data-content > .inspector-pre,
#stuff-data-content.inspector-html-content {
    flex: 1;
    max-height: none;
    min-height: 0;
    overflow-y: auto;
}
.inspector-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}
.inspector-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 999px;
}
.inspector-badge.success {
    background: var(--color-success-bg);
    color: var(--color-success);
}
.inspector-badge.error {
    background: var(--color-error-bg);
    color: var(--color-error);
}
.inspector-badge.neutral {
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
}
.inspector-badge.stuff {
    background: var(--color-stuff-bg);
    color: var(--color-stuff);
}
.inspector-section {
    margin-bottom: 16px;
}
.inspector-section:last-child {
    margin-bottom: 0;
}
.inspector-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-dim);
    margin-bottom: 8px;
}
.inspector-value {
    font-size: 14px;
    color: var(--color-text);
    word-break: break-word;
}
.inspector-value.pipe-code {
    font-family: var(--font-mono);
    color: var(--color-accent);
}
.inspector-pre {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    padding: 12px;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    color: var(--color-text-muted);
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}
/* No-wrap variant for Rich-formatted ASCII tables (Pretty/Text tab) */
.inspector-pre.nowrap {
    white-space: pre;
    word-break: normal;
    line-height: 1;
    padding-right: 20px;
    -webkit-overflow-scrolling: touch;
}
.inspector-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
}
.inspector-row:last-child {
    border-bottom: none;
}
.inspector-row-label {
    color: var(--color-text-dim);
    font-size: 13px;
}
.inspector-row-value {
    color: var(--color-text);
    font-size: 13px;
    font-weight: 500;
}

/* Format toolbar for stuff data */
.format-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    gap: 8px;
}
.format-tabs {
    display: flex;
    gap: 4px;
}
.format-tab {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
    border: none;
    transition: all 0.2s;
}
.format-tab:hover {
    background: var(--color-border);
    color: var(--color-text);
}
.format-tab.active {
    background: var(--color-accent);
    color: #fff;
}
.format-tab:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}
.format-actions {
    display: flex;
    gap: 4px;
}
.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    background: var(--color-surface-hover);
    color: var(--color-text-muted);
    border: none;
    transition: all 0.2s;
}
.action-btn:hover {
    background: var(--color-border);
    color: var(--color-text);
}
.action-btn.copied {
    background: var(--color-success-bg);
    color: var(--color-success);
}
.action-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}
.inspector-html-content {
    background: var(--color-bg);
    color: var(--color-text-muted);
    padding: 12px;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
}
.inspector-html-content table {
    border-collapse: collapse;
    width: 100%;
}
.inspector-html-content th,
.inspector-html-content td {
    border: 1px solid var(--color-border);
    padding: 8px 12px;
    text-align: left;
}
.inspector-html-content th {
    background: var(--color-surface-hover);
    color: var(--color-text);
    font-weight: 600;
}
.inspector-html-content tr:hover {
    background: var(--color-surface-hover);
}
.inspector-pdf-content {
    flex: 1;
    min-height: 400px;
}
.fullscreen-content.inspector-pdf-content {
    height: 100%;
}
.inspector-image-content {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}
.inspector-image-content img {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
}
.fullscreen-content.inspector-image-content {
    height: 100%;
}

/* Top hint capsule */
.top-hint {
    position: fixed;
    top: 70px;
    right: 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-pill);
    padding: 8px 16px;
    font-size: 12px;
    color: var(--color-text-dim);
    z-index: 100;
    box-shadow: var(--shadow-md);
}

/* Footer */
.footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
    font-size: 12px;
}
.footer-legend {
    display: flex;
    gap: 20px;
}
.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-muted);
}
.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}
.legend-dot.pipe {
    background: var(--color-pipe);
}
.legend-dot.stuff {
    background: var(--color-stuff);
    border-radius: 6px;
}
.legend-dot.success {
    background: var(--color-success);
}
.legend-dot.error {
    background: var(--color-error);
}
.footer-stats {
    display: flex;
    gap: 16px;
}

/* Full-screen modal for stuff data */
.fullscreen-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-bg);
    z-index: 2000;
    display: none;
    flex-direction: column;
}
.fullscreen-modal.visible {
    display: flex;
}
.fullscreen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--color-stuff), var(--color-stuff-border));
    color: white;
    border-bottom: 1px solid var(--color-border);
}
.fullscreen-header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.fullscreen-title {
    font-size: 18px;
    font-weight: 600;
}
.fullscreen-subtitle {
    font-size: 13px;
    opacity: 0.9;
}
.fullscreen-header-actions {
    display: flex;
    gap: 8px;
}
.fullscreen-action-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    background: rgba(255,255,255,0.2);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    transition: background 0.15s;
}
.fullscreen-action-btn:hover {
    background: rgba(255,255,255,0.3);
}
.fullscreen-action-btn svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}
.fullscreen-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}
.fullscreen-content {
    flex: 1;
    overflow: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
}
.fullscreen-content > .inspector-pre,
.fullscreen-content.inspector-html-content {
    flex: 1;
    max-height: none;
    min-height: 0;
    margin: 0;
}

