/* ===== Workflow Editor - n8n-inspired Drawflow Theme ===== */

/* Canvas background - dot grid. Uses MudBlazor palette variables so the theme follows
   automatically — both --mud-palette-background and --mud-palette-lines-default are
   updated by MudThemeProvider when IsDarkMode toggles. */
#workflow-editor-container {
    width: 100%;
    height: 100%;
    background-color: var(--mud-palette-background, #f5f5f5);
    background-image: radial-gradient(circle, var(--mud-palette-lines-default, #d0d0d0) 1px, transparent 1px);
    background-size: 24px 24px;
}

/* Hide Drawflow default delete button on nodes */
.drawflow .drawflow-delete {
    display: none !important;
}

/* ===== Drawflow Node Base ===== */

.drawflow .drawflow-node {
    border-radius: 8px;
    border: 2px solid #dbdbdb;
    background: #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    min-width: 180px;
    max-width: 220px;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.mud-theme-dark .drawflow .drawflow-node {
    background: #262640;
    border-color: #3d3d5c;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.drawflow .drawflow-node.selected {
    background: rgba(99, 102, 241, 0.06);
    border-color: rgba(99, 102, 241, 0.5);
    box-shadow: 0 0 0 5px rgba(99, 102, 241, 0.08), 0 2px 8px rgba(0, 0, 0, 0.06);
}

.mud-theme-dark .drawflow .drawflow-node.selected {
    background: rgba(129, 140, 248, 0.1);
    border-color: rgba(129, 140, 248, 0.45);
    box-shadow: 0 0 0 5px rgba(129, 140, 248, 0.1), 0 2px 8px rgba(0, 0, 0, 0.2);
}

.drawflow .drawflow-node:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    border-color: #c0c0c0;
}

.mud-theme-dark .drawflow .drawflow-node:hover {
    border-color: #5555880;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* ===== Connection Lines ===== */

.drawflow .connection .main-path {
    stroke: #b1b1b7;
    stroke-width: 2;
    fill: none;
}

.mud-theme-dark .drawflow .connection .main-path {
    stroke: #555580;
}

.drawflow .connection .main-path:hover {
    stroke: #ff6d5a;
    stroke-width: 2.5;
}

/* ===== Input/Output Ports ===== */

.drawflow .drawflow-node .input,
.drawflow .drawflow-node .output {
    width: 12px;
    height: 12px;
    background: #b1b1b7;
    border: 2px solid #ffffff;
    border-radius: 50%;
    transition: background 0.15s ease, transform 0.15s ease;
}

.mud-theme-dark .drawflow .drawflow-node .input,
.mud-theme-dark .drawflow .drawflow-node .output {
    background: #666690;
    border-color: #262640;
}

.drawflow .drawflow-node .input:hover,
.drawflow .drawflow-node .output:hover {
    background: #ff6d5a;
    transform: scale(1.3);
}

/* ===== n8n-style Node Content ===== */

.wf-node {
    display: flex;
    align-items: center;
    gap: 0;
    min-width: 160px;
}

.wf-node-icon-box {
    width: 48px;
    height: 48px;
    min-width: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px 0 0 6px;
    font-size: 22px;
    line-height: 1;
    color: #ffffff;
    flex-shrink: 0;
}

.wf-node-content {
    display: flex;
    flex-direction: column;
    padding: 8px 12px 8px 10px;
    min-width: 0;
    flex: 1;
    gap: 1px;
}

.wf-node-type {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #909090;
    line-height: 1.2;
}

.mud-theme-dark .wf-node-type {
    color: #8888aa;
}

.wf-node-label {
    font-size: 13px;
    font-weight: 600;
    color: #333333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.mud-theme-dark .wf-node-label {
    color: #e2e2f0;
}

/* ===== Output labels for condition/loop nodes ===== */

.drawflow .drawflow-node.condition .output,
.drawflow .drawflow-node.loop .output {
    position: relative;
}

.drawflow .drawflow-node.condition .output.output_1::after,
.drawflow .drawflow-node.loop .output.output_1::after {
    content: 'true';
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
    font-weight: 700;
    color: #22c55e;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 3px;
    padding: 1px 5px;
    line-height: 14px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.3px;
}

.drawflow .drawflow-node.condition .output.output_2::after,
.drawflow .drawflow-node.loop .output.output_2::after {
    content: 'false';
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
    font-weight: 700;
    color: #ef4444;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 3px;
    padding: 1px 5px;
    line-height: 14px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.3px;
}

.mud-theme-dark .drawflow .drawflow-node.condition .output.output_1::after,
.mud-theme-dark .drawflow .drawflow-node.loop .output.output_1::after {
    color: #4ade80;
    background: #052e16;
    border-color: #166534;
}

.mud-theme-dark .drawflow .drawflow-node.condition .output.output_2::after,
.mud-theme-dark .drawflow .drawflow-node.loop .output.output_2::after {
    color: #f87171;
    background: #350a0a;
    border-color: #991b1b;
}

/* ===== Output labels for http_request nodes (success/error) ===== */

.drawflow .drawflow-node.http_request .output.output_1::after {
    content: 'success';
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
    font-weight: 700;
    color: #22c55e;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 3px;
    padding: 1px 5px;
    line-height: 14px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.3px;
}

.drawflow .drawflow-node.http_request .output.output_2::after {
    content: 'error';
    position: absolute;
    right: 18px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 9px;
    font-weight: 700;
    color: #ef4444;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 3px;
    padding: 1px 5px;
    line-height: 14px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.3px;
}

.drawflow .drawflow-node.http_request .output {
    position: relative;
}

.mud-theme-dark .drawflow .drawflow-node.http_request .output.output_1::after {
    color: #4ade80;
    background: #052e16;
    border-color: #166534;
}

.mud-theme-dark .drawflow .drawflow-node.http_request .output.output_2::after {
    color: #f87171;
    background: #350a0a;
    border-color: #991b1b;
}

/* ===== Node Palette (n8n style) ===== */

.node-palette {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
}

.node-palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #e5e5e5;
    background: #ffffff;
    cursor: grab;
    user-select: none;
    transition: all 0.15s ease;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 13px;
}

.mud-theme-dark .node-palette-item {
    border-color: #3d3d5c;
    background: #262640;
    color: #e2e2f0;
}

.node-palette-item:hover {
    background: #fafafa;
    border-color: #d0d0d0;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.mud-theme-dark .node-palette-item:hover {
    background: #2d2d4a;
    border-color: #5555880;
}

.node-palette-item:active {
    cursor: grabbing;
    transform: scale(0.97);
    opacity: 0.8;
}

.node-palette-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: #ffffff;
    font-size: 16px;
    flex-shrink: 0;
}

.node-palette-label {
    font-weight: 500;
    color: #333333;
}

.mud-theme-dark .node-palette-label {
    color: #e2e2f0;
}

/* ===== Floating Toolbar ===== */

.wf-toolbar {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 2px;
    padding: 4px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e5e5e5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 10;
}

.mud-theme-dark .wf-toolbar {
    background: #262640;
    border-color: #3d3d5c;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* ===== Execution History Panel ===== */

.orchestrator-bottom-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    font-weight: 600;
    color: #909090;
    border-bottom: 1px solid #e5e5e5;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.mud-theme-dark .orchestrator-bottom-toggle {
    color: #8888aa;
    border-color: #3d3d5c;
}

.orchestrator-bottom-toggle:hover {
    background: #fafafa;
    color: #666666;
}

.mud-theme-dark .orchestrator-bottom-toggle:hover {
    background: #2d2d4a;
    color: #aaaacc;
}

/* ===== Switch node ports (one per case + optional default) ===== */

.wf-node-switch {
    min-width: 180px;
}

.wf-switch-ports {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 4px;
    margin-right: 4px;
}

.wf-switch-port {
    font-size: 9px;
    font-weight: 600;
    color: #1f2937;
    background: #f3e5f5;
    border: 1px solid #d1c4e9;
    border-radius: 3px;
    padding: 0 5px;
    line-height: 14px;
    height: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    box-sizing: border-box;
}

.wf-switch-port-default {
    background: #e0e7ff;
    border-color: #c7d2fe;
    color: #312e81;
    font-style: italic;
}

.wf-switch-port-empty {
    font-size: 10px;
    font-style: italic;
    color: #9ca3af;
    padding: 1px 6px;
    line-height: 14px;
}

.wf-switch-port-suffix {
    font-weight: 400;
    opacity: 0.7;
}

.mud-theme-dark .wf-switch-port {
    background: #3a2750;
    border-color: #5e35b1;
    color: #e5e0f7;
}

.mud-theme-dark .wf-switch-port-default {
    background: #1e1b4b;
    border-color: #4338ca;
    color: #e0e7ff;
}

.mud-theme-dark .wf-switch-port-empty {
    color: #6b7280;
}
