﻿/* Global styles for Automation Flow Editor */

.trigger-layout {
    display: flex;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 6px;
}

.trigger-card {
    min-width: 240px;
    max-width: 320px;
    background: #f1f6ff;
    border: 1px solid #cfe0ff;
    border-radius: 8px;
    padding: 8px 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.trigger-card-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    color: #1a5fb4;
    font-weight: 600;
}

.trigger-card-body .trigger-line {
    font-size: 0.85rem;
    color: #234;
    line-height: 1.3;
}

.trigger-connector {
    align-self: center;
    width: 48px;
    height: 2px;
    background: var(--rz-primary, #1976d2);
    border-radius: 1px;
    margin: 0 4px;
}

.flow-left-container {
    width: 100%;
}

.flow-params {
    margin-top: 6px;
    padding-top: 4px;
    border-top: 1px dashed #ddd;
}

.flow-params .param-line {
    font-size: 0.85rem;
    color: #333;
    line-height: 1.3;
}

.flow-params .mud-link {
    font-size: 0.85rem;
}

.no-automationflows {
    text-align: center;
    padding: 20px;
    margin-top: 20px;
    font-size: 1.2rem;
    color: #666;
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    border-radius: 10px;
}

.rz-timeline-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.edit-flow-button, .delete-flow-button {
    margin-left: 16px;
}

.button-container {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.rz-timeline-item:hover .flow-action-button {
    visibility: visible; /* Show the buttons on hover */
}

.flow-action-button {
    visibility: hidden;
}

/* On mobile/touch devices, always show action buttons */
@media (hover: none) and (pointer: coarse), (max-width: 768px) {
    .flow-action-button {
        visibility: visible;
    }
}

/* Condition styling */
.condition-details {
    margin-top: 8px;
    border-left: 3px solid #ffab00;
    padding-left: 10px;
}

.branching-paths {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
}

.path {
    margin: 2px 0;
    padding: 2px 0;
}

.path-label {
    font-weight: bold;
    margin-right: 5px;
}

.true-path .path-label {
    color: #4caf50;
}

.false-path .path-label {
    color: #f44336;
}

/* Flow header with branch indicator */
.flow-header {
    display: flex;
    align-items: center;
    margin-bottom: 4px;
}

/* Branch flow styling */
.rz-timeline-item-point-info {
    background-color: #2196f3;
}

.rz-timeline-item-point-warning {
    background-color: #ff9800;
}

.rz-timeline-item-point-success {
    background-color: #4caf50;
}

/* Branch container styling */
.branch-container {
    margin-top: 20px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.branch {
    margin-left: 30px;
    padding: 15px;
    border-radius: 8px;
    position: relative;
}

.true-branch-container {
    border-left: 3px solid #4caf50;
    background-color: rgba(76, 175, 80, 0.05);
}

.false-branch-container {
    border-left: 3px solid #f44336;
    background-color: rgba(244, 67, 54, 0.05);
}

.branch-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.branch-label {
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: bold;
    font-size: 0.9rem;
}

.true-branch-label {
    background-color: #4caf50;
    color: white;
}

.false-branch-label {
    background-color: #f44336;
    color: white;
}

/* Empty branch message */
.empty-branch-message {
    padding: 15px;
    text-align: center;
    color: #757575;
    font-style: italic;
    background-color: rgba(0, 0, 0, 0.03);
    border-radius: 4px;
}

/* Nested branch styling */
.nested-branch-container {
    margin-top: 15px;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.nested-branch {
    margin-left: 20px;
    padding: 10px;
    border-radius: 6px;
    position: relative;
}

.true-nested-branch {
    border-left: 2px solid #4caf50;
    background-color: rgba(76, 175, 80, 0.03);
}

.false-nested-branch {
    border-left: 2px solid #f44336;
    background-color: rgba(244, 67, 54, 0.03);
}

.nested-branch-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.nested-branch-label {
    font-size: 0.8rem;
    font-weight: bold;
    padding: 2px 6px;
    border-radius: 3px;
}

.nested-flow-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px;
    margin: 5px 0;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.nested-flow-content {
    display: flex;
    align-items: center;
}

.nested-flow-icon {
    margin-right: 5px;
}

.nested-flow-title {
    font-size: 0.9rem;
}

.nested-flow-actions {
    display: flex;
    gap: 5px;
}

.branch-actions {
    display: flex;
    align-items: center;
}

.deeper-nested-branches {
    margin-top: 8px;
    margin-bottom: 8px;
    border-left: 1px dashed rgba(0, 0, 0, 0.1);
    padding-left: 5px;
}

.nested-branch-toggle {
    font-size: 0.8rem;
    color: #666;
    cursor: pointer;
    padding: 2px 4px;
    margin-bottom: 4px;
}

.nested-branch-toggle:hover {
    background-color: rgba(0, 0, 0, 0.05);
    border-radius: 3px;
}

.deeper-branch-container {
    margin-left: 5px;
}

.deeper-nested-branch {
    margin-bottom: 10px;
}

.deeper-branch-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 3px;
}

.deeper-branch-label {
    font-size: 0.7rem;
    font-weight: bold;
    padding: 1px 4px;
    border-radius: 2px;
    margin-right: 5px;
}

.deeper-branch-label.true-label {
    background-color: rgba(76, 175, 80, 0.6);
    color: white;
}

.deeper-branch-label.false-label {
    background-color: rgba(244, 67, 54, 0.6);
    color: white;
}

.nested-condition-summary {
    font-size: 0.8rem;
    color: #666;
    margin-top: 2px;
}

.collapsed .deeper-branch-container {
    display: none;
}

.collapsed .nested-branch-toggle:before {
    content: "►";
}

/* Disable text selection while dragging from the palette */
body.dragging-palette, body.dragging-palette * {
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
    user-select: none !important;
}

/* Visual feedback for palette cards */
.palette-card {
    cursor: grab;
}

.palette-card.dragging {
    cursor: grabbing;
}

/* Avoid image/text dragging artifacts over the canvas */
.flowchart-canvas, .flowchart-canvas * {
    -webkit-user-drag: none;
}

/* Highlight canvas when it is a valid drop target */
.flowchart-canvas.drop-target {
    outline: 2px dashed #90caf9;
    outline-offset: -2px;
    box-shadow: inset 0 0 0 2px rgba(144, 202, 249, 0.35);
}

/* While dragging from the palette, indicate copy/drop cursor over canvas */
body.dragging-palette .flowchart-canvas {
    cursor: copy;
}

/* Highlight inner loop drop area (only the mini-canvas is a valid target) */
.loop-mini-canvas.drop-target {
    outline: 2px dashed #90caf9;
    outline-offset: -2px;
    box-shadow: inset 0 0 0 2px rgba(144, 202, 249, 0.25);
}

body.dragging-palette .loop-mini-canvas {
    cursor: copy;
}

/* Animated per-step "snake" border and overall run pulse */
.automation-outline {
    position: relative;
    padding: 8px;
    border-radius: 12px;
    border: 1px solid #e0e0e0;
}

.automation-outline.running {
    border-color: #e0e0e0; /* keep subtle base border */
}

/* Ensure each step container can host the animated border */
.flow-content {
    position: relative;
    border-radius: 12px;
    --snake-radius: 12px;
    overflow: visible; /* allow the snake ring to render just outside */
    box-sizing: border-box;
}

/* Show the snake border around each flow item while automation is running */
.automation-outline.running .flow-content.is-current::before {
    content: "";
    position: absolute;
    inset: -4px; /* render slightly outside the element box */
    border-radius: 14px; /* match outer offset */
    padding: 4px; /* ring thickness */
    pointer-events: none;
    background: conic-gradient(
            from 0deg,
            rgba(33, 150, 243, 0) 0deg,
            rgba(33, 150, 243, 0.85) 60deg,
            rgba(33, 150, 243, 0) 120deg,
            rgba(33, 150, 243, 0) 360deg
    );
    /* Clip to a border ring without covering content */
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: spin-snake 2s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
    .automation-outline.running {
        animation: none;
    }

    .automation-outline.running .flow-content.is-current::before {
        animation: none;
    }
}

/* Running step indicator: simple line pulsing left to right */
.automation-outline.running .flow-content.is-current::before {
    content: none !important;
}

/* ensure old pseudo not used */
.snake-overlay {
    display: none !important;
}

/* hide any legacy snake overlay */

.automation-outline.running .flow-content.is-current {
    animation: pulse-glow 1.8s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
    .automation-outline.running .flow-content.is-current {
        animation: none;
    }
}

/* Keyframes */
@keyframes spin-snake {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse-glow {
    0% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.10);
    }
    50% {
        box-shadow: 0 0 18px 6px rgba(76, 175, 80, 0.24);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.10);
    }
}

/* Subtle emphasis for timeline points (unchanged) */
.rz-timeline .rz-timeline-item .rz-timeline-point.rz-primary {
    box-shadow: 0 0 8px rgba(33, 150, 243, 0.5);
}

.rz-timeline .rz-timeline-item .rz-timeline-point.rz-success {
    box-shadow: 0 0 6px rgba(76, 175, 80, 0.35);
}

.rz-timeline .rz-timeline-item .rz-timeline-point.rz-danger {
    box-shadow: 0 0 8px rgba(244, 67, 54, 0.45);
}


/* Orange outline to indicate unsaved raw edits */
.raw-editor-dirty {
    outline: 5px solid #ff9800;
    outline-offset: 2px;
    border-radius: 6px;
}


/* n8n-like flowchart designer */
.flowchart-canvas {
    background-image: linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px), linear-gradient(180deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
    background-size: 16px 16px;
}

.edges-layer {
    pointer-events: all;
}

.edge-path {
    stroke: #90caf9;
    fill: none;
    stroke-width: 2;
    marker-end: url(#arrow);
    pointer-events: none;
}

.edge-label {
    font-size: 12px;
    fill: #555;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 3px;
    stroke-linejoin: round;
    pointer-events: none;
}

.edge-handle {
    fill: #fff;
    stroke: #42a5f5;
    stroke-width: 2px;
    cursor: move;
    pointer-events: all;
}

.edge-handle.mini {
    stroke-width: 1.5px;
}

.node {
    position: relative;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    padding: 8px 10px;
    cursor: pointer;
}

.node.draggable {
    cursor: grab;
}

.node.dragging {
    cursor: grabbing;
    opacity: 0.95;
}

.flowchart-canvas.dragging {
    cursor: grabbing;
}

.flowchart-canvas.dragging, .node.dragging {
    user-select: none;
}

.node.condition {
    border-left: 3px solid #ffb74d;
}

.node.is-current {
    outline: 2px solid #42a5f5;
}

.node.is-failed {
    outline: 2px solid #ef5350;
}

.node.is-complete {
    opacity: 0.95;
}

.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.node-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1 1 auto;
    min-width: 0;
}

.node-actions {
    display: flex;
    gap: 6px;
    flex: 0 0 auto;
}

.node-btn {
    background: transparent;
    border: 1px solid #e0e0e0;
    color: #616161;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
}

.node-btn:hover {
    background: #f5f5f5;
}

.node-btn.danger {
    color: #e53935;
    border-color: #ffcdd2;
}

.node-btn.danger:hover {
    background: #ffebee;
}

.node-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.node-sub {
    font-size: 12px;
    color: #666;
    margin-top: 4px;
}

/* Condition ports */
.node-ports {
    position: absolute;
    right: -10px;
    top: 8px;
    bottom: 8px;
    width: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.node-port {
    pointer-events: auto;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid #bbb;
    background: #fff;
    color: #444;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    cursor: pointer;
}

.node-port.true-port {
    border-color: #66bb6a;
    color: #2e7d32;
}

.node-port.false-port {
    border-color: #ef5350;
    color: #b71c1c;
}

.node.condition {
    padding-right: 24px;
}

/* Loop badge */
.node.loop {
    border-left: 3px solid #42a5f5;
}

.node-badge.loop-badge {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #bbdefb;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* Trigger node styling */
.node.trigger-node {
    border-left: 3px solid #66bb6a;
    background: #f3fcf4;
}

/* Ghost add buttons placed on the canvas */
.add-ghost {
    position: absolute;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #1976d2;
    color: #fff;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    font-size: 18px;
    line-height: 36px;
    text-align: center;
    cursor: pointer;
}

.add-ghost.small {
    width: 28px;
    height: 28px;
    font-size: 16px;
    line-height: 28px;
}

.add-ghost.tiny {
    width: 24px;
    height: 24px;
    font-size: 14px;
    line-height: 24px;
    background: #42a5f5;
}

.add-ghost:hover {
    background: #1565c0;
}

.designer-add-btn {
    position: absolute;
    right: 16px;
    bottom: 16px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #1976d2;
    color: #fff;
    border: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    font-size: 20px;
    line-height: 40px;
    text-align: center;
}

.designer-add-btn:hover {
    background: #1565c0;
}

/* Designer layout with right-side palette */
.designer-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 12px;
    align-items: start;
}

.designer-canvas {
    min-height: 400px;
    overflow: auto;
}

.designer-palette {
    position: sticky;
    top: 64px;
    align-self: start;
}

/* Sidebar palette: fixed within viewport with its own internal scroll */
.palette-root {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
    padding: 10px;
    display: flex;
    flex-direction: column;
    /* match viewport minus sticky offset so it never runs off the bottom */
    max-height: calc(100vh - 64px);
    overflow: hidden;
}

.palette-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    position: sticky;
    top: 0;
    z-index: 2;
    background: #fff;
    padding-bottom: 6px;
}

.palette-groups {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding-right: 4px;
}

.palette-group {
    margin-bottom: 12px;
}

.palette-group-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .02em;
    opacity: .7;
    margin: 6px 2px;
}

