/**
 * Node Palette Styles
 * Sidebar for click-to-add step types onto the workflow canvas
 */

/* ============================================================================
   PALETTE SIDEBAR
   ============================================================================ */

.node-palette {
    position: absolute;
    left: 16px;
    top: 60px;
    width: 260px;
    max-height: calc(100% - 80px);
    background: #1F2937;
    border: 1px solid #374151;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.node-palette.hidden {
    transform: translateX(-280px);
    opacity: 0;
    pointer-events: none;
}

.palette-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #111827;
    border-bottom: 1px solid #374151;
}

.palette-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: #F3F4F6;
}

.palette-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: #9CA3AF;
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.palette-close:hover {
    background: #374151;
    color: #F3F4F6;
}

.palette-hint {
    margin: 0;
    padding: 6px 16px 0;
    font-size: 11px;
    color: #9CA3AF;
}

.palette-search {
    padding: 12px;
    border-bottom: 1px solid #374151;
}

.palette-search input {
    width: 100%;
    padding: 8px 12px;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 6px;
    color: #F3F4F6;
    font-size: 13px;
}

.palette-search input:focus {
    outline: none;
    border-color: #6366F1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.palette-search input::placeholder {
    color: #6B7280;
}

.palette-sections {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.palette-section {
    margin-bottom: 16px;
}

.palette-section h4 {
    margin: 0 0 8px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.palette-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ============================================================================
   PALETTE ITEMS (CLICK-TO-ADD)
   ============================================================================ */

.palette-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid var(--item-color, #6366F1);
    user-select: none;
}

.palette-item:hover {
    background: #1F2937;
    border-color: var(--item-color, #6366F1);
    transform: translateX(4px);
}

.palette-item:active {
    transform: translateX(2px) scale(0.98);
    opacity: 0.8;
}

.palette-item-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.palette-item-info {
    flex: 1;
    min-width: 0;
}

.palette-item-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #F3F4F6;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.palette-item-desc {
    display: block;
    font-size: 11px;
    color: #9CA3AF;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* App items (smaller, icon + name only) */
.palette-app-item {
    padding: 8px 12px;
}

.palette-app-item .palette-item-icon {
    font-size: 16px;
    width: 24px;
}

.palette-app-item .palette-item-name {
    font-size: 12px;
}

/* Branded logo images in app items */
.palette-app-logo {
    display: inline-block;
    vertical-align: middle;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    padding: 2px;
    box-sizing: content-box;
}

/* No-results message in search */
.palette-no-results {
    padding: 12px 8px;
    color: #9CA3AF;
    font-size: 12px;
    text-align: center;
}

/* ============================================================================
   DROP ZONE INDICATOR
   ============================================================================ */

#workflow-container.drag-over {
    outline: 2px dashed #6366F1 !important;
    outline-offset: -4px;
    background: rgba(99, 102, 241, 0.05);
}

#workflow-container.drag-over::after {
    content: 'Drop here to add node';
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    background: #6366F1;
    color: white;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    z-index: 1000;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* ============================================================================
   ADD STEP MODAL
   All selectors scoped under .add-step-modal to prevent style collisions
   ============================================================================ */

.add-step-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.add-step-modal.hidden {
    display: none;
}

.add-step-modal .modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.add-step-modal .modal-content {
    position: relative;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    background: #1F2937;
    border: 1px solid #374151;
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.add-step-modal .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    background: #111827;
    border-bottom: 1px solid #374151;
}

.add-step-modal .modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #F3F4F6;
}

.add-step-modal .modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: #9CA3AF;
    font-size: 24px;
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.add-step-modal .modal-close:hover {
    background: #374151;
    color: #F3F4F6;
}

.add-step-modal .modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

/* ============================================================================
   STEP TYPE CARDS (Selection Grid) - scoped under .add-step-modal
   ============================================================================ */

.add-step-modal .step-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}

.add-step-modal .step-type-card {
    padding: 20px;
    background: #111827;
    border: 2px solid #374151;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    font-family: inherit;
    color: inherit;
    width: 100%;
}

