/* Workflow Editor Canvas Styles — applied to JS-rendered DOM (not Blazor-scoped) */

/* ── Theme-dependent canvas variables ── */

:root {
    --wf-canvas-dot: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] {
    --wf-canvas-dot: rgba(255, 255, 255, 0.06);
}

/* ── Reference tags inside contenteditable tag editors (JS-rendered) ── */

.ref-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    vertical-align: baseline;
    cursor: default;
    white-space: nowrap;
    margin: 1px 2px;
    line-height: 1.4;
    user-select: none;
}

.ref-tag-node {
    background: rgba(108, 108, 255, 0.25);
    color: #b0b0ff;
    border: 1px solid rgba(108, 108, 255, 0.4);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.ref-tag-var {
    background: rgba(80, 200, 120, 0.25);
    color: #80e0a0;
    border: 1px solid rgba(80, 200, 120, 0.4);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .ref-tag-node {
    background: rgba(88, 88, 220, 0.15);
    color: #4a4ab0;
    border: 1px solid rgba(88, 88, 220, 0.35);
}

[data-theme="light"] .ref-tag-var {
    background: rgba(40, 160, 80, 0.15);
    color: #1a8a4a;
    border: 1px solid rgba(40, 160, 80, 0.35);
}

/* ── Canvas wrapper (created by JS) ── */

.wf-canvas-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: 0 0;
}

/* ── Workflow Nodes ── */

.wf-node {
    position: absolute;
    min-width: 180px;
    max-width: 260px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color, #333);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    border-left: 4px solid var(--border-color, #333);
    cursor: pointer;
    user-select: none;
}

.wf-node:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.wf-node:focus-visible {
    outline: 2px solid var(--accent-color, #9146ff);
    outline-offset: 2px;
    z-index: 20;
}

.wf-node.wf-node-selected {
    border-color: var(--accent-color, #9146ff);
    border-width: 2px;
    box-shadow: 0 0 0 2px rgba(145, 70, 255, 0.3), 0 4px 16px rgba(0, 0, 0, 0.3);
    outline: 2px solid var(--accent-color, #9146ff);
    outline-offset: 1px;
}

.wf-node[data-highlighted="true"] {
    border-style: dashed;
    border-width: 2px;
}

/* Rubber band selection rectangle */
.wf-selection-rect {
    fill: rgba(99, 102, 241, 0.1);
    stroke: rgba(99, 102, 241, 0.6);
    stroke-width: 1;
    stroke-dasharray: 4 2;
    pointer-events: none;
}

.wf-node-header {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.625rem;
    border-bottom: 1px solid var(--border-color, #333);
}

.wf-node-icon {
    font-size: 1rem;
    flex-shrink: 0;
}

.wf-node-title {
    flex: 1;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-primary, #e0e0e0);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.wf-node-type-badge {
    font-size: 0.5625rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #fff;
    padding: 0.0625rem 0.375rem;
    border-radius: 3px;
    flex-shrink: 0;
    font-weight: 600;
}

/* ── Ports ── */

.wf-node-ports {
    padding: 0.375rem 0.625rem;
}

.wf-node-ports-out {
    border-top: 1px solid var(--border-color, #333);
}

.wf-port {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.125rem 0;
    font-size: 0.75rem;
    color: var(--text-secondary, #6c757d);
    cursor: pointer;
}

.wf-port:hover .wf-port-dot {
    transform: scale(1.3);
}

.wf-port-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-secondary, #6c757d);
}

.wf-port-in .wf-port-dot {
    background: #10b981;
}

.wf-port-out .wf-port-dot {
    background: var(--accent-color, #9146ff);
}

.wf-port-label {
    font-size: 0.6875rem;
}

.wf-port-out {
    justify-content: flex-end;
}

/* ── Edges (SVG) ── */

.wf-edge-path {
    fill: none;
    stroke: var(--text-secondary, #6c757d);
    stroke-width: 2;
    opacity: 0.6;
}

.wf-edge-path:hover {
    opacity: 1;
    stroke-width: 3;
}

/* ── Wire in progress ── */

.wf-wire-path {
    fill: none;
    stroke: var(--accent-color, #9146ff);
    stroke-width: 2;
    stroke-dasharray: 6 3;
    opacity: 0.8;
}

/* ── Reduced motion ── */

@media (prefers-reduced-motion: no-preference) {
    .wf-node {
        transition: box-shadow 0.15s ease, border-color 0.15s ease;
    }

    .wf-port-dot {
        transition: transform 0.15s ease;
    }
}

/* ── Windows High Contrast Mode ── */

@media (forced-colors: active) {
    .wf-node {
        border: 2px solid CanvasText;
        forced-color-adjust: none;
    }

    .wf-node.wf-node-selected {
        border-color: Highlight;
        outline: 2px solid Highlight;
    }

    .wf-node:focus-visible {
        outline: 2px solid Highlight;
    }

    .wf-node[data-highlighted="true"] {
        border-color: LinkText;
    }

    .wf-port-dot {
        border: 2px solid CanvasText;
        background: Canvas;
    }

    .wf-step-badge {
        border: 1px solid CanvasText;
        color: CanvasText;
        background: Canvas;
    }
}

/* ── Touch Context Menu ── */

.wf-context-menu {
    background: var(--bg-secondary, #1e1e2e);
    border: 1px solid var(--border-color, #3a3a5c);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    padding: 4px;
    min-width: 160px;
}

.wf-context-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-primary, #e0e0f0);
    font-size: 13px;
    cursor: pointer;
    text-align: left;
    min-height: 44px;
}

.wf-context-item:hover,
.wf-context-item:focus-visible {
    background: var(--bg-active, #2a2a3e);
}

.wf-context-item:focus-visible {
    outline: 2px solid var(--accent-color, #6c6cff);
    outline-offset: -2px;
}

/* ── Touch Wiring Highlights ── */

.wf-port-wiring .wf-port-dot {
    animation: wf-pulse 1s ease-in-out infinite;
    box-shadow: 0 0 8px var(--accent-color, #6c6cff);
}

.wf-port-target {
    animation: wf-pulse-target 1.2s ease-in-out infinite;
    transform: scale(1.5);
}

@keyframes wf-pulse {
    0%, 100% { box-shadow: 0 0 4px var(--accent-color, #6c6cff); }
    50% { box-shadow: 0 0 12px var(--accent-color, #6c6cff); }
}

@keyframes wf-pulse-target {
    0%, 100% { transform: scale(1.3); }
    50% { transform: scale(1.6); }
}

/* ── Touch-friendly port targets ── */

@media (pointer: coarse) {
    .wf-port {
        min-height: 32px;
        padding: 6px 0;
    }

    .wf-port-dot {
        width: 16px;
        height: 16px;
        position: relative;
    }

    /* Invisible expanded hit area around port dots */
    .wf-port-dot::after {
        content: '';
        position: absolute;
        inset: -12px;
        border-radius: 50%;
    }

    .wf-context-item {
        min-height: 48px;
        font-size: 15px;
    }
}

/* ── Reduced motion for touch animations ── */

@media (prefers-reduced-motion: reduce) {
    .wf-port-wiring .wf-port-dot,
    .wf-port-target {
        animation: none;
    }

    .wf-port-wiring .wf-port-dot {
        box-shadow: 0 0 8px var(--accent-color, #6c6cff);
    }

    .wf-port-target {
        transform: scale(1.5);
    }
}
