/* ========================================
   PIPELINE FLOW BUILDER — Layout, Nodes, Canvas
   ======================================== */

/* ---- Full-bleed section override ---- */
#section-ninjapipeline.app-section {
    max-width: 100%;
    padding: 0;
    margin: 0;
}

#section-ninjapipeline.app-section.active {
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* ---- Dashboard grid (2-column) ---- */
.np-dashboard {
    display: grid;
    grid-template-columns: 260px 1fr;
    grid-template-rows: auto 1fr;
    flex: 1;
    min-height: 0;
    gap: 0;
    background: var(--bg-body, #f0f4f8);
    overflow: hidden;
}

/* ---- Toolbar (spans full width) ---- */
.np-toolbar {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-card, #fff);
    border-bottom: 1px solid var(--border-light, #e2e8f0);
    gap: 16px;
    flex-wrap: wrap;
}

.np-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.np-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.np-flow-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 6px 10px;
    background: transparent;
    max-width: 280px;
    transition:
        border-color 0.15s,
        background 0.15s;
}

.np-flow-name:focus {
    outline: none;
    border-color: var(--primary, #2563eb);
    background: var(--bg-card, #fff);
}

.np-flow-name:disabled {
    opacity: 0.5;
    cursor: default;
}

.np-save-status {
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

/* ---- Buttons ---- */
.np-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.np-btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.np-btn-primary {
    background: var(--primary, #2563eb);
    color: #fff;
}

.np-btn-primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.np-btn-secondary {
    background: var(--bg-body, #f0f4f8);
    color: var(--text-primary, #1e293b);
    border: 1px solid var(--border-light, #e2e8f0);
}

.np-btn-secondary:hover:not(:disabled) {
    background: #e2e8f0;
}

.np-btn-save {
    background: var(--success, #22c55e);
    color: #fff;
}

.np-btn-save:hover:not(:disabled) {
    background: #16a34a;
}

.np-btn-danger {
    background: var(--danger, #ef4444);
    color: #fff;
}

.np-btn-danger:hover:not(:disabled) {
    background: #dc2626;
}

.np-btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

/* ---- Palette (left sidebar) ---- */
.np-palette {
    overflow-y: auto;
    border-right: 1px solid var(--border-light, #e2e8f0);
    background: var(--bg-card, #fff);
    padding: 0;
}

.np-palette-group {
    border-bottom: 1px solid var(--border-light, #e2e8f0);
}

.np-palette-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #64748b);
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.np-palette-group-header:hover {
    background: var(--bg-body, #f0f4f8);
}

.np-palette-group-header .np-chevron {
    transition: transform 0.2s;
    font-size: 10px;
}

.np-palette-group.collapsed .np-chevron {
    transform: rotate(-90deg);
}

.np-palette-group.collapsed .np-palette-group-body {
    display: none;
}

.np-palette-group-body {
    padding: 4px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* ---- Palette items (draggable) ---- */
.np-palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    background: var(--bg-body, #f0f4f8);
    cursor: grab;
    transition: all 0.15s;
    border: 1px solid transparent;
}

.np-palette-item:hover {
    border-color: var(--border-light, #e2e8f0);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

.np-palette-item-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 28px;
    text-align: center;
}

.np-palette-item-info {
    min-width: 0;
    flex: 1;
}

.np-palette-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.np-palette-item-status {
    font-size: 10px;
    font-weight: 500;
    padding: 1px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.np-palette-item-status.live {
    background: #dcfce7;
    color: #15803d;
}

.np-palette-item-status.in_progress {
    background: #fef3c7;
    color: #b45309;
}

.np-palette-item-status.planned {
    background: #f1f5f9;
    color: #64748b;
}

/* ---- Canvas wrapper ---- */
.np-canvas {
    position: relative;
    overflow: hidden;
    background: #f8fafc;
}

.np-canvas-area {
    width: 100%;
    height: 100%;
}

/* ---- Drawflow overrides ---- */
.np-canvas-area .drawflow {
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
    background-size: 20px 20px;
}

.np-canvas-area .drawflow .drawflow-node {
    border: none;
    background: transparent;
    padding: 0;
    min-width: 220px;
    border-radius: 10px;
}

.np-canvas-area .drawflow .drawflow-node.selected {
    box-shadow: 0 0 0 2px var(--primary, #2563eb);
    border-radius: 10px;
}

.np-canvas-area .drawflow .drawflow-node .inputs,
.np-canvas-area .drawflow .drawflow-node .outputs {
    pointer-events: auto;
}

.np-canvas-area .drawflow .drawflow-node .input,
.np-canvas-area .drawflow .drawflow-node .output {
    width: 14px;
    height: 14px;
    border: 2px solid #94a3b8;
    background: #fff;
    border-radius: 50%;
}

.np-canvas-area .drawflow .drawflow-node .input:hover,
.np-canvas-area .drawflow .drawflow-node .output:hover {
    border-color: var(--primary, #2563eb);
    background: #eff6ff;
}

.np-canvas-area .drawflow .connection .main-path {
    stroke: #94a3b8;
    stroke-width: 2;
}

.np-canvas-area .drawflow .connection .main-path:hover {
    stroke: var(--primary, #2563eb);
    stroke-width: 3;
}

/* ---- Custom node styles ---- */
.np-node {
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-card, #fff);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    min-width: 200px;
    max-width: 240px;
    transition: box-shadow 0.15s;
}

.np-node:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.np-node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}

.np-node-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.np-node-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.np-node-body {
    padding: 6px 12px 10px;
}

.np-node-desc {
    font-size: 11px;
    color: var(--text-secondary, #64748b);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ---- Condition branches ---- */
.np-node-branches {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

.np-node-branch {
    flex: 1;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 6px;
    border-radius: 4px;
}

.np-branch-yes {
    background: #dcfce7;
    color: #15803d;
}

.np-branch-no {
    background: #fee2e2;
    color: #dc2626;
}

/* ---- Category border accents ---- */
.np-node-source .np-node-header {
    border-left: 3px solid #2563eb;
    background: #eff6ff;
}
.np-node-action .np-node-header {
    border-left: 3px solid #16a34a;
    background: #f0fdf4;
}
.np-node-condition .np-node-header {
    border-left: 3px solid #d97706;
    background: #fffbeb;
}
.np-node-measurement .np-node-header {
    border-left: 3px solid #7c3aed;
    background: #faf5ff;
}

/* ---- Empty state ---- */
.np-empty-state {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.np-empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.np-empty-title {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    margin-bottom: 8px;
}

.np-empty-text {
    font-size: 14px;
    color: var(--text-secondary, #64748b);
    max-width: 360px;
}

/* ---- Flow list view ---- */
.np-flow-list {
    padding: 24px;
    overflow-y: auto;
    height: 100%;
}

.np-flow-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.np-flow-list-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
}

.np-flow-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}

.np-flow-card {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 10px;
    padding: 16px;
    transition:
        box-shadow 0.15s,
        border-color 0.15s;
    cursor: pointer;
}

.np-flow-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: var(--primary, #2563eb);
}

.np-flow-card-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    margin-bottom: 4px;
}

.np-flow-card-desc {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    margin-bottom: 12px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.np-flow-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
}

.np-flow-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 12px;
}

.np-status-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.np-status-badge.draft {
    background: #f1f5f9;
    color: #64748b;
}
.np-status-badge.active {
    background: #dcfce7;
    color: #15803d;
}

/* ---- New flow modal ---- */
.np-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.np-modal {
    background: var(--bg-card, #fff);
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.np-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    margin-bottom: 16px;
}

.np-modal-field {
    margin-bottom: 14px;
}

.np-modal-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
    margin-bottom: 4px;
}

.np-modal-input {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 6px;
    background: var(--bg-card, #fff);
    color: var(--text-primary, #1e293b);
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.np-modal-input:focus {
    outline: none;
    border-color: var(--primary, #2563eb);
}

.np-modal-textarea {
    resize: vertical;
    min-height: 60px;
}

.np-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .np-dashboard {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - 120px);
    }

    .np-palette {
        display: none;
    }

    .np-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .np-toolbar-right {
        justify-content: flex-end;
    }

    .np-flow-cards {
        grid-template-columns: 1fr;
    }
}
