/* ========================================
   NINJAPIPELINE — Clean Step Editor UI
   ======================================== */

/* ─── Section override ─────────────────── */

#section-ninjapipeline {
    padding: 0 !important;
    max-width: 100% !important;
    margin: 0 !important;
}

#ninjapipelineContainer {
    background: var(--bg-body, #f0f4f8);
}

/* ─── Tab bar ──────────────────────────── */

.np-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-card, #fff);
    border-bottom: 1px solid var(--border-light, #e2e8f0);
    flex-wrap: wrap;
}

.np-header h2 {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    margin: 0;
    margin-right: 12px;
}

.np-tabs {
    display: flex;
    gap: 4px;
}

.np-tab {
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--text-secondary, #64748b);
    transition: all 0.15s;
}

.np-tab:hover {
    background: #f1f5f9;
    color: var(--text-primary, #1e293b);
}

.np-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

.np-header-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
}

/* ─── Content area ─────────────────────── */

.np-content {
    padding: 12px 16px;
    max-width: 100%;
}

/* ─── Cards / Table ────────────────────── */

.np-card {
    background: var(--bg-card, #fff);
    border-radius: 12px;
    border: 1px solid var(--border-light, #e2e8f0);
    overflow: hidden;
}

.np-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light, #e2e8f0);
}

.np-card-header h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary, #1e293b);
}

.np-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.np-table th {
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #94a3b8);
    background: #f8fafc;
    border-bottom: 1px solid var(--border-light, #e2e8f0);
}

.np-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-primary, #1e293b);
    vertical-align: middle;
}

.np-table tr:hover td {
    background: #f8fafc;
}

.np-table tr:last-child td {
    border-bottom: none;
}

/* ─── Badges ───────────────────────────── */

.np-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
}

.np-badge-draft {
    background: #f1f5f9;
    color: #64748b;
}
.np-badge-active {
    background: #dcfce7;
    color: #16a34a;
}
.np-badge-paused {
    background: #fef3c7;
    color: #d97706;
}
.np-badge-archived {
    background: #fee2e2;
    color: #dc2626;
}

.np-badge-pending {
    background: #dbeafe;
    color: #2563eb;
}
.np-badge-running {
    background: #fef3c7;
    color: #d97706;
}
.np-badge-waiting {
    background: #f1f5f9;
    color: #64748b;
}
.np-badge-completed {
    background: #dcfce7;
    color: #16a34a;
}
.np-badge-failed {
    background: #fee2e2;
    color: #dc2626;
}

/* ─── Buttons ──────────────────────────── */

.np-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: 1px solid var(--border-light, #e2e8f0);
    background: var(--bg-card, #fff);
    color: var(--text-primary, #1e293b);
    transition: all 0.15s;
    white-space: nowrap;
}

.np-btn:hover {
    border-color: #cbd5e1;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.np-btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: transparent;
}

.np-btn-primary:hover {
    opacity: 0.9;
}

.np-btn-danger {
    color: #dc2626;
    border-color: #fecaca;
}

.np-btn-danger:hover {
    background: #fef2f2;
}

.np-btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 6px;
}

.np-btn-icon {
    padding: 6px;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ─── Stats row ────────────────────────── */

.np-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.np-stat {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 10px;
    padding: 14px 16px;
    text-align: center;
}

.np-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
}

.np-stat-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #94a3b8);
    margin-top: 2px;
}

/* ─── Editor: Back bar ─────────────────── */

.np-editor-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: var(--bg-card, #fff);
    border-bottom: 1px solid var(--border-light, #e2e8f0);
}

.np-editor-bar input {
    font-size: 16px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: var(--text-primary, #1e293b);
    flex: 1;
    min-width: 200px;
    padding: 4px 0;
}

.np-editor-bar input:focus {
    outline: none;
    border-bottom: 2px solid #667eea;
}

/* ─── Editor: Step list ────────────────── */

.np-steps {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 4px 0;
}

.np-step-wrapper {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.np-step-connector {
    width: 2px;
    height: 20px;
    background: #cbd5e1;
}

.np-step {
    width: 100%;
    background: var(--bg-card, #fff);
    border: 2px solid var(--border-light, #e2e8f0);
    border-radius: 12px;
    transition: all 0.15s;
    overflow: hidden;
}

.np-step:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.12);
}

.np-step-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
}

.np-step-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

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

.np-step-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}

.np-step-summary {
    font-size: 12px;
    color: var(--text-muted, #94a3b8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.np-step-num {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #94a3b8);
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.np-step-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.np-step-actions button {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary, #64748b);
    transition: all 0.1s;
}

.np-step-actions button:hover {
    background: #f1f5f9;
    color: var(--text-primary, #1e293b);
}

/* ─── Step config panel ────────────────── */

.np-step-config {
    border-top: 1px solid #f1f5f9;
    padding: 16px;
    background: #f8fafc;
}

.np-field {
    margin-bottom: 12px;
}

.np-field:last-child {
    margin-bottom: 0;
}

.np-field label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
    margin-bottom: 4px;
}

.np-field input[type='text'],
.np-field input[type='number'],
.np-field textarea,
.np-field select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 6px;
    font-size: 13px;
    color: var(--text-primary, #1e293b);
    background: #fff;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.15s;
}

.np-field input[type='text'],
.np-field input[type='number'],
.np-field textarea {
    cursor: text;
}

.np-field input:focus,
.np-field textarea:focus,
.np-field select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.15);
}

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

.np-field-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.np-field-toggle input[type='checkbox'] {
    width: 16px;
    height: 16px;
    accent-color: #667eea;
}

.np-field-info {
    font-size: 12px;
    color: var(--text-muted, #94a3b8);
    font-style: italic;
    padding: 8px;
    background: #f1f5f9;
    border-radius: 6px;
}

.np-field-hint {
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    margin-top: 2px;
}

/* Routing section inside step config */
.np-routing {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed #e2e8f0;
}

.np-routing-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 4px;
}

/* ─── Add step button ──────────────────── */

.np-add-step {
    width: 100%;
    padding: 12px;
    border: 2px dashed #cbd5e1;
    border-radius: 12px;
    background: transparent;
    color: var(--text-secondary, #64748b);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    margin-top: 4px;
}

.np-add-step:hover {
    border-color: #667eea;
    color: #667eea;
    background: rgba(102, 126, 234, 0.04);
}

/* ─── Block picker modal ───────────────── */

.np-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: npFadeIn 0.15s;
}

@keyframes npFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.np-modal {
    background: var(--bg-card, #fff);
    border-radius: 16px;
    width: 90%;
    max-width: 520px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.np-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light, #e2e8f0);
}

.np-modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.np-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: #f1f5f9;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.np-modal-body {
    padding: 16px 20px;
}

.np-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-light, #e2e8f0);
}