.add-step-modal .step-type-card:hover,
.add-step-modal .step-type-card:focus {
    border-color: var(--card-color, #6366F1);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
    outline: none;
}

.add-step-modal .step-type-card:focus-visible {
    outline: 2px solid #6366F1;
    outline-offset: 2px;
}

.add-step-modal .step-type-card .card-icon {
    font-size: 36px;
    display: block;
    margin-bottom: 12px;
}

.add-step-modal .step-type-card h3 {
    margin: 0 0 8px 0;
    font-size: 16px;
    font-weight: 600;
    color: #F3F4F6;
}

.add-step-modal .step-type-card p {
    margin: 0;
    font-size: 12px;
    color: #9CA3AF;
    line-height: 1.4;
}

/* ============================================================================
   STEP CONFIG FORM - scoped under .add-step-modal
   ============================================================================ */

.add-step-modal .step-config-form {
    animation: add-step-modal-slide-in 0.2s ease;
}

@keyframes add-step-modal-slide-in {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.add-step-modal .back-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid #374151;
    border-radius: 6px;
    color: #9CA3AF;
    font-size: 13px;
    cursor: pointer;
    margin-bottom: 20px;
    transition: all 0.15s ease;
}

.add-step-modal .form-instruction {
    margin: 0 0 16px 0;
    font-size: 13px;
    color: #9CA3AF;
}

.add-step-modal .back-btn:hover {
    background: #374151;
    color: #F3F4F6;
}

.add-step-modal .form-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid #374151;
}

.add-step-modal .form-header .form-icon {
    font-size: 32px;
}

.add-step-modal .form-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #F3F4F6;
}

.add-step-modal .form-fields {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.add-step-modal .form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.add-step-modal .form-field label {
    font-size: 13px;
    font-weight: 500;
    color: #D1D5DB;
}

.add-step-modal .form-field input[type="text"],
.add-step-modal .form-field input[type="number"],
.add-step-modal .form-field textarea,
.add-step-modal .form-field select {
    padding: 10px 14px;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 8px;
    color: #F3F4F6;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.15s ease;
}

.add-step-modal .form-field input:focus,
.add-step-modal .form-field textarea:focus,
.add-step-modal .form-field select:focus {
    outline: none;
    border-color: #6366F1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.add-step-modal .form-field input::placeholder,
.add-step-modal .form-field textarea::placeholder {
    color: #6B7280;
}

.add-step-modal .form-field textarea {
    resize: vertical;
    min-height: 80px;
}

.add-step-modal .form-field textarea.code-input {
    font-family: 'SF Mono', Consolas, Monaco, monospace;
    font-size: 13px;
    line-height: 1.5;
    min-height: 120px;
    background: #0D1117;
}

.add-step-modal .form-field select {
    cursor: pointer;
}

.add-step-modal .form-field select[multiple] {
    min-height: 100px;
}

.add-step-modal .field-hint {
    font-size: 11px;
    color: #6B7280;
}

.add-step-modal .form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid #374151;
}

.add-step-modal .btn-secondary,
.add-step-modal .btn-primary {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.add-step-modal .btn-secondary {
    background: #374151;
    color: #D1D5DB;
}

.add-step-modal .btn-secondary:hover {
    background: #4B5563;
}

.add-step-modal .btn-primary {
    background: #6366F1;
    color: white;
}

.add-step-modal .btn-primary:hover {
    background: #4F46E5;
}

/* ============================================================================
   TOOLBAR BUTTONS
   ============================================================================ */

#toggle-palette-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#toggle-palette-btn.active {
    background: #6366F1 !important;
    color: white !important;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: #4B5563;
    margin: 0 4px;
}

/* ============================================================================
   EDGE/CONNECTION CONTEXT MENU
   ============================================================================ */

.workflow-context-menu .menu-item {
    padding: 10px 16px;
    cursor: pointer;
    color: #D1D5DB;
    font-size: 13px;
    transition: background 0.15s ease;
}

.workflow-context-menu .menu-item:hover {
    background: #374151;
}

.workflow-context-menu .menu-item.danger {
    color: #F87171;
}

.workflow-context-menu .menu-item.danger:hover {
    background: #7F1D1D;
}

/* ============================================================================
   PORT HIGHLIGHTING (Connection Mode)
   ============================================================================ */

/* Make ports more visible during connection */
.x6-port-body {
    transition: all 0.15s ease;
}

.x6-graph-connecting .x6-port-body {
    r: 8px !important;
}

/* Highlight available connection targets */
.x6-graph-connecting .x6-node .x6-port-body[magnet="true"] {
    stroke: #6366F1 !important;
    stroke-width: 3px !important;
    fill: #4F46E5 !important;
}

/* Port hover effect */
.x6-port-body:hover {
    cursor: crosshair;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */

@media (max-width: 768px) {
    .node-palette {
        width: 100%;
        left: 0;
        top: auto;
        bottom: 0;
        max-height: 50vh;
        border-radius: 16px 16px 0 0;
    }

    .node-palette.hidden {
        transform: translateY(100%);
    }

    .add-step-modal .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 20px;
    }

    .add-step-modal .step-type-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .add-step-modal .step-type-card {
        padding: 16px;
    }

    .add-step-modal .step-type-card .card-icon {
        font-size: 28px;
    }

    .add-step-modal .step-type-card h3 {
        font-size: 14px;
    }

    .add-step-modal .step-type-card p {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .add-step-modal .step-type-grid {
        grid-template-columns: 1fr;
    }
}
