/* ============================================================================
   LOBEY OS — N8N WORKFLOW APP STUDIO STYLESHEET
   Accurate N8N-grade visual canvas, authentic node cards, SVG bezier connections,
   execution badges, live data inspector & responsive theme adaptation.
   Respects all Lobey OS theme variables: --bg-canvas, --bg-surface, --bg-elevated,
   --ink-primary, --ink-secondary, --border-subtle, --border-strong, --accent.
   ============================================================================ */

/* 1. Main Studio Shell & Viewport */
.workflow-studio-root {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 56px);
    overflow: hidden;
    background: var(--bg-canvas, #0B0C0E);
    color: var(--ink-primary, #F3F2EE);
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    font-family: inherit;
}

/* 2. App Catalog View */
.wf-catalog-wrap {
    height: 100%;
    overflow-y: auto;
    padding: 1.5rem 2rem 3rem;
    background: var(--bg-canvas, #0B0C0E);
    user-select: text;
    -webkit-user-select: text;
}

.wf-kpi-card {
    background: var(--bg-surface, #121418);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    position: relative;
    overflow: hidden;
    transition: transform var(--co-dur-normal, 240ms) var(--co-spring, cubic-bezier(0.16, 1, 0.3, 1)),
                border-color var(--co-dur-fast, 140ms);
}

.wf-kpi-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong, rgba(255, 255, 255, 0.2));
}

.wf-app-card {
    background: var(--bg-surface, #121418);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 14px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    position: relative;
    transition: all var(--co-dur-normal, 240ms) var(--co-spring, cubic-bezier(0.16, 1, 0.3, 1));
}

.wf-app-card:hover {
    transform: translateY(-3px);
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 14px 32px -8px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(99, 102, 241, 0.3);
}

.wf-app-icon-badge {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

/* 3. Real N8N Canvas Workspace */
.wf-canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    cursor: grab;
    background-color: var(--bg-canvas, #0B0C0E);
    background-image: radial-gradient(circle, var(--border-subtle, rgba(255, 255, 255, 0.12)) 1.25px, transparent 1.25px);
    background-size: 22px 22px;
}

.wf-canvas-container.panning {
    cursor: grabbing;
}

.wf-canvas-world {
    position: absolute;
    top: 0;
    left: 0;
    width: 0;
    height: 0;
    transform-origin: 0 0;
    will-change: transform;
}

/* SVG Connection Wire Layer */
.wf-svg-layer {
    position: absolute;
    top: 0;
    left: 0;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}

.wf-wire-path {
    fill: none;
    stroke: var(--ink-tertiary, #64748b);
    stroke-width: 2.75px;
    pointer-events: stroke;
    cursor: pointer;
    transition: stroke 0.15s ease, stroke-width 0.15s ease;
}

.wf-wire-path:hover {
    stroke: #38bdf8;
    stroke-width: 4.5px;
}

.wf-wire-path.wire-active {
    stroke: #10b981;
    stroke-dasharray: 6 4;
    animation: wfWireFlow 0.8s linear infinite;
}

.wf-wire-path.wire-branch-true {
    stroke: #10b981;
}

.wf-wire-path.wire-branch-false {
    stroke: #f59e0b;
}

.wf-wire-path.wire-dragging {
    stroke: #ff6d5a;
    stroke-width: 3px;
    stroke-dasharray: 5 4;
    animation: wfWireFlow 0.5s linear infinite;
}

@keyframes wfWireFlow {
    from { stroke-dashoffset: 20; }
    to { stroke-dashoffset: 0; }
}

/* 4. Canvas Floating Chrome (Authentic N8N Topbar) */
.wf-canvas-topbar {
    position: absolute;
    top: 0.85rem;
    left: 1rem;
    right: 1rem;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
}

.wf-canvas-topbar > * {
    pointer-events: auto;
}

.wf-glass-pill {
    background: color-mix(in srgb, var(--bg-surface, #121418) 88%, transparent);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
    border-radius: 9999px;
    padding: 0.35rem 0.85rem;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

.wf-canvas-nav-controls {
    position: absolute;
    bottom: 1.25rem;
    left: 1.25rem;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: color-mix(in srgb, var(--bg-surface, #121418) 90%, transparent);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
    border-radius: 10px;
    padding: 0.35rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.wf-canvas-btn {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--ink-secondary, #9296A0);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.15s ease;
}

.wf-canvas-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--ink-primary, #F3F2EE);
}

/* 5. Real N8N Node Cards */
.wf-node-card {
    position: absolute;
    width: 270px;
    background: var(--bg-surface, #121418);
    border: 1.5px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    box-shadow: 0 12px 32px -6px rgba(0, 0, 0, 0.65), 0 0 0 1px rgba(255, 255, 255, 0.04);
    z-index: 2;
    cursor: default;
    transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    user-select: none;
}

.wf-node-card:hover {
    border-color: var(--border-strong, rgba(255, 255, 255, 0.25));
    box-shadow: 0 16px 40px -6px rgba(0, 0, 0, 0.75), 0 0 0 1.5px rgba(255, 255, 255, 0.12);
}

.wf-node-card.selected {
    border-color: #ff6d5a;
    box-shadow: 0 0 0 2px #ff6d5a, 0 18px 44px -4px rgba(255, 109, 90, 0.35);
}

.wf-node-card.node-running {
    border-color: #f59e0b;
    box-shadow: 0 0 0 2.5px #f59e0b, 0 0 28px rgba(245, 158, 11, 0.45);
    animation: wfNodePulse 1s infinite alternate;
}

.wf-node-card.node-success {
    border-color: #10b981;
    box-shadow: 0 0 0 1.5px #10b981;
}

.wf-node-card.node-error {
    border-color: #ef4444;
    box-shadow: 0 0 0 2px #ef4444, 0 0 24px rgba(239, 68, 68, 0.4);
}

@keyframes wfNodePulse {
    from { transform: scale(1); }
    to { transform: scale(1.02); }
}

.wf-node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
    cursor: move;
    border-top-left-radius: 11px;
    border-top-right-radius: 11px;
    background: color-mix(in srgb, var(--bg-surface) 96%, var(--bg-canvas));
}

.wf-node-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.wf-node-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-primary, #F3F2EE);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-left: 0.65rem;
    flex: 1;
}

.wf-node-body {
    padding: 0.7rem 0.9rem;
    font-size: 0.74rem;
    color: var(--ink-secondary, #9296A0);
    line-height: 1.45;
    word-break: break-word;
    background: var(--bg-surface, #121418);
    border-bottom-left-radius: 11px;
    border-bottom-right-radius: 11px;
}

/* Iconic N8N Execution Badge */
.wf-node-exec-badge {
    position: absolute;
    top: -12px;
    right: 12px;
    border-radius: 9999px;
    padding: 0.2rem 0.65rem;
    font-size: 0.68rem;
    font-family: var(--font-mono, monospace);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.6);
    z-index: 5;
    animation: wfBadgePop 0.25s var(--co-spring, cubic-bezier(0.16, 1, 0.3, 1));
}

@keyframes wfBadgePop {
    0% { transform: scale(0.6); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.wf-node-exec-badge.is-success {
    background: #064e3b;
    border: 1px solid #10b981;
    color: #34d399;
}

.wf-node-exec-badge.is-error {
    background: #7f1d1d;
    border: 1px solid #ef4444;
    color: #f87171;
}

.wf-node-exec-badge.is-running {
    background: #78350f;
    border: 1px solid #f59e0b;
    color: #fcd34d;
}

/* 6. Ports (Inputs & Outputs) */
.wf-port {
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--bg-surface, #121418);
    border: 2px solid var(--border-strong, #94a3b8);
    cursor: crosshair;
    z-index: 4;
    transition: all 0.15s ease;
}

.wf-port:hover {
    background: #ff6d5a;
    border-color: #fff;
    transform: scale(1.4);
    box-shadow: 0 0 12px rgba(255, 109, 90, 0.8);
}

.wf-port.input-port {
    left: -7px;
    top: 50%;
    transform: translateY(-50%);
}

.wf-port.input-port:hover {
    transform: translateY(-50%) scale(1.4);
}

.wf-port.output-port {
    right: -7px;
    top: 50%;
    transform: translateY(-50%);
}

.wf-port.output-port:hover {
    transform: translateY(-50%) scale(1.4);
}

.wf-port.port-true {
    top: 36%;
    border-color: #10b981;
}

.wf-port.port-false {
    top: 66%;
    border-color: #f59e0b;
}

.wf-port-label {
    position: absolute;
    right: 15px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    pointer-events: none;
}

.wf-label-true {
    top: calc(36% - 8px);
    color: #10b981;
}

.wf-label-false {
    top: calc(66% - 8px);
    color: #f59e0b;
}

/* N8N Quick Connector '+' button on hover */
.wf-quick-add-btn {
    position: absolute;
    right: -28px;
    top: 50%;
    transform: translateY(-50%) scale(0);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ff6d5a;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(255, 109, 90, 0.5);
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 5;
}

.wf-node-card:hover .wf-quick-add-btn {
    transform: translateY(-50%) scale(1);
}

/* 7. Component Palette Drawer */
.wf-palette-category {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-secondary, #9296A0);
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}

.wf-palette-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.75rem 0.95rem;
    background: var(--bg-surface, #121418);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    margin-bottom: 0.45rem;
}

.wf-palette-item:hover {
    background: color-mix(in srgb, var(--bg-elevated) 90%, #ff6d5a 10%);
    border-color: rgba(255, 109, 90, 0.4);
    transform: translateX(4px);
}

/* 8. Code & JSON Inspection Trees */
.wf-json-viewer {
    background: var(--bg-canvas, #090c13);
    border: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.08));
    border-radius: 8px;
    padding: 0.95rem;
    font-family: var(--font-mono, monospace);
    font-size: 0.76rem;
    color: #67e8f9;
    overflow-x: auto;
    max-height: 290px;
    line-height: 1.5;
    user-select: text;
    -webkit-user-select: text;
}

.wf-var-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.22rem 0.55rem;
    background: rgba(255, 109, 90, 0.14);
    border: 1px solid rgba(255, 109, 90, 0.35);
    border-radius: 6px;
    color: #fca5a5;
    font-family: var(--font-mono, monospace);
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.12s ease;
}

.wf-var-chip:hover {
    background: #ff6d5a;
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(255, 109, 90, 0.4);
}

/* 9. Execution Trace Overlay */
.wf-execution-timeline {
    border-left: 2px solid var(--border-subtle, rgba(255, 255, 255, 0.1));
    margin-left: 0.75rem;
    padding-left: 1rem;
    user-select: text;
    -webkit-user-select: text;
}

.wf-exec-step {
    position: relative;
    margin-bottom: 1rem;
    user-select: text;
    -webkit-user-select: text;
}

.wf-exec-step-dot {
    position: absolute;
    left: calc(-1rem - 5px);
    top: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--ink-tertiary, #64748b);
}

.wf-exec-step-dot.success { background: #10b981; box-shadow: 0 0 8px #10b981; }
.wf-exec-step-dot.error { background: #ef4444; box-shadow: 0 0 8px #ef4444; }
.wf-exec-step-dot.running { background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }

/* 10. Selectable Inspection & Trace Content */
.wf-inspector-panel,
.wf-inspector-body,
.wf-node-inspector,
.wf-node-body,
.offcanvas-body,
.workflow-studio-root input,
.workflow-studio-root textarea,
.workflow-studio-root select,
.workflow-studio-root pre,
.workflow-studio-root code,
.workflow-studio-root .user-select-text {
    user-select: text !important;
    -webkit-user-select: text !important;
}

/* 11. Prefers-Reduced-Motion Support */
@media (prefers-reduced-motion: reduce) {
    .workflow-studio-root,
    .workflow-studio-root *,
    .workflow-studio-root *::before,
    .workflow-studio-root *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
    }
}