.palette-title {
    font-weight: 600;
}

.palette-search {
    flex: 0 0 160px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 6px 8px;
}

.palette-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.palette-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    cursor: grab;
    background: #fafafa;
}

.palette-card:hover {
    background: #f5f5f5;
}

.palette-card i {
    font-size: 18px;
    color: #616161;
}

.palette-card-text {
    font-size: 14px;
    color: #333;
}

@media (max-width: 992px) {
    .designer-layout {
        grid-template-columns: 1fr;
    }

    .designer-palette {
        position: static;
    }

    .palette-root {
        max-height: none;
        overflow: visible;
    }
}

/* Simple line-numbered raw editor */
.raw-editor-container {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 6px;
    background: #fff;
    height: 100%;
}

/* Draft/unlinked node styling */
.node.draft {
    border: 2px dashed #c7c7c7;
    opacity: 0.85;
}

.node.draft .node-header {
    filter: grayscale(0.4);
}

.node.draft::after {
    content: 'Unlinked: won\'t run until connected';
    position: absolute;
    bottom: -18px;
    left: 0;
    font-size: 11px;
    color: #777;
}

/* Connector handle for drag-to-connect */
.connector-handle.right {
    position: absolute;
    right: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #4a90e2;
    cursor: crosshair;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    z-index: 3;
}