.np-block-cat {
    margin-bottom: 16px;
}

.np-block-cat:last-child {
    margin-bottom: 0;
}

.np-block-cat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted, #94a3b8);
    margin-bottom: 8px;
}

.np-block-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.np-block-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    background: #fff;
}

.np-block-option:hover {
    border-color: #667eea;
    background: rgba(102, 126, 234, 0.04);
}

.np-block-option-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    color: #fff;
    flex-shrink: 0;
}

.np-block-option-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary, #1e293b);
}

.np-block-option-desc {
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
}

/* ─── Empty state ──────────────────────── */

.np-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted, #94a3b8);
}

.np-empty-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.np-empty h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-secondary, #64748b);
    margin: 0 0 8px;
}

.np-empty p {
    font-size: 13px;
    max-width: 400px;
    margin: 0 auto 20px;
}

/* ─── Execution log ────────────────────── */

.np-log {
    font-size: 12px;
    padding: 12px 16px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
}

.np-log-entry {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    border-bottom: 1px solid #f1f5f9;
}

.np-log-entry:last-child {
    border-bottom: none;
}

.np-log-time {
    font-size: 11px;
    color: var(--text-muted, #94a3b8);
    flex-shrink: 0;
    width: 130px;
}

.np-log-block {
    font-weight: 600;
    width: 100px;
    flex-shrink: 0;
}

.np-log-status {
    flex-shrink: 0;
}
.np-log-detail {
    color: var(--text-secondary, #64748b);
}

/* ─── Trigger rule cards ───────────────── */

.np-trigger-card {
    background: var(--bg-card, #fff);
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 10px;
    margin-bottom: 12px;
    overflow: hidden;
}

.np-trigger-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    cursor: pointer;
    transition: background 0.15s;
    min-height: 56px;
}

.np-trigger-head:hover {
    background: #f8fafc;
}

.np-trigger-info {
    flex: 1;
}

.np-trigger-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #1e293b);
}

.np-trigger-detail {
    font-size: 12px;
    color: var(--text-secondary, #64748b);
    margin-top: 4px;
}

.np-trigger-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}

/* ─── Trigger inline editor ───────────── */

.np-trigger-edit {
    padding: 0 16px 16px;
    border-top: 1px solid var(--border-light, #e2e8f0);
    background: #f8fafc;
}

.np-trigger-edit-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-top: 12px;
    align-items: start;
}

.np-trigger-edit-row .np-field {
    min-width: 0;
}

.np-trigger-edit-row label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary, #64748b);
    margin-bottom: 4px;
}

.np-trigger-edit-row input,
.np-trigger-edit-row select {
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 6px;
    font-size: 13px;
    box-sizing: border-box;
    width: 100%;
    background: #fff;
}

.np-trigger-bottom-row {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.np-trigger-bottom-row .np-field label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary, #64748b);
    margin-bottom: 4px;
}

.np-trigger-bottom-row input[type='number'] {
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 6px;
    font-size: 13px;
    box-sizing: border-box;
    width: 100%;
}

.np-trigger-conditions {
    margin-top: 12px;
}

.np-trigger-conditions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.np-trigger-cond-row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
    align-items: center;
}

.np-trigger-cond-row select,
.np-trigger-cond-row input {
    padding: 7px 10px;
    border: 1px solid var(--border-light, #e2e8f0);
    border-radius: 6px;
    font-size: 12px;
    background: #fff;
}

.np-trigger-cond-row select:focus,
.np-trigger-cond-row input:focus {
    border-color: #667eea;
    outline: none;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.15);
}

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

@media (max-width: 768px) {
    .np-header {
        padding: 8px 12px;
    }
    .np-content {
        padding: 8px;
    }
    .np-block-grid {
        grid-template-columns: 1fr;
    }
    .np-stats {
        grid-template-columns: repeat(2, 1fr);
    }
    .np-step-wrapper {
        max-width: 100%;
    }
    .np-step {
        max-width: 100%;
    }
    .np-routing-row {
        grid-template-columns: 1fr;
    }
}
