/* ══════════════════════════════════════════════
   Interactive Automation Builder
   ══════════════════════════════════════════════ */

.builder-section {
    padding: 6rem 0;
}

.builder-workspace {
    display: grid;
    grid-template-columns: 200px 1fr 260px;
    gap: 1.25rem;
    margin-top: 3rem;
    min-height: 440px;
}

/* ── Palette ──────────────────────────────── */

.builder-palette {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
}

.palette-header {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.palette-blocks {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    flex: 1;
}

.palette-block {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: grab;
    font-size: 0.78rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
    user-select: none;
}

.palette-block:hover {
    border-color: var(--accent-blue);
    background: rgba(79, 142, 255, 0.06);
    transform: translateX(4px);
}

.palette-block:active {
    cursor: grabbing;
}

.palette-block.placed {
    opacity: 0.3;
    pointer-events: none;
    transform: scale(0.95);
    border-style: dashed;
}

.palette-block .block-icon {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.palette-block .block-icon svg {
    width: 15px;
    height: 15px;
}

.palette-block .block-icon.blue {
    background: rgba(79, 142, 255, 0.15);
    color: #4f8eff;
}

.palette-block .block-icon.green {
    background: rgba(40, 200, 64, 0.15);
    color: #28c840;
}

.palette-block .block-icon.violet {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

.palette-block .block-icon.amber {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.palette-hint {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: auto;
    padding-top: 1rem;
    opacity: 0.6;
}

/* ── Canvas ───────────────────────────────── */

.builder-canvas {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
}

.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.canvas-actions {
    display: flex;
    gap: 0.5rem;
}

.canvas-btn {
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.65rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.canvas-btn:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.canvas-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.canvas-pipeline {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: center;
}

/* ── Pipeline Slots ───────────────────────── */

.pipeline-slot {
    width: 88px;
    min-height: 88px;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    position: relative;
    transition: all 0.3s ease;
    flex-shrink: 0;
}

.pipeline-slot.empty {
    border: 2px dashed rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.015);
}

.pipeline-slot.empty.ready {
    border-color: rgba(79, 142, 255, 0.3);
    background: rgba(79, 142, 255, 0.04);
}

.pipeline-slot.drag-over {
    border-color: var(--accent-blue) !important;
    background: rgba(79, 142, 255, 0.1) !important;
    box-shadow: 0 0 24px rgba(79, 142, 255, 0.15);
    transform: scale(1.08);
}

.slot-placeholder {
    font-size: 1.4rem;
    color: rgba(255, 255, 255, 0.12);
    font-weight: 300;
}

/* Filled slot */
.pipeline-slot.filled {
    border: 1px solid var(--border-subtle);
    background: var(--bg-primary);
}

.pipeline-slot .slot-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem;
}

.pipeline-slot .slot-block .block-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pipeline-slot .slot-block .block-icon svg {
    width: 18px;
    height: 18px;
}

.pipeline-slot .slot-block .block-name {
    font-size: 0.6rem;
    color: var(--text-secondary);
    line-height: 1.3;
    max-width: 75px;
}

/* Pipeline connectors */
.pipeline-connector {
    width: 32px;
    height: 2px;
    position: relative;
    flex-shrink: 0;
}

.pipeline-connector .connector-line {
    width: 100%;
    height: 2px;
    background: rgba(255, 255, 255, 0.08);
}

/* Running states */
.pipeline-slot.running {
    border-color: var(--accent-blue);
    box-shadow: 0 0 25px rgba(79, 142, 255, 0.2), 0 0 50px rgba(79, 142, 255, 0.06);
}

.pipeline-slot.running .block-icon {
    animation: blockPulse 0.8s ease-in-out infinite;
}

.pipeline-slot.completed {
    border-color: #28c840;
}

.pipeline-slot.completed::after {
    content: '✓';
    position: absolute;
    top: -7px;
    right: -7px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #28c840;
    color: #000;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    animation: checkPop 0.3s var(--ease-out);
}

.pipeline-connector.active .connector-line {
    background: var(--accent-blue);
}

.pipeline-connector.active .connector-line::after {
    content: '';
    position: absolute;
    top: -3px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-blue);
    box-shadow: 0 0 12px rgba(79, 142, 255, 0.6);
    animation: connectorFlow 0.5s ease-out forwards;
}

@keyframes connectorFlow {
    from {
        left: 0;
    }

    to {
        left: calc(100% - 8px);
    }
}

@keyframes blockPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.12);
    }
}

@keyframes checkPop {
    from {
        transform: scale(0);
    }

    to {
        transform: scale(1);
    }
}

@keyframes slotFill {
    from {
        transform: scale(0.7);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Canvas footer */
.canvas-footer {
    padding: 0.8rem 1.25rem;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: center;
    gap: 0.75rem;
}

.run-btn {
    padding: 0.55rem 1.75rem;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, #4f8eff, #6366f1);
    color: white;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.run-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.run-btn:not(:disabled):hover {
    box-shadow: 0 4px 24px rgba(79, 142, 255, 0.35);
    transform: translateY(-1px);
}

.run-btn.running {
    background: linear-gradient(135deg, #28c840, #22a837);
    pointer-events: none;
}

/* ── Output Panel ─────────────────────────── */

.builder-output {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
}

.output-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.output-header .live-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #28c840;
    animation: livePulse 2s infinite;
}

@keyframes livePulse {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 0 0 rgba(40, 200, 64, 0.4);
    }

    50% {
        opacity: 0.5;
        box-shadow: 0 0 0 4px rgba(40, 200, 64, 0);
    }
}

.output-feed {
    flex: 1;
    padding: 0.75rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.output-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 1rem;
    line-height: 1.6;
}

.output-entry {
    padding: 0.6rem 0.7rem;
    background: rgba(255, 255, 255, 0.025);
    border-radius: var(--radius-sm);
    border-left: 2px solid var(--accent-blue);
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.4;
    opacity: 0;
    transform: translateY(8px);
    animation: feedSlideIn 0.35s ease forwards;
}

@keyframes feedSlideIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.output-entry .entry-title {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 2px;
}

.output-entry .entry-detail {
    color: var(--text-muted);
    font-size: 0.65rem;
}

.output-entry.success {
    border-left-color: #28c840;
    background: rgba(40, 200, 64, 0.04);
}

.output-metrics {
    padding: 0.75rem;
    border-top: 1px solid var(--border-subtle);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.output-metrics.visible {
    opacity: 1;
}

.output-metric {
    text-align: center;
    padding: 0.5rem 0.25rem;
    background: rgba(255, 255, 255, 0.025);
    border-radius: var(--radius-sm);
}

.output-metric .metric-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--accent-blue);
}

.output-metric .metric-label {
    font-size: 0.55rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-top: 2px;
}

/* ── Responsive ───────────────────────────── */

@media (max-width: 1024px) {
    .builder-workspace {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .builder-palette {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    .palette-header {
        margin-bottom: 0;
        margin-right: 0.5rem;
    }

    .palette-blocks {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .palette-hint {
        display: none;
    }

    .canvas-pipeline {
        flex-wrap: wrap;
        gap: 0.75rem;
        justify-content: center;
    }

    .pipeline-connector {
        display: none;
    }

    .output-metrics {
        grid-template-columns: repeat(3, 1fr);
    }
}