.connector-handle.right:hover {
    background: #e8f1ff;
}

/* Mirror for left-side handle */
.connector-handle.left {
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #4a90e2;
    cursor: crosshair;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    z-index: 3;
}

.connector-handle.left:hover {
    background: #e8f1ff;
}

/* Ghost edge while dragging */
.edge-ghost {
    stroke: #4a90e2;
    stroke-opacity: 0.6;
    stroke-dasharray: 6 4;
}

/* Invisible overlay path on top of edges to capture click/right-click */
.edge-overlay {
    fill: none;
    stroke: #000; /* fully transparent but avoids GPU artifacts */
    stroke-opacity: 0; /* invisible */
    stroke-width: 18px; /* widen hit area a bit more */
    pointer-events: visibleStroke; /* only stroke captures events */
    cursor: pointer;
}

/* Edge context menu */
.edge-context-menu {
    position: fixed;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 4px;
    z-index: 1000;
}

.edge-menu-item {
    display: block;
    width: 120px;
    text-align: left;
    background: transparent;
    border: none;
    padding: 6px 10px;
    cursor: pointer;
}

.edge-menu-item:hover {
    background: #f5f5f5;
}

.edge-menu-item.delete {
    color: #b71c1c;
}

/* Mini (loop) edges and connectors */
.mini-edges {
    pointer-events: none;
}

.mini-edge-path {
    stroke: #90caf9;
    fill: none;
    stroke-width: 2;
    pointer-events: none;
}

.mini-edge-overlay {
    fill: none;
    stroke: #000; /* fully transparent but avoids GPU artifacts */
    stroke-opacity: 0; /* invisible */
    stroke-width: 16px; /* widen hit area */
    pointer-events: visibleStroke; /* only stroke captures events */
    cursor: pointer;
}

.mini-connector-handle.left,
.mini-connector-handle.right {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #4a90e2;
    cursor: crosshair;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    z-index: 3;
}

.mini-connector-handle.left {
    left: -6px;
}

.mini-connector-handle.right {
    right: -6px;
}

.mini-connector-handle.left:hover,
.mini-connector-handle.right:hover {
    background: #e8f1ff;
}

/* Designer footer and edge add buttons */
.node-footer-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    margin-top: 6px;
    padding-top: 6px;
}

.node-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.edge-add {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: none;
    background: #1976d2;
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.edge-add.left {
    left: -12px;
}

.edge-add.right {
    right: -12px;
}

.edge-add:hover {
    background: #1565c0;
}

.mini-edge-add {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: #1976d2;
    color: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
}

.mini-edge-add.left {
    left: -10px;
}

.mini-edge-add.right {
    right: -10px;
}

.mini-edge-add:hover {
    background: #1565c0;
}

.raw-editor-gutter {
    margin: 0;
    padding: 6px 4px;
    background: #f7f7f7;
    color: #888;
    text-align: right;
    user-select: none;
    overflow: hidden;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    line-height: 1.4;
}

/* Inline loop preview inside loop nodes */
.loop-preview {
    margin-top: 6px;
    border-top: 1px dashed rgba(0, 0, 0, 0.1);
    padding-top: 4px;
}

.loop-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.loop-preview-title {
    font-size: 11px;
    color: #555;
}

.loop-preview-add {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: #1976d2;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.loop-preview-add:hover {
    background: #1565c0;
}

.loop-preview-body {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    max-height: 44px;
    padding-bottom: 2px;
}

.loop-preview-empty {
    font-size: 11px;
    color: #777;
}

.loop-item {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 6px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: #fafafa;
    border-radius: 12px;
}

.loop-item-left {
    display: flex;
    align-items: center;
    gap: 6px;
}

.loop-item-title {
    font-size: 12px;
    max-width: 130px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.loop-item-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.raw-editor-textarea {
    width: 100%;
    min-height: 320px;
    border: none;
    outline: none;
    resize: vertical;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    line-height: 1.4;
}

/* Loop mini flowchart (expandable) */
.node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.node-header-right {
    display: flex;
    align-items: center;
    gap: 6px;
}

.node-toggle {
    border: none;
    background: transparent;
    color: #444;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}

.node-toggle:hover {
    color: #000;
}

.loop-mini {
    margin-top: 6px;
    border: 1px dashed rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    background: #fafafa;
    overflow: auto;
    position: relative;
}

.loop-mini-canvas {
    position: relative;
    min-height: 88px;
}

.mini-edge-path {
    stroke: #90caf9;
    stroke-width: 2;
    fill: none;
    marker-end: url(#mini-arrow);
}

.mini-edge-label {
    font-size: 11px;
    fill: #555;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 2px;
    stroke-linejoin: round;
}

.mini-node {
    position: absolute;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    overflow: visible; /* allow T/F ports to protrude outside node bounds */
    cursor: grab;
}

.mini-node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
    gap: 6px;
    font-weight: 600;
    font-size: 12px;
}

.mini-node-title {
    font-size: 12px;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
    max-height: calc(1.2em * 2);
}

.mini-node-sub {
    padding: 4px 8px;
    font-size: 11px;
    color: #666;
    background: white;
    border-top: 1px solid #f0f0f0;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.2;
    max-height: calc(1.2em * 2);
}

/* Mini node footer actions (inside loop mini flow) */
.mini-node-footer-actions {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
    margin-top: 4px;
}

.mini-btn {
    background: transparent;
    border: 1px solid #e0e0e0;
    color: #616161;
    border-radius: 6px;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    cursor: pointer;
}

.mini-btn:hover {
    background: #f5f5f5;
}

.mini-btn.danger {
    color: #e53935;
    border-color: #ffcdd2;
}

.mini-btn.danger:hover {
    background: #ffebee;
}

.mini-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Mini condition ports (True/False) inside loop mini nodes */
.mini-node-ports {
    position: absolute;
    right: -8px;
    top: 6px;
    bottom: 6px;
    width: 16px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    pointer-events: none;
}

.mini-node-port {
    pointer-events: auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #bbb;
    background: #fff;
    color: #444;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
    cursor: pointer;
}

.mini-node-port.true-port {
    border-color: #66bb6a;
    color: #2e7d32;
}

.mini-node-port.false-port {
    border-color: #ef5350;
    color: #b71c1c;
}

/* Resize handle for loop mini flow */
.loop-resize-handle {
    position: absolute;
    right: 6px;
    bottom: 6px;
    width: 14px;
    height: 14px;
    cursor: nwse-resize;
    opacity: 0.6;
    background: linear-gradient(135deg, rgba(0, 0, 0, 0) 50%, rgba(0, 0, 0, 0.25) 50%),
    linear-gradient(135deg, rgba(0, 0, 0, 0) 70%, rgba(0, 0, 0, 0.15) 70%);
    background-repeat: no-repeat;
    background-position: center;
    background-size: 100% 100%;
    border-radius: 2px;
}

.loop-resize-handle:hover {
    opacity: 1;
}

/* Workspace refresh for the visual automation designer. Scoped under the editor shell so
   older embedded component styles can remain in place without leaking into other pages. */
.automation-editor-shell {
    --automation-bg: var(--app-surface-soft, #f5f7f6);
    --automation-surface: var(--app-surface, #ffffff);
    --automation-surface-raised: var(--app-background-elevated, #fbfcfd);
    --automation-border: var(--app-border, rgba(18, 32, 27, 0.12));
    --automation-border-strong: var(--app-border-strong, rgba(18, 32, 27, 0.2));
    --automation-text: var(--app-text, #202924);
    --automation-muted: var(--app-text-muted, #65736b);
    --automation-green: var(--app-primary, #2f7d43);
    --automation-green-soft: var(--app-primary-soft, #eaf6ee);
    --automation-blue: var(--app-accent, #2c6fbb);
    --automation-blue-soft: color-mix(in srgb, var(--app-accent, #2c6fbb) 11%, var(--automation-surface));
    --automation-amber: #b7791f;
    --automation-amber-soft: #fff7e6;
    --automation-red: #c2413b;
    --automation-red-soft: #fff0ee;
    --automation-shadow: var(--app-shadow-md, 0 18px 40px rgba(18, 32, 27, 0.11));
    --automation-shadow-soft: var(--app-shadow-sm, 0 10px 22px rgba(18, 32, 27, 0.08));
    color: var(--automation-text);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.automation-editor-shell .automation-editor-topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto auto;
    gap: 16px;
    align-items: center;
    padding: 12px 16px;
    margin: -4px -4px 12px;
    border: 1px solid var(--automation-border);
    border-radius: 8px;
    background: color-mix(in srgb, var(--automation-surface) 94%, transparent);
    box-shadow: var(--automation-shadow-soft);
    backdrop-filter: blur(10px);
}

.automation-editor-shell .automation-editor-title,
.automation-editor-shell .automation-mode-switches,
.automation-editor-shell .automation-topbar-actions,
.automation-editor-shell .designer-toolbar-title,
.automation-editor-shell .designer-toolbar-actions {
    display: flex;
    align-items: center;
}

.automation-editor-shell .automation-editor-title {
    gap: 12px;
    min-width: 0;
}

.automation-editor-shell .automation-title-icon {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(47, 125, 67, 0.22);
    border-radius: 8px;
    background: var(--automation-green-soft);
    color: var(--automation-green);
    font-size: 22px;
    flex: 0 0 auto;
}

.automation-editor-shell .automation-title-text {
    font-size: 1rem;
    font-weight: 800;
    line-height: 1.15;
}

.automation-editor-shell .automation-title-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    color: var(--automation-muted);
    font-size: 0.78rem;
    line-height: 1.2;
}

.automation-editor-shell .automation-title-meta span {
    display: inline-flex;
    align-items: center;
    min-height: 18px;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--app-surface-soft, #eef2f0);
    color: var(--automation-muted);
}

.automation-editor-shell .automation-mode-switches {
    gap: 6px;
    padding: 4px 8px;
    border: 1px solid var(--automation-border);
    border-radius: 8px;
    background: var(--app-surface-soft, #f7f9f8);
}

.automation-editor-shell .automation-topbar-actions {
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.automation-editor-shell .automation-flow-diagram {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    margin: 0;
    min-height: 0;
}

.automation-editor-shell .automation-outline {
    border: 1px solid var(--automation-border);
    border-radius: 8px;
    background: var(--automation-bg);
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-height: 0;
    padding: 12px;
    overflow: visible;
}

.automation-editor-shell .automation-outline.running {
    border-color: rgba(47, 125, 67, 0.45);
    box-shadow: 0 0 0 3px rgba(47, 125, 67, 0.1);
}

.automation-editor-shell .designer-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 12px;
    align-items: stretch;
    flex: 1 1 auto;
    min-height: 0;
}

.automation-editor-shell .designer-toolbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 52px;
    padding: 8px 10px;
    border: 1px solid var(--automation-border);
    border-radius: 8px;
    background: var(--automation-surface);
    box-shadow: 0 1px 2px rgba(18, 32, 27, 0.05);
}

.automation-editor-shell .designer-toolbar-title {
    gap: 8px;
    font-weight: 800;
    color: var(--automation-text);
}

.automation-editor-shell .designer-toolbar-title .material-icons {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--automation-blue-soft);
    color: var(--automation-blue);
    font-size: 18px;
}

.automation-editor-shell .designer-toolbar-actions {
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.automation-editor-shell .designer-canvas {
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--automation-border);
    border-radius: 8px;
    background: var(--automation-bg);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.automation-editor-shell .flowchart-canvas {
    min-height: 680px;
    border-radius: 8px;
    background-color: var(--automation-surface-raised);
    background-image:
        linear-gradient(rgba(39, 58, 47, 0.055) 1px, transparent 1px),
        linear-gradient(90deg, rgba(39, 58, 47, 0.055) 1px, transparent 1px),
        linear-gradient(rgba(39, 58, 47, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(39, 58, 47, 0.025) 1px, transparent 1px);
    background-size: 80px 80px, 80px 80px, 16px 16px, 16px 16px;
    background-position: -1px -1px;
}

.automation-editor-shell .flowchart-canvas.dragging {
    cursor: grabbing;
}

.automation-editor-shell .flowchart-canvas.drop-target {
    outline: 3px solid rgba(47, 125, 67, 0.35);
    outline-offset: -6px;
    background-color: #f2faf4;
}

.automation-editor-shell .edges-layer {
    z-index: 1;
}

.automation-editor-shell .edge-path,
.automation-editor-shell .mini-edge-path {
    stroke: #789189;
    stroke-width: 2.4;
    fill: none;
    filter: drop-shadow(0 1px 0 rgba(255, 255, 255, 0.9));
}

.automation-editor-shell .edge-ghost {
    stroke: var(--automation-blue);
    stroke-width: 2.6;
    stroke-dasharray: 7 5;
}

.automation-editor-shell .edge-label,
.automation-editor-shell .mini-edge-label {
    fill: #43524b;
    font-size: 12px;
    font-weight: 800;
    paint-order: stroke;
    stroke: #ffffff;
    stroke-width: 5px;
    stroke-linejoin: round;
}

.automation-editor-shell .edge-overlay {
    stroke-width: 22px;
}

.automation-editor-shell .edge-handle {
    fill: #ffffff;
    stroke: var(--automation-blue);
    stroke-width: 2.2px;
    filter: drop-shadow(0 2px 4px rgba(18, 32, 27, 0.18));
}

.automation-editor-shell .node {
    z-index: 2;
    min-width: 240px;
    border: 1px solid var(--automation-border-strong);
    border-left: 0;
    border-radius: 8px;
    background: var(--automation-surface);
    box-shadow: var(--automation-shadow-soft);
    padding: 0;
    cursor: pointer;
    transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.automation-editor-shell .flowchart-canvas > .node {
    border-left: 0;
}

.automation-editor-shell .flowchart-canvas > .node::before {
    content: "";
    position: absolute;
    left: -1px;
    top: -1px;
    bottom: -1px;
    width: 6px;
    border-radius: 8px 0 0 8px;
    background: var(--automation-green);
    pointer-events: none;
}

.automation-editor-shell .node:hover {
    border-color: rgba(47, 125, 67, 0.36);
    box-shadow: var(--automation-shadow);
    transform: translateY(-1px);
}

.automation-editor-shell .node.draggable {
    cursor: grab;
}

.automation-editor-shell .node.dragging {
    cursor: grabbing;
    opacity: 0.96;
    transform: scale(1.01);
}

.automation-editor-shell .node.condition {
    padding-right: 24px;
}

.automation-editor-shell .flowchart-canvas > .node.condition::before {
    background: var(--automation-amber);
}

.automation-editor-shell .flowchart-canvas > .node.loop::before {
    background: var(--automation-blue);
}

.automation-editor-shell .trigger-node,
.automation-editor-shell .node.trigger-node {
    background: linear-gradient(180deg, #ffffff 0%, #fbfffc 100%);
}

.automation-editor-shell .node.is-current {
    outline: 3px solid rgba(44, 111, 187, 0.26);
    outline-offset: 2px;
}

.automation-editor-shell .node.is-failed {
    outline: 3px solid rgba(194, 65, 59, 0.28);
    outline-offset: 2px;
}

.automation-editor-shell .node.draft {
    border-style: dashed;
    opacity: 0.92;
    background: #fffdf7;
    box-shadow: 0 10px 22px rgba(89, 67, 26, 0.11);
}

.automation-editor-shell .flowchart-canvas > .node.draft::before {
    background: repeating-linear-gradient(
        180deg,
        var(--automation-amber) 0,
        var(--automation-amber) 8px,
        rgba(166, 108, 19, 0.48) 8px,
        rgba(166, 108, 19, 0.48) 14px
    );
}

.automation-editor-shell .flowchart-canvas > .node.draft::after {
    content: "Unlinked";
    position: absolute;
    top: 9px;
    right: 10px;
    bottom: auto;
    left: auto;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border: 1px solid rgba(166, 108, 19, 0.24);
    border-radius: 999px;
    background: var(--automation-amber-soft);
    color: var(--automation-amber);
    font-size: 0.66rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    line-height: 1;
    text-transform: uppercase;
    pointer-events: none;
}

.automation-editor-shell .flowchart-canvas > .node.draft .node-header {
    padding-right: 88px;
    background: #fffaf0;
}

.automation-editor-shell .flowchart-canvas > .node.draft .node-sub {
    color: #6d5330;
}

.automation-editor-shell .node-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 50px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(18, 32, 27, 0.08);
    background: var(--automation-surface-raised);
    border-radius: 3px 8px 0 0;
}

.automation-editor-shell .node-header-left,
.automation-editor-shell .node-header-right {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.automation-editor-shell .node-header-left {
    flex: 1 1 auto;
}

.automation-editor-shell .node-header-left > i,
.automation-editor-shell .node-header-left > .material-icons,
.automation-editor-shell .node-header-left > .iconify {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--automation-green-soft);
    color: var(--automation-green);
    font-size: 18px;
    flex: 0 0 auto;
}

.automation-editor-shell .node.condition .node-header-left > i,
.automation-editor-shell .node.condition .node-header-left > .material-icons,
.automation-editor-shell .node.condition .node-header-left > .iconify {
    background: var(--automation-amber-soft);
    color: var(--automation-amber);
}

.automation-editor-shell .node.loop .node-header-left > i,
.automation-editor-shell .node.loop .node-header-left > .material-icons,
.automation-editor-shell .node.loop .node-header-left > .iconify {
    background: var(--automation-blue-soft);
    color: var(--automation-blue);
}

.automation-editor-shell .node-title {
    color: var(--automation-text);
    font-size: 0.92rem;
    font-weight: 800;
    line-height: 1.25;
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
}

.automation-editor-shell .node-sub {
    padding: 9px 12px;
    margin: 0;
    color: var(--automation-muted);
    font-size: 0.78rem;
    line-height: 1.35;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.automation-editor-shell .node-actions,
.automation-editor-shell .node-footer-actions,
.automation-editor-shell .mini-node-footer-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

.automation-editor-shell .node-footer-actions {
    margin: 0;
    padding: 8px 10px;
    border-top: 1px solid rgba(18, 32, 27, 0.08);
    background: #fcfdfc;
    border-radius: 0 0 8px 8px;
}

.automation-editor-shell .node-btn,
.automation-editor-shell .mini-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--automation-border);
    border-radius: 7px;
    background: #ffffff;
    color: #53625a;
    box-shadow: 0 1px 1px rgba(18, 32, 27, 0.04);
}

.automation-editor-shell .node-btn:hover,
.automation-editor-shell .mini-btn:hover {
    border-color: rgba(44, 111, 187, 0.32);
    background: var(--automation-blue-soft);
    color: var(--automation-blue);
}

.automation-editor-shell .node-btn.danger,
.automation-editor-shell .mini-btn.danger {
    color: var(--automation-red);
    border-color: rgba(194, 65, 59, 0.2);
}

.automation-editor-shell .node-btn.danger:hover,
.automation-editor-shell .mini-btn.danger:hover {
    background: var(--automation-red-soft);
    border-color: rgba(194, 65, 59, 0.35);
}

.automation-editor-shell .connector-handle.left,
.automation-editor-shell .connector-handle.right,
.automation-editor-shell .mini-connector-handle.left,
.automation-editor-shell .mini-connector-handle.right {
    border: 2px solid var(--automation-blue);
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(44, 111, 187, 0.12), 0 2px 7px rgba(18, 32, 27, 0.18);
}

.automation-editor-shell .connector-handle.right.true,
.automation-editor-shell .node-port.true-port,
.automation-editor-shell .mini-node-port.true-port {
    border-color: var(--automation-green);
    color: var(--automation-green);
}

.automation-editor-shell .connector-handle.right.false,
.automation-editor-shell .node-port.false-port,
.automation-editor-shell .mini-node-port.false-port {
    border-color: var(--automation-red);
    color: var(--automation-red);
}

.automation-editor-shell .node-ports,
.automation-editor-shell .mini-node-ports {
    right: -11px;
}

.automation-editor-shell .node-port,
.automation-editor-shell .mini-node-port {
    background: #ffffff;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.9), 0 2px 7px rgba(18, 32, 27, 0.18);
    font-weight: 800;
}

.automation-editor-shell .add-ghost,
.automation-editor-shell .edge-add,
.automation-editor-shell .mini-edge-add,
.automation-editor-shell .loop-preview-add,
.automation-editor-shell .designer-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(47, 125, 67, 0.25);
    background: var(--automation-green);
    color: #ffffff;
    box-shadow: 0 10px 22px rgba(47, 125, 67, 0.28), 0 2px 6px rgba(18, 32, 27, 0.14);
    font-weight: 800;
}

.automation-editor-shell .add-ghost:hover,
.automation-editor-shell .edge-add:hover,
.automation-editor-shell .mini-edge-add:hover,
.automation-editor-shell .loop-preview-add:hover,
.automation-editor-shell .designer-add-btn:hover {
    background: #276c38;
}

.automation-editor-shell .designer-add-btn {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 35;
    width: 48px;
    height: 48px;
    border-radius: 999px;
    font-size: 26px;
    line-height: 1;
}

.automation-editor-shell .designer-palette {
    position: sticky;
    top: 84px;
    align-self: start;
    min-width: 0;
}

.automation-editor-shell .palette-root {
    max-height: calc(100vh - 124px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 12px;
    border: 1px solid var(--automation-border);
    border-radius: 8px;
    background: var(--automation-surface);
    box-shadow: var(--automation-shadow-soft);
}

.automation-editor-shell .palette-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: stretch;
    margin: 0 0 10px;
    padding: 0 0 10px;
    border-bottom: 1px solid rgba(18, 32, 27, 0.08);
    background: transparent;
    position: static;
}

.automation-editor-shell .palette-title {
    font-size: 0.92rem;
    font-weight: 800;
    color: var(--automation-text);
}

.automation-editor-shell .palette-search {
    width: 100%;
    min-height: 36px;
    border: 1px solid var(--automation-border);
    border-radius: 7px;
    padding: 7px 10px;
    background: #f8faf9;
    color: var(--automation-text);
    outline: none;
}

.automation-editor-shell .palette-search:focus {
    border-color: rgba(47, 125, 67, 0.45);
    box-shadow: 0 0 0 3px rgba(47, 125, 67, 0.12);
    background: #ffffff;
}

.automation-editor-shell .palette-groups {
    overflow: auto;
    padding-right: 4px;
}

.automation-editor-shell .palette-group {
    margin-bottom: 14px;
}

.automation-editor-shell .palette-group-title {
    margin: 8px 2px 7px;
    color: #526159;
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.automation-editor-shell .palette-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.automation-editor-shell .palette-card {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
    min-height: 54px;
    padding: 9px 10px;
    border: 1px solid var(--automation-border);
    border-left: 4px solid transparent;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(18, 32, 27, 0.05);
    cursor: grab;
    transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease, background-color 140ms ease;
}

.automation-editor-shell .palette-card .node-header {
    width: 100%;
    align-items: flex-start;
}

.automation-editor-shell .palette-card .node-header-left {
    align-items: flex-start;
}

.automation-editor-shell .palette-card .node-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.automation-editor-shell .palette-card .node-sub {
    padding: 0 0 0 42px;
}

.automation-editor-shell .palette-card:hover,
.automation-editor-shell .palette-card:focus-visible {
    border-color: rgba(47, 125, 67, 0.28);
    border-left-color: var(--automation-green);
    background: #fbfffc;
    box-shadow: 0 8px 18px rgba(18, 32, 27, 0.1);
    transform: translateY(-1px);
}

.automation-editor-shell .palette-card.dragging {
    cursor: grabbing;
    opacity: 0.72;
}

.automation-editor-shell .palette-card i,
.automation-editor-shell .palette-card .material-icons,
.automation-editor-shell .palette-card .iconify {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: var(--automation-green-soft);
    color: var(--automation-green);
    font-size: 18px;
}

.automation-editor-shell .palette-card-text {
    min-width: 0;
    color: var(--automation-text);
    font-size: 0.86rem;
    font-weight: 800;
    line-height: 1.25;
}

.automation-editor-shell .palette-card-sub {
    margin-top: 2px;
    color: var(--automation-muted);
    font-size: 0.75rem;
    line-height: 1.25;
}

.automation-editor-shell .loop-mini {
    margin: 8px 10px 10px;
    border: 1px dashed rgba(44, 111, 187, 0.34);
    border-radius: 8px;
    background: #f8fbff;
}

.automation-editor-shell .loop-preview {
    margin: 0 10px 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(18, 32, 27, 0.08);
}

.automation-editor-shell .loop-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.automation-editor-shell .loop-preview-title {
    color: #4b5a52;
    font-size: 0.76rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.automation-editor-shell .loop-canvas-btn {
    flex: 0 0 auto;
}

.automation-editor-shell .mini-node {
    border: 1px solid rgba(44, 111, 187, 0.2);
    border-left: 4px solid var(--automation-blue);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 6px 14px rgba(18, 32, 27, 0.08);
    padding: 0;
}

.automation-editor-shell .mini-node-header {
    padding: 7px 8px;
    background: #f7fbff;
    border-bottom: 1px solid rgba(18, 32, 27, 0.08);
}

.automation-editor-shell .mini-node-title,
.automation-editor-shell .mini-node-sub {
    padding-left: 8px;
    padding-right: 8px;
}

.automation-editor-shell .edge-context-menu {
    border: 1px solid var(--automation-border);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--automation-shadow);
    padding: 6px;
}

.automation-editor-shell .edge-menu-item {
    width: 144px;
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--automation-text);
}

.automation-editor-shell .edge-menu-item:hover {
    background: #f1f5f3;
}

.automation-editor-shell .edge-menu-item.delete {
    color: var(--automation-red);
}

.automation-editor-shell .no-automationflows {
    display: flex;
    min-height: 240px;
    align-items: center;
    justify-content: center;
    margin: 0;
    border: 1px dashed var(--automation-border-strong);
    border-radius: 8px;
    background: #fbfcfb;
    color: var(--automation-muted);
    font-size: 1rem;
    font-weight: 700;
}

html[data-theme='dark'] .automation-editor-shell,
body.rz-theme-dark .automation-editor-shell {
    --automation-bg: #151a17;
    --automation-surface: #1f2622;
    --automation-surface-raised: #242c27;
    --automation-border: rgba(229, 236, 231, 0.13);
    --automation-border-strong: rgba(229, 236, 231, 0.22);
    --automation-text: #eef4ef;
    --automation-muted: #a5b2aa;
    --automation-green-soft: rgba(65, 152, 87, 0.16);
    --automation-blue-soft: rgba(70, 135, 210, 0.16);
    --automation-amber-soft: rgba(190, 125, 25, 0.16);
    --automation-red-soft: rgba(194, 65, 59, 0.16);
    --automation-shadow: 0 18px 40px rgba(0, 0, 0, 0.38), 0 2px 8px rgba(0, 0, 0, 0.28);
    --automation-shadow-soft: 0 10px 22px rgba(0, 0, 0, 0.28), 0 1px 3px rgba(0, 0, 0, 0.24);
}

html[data-theme='dark'] .automation-editor-shell .automation-editor-topbar,
body.rz-theme-dark .automation-editor-shell .automation-editor-topbar,
html[data-theme='dark'] .automation-editor-shell .designer-toolbar,
body.rz-theme-dark .automation-editor-shell .designer-toolbar,
html[data-theme='dark'] .automation-editor-shell .palette-root,
body.rz-theme-dark .automation-editor-shell .palette-root,
html[data-theme='dark'] .automation-editor-shell .node,
body.rz-theme-dark .automation-editor-shell .node,
html[data-theme='dark'] .automation-editor-shell .edge-context-menu,
body.rz-theme-dark .automation-editor-shell .edge-context-menu {
    background: var(--automation-surface);
}

html[data-theme='dark'] .automation-editor-shell .automation-mode-switches,
body.rz-theme-dark .automation-editor-shell .automation-mode-switches,
html[data-theme='dark'] .automation-editor-shell .automation-outline,
body.rz-theme-dark .automation-editor-shell .automation-outline,
html[data-theme='dark'] .automation-editor-shell .designer-canvas,
body.rz-theme-dark .automation-editor-shell .designer-canvas {
    background: var(--automation-bg);
}

html[data-theme='dark'] .automation-editor-shell .flowchart-canvas,
body.rz-theme-dark .automation-editor-shell .flowchart-canvas {
    background-color: #171d1a;
    background-image:
        linear-gradient(rgba(229, 236, 231, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(229, 236, 231, 0.06) 1px, transparent 1px),
        linear-gradient(rgba(229, 236, 231, 0.025) 1px, transparent 1px),
        linear-gradient(90deg, rgba(229, 236, 231, 0.025) 1px, transparent 1px);
}

html[data-theme='dark'] .automation-editor-shell .node-header,
body.rz-theme-dark .automation-editor-shell .node-header,
html[data-theme='dark'] .automation-editor-shell .node-footer-actions,
body.rz-theme-dark .automation-editor-shell .node-footer-actions,
html[data-theme='dark'] .automation-editor-shell .palette-search,
body.rz-theme-dark .automation-editor-shell .palette-search,
html[data-theme='dark'] .automation-editor-shell .palette-card,
body.rz-theme-dark .automation-editor-shell .palette-card,
html[data-theme='dark'] .automation-editor-shell .mini-node-header,
body.rz-theme-dark .automation-editor-shell .mini-node-header {
    background: var(--automation-surface-raised);
}

html[data-theme='dark'] .automation-editor-shell .node-btn,
body.rz-theme-dark .automation-editor-shell .node-btn,
html[data-theme='dark'] .automation-editor-shell .mini-btn,
body.rz-theme-dark .automation-editor-shell .mini-btn,
html[data-theme='dark'] .automation-editor-shell .connector-handle.left,
body.rz-theme-dark .automation-editor-shell .connector-handle.left,
html[data-theme='dark'] .automation-editor-shell .connector-handle.right,
body.rz-theme-dark .automation-editor-shell .connector-handle.right {
    background: #222a25;
    color: var(--automation-text);
}

@media (max-width: 1100px) {
    .automation-editor-shell .automation-editor-topbar {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .automation-editor-shell .automation-mode-switches,
    .automation-editor-shell .automation-topbar-actions {
        justify-content: flex-start;
    }

    .automation-editor-shell .designer-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(520px, auto) auto;
    }

    .automation-editor-shell .designer-palette {
        position: static;
    }

    .automation-editor-shell .palette-root {
        max-height: none;
    }
}

@media (max-width: 720px) {
    .automation-editor-shell .automation-editor-topbar,
    .automation-editor-shell .automation-outline,
    .automation-editor-shell .designer-toolbar {
        border-radius: 6px;
    }

    .automation-editor-shell .designer-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .automation-editor-shell .designer-toolbar-actions {
        justify-content: flex-start;
    }

    .automation-editor-shell .designer-canvas {
        min-height: 560px;
    }

    .automation-editor-shell .flowchart-canvas {
        min-height: 620px;
    }

    .automation-editor-shell .designer-add-btn {
        right: 14px;
        bottom: 14px;
    }
}

.foreach-flow-editor {
    min-width: min(560px, 82vw);
}

.foreach-source-panel {
    padding: 14px;
    border: 1px solid rgba(18, 32, 27, 0.12);
    border-radius: 8px;
    background: #fbfcfb;
}

.foreach-source-heading {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.foreach-source-heading .material-icons {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: #eaf2fb;
    color: #2c6fbb;
    font-size: 19px;
}

.foreach-source-title {
    font-weight: 800;
    line-height: 1.2;
    color: #202924;
}

.foreach-source-subtitle {
    margin-top: 2px;
    color: #65736b;
    font-size: 0.82rem;
    line-height: 1.25;
}

.foreach-advanced-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

html[data-theme='dark'] .foreach-source-panel,
body.rz-theme-dark .foreach-source-panel {
    border-color: rgba(229, 236, 231, 0.13);
    background: #1f2622;
}

html[data-theme='dark'] .foreach-source-title,
body.rz-theme-dark .foreach-source-title {
    color: #eef4ef;
}

html[data-theme='dark'] .foreach-source-subtitle,
body.rz-theme-dark .foreach-source-subtitle {
    color: #a5b2aa;
}

@media (max-width: 620px) {
    .foreach-flow-editor {
        min-width: 0;
    }

    .foreach-advanced-grid {
        grid-template-columns: 1fr;
    }
}
